diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b5c7428a4b7e7b3edb40d5f60c4fd3972c74014d..a543ada95089e2348ada2f5c32a08bfd0877e6af 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 0000000000000000000000000000000000000000..e514752212af6b9f355d52c7a4ee049296d2dd61 --- /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 0000000000000000000000000000000000000000..2be5e3aec47f1dae272e669a488ba7120e14973d --- /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 0000000000000000000000000000000000000000..d379a47e5331076a25a173b4ff3fc84b1d20fed8 --- /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; +}