5#include <dune/common/version.hh>
7#include <dune/common/ftraits.hh>
8#include <dune/istl/solvers.hh>
9#include <dune/istl/solvertype.hh>
11#if HAVE_SUITESPARSE_UMFPACK
12#include <dune/istl/umfpack.hh>
14#if HAVE_SUITESPARSE_LDL
15#include <dune/istl/ldl.hh>
17#if HAVE_SUITESPARSE_SPQR
18#include <dune/istl/spqr.hh>
21#include <dune/istl/superlu.hh>
24#include <amdis/CreatorMap.hpp>
25#include <amdis/Environment.hpp>
26#include <amdis/Initfile.hpp>
27#include <amdis/Output.hpp>
29#include <amdis/linearalgebra/istl/ISTLPreconCreator.hpp>
30#include <amdis/linearalgebra/istl/SolverWrapper.hpp>
31#include <amdis/linearalgebra/istl/Traits.hpp>
32#include <amdis/linearalgebra/istl/precompiled/Solvers.hpp>
38 template <
class Traits>
42 template <
class Traits>
53 template <
class Traits>
57 using X =
typename Traits::X;
58 using Y =
typename Traits::Y;
60 std::unique_ptr<tag::solver<Traits>> create()
final {
return {}; };
64 virtual void init(std::string
const& prefix)
70 virtual std::unique_ptr<Dune::InverseOperator<X,Y>>
71 createSolver(
typename Traits::M
const& A,
typename Traits::Comm
const& comm)
const = 0;
87 template <
class Traits>
93 using real_type =
typename Dune::FieldTraits<typename Traits::M::field_type>::real_type;
96 void init(std::string
const& prefix)
override
100 maxIter_ = Parameters::get<int>(prefix +
"->maxit").value_or(
101 Parameters::get<int>(prefix +
"->max iteration").value_or(maxIter_));
102 rTol_ = Parameters::get<real_type>(prefix +
"->reduction").value_or(
103 Parameters::get<real_type>(prefix +
"->relative tolerance").value_or(rTol_));
105 std::string precon =
"default";
111 assert(preconCreator_ !=
nullptr);
112 preconCreator_->init(prefix +
"->precon");
116 template <
class Solver,
class... Args>
117 auto create_impl(
typename Traits::M
const& mat,
typename Traits::Comm
const& comm, Args&&... args)
const
119 auto cat = Dune::SolverCategory::category(comm);
120 auto sp = Traits::ScalProdCreator::create(cat, comm);
121 auto linOp = Traits::LinOpCreator::create(cat, mat, comm);
123 assert(preconCreator_ !=
nullptr);
124 auto precon = preconCreator_->createPrecon(mat, comm);
125 return std::make_unique<IterativeSolverWrapper<Solver>>(
126 std::move(linOp), std::move(sp), std::move(precon), FWD(args)...);
131 real_type rTol_ = 1.e-6;
132 ISTLPreconCreatorBase<Traits>* preconCreator_ =
nullptr;
141 template <
class Solver,
class Traits>
142 class IterativeSolverCreator
143 :
public ISTLIterativeSolverCreatorBase<Traits>
145 using Super = ISTLIterativeSolverCreatorBase<Traits>;
146 using Interface =
typename Traits::Solver;
149 std::unique_ptr<Interface>
150 createSolver(
typename Traits::M
const& mat,
typename Traits::Comm
const& comm)
const override
152 return this->
template create_impl<Solver>(mat, comm, this->rTol_, this->maxIter_, this->info_);
165 template <
class Solver,
class Traits>
170 using Interface =
typename Traits::Solver;
173 void init(std::string
const& prefix)
override
179 std::unique_ptr<Interface>
180 createSolver(
typename Traits::M
const& mat,
typename Traits::Comm
const& comm)
const override
182 return this->
template create_impl<Solver>(mat, comm, this->rTol_, restart_, this->maxIter_, this->info_);
189 template <
class X,
class Y,
class Traits>
190 struct IterativeSolverCreator<Dune::RestartedGMResSolver<X,Y>,
Traits>
191 :
public GMResSolverCreator<Dune::RestartedGMResSolver<X,Y>,
Traits>
194 template <
class X,
class Y,
class Traits>
195 struct IterativeSolverCreator<Dune::RestartedFlexibleGMResSolver<X,Y>,
Traits>
196 :
public GMResSolverCreator<Dune::RestartedFlexibleGMResSolver<X,Y>, Traits>
208 template <
class Solver,
class Traits>
213 using Interface =
typename Traits::Solver;
216 void init(std::string
const& prefix)
override
222 std::unique_ptr<Interface>
223 createSolver(
typename Traits::M
const& mat,
typename Traits::Comm
const& comm)
const override
225 return this->
template create_impl<Solver>(mat, comm, this->rTol_, this->maxIter_, this->info_, restart_);
232 template <
class X,
class Traits>
233 struct IterativeSolverCreator<Dune::GeneralizedPCGSolver<X>,
Traits>
234 :
public PCGSolverCreator<Dune::GeneralizedPCGSolver<X>,
Traits>
237 template <
class X,
class Traits>
238 struct IterativeSolverCreator<Dune::RestartedFCGSolver<X>,
Traits>
239 :
public PCGSolverCreator<Dune::RestartedFCGSolver<X>, Traits>
242 template <
class X,
class Traits>
243 struct IterativeSolverCreator<Dune::CompleteFCGSolver<X>,
Traits>
244 :
public PCGSolverCreator<Dune::CompleteFCGSolver<X>, Traits>
259 template <
class Solver,
class Traits>
265 void init(std::string
const& prefix)
override
271 std::unique_ptr<typename Traits::Solver>
272 createSolver(
typename Traits::M
const& mat,
typename Traits::Comm
const& comm)
const override
274 test_exit(Dune::SolverCategory::category(comm) == Dune::SolverCategory::sequential,
275 "Direct solver can be used as sequential solver only.");
276 return std::make_unique<Solver>(mat, this->info_, reuseVector_);
280 bool reuseVector_ =
true;
284 template <
class Solver,
class Traits>
285 using ISTLSolverCreator = std::conditional_t<Dune::IsDirectSolver<Solver>::value,
286 DirectSolverCreator<Solver,Traits>,
287 IterativeSolverCreator<Solver,Traits>>;
Interface for the implementation of the factory method pattern. The creation of an object of a sub cl...
Definition: CreatorInterface.hpp:24
A CreatorMap is used to construct objects, which types depends on key words determined at run time....
Definition: CreatorMap.hpp:30
static CreatorInterface< BaseClass > * get(std::string key, std::string initFileStr)
Creates a object of the type corresponding to key.
Definition: CreatorMap.hpp:44
static int mpiRank()
Return the MPI_Rank of the current processor.
Definition: Environment.hpp:68
Base solver creator for iterative solvers.
Definition: ISTLSolverCreator.hpp:90
void init(std::string const &prefix) override
Prepare the solver for the creation.
Definition: ISTLSolverCreator.hpp:96
Base class for precon creators,.
Definition: ISTLPreconCreator.hpp:41
Base class for solver creators,.
Definition: ISTLSolverCreator.hpp:56
virtual void init(std::string const &prefix)
Prepare the solver for the creation.
Definition: ISTLSolverCreator.hpp:64
static std::optional< T > get(std::string const &key)
Get parameter-values from parameter-tree.
Definition: Initfile.hpp:25
Default creator for direct solvers.
Definition: ISTLSolverCreator.hpp:262
void init(std::string const &prefix) override
Prepare the solver for the creation.
Definition: ISTLSolverCreator.hpp:265
Solver creator for iterative GMRes-like solvers.
Definition: ISTLSolverCreator.hpp:168
void init(std::string const &prefix) override
Prepare the solver for the creation.
Definition: ISTLSolverCreator.hpp:173
Solver creator for iterative CG-like solvers.
Definition: ISTLSolverCreator.hpp:211
void init(std::string const &prefix) override
Prepare the solver for the creation.
Definition: ISTLSolverCreator.hpp:216
Definition: ISTLPreconCreator.hpp:26
Definition: ISTLSolverCreator.hpp:39