diff --git a/test/common/CMakeLists.txt b/test/common/CMakeLists.txt index 16afa18bdd8eb401cbf97e76d9a6fd3b50fe7565..8c8c1ee2e273e88e4d5050dac2158f6b83de742a 100644 --- a/test/common/CMakeLists.txt +++ b/test/common/CMakeLists.txt @@ -1,4 +1,5 @@ -add_subdirectory(propertysystem) -add_subdirectory(spline) add_subdirectory(boundingboxtree) +add_subdirectory(math) add_subdirectory(parameters) +add_subdirectory(propertysystem) +add_subdirectory(spline) diff --git a/test/common/math/CMakeLists.txt b/test/common/math/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..08a8c62e5572013f0a57c3d09b17687828a37277 --- /dev/null +++ b/test/common/math/CMakeLists.txt @@ -0,0 +1,7 @@ +# build the test for the property system +dune_add_test(SOURCES test_vtmv.cc) + +#install sources +install(FILES +test_vtmv.cc +DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dumux/test/common/math) \ No newline at end of file diff --git a/test/common/math/test_vtmv.cc b/test/common/math/test_vtmv.cc new file mode 100644 index 0000000000000000000000000000000000000000..d59d6be3071a097bdd35888e54975843d9a9a151 --- /dev/null +++ b/test/common/math/test_vtmv.cc @@ -0,0 +1,97 @@ +// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +// vi: set et ts=4 sw=4 sts=4: +/***************************************************************************** + * See the file COPYING for full copying permissions. * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + *****************************************************************************/ +/*! + * \file + * + * \brief This file tests the vtmv function with + * vtmv(Vector, FieldScalar, Vector) and vtmv(Vector, Matrix, Vector). + * + * We declare some vectors and matrices and test the combinations of them + * against a previously calculated result. + */ +#include <config.h> + +#include <iostream> + +#include <dune/common/float_cmp.hh> +#include <dune/common/fmatrix.hh> +#include <dune/common/dynmatrix.hh> +#include <dune/common/fvector.hh> +#include <dune/common/dynvector.hh> + +#include <dumux/common/math.hh> + + +int main() try +{ + //! Declare Vectors (FieldVector and DynamicVector) + Dune::FieldVector<double, 3> v1({1.0, 2.0, 3.0}); + Dune::FieldVector<double, 3> v2({1.0, 0.0, -2.0}); + + Dune::DynamicVector<double> v1_dyn(v1); + Dune::DynamicVector<double> v2_dyn(v2); + + //! Declare 3x3 Matrices with 3's on the principal diagonal + double k = 3.0; + Dune::FieldMatrix<double, 3, 3> K(0.0); + K[0][0] = k; + K[1][1] = k; + K[2][2] = k; + Dune::DynamicMatrix<double> K_dyn(K); + + //! Set reference result. Should be -15 for all combinations + const double reference = -15; + + //! Test with FieldVector v1 + //! Test vtmv function with FieldVector v1 and Scalar k and FieldVector v2 + if (!Dune::FloatCmp::eq(reference, Dumux::vtmv(v1, k, v2), 1e-6)) + DUNE_THROW(Dune::Exception, "vtmv-result does not match reference"); + //! Test vtmv function with FieldVector v1 and FieldMatrix K and FieldVector v2 + if (!Dune::FloatCmp::eq(reference, Dumux::vtmv(v1, K, v2), 1e-6)) + DUNE_THROW(Dune::Exception, "vtmv-result does not match reference"); + //! Test vtmv function with FieldVector v1 and FieldMatrix K and DynamicVector v2_dyn + if (!Dune::FloatCmp::eq(reference, Dumux::vtmv(v1, K, v2_dyn), 1e-6)) + DUNE_THROW(Dune::Exception, "vtmv-result does not match reference"); + //! Test vtmv function with FieldVector v1 and DynamicMatrix K_dyn and FieldVector v2 + if (!Dune::FloatCmp::eq(reference, Dumux::vtmv(v1, K_dyn, v2), 1e-6)) + DUNE_THROW(Dune::Exception, "vtmv-result does not match reference"); + + //! Test with DynamicVector v1_dyn + //! Test vtmv function with DynamicVector v1_dyn and Scalar k and FieldVector v2 + if (!Dune::FloatCmp::eq(reference, Dumux::vtmv(v1_dyn, k, v2), 1e-6)) + DUNE_THROW(Dune::Exception, "vtmv-result does not match reference"); + //! Test vtmv function with DynamicVector v1_dyn and FieldMatrix K and FieldVector v2 + if (!Dune::FloatCmp::eq(reference, Dumux::vtmv(v1_dyn, K, v2), 1e-6)) + DUNE_THROW(Dune::Exception, "vtmv-result does not match reference"); + //! Test vtmv function with DynamicVector v1_dyn and Scalar k and DynamicVector v2_dyn + if (!Dune::FloatCmp::eq(reference, Dumux::vtmv(v1_dyn, K, v2_dyn), 1e-6)) + DUNE_THROW(Dune::Exception, "vtmv-result does not match reference"); + //! Test vtmv function with DynamicVector v1_dyn and DynamicMatrix K_dyn and FieldVector v2 + if (!Dune::FloatCmp::eq(reference, Dumux::vtmv(v1_dyn, K_dyn, v2), 1e-6)) + DUNE_THROW(Dune::Exception, "vtmv-result does not match reference"); + + //! Test Dynamic Vectors and Dynamic Matrices + //! 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"); +} +catch (Dune::Exception& e) { + std::cerr << e << std::endl; + return 1; +}