Skip to content
Snippets Groups Projects
Commit 2e67dc60 authored by Timo Koch's avatar Timo Koch
Browse files

[test] Add linear solver unit test for istlsolverfactory

parent 59bc45cf
No related branches found
No related tags found
1 merge request!1845Feature/istl solver factory
TestSolver = CG
ProblemSize = 2 ProblemSize = 2
[CG.LinearSolver] [LinearSolver]
Verbosity = 1
[AMGCG.LinearSolver]
Type = cgsolver Type = cgsolver
Preconditioner.Type = amg Preconditioner.Type = amg
[SSORCG.LinearSolver]
Type = cgsolver
Preconditioner.Type = ssor
[AMGBiCGSTAB.LinearSolver]
Verbosity = 1
...@@ -4,13 +4,8 @@ ...@@ -4,13 +4,8 @@
#include <iomanip> #include <iomanip>
#include <cmath> #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/exceptions.hh>
#include <dune/common/version.hh>
#include <dune/common/fvector.hh> #include <dune/common/fvector.hh>
#include <dune/common/fmatrix.hh> #include <dune/common/fmatrix.hh>
...@@ -23,6 +18,15 @@ ...@@ -23,6 +18,15 @@
#include <dune/istl/test/laplacian.hh> #include <dune/istl/test/laplacian.hh>
#include <dune/istl/paamg/test/anisotropic.hh> #include <dune/istl/paamg/test/anisotropic.hh>
#include <dumux/common/parameters.hh>
#include <dumux/discretization/method.hh>
#include <dumux/linear/linearsolvertraits.hh>
#if DUNE_VERSION_NEWER_REV(DUNE_ISTL,2,7,1)
#include <dumux/linear/istlsolverfactorybackend.hh>
#endif
#include <dumux/linear/amgbackend.hh>
namespace Dumux::Test { namespace Dumux::Test {
struct MockGridGeometry struct MockGridGeometry
...@@ -33,6 +37,22 @@ struct MockGridGeometry ...@@ -33,6 +37,22 @@ struct MockGridGeometry
static constexpr auto discMethod = DiscretizationMethod::box; static constexpr auto discMethod = DiscretizationMethod::box;
}; };
#if DUNE_VERSION_NEWER_REV(DUNE_ISTL,2,7,1)
template<class M, class X, class V>
void solveWithFactory(M& A, X& x, V& b, const std::string& paramGroup)
{
std::cout << std::endl;
using LinearSolver = IstlSolverFactoryBackend<LinearSolverTraits<Test::MockGridGeometry>>;
LinearSolver solver(paramGroup);
std::cout << "Solving Laplace problem with " << solver.name() << "\n";
solver.solve(A, x, b);
if (!solver.result().converged)
DUNE_THROW(Dune::Exception, solver.name() << " did not converge!");
}
#endif
} // end namespace Dumux::Test } // end namespace Dumux::Test
int main(int argc, char* argv[]) try int main(int argc, char* argv[]) try
...@@ -53,15 +73,25 @@ int main(int argc, char* argv[]) try ...@@ -53,15 +73,25 @@ int main(int argc, char* argv[]) try
Vector x(A.N()); Vector b(A.M()); Vector x(A.N()); Vector b(A.M());
x = 0; b = 1; x = 0; b = 1;
using LinearSolverTraits = Dumux::LinearSolverTraits<Test::MockGridGeometry>; // AMGBiCGSTABBackend
using LinearSolver = AMGBiCGSTABBackend<LinearSolverTraits>; {
std::cout << std::endl;
const auto testSolverName = getParam<std::string>("TestSolver");
LinearSolver solver(testSolverName); const auto testSolverName = "AMGBiCGSTAB";
using LinearSolver = AMGBiCGSTABBackend<LinearSolverTraits<Test::MockGridGeometry>>;
solver.solve(A, x, b); LinearSolver solver(testSolverName);
if (!solver.result().converged)
DUNE_THROW(Dune::Exception, testSolverName << " did not converge!"); std::cout << "Solving Laplace problem with " << solver.name() << "\n";
solver.solve(A, x, b);
if (!solver.result().converged)
DUNE_THROW(Dune::Exception, testSolverName << " did not converge!");
}
#if DUNE_VERSION_NEWER_REV(DUNE_ISTL,2,7,1)
// IstlSolverFactoryBackend
Test::solveWithFactory(A, x, b, "AMGCG");
Test::solveWithFactory(A, x, b, "SSORCG");
#endif
return 0; return 0;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment