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
[CG.LinearSolver]
[LinearSolver]
Verbosity = 1
[AMGCG.LinearSolver]
Type = cgsolver
Preconditioner.Type = amg
[SSORCG.LinearSolver]
Type = cgsolver
Preconditioner.Type = ssor
[AMGBiCGSTAB.LinearSolver]
Verbosity = 1
......@@ -4,13 +4,8 @@
#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/version.hh>
#include <dune/common/fvector.hh>
#include <dune/common/fmatrix.hh>
......@@ -23,6 +18,15 @@
#include <dune/istl/test/laplacian.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 {
struct MockGridGeometry
......@@ -33,6 +37,22 @@ struct MockGridGeometry
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
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());
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!");
// AMGBiCGSTABBackend
{
std::cout << std::endl;
const auto testSolverName = "AMGBiCGSTAB";
using LinearSolver = AMGBiCGSTABBackend<LinearSolverTraits<Test::MockGridGeometry>>;
LinearSolver solver(testSolverName);
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;
}
......
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