6#ifndef DUNE_ISTL_SOLVERFACTORY_HH
7#define DUNE_ISTL_SOLVERFACTORY_HH
9#include <unordered_map>
13#include <dune/common/parametertree.hh>
14#include <dune/common/std/type_traits.hh>
15#include <dune/common/singleton.hh>
16#include <dune/common/parameterizedobject.hh>
31 using PreconditionerSignature = std::shared_ptr<Preconditioner<typename OP::domain_type,typename OP::range_type>>(
const std::shared_ptr<OP>&,
const ParameterTree&);
37 using SolverSignature = std::shared_ptr<InverseOperator<typename OP::domain_type,typename OP::range_type>>(
const std::shared_ptr<OP>&,
const ParameterTree&);
39 using SolverFactory = Singleton<ParameterizedObjectFactory<SolverSignature<OP>>>;
41 template<
class Operator>
45 using _matrix_type =
typename O::matrix_type;
47 using _comm_type =
typename O::communication_type;
53 using matrix_type = Std::detected_or_t<int, _matrix_type, Operator>;
54 static constexpr bool isAssembled = !std::is_same<matrix_type, int>::value;
55 using comm_type = Std::detected_or_t<int, _comm_type, Operator>;
56 static constexpr bool isParallel = !std::is_same<comm_type, int>::value;
58 static const std::shared_ptr<AssembledLinearOperator<matrix_type, domain_type, range_type>>
60 std::shared_ptr<AssembledLinearOperator<matrix_type, domain_type, range_type>> aop
61 = std::dynamic_pointer_cast<AssembledLinearOperator<matrix_type, domain_type, range_type>>(op);
64 DUNE_THROW(
NoAssembledOperator,
"Failed to cast to AssembledLinearOperator. Please pass in an AssembledLinearOperator.");
68 std::shared_ptr<Operator> _op
69 = std::dynamic_pointer_cast<Operator>(op);
71 return _op->getCommunication();
73 DUNE_THROW(
NoAssembledOperator,
"Could not obtain communication object from operator. Please pass in a parallel operator.");
82 return std::make_shared<SeqScalarProduct<domain_type>>();
97 int initSolverFactories(){
98 using OpInfo = OperatorTraits<O>;
100 addRegistryToFactory<OpInfo>(pfac, PreconditionerTag{});
101 auto& isfac=Dune::SolverFactory<O>::instance();
102 return addRegistryToFactory<OpInfo>(isfac, SolverTag{});
130 template<
class Operator>
132 typename Operator::range_type>>
141 ParameterTree config_tmp = config;
142 config_tmp.sub(
"preconditioner")[
"type"] = std::string(
"__passed at runtime__");
144 create(config.get<std::string>(
"type"),op, config_tmp);
147 create(config.get<std::string>(
"type"),op, config);
154 template<
class Operator>
156 typename Operator::range_type>>
158 const ParameterTree& config){
159 using Domain =
typename Operator::domain_type;
160 using Range =
typename Operator::range_type;
161 std::string prec_type = config.get<std::string>(
"type");
168 return std::make_shared<BlockPreconditioner<Domain,Range,Comm> >(prec, comm);
170 return std::make_shared<NonoverlappingBlockPreconditioner<Comm, Preconditioner<Domain, Range>> >(prec, comm);
Define general, extensible interface for inverse operators.
Singleton< ParameterizedObjectFactory< SolverSignature< OP > > > SolverFactory
Definition solverfactory.hh:39
std::shared_ptr< Preconditioner< typename Operator::domain_type, typename Operator::range_type > > getPreconditionerFromFactory(std::shared_ptr< Operator > op, const ParameterTree &config)
Construct a Preconditioner for a given Operator.
Definition solverfactory.hh:157
Singleton< ParameterizedObjectFactory< PreconditionerSignature< OP > > > PreconditionerFactory
Definition solverfactory.hh:33
std::shared_ptr< Preconditioner< typename OP::domain_type, typename OP::range_type > >(const std::shared_ptr< OP > &, const ParameterTree &) PreconditionerSignature
Definition solverfactory.hh:31
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:133
std::shared_ptr< InverseOperator< typename OP::domain_type, typename OP::range_type > >(const std::shared_ptr< OP > &, const ParameterTree &) SolverSignature
Definition solverfactory.hh:37
Definition allocator.hh:11
std::shared_ptr< ScalarProduct< X > > createScalarProduct(const Comm &comm, SolverCategory::Category category)
Definition scalarproducts.hh:242
A linear operator.
Definition operators.hh:68
Base class for matrix free definition of preconditioners.
Definition preconditioner.hh:33
Abstract base class for all solvers.
Definition solver.hh:101
@ sequential
Category for sequential solvers.
Definition solvercategory.hh:25
@ nonoverlapping
Category for non-overlapping solvers.
Definition solvercategory.hh:27
@ overlapping
Category for overlapping solvers.
Definition solvercategory.hh:29
Definition solverfactory.hh:42
static constexpr bool isParallel
Definition solverfactory.hh:56
Std::detected_or_t< int, _matrix_type, Operator > matrix_type
Definition solverfactory.hh:53
Operator operator_type
Definition solverfactory.hh:51
typename Operator::domain_type domain_type
Definition solverfactory.hh:49
InverseOperator< domain_type, range_type > solver_type
Definition solverfactory.hh:52
typename Operator::range_type range_type
Definition solverfactory.hh:50
static constexpr bool isAssembled
Definition solverfactory.hh:54
static const comm_type & getCommOrThrow(std::shared_ptr< LinearOperator< domain_type, range_type > > op)
Definition solverfactory.hh:67
Std::detected_or_t< int, _comm_type, Operator > comm_type
Definition solverfactory.hh:55
static const std::shared_ptr< AssembledLinearOperator< matrix_type, domain_type, range_type > > getAssembledOpOrThrow(std::shared_ptr< LinearOperator< domain_type, range_type > > op)
Definition solverfactory.hh:59
static std::shared_ptr< ScalarProduct< domain_type > > getScalarProduct(std::shared_ptr< LinearOperator< domain_type, range_type > > op)
Definition solverfactory.hh:77
Definition solverfactory.hh:150
This exception is thrown if the requested solver or preconditioner needs an assembled matrix.
Definition solverregistry.hh:31