1#ifndef DUNE_COPASI_SOLVER_ISTL_FACTORY_PRECONDITIONER_HH
2#define DUNE_COPASI_SOLVER_ISTL_FACTORY_PRECONDITIONER_HH
9#include <dune/istl/blocklevel.hh>
10#include <dune/istl/preconditioner.hh>
11#include <dune/istl/preconditioners.hh>
13#include <dune/common/parameterizedobject.hh>
15#include <fmt/ranges.h>
17#define DUNE_COPASI_DEFAULT_PRECONDITIONER "SSOR"
21template<Concept::LinearOperator O,
class A>
23 std::shared_ptr<Preconditioner<typename O::domain_type, typename O::range_type>>(
24 const std::shared_ptr<O>&,
27template<Concept::LinearOperator O,
class A>
32template<
class Prec,
class Alloc,
bool matrix_free = false>
34defaultPreconditionerFactory(std::bool_constant<matrix_free> = {})
36 using X =
typename Prec::domain_type;
37 using Y =
typename Prec::range_type;
38 return [&](
const std::shared_ptr<LinearOperator<X, Y>>&
op,
40 const Alloc&
alloc) -> std::shared_ptr<Preconditioner<X, Y>> {
49 using M =
typename Prec::matrix_type;
50 auto aop = std::dynamic_pointer_cast<AssembledLinearOperator<M, X, Y>>(
op);
58template<
class X,
class Y,
class Alloc>
60inverseOperator2PreconditionerFactory()
62 return [](
const std::shared_ptr<LinearOperator<X, Y>>&
op,
64 const Alloc&
alloc) -> std::shared_ptr<Preconditioner<X, Y>> {
66 struct Prec :
public Dune::InverseOperator2Preconditioner<InverseOperator<X, Y>>
68 using InverseOperator2Preconditioner<InverseOperator<X, Y>>::InverseOperator2Preconditioner;
69 std::shared_ptr<InverseOperator<X, Y>> inverse;
87template<Concept::LinearOperator O,
class Alloc>
91 using X =
typename O::domain_type;
92 using Y =
typename O::range_type;
94 static std::once_flag
flag;
95 std::call_once(
flag, [] {
97 registry.define(
"InverseOperator", Impl::inverseOperator2PreconditionerFactory<X, Y, Alloc>());
100 using M =
typename O::matrix_type;
119template<Concept::LinearOperator Op,
class Alloc = std::allocator<Op>>
120std::shared_ptr<Preconditioner<typename Op::domain_type, typename Op::range_type>>
128 if (
config.get(
"verbosity", 1) > 0)
129 spdlog::info(
"Creating preconditioner with type '{}'",
type_name);
134 "The key '{}' is not a known preconditioner type. Allowed types are {}",
Definition block_jacobi.hh:18
simple wrapper that captures and exposes the keys of Dune::ParameterizedObjectFactory
Definition parameterized_object.hh:14
Definition concepts.hh:14
Definition block_jacobi.hh:14
const PreconditionerRegistry< O, Alloc > & getPreconditionerRegistry()
Definition preconditioner.hh:89
std::shared_ptr< Preconditioner< typename Op::domain_type, typename Op::range_type > > makePreconditioner(const std::shared_ptr< Op > &op, const ParameterTree &config, const Alloc &alloc=Alloc())
Definition preconditioner.hh:121
std::shared_ptr< Preconditioner< typename O::domain_type, typename O::range_type > >( const std::shared_ptr< O > &, const ParameterTree &, const A &) PreconditionerFactorySignature
Definition preconditioner.hh:22
auto format_exception(Exception &&e, fmt::format_string< Args... > format, Args &&... args)
Definition exceptions.hh:23
constexpr bool is_bitflags_v
Alias for Bitflag indicator.
Definition bit_flags.hh:24
#define DUNE_COPASI_DEFAULT_PRECONDITIONER
Definition preconditioner.hh:17