5 #include <dune/common/classname.hh> 6 #include <dune/common/version.hh> 8 #include <dune/common/ftraits.hh> 10 #include <amdis/CreatorMap.hpp> 11 #include <amdis/Environment.hpp> 12 #include <amdis/Initfile.hpp> 13 #include <amdis/Output.hpp> 15 #include <amdis/linearalgebra/LinearSolver.hpp> 16 #include <amdis/linearalgebra/istl/CreatorInterfaces.hpp> 17 #include <amdis/linearalgebra/istl/ISTLSolver.hpp> 18 #include <amdis/linearalgebra/istl/SolverWrapper.hpp> 19 #include <amdis/linearalgebra/istl/precompiled/Solvers.hpp> 25 template <
class Solver>
struct pcg {};
26 template <
class Solver>
struct gmres {};
36 template <
class Model,
class Traits>
45 return std::make_unique<Model>(prefix);
69 template <
class Creator,
class Traits>
75 using LinOp =
typename Traits::LinOp;
76 using ScalProd =
typename Traits::ScalProd;
77 using Prec =
typename Traits::Prec;
79 using real_type =
typename Dune::FieldTraits<typename Traits::M::field_type>::real_type;
88 std::string precon =
"default";
93 preconCreator_ = creator->createWithString(prefix +
"->precon");
94 assert(preconCreator_);
98 template <
class Solver,
class... Args>
99 auto create_impl(
typename Traits::M
const& mat,
typename Traits::Comm
const& comm, Args&&... args)
const 101 auto cat = Dune::SolverCategory::category(comm);
102 auto sp = Traits::ScalProdCreator::create(
cat, comm);
103 auto linOp = Traits::LinOpCreator::create(
cat, mat, comm);
105 auto precon = preconCreator_->create(mat, comm);
106 return std::make_unique<IterativeSolverWrapper<Solver>>(
107 std::move(linOp), std::move(sp), std::move(precon), FWD(args)...);
112 real_type rTol_ = 1.e-6;
113 std::shared_ptr<ISTLPreconCreatorInterface<Traits>> preconCreator_;
122 template <
class Solver,
class Traits>
127 using Interface =
typename Traits::Solver;
132 std::unique_ptr<Interface> create(
typename Traits::M
const& mat,
typename Traits::Comm
const& comm)
const override 134 return this->
template create_impl<Solver>(mat, comm, this->rTol_, this->maxIter_, this->
info_);
147 template <
class Solver,
class Traits>
152 using Interface =
typename Traits::Solver;
161 std::unique_ptr<Interface> create(
typename Traits::M
const& mat,
typename Traits::Comm
const& comm)
const override 163 return this->
template create_impl<Solver>(mat, comm, this->rTol_, restart_, this->maxIter_, this->
info_);
179 template <
class Solver,
class Traits>
184 using Interface =
typename Traits::Solver;
193 std::unique_ptr<Interface> create(
typename Traits::M
const& mat,
typename Traits::Comm
const& comm)
const override 195 return this->
template create_impl<Solver>(mat, comm, this->rTol_, this->maxIter_, this->
info_, restart_);
214 template <
class Solver,
class Traits>
226 std::unique_ptr<typename Traits::Solver>
227 create(
typename Traits::M
const& mat,
typename Traits::Comm
const& comm)
const override 229 test_exit(Dune::SolverCategory::category(comm) == Dune::SolverCategory::sequential,
230 "Direct solver can be used as sequential solver only.");
231 return std::make_unique<Solver>(mat, this->
info_, reuseVector_);
235 bool reuseVector_ =
true;
238 #if HAVE_SUITESPARSE_CHOLMOD && DUNE_VERSION_GTE(DUNE_ISTL,2,7) 239 template <
class X,
class Traits>
247 std::unique_ptr<typename Traits::Solver>
248 create(
typename Traits::M
const& mat,
typename Traits::Comm
const& comm)
const override 250 test_exit(Dune::SolverCategory::category(comm) == Dune::SolverCategory::sequential,
251 "Direct solver can be used as sequential solver only.");
252 auto solver = std::make_unique<Dune::Cholmod<X>>();
253 solver->setMatrix(mat);
254 return std::move(solver);
277 template <
class Traits,
class Interface>
280 using M =
typename Traits::M;
281 using X =
typename Traits::X;
282 using Y =
typename Traits::Y;
284 using FTraits = Dune::FieldTraits<typename M::field_type>;
286 template <
class Solver>
289 template <
class Solver>
297 auto cg =
new IterativeSolver<Dune::CGSolver<X>>;
298 addCreator(
"cg", cg);
301 auto pcg =
new IterativeSolver<tag::pcg<Dune::GeneralizedPCGSolver<X>>>;
302 addCreator(
"pcg", pcg);
304 #if DUNE_VERSION_GTE(DUNE_ISTL,2,7) 305 auto fcg =
new IterativeSolver<tag::pcg<Dune::RestartedFCGSolver<X>>>;
306 addCreator(
"fcg", fcg);
308 auto cfcg =
new IterativeSolver<tag::pcg<Dune::CompleteFCGSolver<X>>>;
309 addCreator(
"cfcg", cfcg);
312 auto bicgstab =
new IterativeSolver<Dune::BiCGSTABSolver<X>>;
313 addCreator(
"bicgstab", bicgstab);
314 addCreator(
"bcgs", bicgstab);
315 addCreator(
"default", bicgstab);
317 auto minres =
new IterativeSolver<Dune::MINRESSolver<X>>;
318 addCreator(
"minres", minres);
320 auto gmres =
new IterativeSolver<tag::gmres<Dune::RestartedGMResSolver<X,Y>>>;
321 addCreator(
"gmres", gmres);
323 #if DUNE_VERSION_GTE(DUNE_ISTL,2,7) 324 auto fgmres =
new IterativeSolver<tag::gmres<Dune::RestartedFlexibleGMResSolver<X,Y>>>;
325 addCreator(
"fgmres", fgmres);
328 init_direct(std::is_same<typename FTraits::real_type, double>{});
331 static void init_direct(std::false_type)
333 warning(
"Direct solvers not created for the matrix with real_type = {}.",
334 Dune::className<typename FTraits::real_type>());
337 static void init_direct(std::true_type)
339 #if HAVE_SUITESPARSE_UMFPACK 340 auto umfpack =
new DirectSolver<Dune::UMFPack<M>>;
341 addCreator(
"umfpack", umfpack);
344 #if HAVE_SUITESPARSE_LDL 345 auto ldl =
new DirectSolver<Dune::LDL<M>>;
346 addCreator(
"ldl", ldl);
349 #if HAVE_SUITESPARSE_SPQR 350 auto spqr =
new DirectSolver<Dune::SPQR<M>>;
351 addCreator(
"spqr", spqr);
354 #if HAVE_SUITESPARSE_CHOLMOD && DUNE_VERSION_GTE(DUNE_ISTL,2,7) 355 auto cholmod =
new DirectSolver<Dune::Cholmod<X>>;
356 addCreator(
"cholmod", cholmod);
360 auto superlu =
new DirectSolver<Dune::SuperLU<M>>;
361 addCreator(
"superlu", superlu);
365 #if HAVE_SUITESPARSE_UMFPACK 366 addCreator(
"direct", umfpack);
368 addCreator(
"direct", superlu);
373 template <
class T>
struct Type {};
375 template <
class Creator>
376 static void addCreator(std::string name, Creator* creator)
378 addCreatorImpl(name, creator, Type<Interface>{});
381 template <
class Creator>
384 Map::addCreator(name, creator);
387 template <
class Creator,
class Mat,
class Vec>
391 Map::addCreator(name,
new LinearSolverCreator);
396 template <
class Traits>
401 template <
class Mat,
class Vec>
std::unique_ptr< Interface > createWithString(std::string prefix) override
Must be implemented by sub classes of CreatorInterfaceName. Creates a new instance of the sub class o...
Definition: SolverCreator.hpp:43
Definition: SolverCreator.hpp:41
A creator to be used instead of the constructor.
Definition: ISTLSolver.hpp:26
Adds default creators for linear solvers based on Dune::BCRSMatrix.
Definition: SolverCreator.hpp:278
Interface for creators with name.
Definition: CreatorInterface.hpp:42
A CreatorMap is used to construct objects, which types depends on key words determined at run time...
Definition: CreatorMap.hpp:29
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
auto cat(Dune::TypeTree::HybridTreePath< S... > const &tp0, Dune::TypeTree::HybridTreePath< T... > const &tp1)
Concatenate two treepaths.
Definition: TreePath.hpp:209
Definition: SolverCreator.hpp:26
Definition: SolverCreator.hpp:25
void info_(int noInfoLevel, std::string const &str, Args &&... args)
prints a message, if Environment::infoLevel() >= noInfoLevel
Definition: Output.hpp:127
static std::optional< T > get(std::string const &key)
Get parameter-values from parameter-tree.
Definition: Initfile.hpp:25
CreatorInterfaceName< BaseClass > * named(CreatorInterface< BaseClass > *ptr)
cast a ptr of CreatorInterface to CreatorInterfaceName
Definition: CreatorInterface.hpp:64
Abstract base class for linear solvers.
Definition: LinearSolverInterface.hpp:27
Default creator for direct solvers.
Definition: SolverCreator.hpp:215
Base solver creator for iterative solvers.
Definition: SolverCreator.hpp:70
Definition: CreatorMap.hpp:16
Definition: CreatorInterfaces.hpp:20
static CreatorInterface< BaseClass > * getCreator(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: SolverCreator.hpp:37
Default solver creator for iterative solvers.
Definition: SolverCreator.hpp:24
void init(int &argc, char **&argv, std::string const &initFileName="")
Initialized the Environment for MPI.
Definition: AMDiS.hpp:29
void test_exit(bool condition, std::string const &str, Args &&... args)
test for condition and in case of failure print message and exit
Definition: Output.hpp:163
static int mpiRank()
Return the MPI_Rank of the current processor.
Definition: Environment.hpp:68