DUNE-FEM (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
13#define DUNE_REGISTER_PRECONDITIONER(name, ...) \
14 DUNE_REGISTRY_PUT(PreconditionerTag, name, __VA_ARGS__)
15
16#define DUNE_REGISTER_SOLVER(name, ...) \
17 DUNE_REGISTRY_PUT(SolverTag, name, __VA_ARGS__)
18
19namespace Dune{
20
25 namespace {
26 struct PreconditionerTag {};
27 struct SolverTag {};
28 }
29
32
33 template<template<class,class,class,int>class Preconditioner, int blockLevel=1>
34 auto defaultPreconditionerBlockLevelCreator(){
35 return [](auto opInfo, const auto& linearOperator, const Dune::ParameterTree& config)
36 {
37 using OpInfo = std::decay_t<decltype(opInfo)>;
38 using Matrix = typename OpInfo::matrix_type;
39 using Domain = typename OpInfo::domain_type;
40 using Range = typename OpInfo::range_type;
41 std::shared_ptr<Dune::Preconditioner<Domain, Range>> preconditioner;
42 if constexpr (OpInfo::isAssembled){
43 const auto& A = opInfo.getAssembledOpOrThrow(linearOperator);
44 // const Matrix& matrix = A->getmat();
45 preconditioner
46 = std::make_shared<Preconditioner<Matrix, Domain, Range, blockLevel>>(A, config);
47 }else{
48 DUNE_THROW(NoAssembledOperator, "Could not obtain matrix from operator. Please pass in an AssembledLinearOperator.");
49 }
50 return preconditioner;
51 };
52 }
53
54 template<template<class,class,class>class Preconditioner>
55 auto defaultPreconditionerCreator(){
56 return [](auto opInfo, const auto& linearOperator, const Dune::ParameterTree& config)
57 {
58 using OpInfo = std::decay_t<decltype(opInfo)>;
59 using Matrix = typename OpInfo::matrix_type;
60 using Domain = typename OpInfo::domain_type;
61 using Range = typename OpInfo::range_type;
62 std::shared_ptr<Dune::Preconditioner<Domain, Range>> preconditioner;
63 if constexpr (OpInfo::isAssembled){
64 const auto& A = opInfo.getAssembledOpOrThrow(linearOperator);
65 // const Matrix& matrix = A->getmat();
66 preconditioner
67 = std::make_shared<Preconditioner<Matrix, Domain, Range>>(A, config);
68 }else{
69 DUNE_THROW(NoAssembledOperator, "Could not obtain matrix from operator. Please pass in an AssembledLinearOperator.");
70 }
71 return preconditioner;
72 };
73 }
74
75 template<template<class...>class Solver>
76 auto defaultIterativeSolverCreator(){
77 return [](auto opInfo,
78 const auto& linearOperator,
79 const Dune::ParameterTree& config)
80 {
81 using OpInfo = std::decay_t<decltype(opInfo)>;
82 using Operator = typename OpInfo::operator_type;
83 using Domain = typename OpInfo::domain_type;
84 using Range = typename OpInfo::range_type;
85 std::shared_ptr<Operator> _op = std::dynamic_pointer_cast<Operator>(linearOperator);
86 std::shared_ptr<Preconditioner<Domain,Range>> preconditioner = getPreconditionerFromFactory(_op, config.sub("preconditioner"));
87 std::shared_ptr<ScalarProduct<Range>> scalarProduct = opInfo.getScalarProduct(linearOperator);
88 std::shared_ptr<Dune::InverseOperator<Domain, Range>> solver
89 = std::make_shared<Solver<Domain>>(linearOperator, scalarProduct, preconditioner, config);
90 return solver;
91 };
92 }
93
94 /* This exception is thrown, when the requested solver is in the factory but
95 cannot be instantiated for the required template parameters
96 */
97 class UnsupportedType : public NotImplemented {};
98
99 class InvalidSolverFactoryConfiguration : public InvalidStateException{};
100} // end namespace Dune
101
102#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:375
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:31
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:314
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
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 & Uni Heidelberg  |  generated with Hugo v0.111.3 (Jan 9, 23:34, 2026)