From 344d756b2d98b90c01083fda293eed6903ae7dcc Mon Sep 17 00:00:00 2001 From: Timo Koch <timo.koch@iws.uni-stuttgart.de> Date: Fri, 31 Jan 2020 17:37:10 +0100 Subject: [PATCH] [test] Add unit test for sequential linear solver --- test/CMakeLists.txt | 1 + test/linear/CMakeLists.txt | 4 ++ test/linear/params.input | 6 +++ test/linear/test_linearsolver.cc | 72 ++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 test/linear/CMakeLists.txt create mode 100644 test/linear/params.input create mode 100644 test/linear/test_linearsolver.cc diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b5c7428a4b..a543ada950 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,6 +2,7 @@ add_subdirectory(common) add_subdirectory(geomechanics) add_subdirectory(freeflow) add_subdirectory(io) +add_subdirectory(linear) add_subdirectory(material) add_subdirectory(multidomain) add_subdirectory(nonlinear) diff --git a/test/linear/CMakeLists.txt b/test/linear/CMakeLists.txt new file mode 100644 index 0000000000..e514752212 --- /dev/null +++ b/test/linear/CMakeLists.txt @@ -0,0 +1,4 @@ +dune_symlink_to_source_files(FILES "params.input") +dumux_add_test(NAME test_linearsolver + SOURCES test_linearsolver.cc + LABELS linear unit) diff --git a/test/linear/params.input b/test/linear/params.input new file mode 100644 index 0000000000..2be5e3aec4 --- /dev/null +++ b/test/linear/params.input @@ -0,0 +1,6 @@ +TestSolver = CG +ProblemSize = 2 + +[CG.LinearSolver] +Type = cgsolver +Preconditioner.Type = amg diff --git a/test/linear/test_linearsolver.cc b/test/linear/test_linearsolver.cc new file mode 100644 index 0000000000..d379a47e53 --- /dev/null +++ b/test/linear/test_linearsolver.cc @@ -0,0 +1,72 @@ +#include <config.h> + +#include <iostream> +#include <iomanip> +#include <cmath> + +#include <dumux/common/parameters.hh> +#include <dumux/discretization/method.hh> +#include <dumux/linear/linearsolvertraits.hh> +//#include <dumux/linear/istlsolverfactorybackend.hh> +#include <dumux/linear/amgbackend.hh> + +#include <dune/common/exceptions.hh> +#include <dune/common/fvector.hh> +#include <dune/common/fmatrix.hh> + +#include <dune/grid/common/mcmgmapper.hh> +#include <dune/grid/yaspgrid.hh> + +#include <dune/istl/bvector.hh> +#include <dune/istl/bcrsmatrix.hh> + +#include <dune/istl/test/laplacian.hh> +#include <dune/istl/paamg/test/anisotropic.hh> + +namespace Dumux::Test { + +struct MockGridGeometry +{ + using GridView = Dune::YaspGrid<2>::LeafGridView; + using DofMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>; + using VertexMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>; + static constexpr auto discMethod = DiscretizationMethod::box; +}; + +} // end namespace Dumux::Test + +int main(int argc, char* argv[]) try +{ + using namespace Dumux; + + Dune::MPIHelper::instance(argc, argv); + + Parameters::init(argc, argv, "params.input"); + + using Vector = Dune::BlockVector<Dune::FieldVector<double, 2>>; + using Matrix = Dune::BCRSMatrix<Dune::FieldMatrix<double, 2, 2>>; + + // create matrix & vectors (we want to solve Ax=b) + Matrix A; const int numDofs = getParam<int>("ProblemSize"); + setupLaplacian(A, numDofs); + + Vector x(A.N()); Vector b(A.M()); + x = 0; b = 1; + + using LinearSolverTraits = Dumux::LinearSolverTraits<Test::MockGridGeometry>; + using LinearSolver = AMGBiCGSTABBackend<LinearSolverTraits>; + + const auto testSolverName = getParam<std::string>("TestSolver"); + LinearSolver solver(testSolverName); + + solver.solve(A, x, b); + if (!solver.result().converged) + DUNE_THROW(Dune::Exception, testSolverName << " did not converge!"); + + return 0; +} +catch (const Dune::Exception& e) +{ + std::cout << e << std::endl; + return 1; +} -- GitLab