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>
37 template <
class Traits>
41 template <
class Traits>
52 template <
class Traits>
56 using X =
typename Traits::X;
57 using Y =
typename Traits::Y;
59 std::unique_ptr<tag::solver<Traits>> create()
final {
return {}; };
63 virtual void init(std::string
const& prefix)
69 virtual std::unique_ptr<Dune::InverseOperator<X,Y>>
70 createSolver(
typename Traits::M
const& A,
typename Traits::Comm
const& comm)
const = 0;
86 template <
class Traits>
92 using real_type =
typename Dune::FieldTraits<typename Traits::M::field_type>::real_type;
95 void init(std::string
const& prefix)
override
99 maxIter_ = Parameters::get<int>(prefix +
"->maxit").value_or(
100 Parameters::get<int>(prefix +
"->max iteration").value_or(maxIter_));
101 rTol_ = Parameters::get<real_type>(prefix +
"->reduction").value_or(
102 Parameters::get<real_type>(prefix +
"->relative tolerance").value_or(rTol_));
104 std::string precon =
"default";
110 assert(preconCreator_ !=
nullptr);
111 preconCreator_->init(prefix +
"->precon");
115 template <
class Solver,
class... Args>
116 auto create_impl(
typename Traits::M
const& mat,
typename Traits::Comm
const& comm, Args&&... args)
const
118 auto cat = Dune::SolverCategory::category(comm);
119 auto sp = Traits::ScalProdCreator::create(cat, comm);
120 auto linOp = Traits::LinOpCreator::create(cat, mat, comm);
122 assert(preconCreator_ !=
nullptr);
123 auto precon = preconCreator_->createPrecon(mat, comm);
124 return std::make_unique<IterativeSolverWrapper<Solver>>(
125 std::move(linOp), std::move(sp), std::move(precon), FWD(args)...);
130 real_type rTol_ = 1.e-6;
131 ISTLPreconCreatorBase<Traits>* preconCreator_ =
nullptr;
140 template <
class Solver,
class Traits>
141 class IterativeSolverCreator
142 :
public ISTLIterativeSolverCreatorBase<Traits>
144 using Super = ISTLIterativeSolverCreatorBase<Traits>;
145 using Interface =
typename Traits::Solver;
148 std::unique_ptr<Interface>
149 createSolver(
typename Traits::M
const& mat,
typename Traits::Comm
const& comm)
const override
151 return this->
template create_impl<Solver>(mat, comm, this->rTol_, this->maxIter_, this->info_);
164 template <
class Solver,
class Traits>
169 using Interface =
typename Traits::Solver;
172 void init(std::string
const& prefix)
override
178 std::unique_ptr<Interface>
179 createSolver(
typename Traits::M
const& mat,
typename Traits::Comm
const& comm)
const override
181 return this->
template create_impl<Solver>(mat, comm, this->rTol_, restart_, this->maxIter_, this->info_);
188 template <
class X,
class Y,
class Traits>
189 struct IterativeSolverCreator<Dune::RestartedGMResSolver<X,Y>,
Traits>
190 :
public GMResSolverCreator<Dune::RestartedGMResSolver<X,Y>,
Traits>
193 template <
class X,
class Y,
class Traits>
194 struct IterativeSolverCreator<Dune::RestartedFlexibleGMResSolver<X,Y>,
Traits>
195 :
public GMResSolverCreator<Dune::RestartedFlexibleGMResSolver<X,Y>, Traits>
207 template <
class Solver,
class Traits>
212 using Interface =
typename Traits::Solver;
215 void init(std::string
const& prefix)
override
221 std::unique_ptr<Interface>
222 createSolver(
typename Traits::M
const& mat,
typename Traits::Comm
const& comm)
const override
224 return this->
template create_impl<Solver>(mat, comm, this->rTol_, this->maxIter_, this->info_, restart_);
231 template <
class X,
class Traits>
232 struct IterativeSolverCreator<Dune::GeneralizedPCGSolver<X>,
Traits>
233 :
public PCGSolverCreator<Dune::GeneralizedPCGSolver<X>,
Traits>
236 template <
class X,
class Traits>
237 struct IterativeSolverCreator<Dune::RestartedFCGSolver<X>,
Traits>
238 :
public PCGSolverCreator<Dune::RestartedFCGSolver<X>, Traits>
241 template <
class X,
class Traits>
242 struct IterativeSolverCreator<Dune::CompleteFCGSolver<X>,
Traits>
243 :
public PCGSolverCreator<Dune::CompleteFCGSolver<X>, Traits>
258 template <
class Solver,
class Traits>
264 void init(std::string
const& prefix)
override
270 std::unique_ptr<typename Traits::Solver>
271 createSolver(
typename Traits::M
const& mat,
typename Traits::Comm
const& comm)
const override
273 test_exit(Dune::SolverCategory::category(comm) == Dune::SolverCategory::sequential,
274 "Direct solver can be used as sequential solver only.");
275 return std::make_unique<Solver>(mat, this->info_, reuseVector_);
279 bool reuseVector_ =
true;
283 template <
class Solver,
class Traits>
284 using ISTLSolverCreator = std::conditional_t<Dune::IsDirectSolver<Solver>::value,
285 DirectSolverCreator<Solver,Traits>,
286 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:71
Base solver creator for iterative solvers.
Definition ISTLSolverCreator.hpp:89
void init(std::string const &prefix) override
Prepare the solver for the creation.
Definition ISTLSolverCreator.hpp:95
Base class for precon creators,.
Definition ISTLPreconCreator.hpp:41
Base class for solver creators,.
Definition ISTLSolverCreator.hpp:55
virtual void init(std::string const &prefix)
Prepare the solver for the creation.
Definition ISTLSolverCreator.hpp:63
static std::optional< T > get(std::string const &key)
Get parameter-values from parameter-tree.
Definition Initfile.hpp:31
Default creator for direct solvers.
Definition ISTLSolverCreator.hpp:261
void init(std::string const &prefix) override
Prepare the solver for the creation.
Definition ISTLSolverCreator.hpp:264
Solver creator for iterative GMRes-like solvers.
Definition ISTLSolverCreator.hpp:167
void init(std::string const &prefix) override
Prepare the solver for the creation.
Definition ISTLSolverCreator.hpp:172
Solver creator for iterative CG-like solvers.
Definition ISTLSolverCreator.hpp:210
void init(std::string const &prefix) override
Prepare the solver for the creation.
Definition ISTLSolverCreator.hpp:215
Definition ISTLPreconCreator.hpp:26
Definition ISTLSolverCreator.hpp:38