4#ifndef DUNE_ISTL_SOLVERFACTORY_HH
5#define DUNE_ISTL_SOLVERFACTORY_HH
7#include <unordered_map>
11#include <dune/common/parametertree.hh>
12#include <dune/common/singleton.hh>
25 template<
class M,
class X,
class Y>
27 template<
class M,
class X,
class Y>
31 template<
class M,
class X,
class Y>
33 template<
class M,
class X,
class Y>
37 template<
class X,
class Y>
38 using IterativeSolverSignature = std::shared_ptr<InverseOperator<X,Y>>(
const std::shared_ptr<LinearOperator<X,Y>>&,
const std::shared_ptr<ScalarProduct<X>>&,
const std::shared_ptr<Preconditioner<X,Y>>,
const ParameterTree&);
39 template<
class X,
class Y>
52 int initSolverFactories(){
53 using M =
typename O::matrix_type;
54 using X =
typename O::range_type;
55 using Y =
typename O::domain_type;
56 using TL = Dune::TypeList<M,X,Y>;
58 addRegistryToFactory<TL>(dsfac, DirectSolverTag{});
60 addRegistryToFactory<TL>(pfac, PreconditionerTag{});
61 using TLS = Dune::TypeList<X,Y>;
63 return addRegistryToFactory<TLS>(isfac, IterativeSolverTag{});
75 template<
class O,
class X,
class Y>
76 [[deprecated(
"Use method 'initSolverFactories<O>' instead")]]
77 int initSolverFactories() {
78 return initSolverFactories<O>();
83 template<
class O,
class Preconditioner>
90 template<
class M,
class X,
class Y,
class C,
class Preconditioner>
91 std::shared_ptr<Preconditioner>
95 return std::make_shared<BlockPreconditioner<X,Y,C,Preconditioner> >(prec, op->getCommunication());
98 template<
class M,
class X,
class Y,
class C,
class Preconditioner>
99 std::shared_ptr<Preconditioner>
103 return std::make_shared<NonoverlappingBlockPreconditioner<C,Preconditioner> >(prec, op->getCommunication());
106 template<
class M,
class X,
class Y>
109 return std::make_shared<SeqScalarProduct<X>>();
111 template<
class M,
class X,
class Y,
class C>
114 return createScalarProduct<X>(op->getCommunication(), op->category());
117 template<
class M,
class X,
class Y,
class C>
120 return createScalarProduct<X>(op->getCommunication(), op->category());
142 template<
class Operator>
144 using Domain =
typename Operator::domain_type;
145 using Range =
typename Operator::range_type;
150 using _matrix_type =
typename O::matrix_type;
151 using matrix_type = Std::detected_or_t<int, _matrix_type, Operator>;
152 static constexpr bool isAssembled = !std::is_same<matrix_type, int>::value;
154 static const matrix_type* getmat(std::shared_ptr<Operator> op){
155 std::shared_ptr<AssembledLinearOperator<matrix_type, Domain, Range>> aop
156 = std::dynamic_pointer_cast<AssembledLinearOperator<matrix_type, Domain, Range>>(op);
158 return &aop->getmat();
166 static std::shared_ptr<Solver>
get(std::shared_ptr<Operator> op,
167 const ParameterTree& config,
168 std::shared_ptr<Preconditioner> prec =
nullptr){
169 std::string type = config.get<std::string>(
"type");
170 std::shared_ptr<Solver> result;
171 const matrix_type*
mat = getmat(op);
175 DUNE_THROW(NotImplemented,
"The solver factory does not support parallel direct solvers!");
183 DUNE_THROW(Dune::InvalidStateException,
"Solver not found in the factory.");
186 const ParameterTree& precConfig = config.sub(
"preconditioner");
187 std::string prec_type = precConfig.get<std::string>(
"type");
202 const ParameterTree& config){
203 const matrix_type*
mat = getmat(op);
205 std::string prec_type = config.get<std::string>(
"type");
208 DUNE_THROW(InvalidStateException,
"Could not obtain matrix from operator. Please pass in an AssembledLinearOperator.");
223 template<
class Operator>
224 std::shared_ptr<InverseOperator<
typename Operator::domain_type,
226 const ParameterTree& config,
228 typename Operator::range_type>> prec =
nullptr){
Define general, extensible interface for inverse operators.
Matrix & mat
Definition: matrixmatrix.hh:345
Singleton< ParameterizedObjectFactory< PreconditionerSignature< M, X, Y > > > PreconditionerFactory
Definition: solverfactory.hh:34
Singleton< ParameterizedObjectFactory< DirectSolverSignature< M, X, Y > > > DirectSolverFactory
Definition: solverfactory.hh:28
std::shared_ptr< InverseOperator< X, Y > >(const std::shared_ptr< LinearOperator< X, Y > > &, const std::shared_ptr< ScalarProduct< X > > &, const std::shared_ptr< Preconditioner< X, Y > >, const ParameterTree &) IterativeSolverSignature
Definition: solverfactory.hh:38
std::shared_ptr< Preconditioner > wrapPreconditioner4Parallel(const std::shared_ptr< Preconditioner > &prec, const O &)
Definition: solverfactory.hh:84
std::shared_ptr< InverseOperator< X, Y > >(const M &, const ParameterTree &) DirectSolverSignature
Definition: solverfactory.hh:26
std::shared_ptr< InverseOperator< typename Operator::domain_type, typename Operator::range_type > > getSolverFromFactory(std::shared_ptr< Operator > op, const ParameterTree &config, std::shared_ptr< Preconditioner< typename Operator::domain_type, typename Operator::range_type > > prec=nullptr)
Instantiates an InverseOperator from an Operator and a configuration given as a ParameterTree.
Definition: solverfactory.hh:225
Singleton< ParameterizedObjectFactory< IterativeSolverSignature< X, Y > > > IterativeSolverFactory
Definition: solverfactory.hh:40
std::shared_ptr< Preconditioner< X, Y > >(const std::shared_ptr< M > &, const ParameterTree &) PreconditionerSignature
Definition: solverfactory.hh:32
Definition: allocator.hh:9
std::shared_ptr< ScalarProduct< X > > createScalarProduct(const Comm &comm, SolverCategory::Category category)
Definition: scalarproducts.hh:240
A nonoverlapping operator with communication object.
Definition: novlpschwarz.hh:62
Adapter to turn a matrix into a linear operator.
Definition: operators.hh:135
An overlapping Schwarz operator.
Definition: schwarz.hh:76
Base class for matrix free definition of preconditioners.
Definition: preconditioner.hh:30
@ sequential
Category for sequential solvers.
Definition: solvercategory.hh:23
Factory to assembly solvers configured by a ParameterTree.
Definition: solverfactory.hh:143
static std::shared_ptr< Solver > get(std::shared_ptr< Operator > op, const ParameterTree &config, std::shared_ptr< Preconditioner > prec=nullptr)
get a solver from the factory
Definition: solverfactory.hh:166
static std::shared_ptr< Preconditioner > getPreconditioner(std::shared_ptr< Operator > op, const ParameterTree &config)
Construct a Preconditioner for a given Operator.
Definition: solverfactory.hh:201