4#ifndef DUNE_ISTL_SOLVERFACTORY_HH
5#define DUNE_ISTL_SOLVERFACTORY_HH
7#include <unordered_map>
14#include <dune/istl/common/registry.hh>
17#define DUNE_REGISTER_DIRECT_SOLVER(name, ...) \
18 DUNE_REGISTRY_PUT(DirectSolverTag, name, __VA_ARGS__)
20#define DUNE_REGISTER_PRECONDITIONER(name, ...) \
21 DUNE_REGISTRY_PUT(PreconditionerTag, name, __VA_ARGS__)
23#define DUNE_REGISTER_ITERATIVE_SOLVER(name, ...) \
24 DUNE_REGISTRY_PUT(IterativeSolverTag, name, __VA_ARGS__)
32 struct DirectSolverTag {};
33 struct PreconditionerTag {};
34 struct IterativeSolverTag {};
37 template<
template<
class,
class,
class,
int>
class Preconditioner,
int blockLevel=1>
38 auto defaultPreconditionerBlockLevelCreator(){
41 using Matrix =
typename Dune::TypeListElement<0,
decltype(typeList)>::type;
42 using Domain =
typename Dune::TypeListElement<1,
decltype(typeList)>::type;
43 using Range =
typename Dune::TypeListElement<2,
decltype(typeList)>::type;
44 std::shared_ptr<Dune::Preconditioner<Domain, Range>> preconditioner
45 = std::make_shared<Preconditioner<Matrix, Domain, Range, blockLevel>>(matrix, config);
46 return preconditioner;
50 template<
template<
class,
class,
class>
class Preconditioner>
51 auto defaultPreconditionerCreator(){
54 using Matrix =
typename Dune::TypeListElement<0,
decltype(typeList)>::type;
55 using Domain =
typename Dune::TypeListElement<1,
decltype(typeList)>::type;
56 using Range =
typename Dune::TypeListElement<2,
decltype(typeList)>::type;
57 std::shared_ptr<Dune::Preconditioner<Domain, Range>> preconditioner
58 = std::make_shared<Preconditioner<Matrix, Domain, Range>>(matrix, config);
59 return preconditioner;
63 template<
template<
class...>
class Solver>
64 auto defaultIterativeSolverCreator(){
65 return [](
auto typeList,
66 const auto& linearOperator,
67 const auto& scalarProduct,
68 const auto& preconditioner,
71 using Domain =
typename Dune::TypeListElement<0,
decltype(typeList)>::type;
72 using Range =
typename Dune::TypeListElement<1,
decltype(typeList)>::type;
73 std::shared_ptr<Dune::InverseOperator<Domain, Range>> solver
74 = std::make_shared<Solver<Domain>>(linearOperator, scalarProduct, preconditioner, config);
80 template<
class M,
class X,
class Y>
81 using DirectSolverSignature = std::shared_ptr<InverseOperator<X,Y>>(
const M&,
const ParameterTree&);
82 template<
class M,
class X,
class Y>
83 using DirectSolverFactory = Singleton<ParameterizedObjectFactory<DirectSolverSignature<M,X,Y>>>;
86 template<
class M,
class X,
class Y>
87 using PreconditionerSignature = std::shared_ptr<Preconditioner<X,Y>>(
const M&,
const ParameterTree&);
88 template<
class M,
class X,
class Y>
89 using PreconditionerFactory = Singleton<ParameterizedObjectFactory<PreconditionerSignature<M,X,Y>>>;
92 template<
class X,
class Y>
93 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&);
94 template<
class X,
class Y>
95 using IterativeSolverFactory = Singleton<ParameterizedObjectFactory<IterativeSolverSignature<X,Y>>>;
108 template<
class M,
class X,
class Y>
109 int initSolverFactories(){
112 addRegistryToFactory<TL>(dsfac, DirectSolverTag{});
114 addRegistryToFactory<TL>(pfac, PreconditionerTag{});
117 return addRegistryToFactory<TLS>(isfac, IterativeSolverTag{});
124 class UnsupportedType :
public NotImplemented {};
145 template<
class Operator>
147 using Domain =
typename Operator::domain_type;
148 using Range =
typename Operator::range_type;
153 using _matrix_type =
typename O::matrix_type;
155 static constexpr bool isAssembled = !std::is_same<matrix_type, int>::value;
157 static const matrix_type* getmat(std::shared_ptr<Operator> op){
158 std::shared_ptr<AssembledLinearOperator<matrix_type, Domain, Range>> aop
159 = std::dynamic_pointer_cast<AssembledLinearOperator<matrix_type, Domain, Range>>(op);
161 return &aop->getmat();
168 static std::shared_ptr<Solver> get(std::shared_ptr<Operator> op,
170 std::shared_ptr<Preconditioner> prec =
nullptr){
171 std::string type = config.
get<std::string>(
"type");
172 std::shared_ptr<Solver> result;
173 const matrix_type* mat = getmat(op);
186 std::string prec_type = precConfig.
get<std::string>(
"type");
192 std::shared_ptr<ScalarProduct<Domain>> sp = std::make_shared<SeqScalarProduct<Domain>>();
200 static std::shared_ptr<Preconditioner> getPreconditioner(std::shared_ptr<Operator> op,
202 const matrix_type* mat = getmat(op);
204 std::string prec_type = config.
get<std::string>(
"type");
222 template<
class Operator>
227 typename Operator::range_type>> prec =
nullptr){
Default exception if a function was called while the object is not in a valid state for that function...
Definition: exceptions.hh:279
Default exception for dummy implementations.
Definition: exceptions.hh:261
Hierarchical structure of string parameters.
Definition: parametertree.hh:35
std::string get(const std::string &key, const std::string &defaultValue) const
get value as string
Definition: parametertree.cc:183
ParameterTree & sub(const std::string &sub)
get substructure by name
Definition: parametertree.cc:101
Base class for matrix free definition of preconditioners.
Definition: preconditioner.hh:30
An adapter to turn a class into a singleton.
Definition: singleton.hh:54
static DUNE_EXPORT T & instance()
Get the instance of the singleton.
Definition: singleton.hh:68
Factory to assembly solvers configured by a ParameterTree.
Definition: solverfactory.hh:146
typename detected_or< Default, Op, Args... >::type detected_or_t
Returns Op<Args...> if that is valid; otherwise returns the fallback type Default.
Definition: type_traits.hh:384
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
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:224
std::tuple< MetaType< T >... > TypeList
A simple type list.
Definition: typelist.hh:87
Dune namespace.
Definition: alignedallocator.hh:14
A hierarchical structure of string parameters.
Useful wrapper for creating singletons.
Define general, extensible interface for inverse operators.
@ sequential
Category for sequential solvers.
Definition: solvercategory.hh:23