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>
43 struct preconditioner;
53 template <
class Traits>
54 class ISTLSolverCreatorBase
55 :
public CreatorInterface<tag::solver<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;
141 template <
class Solver,
class 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>
194 template <
class X,
class Y,
class 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>
237 template <
class X,
class Traits>
242 template <
class X,
class 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,
static CreatorInterface< BaseClass > * get(std::string key, std::string initFileStr)
Creates a object of the type corresponding to key.
Definition: CreatorMap.hpp:44
Base class for solver creators,.
Definition: ISTLPreconCreator.hpp:132
A CreatorMap is used to construct objects, which types depends on key words determined at run time...
Definition: CreatorMap.hpp:29
Definition: AdaptBase.hpp:6
Solver creator for iterative GMRes-like solvers.
Definition: ISTLSolverCreator.hpp:166
Base class for precon creators,.
Definition: ISTLPreconCreator.hpp:39
void init(std::string const &prefix) override
Prepare the solver for the creation.
Definition: ISTLSolverCreator.hpp:173
static std::optional< T > get(std::string const &key)
Get parameter-values from parameter-tree.
Definition: Initfile.hpp:25
void init(std::string const &prefix) override
Prepare the solver for the creation.
Definition: ISTLSolverCreator.hpp:265
void init(std::string const &prefix) override
Prepare the solver for the creation.
Definition: ISTLSolverCreator.hpp:216
Default creator for direct solvers.
Definition: ISTLSolverCreator.hpp:260
virtual void init(std::string const &prefix)
Prepare the solver for the creation.
Definition: ISTLSolverCreator.hpp:64
Base solver creator for iterative solvers.
Definition: ISTLSolverCreator.hpp:88
Default solver creator for iterative solvers.
Definition: Solvers.hpp:24
Solver creator for iterative CG-like solvers.
Definition: ISTLSolverCreator.hpp:209
void init(std::string const &prefix) override
Prepare the solver for the creation.
Definition: ISTLSolverCreator.hpp:96
static int mpiRank()
Return the MPI_Rank of the current processor.
Definition: Environment.hpp:68