Dune Core Modules (unstable)

solverregistry.hh
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5
6#ifndef DUNE_ISTL_SOLVERREGISTRY_HH
7#define DUNE_ISTL_SOLVERREGISTRY_HH
8
9#include <dune/istl/common/registry.hh>
10#include <dune/istl/preconditioner.hh>
11#include <dune/istl/solver.hh>
12
13namespace Dune::Impl {
14 template<class C>
15 [[deprecated("DUNE_REGISTER_ITERATIVE_SOLVER is deprecated. Please use DUNE_REGISTER_SOLVER instead.")]]
16 auto translateToOldIterativeSolverInterface(C oldCreator){
17 return [=](auto optraits, auto&&... args){
18 using OpTraits = decltype(optraits);
19 using TL = TypeList<typename OpTraits::domain_type, typename OpTraits::range_type>;
20 return oldCreator(TL{}, args...);
21 };
22 }
23}
24
25#define DUNE_REGISTER_DIRECT_SOLVER(name, ...) \
26 _Pragma ("GCC warning \"'DUNE_REGISTER_DIRECT_SOLVER' macro is deprecated and will be removed after the release of DUNE 2.9. Please use 'DUNE_REGISTER_SOLVER'\"") \
27 DUNE_REGISTER_SOLVER(name, __VA_ARGS__);
28
29#define DUNE_REGISTER_ITERATIVE_SOLVER(name, ...) \
30 _Pragma ("GCC warning \"'DUNE_REGISTER_ITERATIVE_SOLVER' macro is deprecated and will be removed after the release of DUNE 2.9. Please use 'DUNE_REGISTER_SOLVER'\"") \
31 DUNE_REGISTER_SOLVER(name, Impl::translateToOldIterativeSolverInterface(__VA_ARGS__));
32
33#define DUNE_REGISTER_PRECONDITIONER(name, ...) \
34 DUNE_REGISTRY_PUT(PreconditionerTag, name, __VA_ARGS__)
35
36#define DUNE_REGISTER_SOLVER(name, ...) \
37 DUNE_REGISTRY_PUT(SolverTag, name, __VA_ARGS__)
38
39namespace Dune{
40
45 namespace {
46 struct PreconditionerTag {};
47 struct SolverTag {};
48 }
49
52
53 template<template<class,class,class,int>class Preconditioner, int blockLevel=1>
54 auto defaultPreconditionerBlockLevelCreator(){
55 return [](auto opInfo, const auto& linearOperator, const Dune::ParameterTree& config)
56 {
57 using OpInfo = std::decay_t<decltype(opInfo)>;
58 using Matrix = typename OpInfo::matrix_type;
59 using Domain = typename OpInfo::domain_type;
60 using Range = typename OpInfo::range_type;
61 std::shared_ptr<Dune::Preconditioner<Domain, Range>> preconditioner;
62 if constexpr (OpInfo::isAssembled){
63 const auto& A = opInfo.getAssembledOpOrThrow(linearOperator);
64 // const Matrix& matrix = A->getmat();
65 preconditioner
66 = std::make_shared<Preconditioner<Matrix, Domain, Range, blockLevel>>(A, config);
67 }else{
68 DUNE_THROW(NoAssembledOperator, "Could not obtain matrix from operator. Please pass in an AssembledLinearOperator.");
69 }
70 return preconditioner;
71 };
72 }
73
74 template<template<class,class,class>class Preconditioner>
75 auto defaultPreconditionerCreator(){
76 return [](auto opInfo, const auto& linearOperator, const Dune::ParameterTree& config)
77 {
78 using OpInfo = std::decay_t<decltype(opInfo)>;
79 using Matrix = typename OpInfo::matrix_type;
80 using Domain = typename OpInfo::domain_type;
81 using Range = typename OpInfo::range_type;
82 std::shared_ptr<Dune::Preconditioner<Domain, Range>> preconditioner;
83 if constexpr (OpInfo::isAssembled){
84 const auto& A = opInfo.getAssembledOpOrThrow(linearOperator);
85 // const Matrix& matrix = A->getmat();
86 preconditioner
87 = std::make_shared<Preconditioner<Matrix, Domain, Range>>(A, config);
88 }else{
89 DUNE_THROW(NoAssembledOperator, "Could not obtain matrix from operator. Please pass in an AssembledLinearOperator.");
90 }
91 return preconditioner;
92 };
93 }
94
95 template<template<class...>class Solver>
96 auto defaultIterativeSolverCreator(){
97 return [](auto opInfo,
98 const auto& linearOperator,
99 const Dune::ParameterTree& config)
100 {
101 using OpInfo = std::decay_t<decltype(opInfo)>;
102 using Operator = typename OpInfo::operator_type;
103 using Domain = typename OpInfo::domain_type;
104 using Range = typename OpInfo::range_type;
105 std::shared_ptr<Operator> _op = std::dynamic_pointer_cast<Operator>(linearOperator);
106 std::shared_ptr<Preconditioner<Domain,Range>> preconditioner = getPreconditionerFromFactory(_op, config.sub("preconditioner"));
107 std::shared_ptr<ScalarProduct<Range>> scalarProduct = opInfo.getScalarProduct(linearOperator);
108 std::shared_ptr<Dune::InverseOperator<Domain, Range>> solver
109 = std::make_shared<Solver<Domain>>(linearOperator, scalarProduct, preconditioner, config);
110 return solver;
111 };
112 }
113
114 /* This exception is thrown, when the requested solver is in the factory but
115 cannot be instantiated for the required template parameters
116 */
117 class UnsupportedType : public NotImplemented {};
118
119 class InvalidSolverFactoryConfiguration : public InvalidStateException{};
120} // end namespace Dune
121
122#endif // DUNE_ISTL_SOLVERREGISTRY_HH
Default exception if a function was called while the object is not in a valid state for that function...
Definition: exceptions.hh:373
A generic dynamic dense matrix.
Definition: matrix.hh:561
This exception is thrown if the requested solver or preconditioner needs an assembled matrix.
Definition: solverregistry.hh:51
Hierarchical structure of string parameters.
Definition: parametertree.hh:37
Base class for matrix free definition of preconditioners.
Definition: preconditioner.hh:33
#define DUNE_THROW(E,...)
Definition: exceptions.hh:312
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:175
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::size_t blockLevel()
Determine the block level of a possibly nested vector/matrix type.
Definition: blocklevel.hh:176
Define general, extensible interface for inverse operators.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)