diff --git a/test/common/math/CMakeLists.txt b/test/common/math/CMakeLists.txt index 08a8c62e5572013f0a57c3d09b17687828a37277..f5836ca31593b4e2dbd52e693fa2e3ca4e3237f7 100644 --- a/test/common/math/CMakeLists.txt +++ b/test/common/math/CMakeLists.txt @@ -1,7 +1,7 @@ # build the test for the property system -dune_add_test(SOURCES test_vtmv.cc) +dune_add_test(SOURCES test_math.cc) #install sources install(FILES -test_vtmv.cc -DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dumux/test/common/math) \ No newline at end of file +test_math.cc +DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dumux/test/common/math) diff --git a/test/common/math/test_vtmv.cc b/test/common/math/test_math.cc similarity index 71% rename from test/common/math/test_vtmv.cc rename to test/common/math/test_math.cc index d59d6be3071a097bdd35888e54975843d9a9a151..7c62d3e0c3a94dcd2545a5ad96065a5ae5db9e15 100644 --- a/test/common/math/test_vtmv.cc +++ b/test/common/math/test_math.cc @@ -19,8 +19,11 @@ /*! * \file * - * \brief This file tests the vtmv function with - * vtmv(Vector, FieldScalar, Vector) and vtmv(Vector, Matrix, Vector). + * \brief This file tests several math functions: + * the vtmv function with vtmv(Vector, FieldScalar, Vector) and vtmv(Vector, Matrix, Vector). + * the trace function + * the harmonicMean function + * \todo test more math functions! * * We declare some vectors and matrices and test the combinations of them * against a previously calculated result. @@ -55,6 +58,11 @@ int main() try K[2][2] = k; Dune::DynamicMatrix<double> K_dyn(K); + + ////////////////////////////////////////////////////////////////// + ///// Dumux::vtmv //////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////// + //! Set reference result. Should be -15 for all combinations const double reference = -15; @@ -90,6 +98,37 @@ int main() try //! Test vtmv function with DynamicVector v1_dyn and DynamicMatrix K_dyn and DynamicVector v2_dyn if (!Dune::FloatCmp::eq(reference, Dumux::vtmv(v1_dyn, K_dyn, v2_dyn), 1e-6)) DUNE_THROW(Dune::Exception, "vtmv-result does not match reference"); + + + ////////////////////////////////////////////////////////////////// + ///// Dumux::trace /////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////// + + const auto t1 = Dumux::trace(K); + const auto t2 = Dumux::trace(K_dyn); + if (!Dune::FloatCmp::eq(t1, t2, 1e-30)) + DUNE_THROW(Dune::Exception, "Traces do not match!"); + + + ////////////////////////////////////////////////////////////////// + ///// Dumux::harmonicMean //////////////////////////////////////// + ////////////////////////////////////////////////////////////////// + + constexpr auto mean = Dumux::harmonicMean(4.0, 5.0); + static_assert( (mean - 4.0*5.0*2.0/(4.0+5.0)) < 1e-30 && (mean - 4.0*5.0*2.0/(4.0+5.0)) > -1e-30 , "Wrong harmonic mean!"); + + ////////////////////////////////////////////////////////////////// + ///// Dumux::sign //////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////// + + static_assert(Dumux::sign(0.0) == 0, "Wrong sign!"); + static_assert(Dumux::sign(-0.0) == 0, "Wrong sign!"); + static_assert(Dumux::sign(0) == 0, "Wrong sign!"); + static_assert(Dumux::sign(-0) == 0, "Wrong sign!"); + static_assert(Dumux::sign(1) == 1, "Wrong sign!"); + static_assert(Dumux::sign(2.0) == 1, "Wrong sign!"); + static_assert(Dumux::sign(-2) == -1, "Wrong sign!"); + static_assert(Dumux::sign(-3.5) == -1, "Wrong sign!"); } catch (Dune::Exception& e) { std::cerr << e << std::endl;