version 3.10-dev
common/pdesolver.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_COMMON_PDESOLVER_HH
13#define DUMUX_COMMON_PDESOLVER_HH
14
15#include <memory>
16#include <utility>
17
18#include <dune/common/hybridutilities.hh>
19#include <dune/common/std/type_traits.hh>
20
22
23// forward declare
24namespace Dune {
25template <class FirstRow, class ... Args>
27} // end namespace Dune
28
30
31template<class Assembler>
32using AssemblerVariablesType = typename Assembler::Variables;
33
34template<class Assembler>
35inline constexpr bool assemblerExportsVariables = Dune::Std::is_detected_v<AssemblerVariablesType, Assembler>;
36
37template<class A, bool exports = assemblerExportsVariables<A>> struct VariablesChooser;
38template<class A> struct VariablesChooser<A, true> { using Type = AssemblerVariablesType<A>; };
39template<class A> struct VariablesChooser<A, false> { using Type = typename A::SolutionVector; };
40
41template<class Assembler>
43
44} // end namespace Dumux::Detail::PDESolver
45
46namespace Dumux {
47
59template<class A, class LS>
61{
62 using Scalar = typename A::Scalar;
64
65public:
67 using Assembler = A;
68 using LinearSolver = LS;
69
72
78 PDESolver(std::shared_ptr<Assembler> assembler,
79 std::shared_ptr<LinearSolver> linearSolver)
80 : assembler_(assembler)
81 , linearSolver_(linearSolver)
82 {}
83
84 virtual ~PDESolver() = default;
85
95 virtual bool apply(Variables& vars) = 0;
96
103 virtual void solve(Variables& vars) = 0;
104
112 virtual void solve(Variables& vars, TimeLoop& timeLoop)
113 {
114 // per default we just forward to the method without time step control
115 solve(vars);
116 }
117
121 const Assembler& assembler() const
122 { return *assembler_; }
123
128 { return *assembler_; }
129
134 { return *linearSolver_; }
135
136protected:
137
142 { return *linearSolver_; }
143
147 template <class FirstRow, class ... Args>
149 {
150 bool matrixHasCorrectSize = true;
151 using namespace Dune::Hybrid;
152 forEach(std::make_index_sequence<Dune::MultiTypeBlockMatrix<FirstRow, Args...>::N()>(), [&](const auto i)
153 {
154 const auto& row = matrix[i];
155 const auto numRowsLeftMostBlock = row[Dune::index_constant<0>{}].N();
156 forEach(row, [&](const auto& subBlock)
157 {
158 if (subBlock.N() != numRowsLeftMostBlock)
159 matrixHasCorrectSize = false;
160 });
161 });
162 return matrixHasCorrectSize;
163 }
164
168 template <class M>
169 bool checkSizesOfSubMatrices(const M&) const { return true; }
170
171private:
172 std::shared_ptr<Assembler> assembler_;
173 std::shared_ptr<LinearSolver> linearSolver_;
174};
175
176} // namespace Dumux
177
178#endif
A high-level interface for a PDESolver.
Definition: common/pdesolver.hh:61
LS LinearSolver
Definition: common/pdesolver.hh:68
virtual void solve(Variables &vars, TimeLoop &timeLoop)
Solve the given PDE system with time step control.
Definition: common/pdesolver.hh:112
A Assembler
export the assembler and linear solver types
Definition: common/pdesolver.hh:67
bool checkSizesOfSubMatrices(const M &) const
Default implementation for any matrix type.
Definition: common/pdesolver.hh:169
virtual bool apply(Variables &vars)=0
Solve the given PDE system (usually assemble + solve linear system + update)
bool checkSizesOfSubMatrices(const Dune::MultiTypeBlockMatrix< FirstRow, Args... > &matrix) const
Helper function to assure the MultiTypeBlockMatrix's sub-blocks have the correct sizes.
Definition: common/pdesolver.hh:148
const LinearSolver & linearSolver() const
Access the linear solver.
Definition: common/pdesolver.hh:133
virtual void solve(Variables &vars)=0
Solve the given PDE system (usually assemble + solve linear system + update)
Assembler & assembler()
Access the assembler.
Definition: common/pdesolver.hh:127
const Assembler & assembler() const
Access the assembler.
Definition: common/pdesolver.hh:121
PDESolver(std::shared_ptr< Assembler > assembler, std::shared_ptr< LinearSolver > linearSolver)
Constructor.
Definition: common/pdesolver.hh:78
LinearSolver & linearSolver()
Access the linear solver.
Definition: common/pdesolver.hh:141
virtual ~PDESolver()=default
Detail::PDESolver::AssemblerVariables< Assembler > Variables
export the type of variables that represent a numerical solution
Definition: common/pdesolver.hh:71
Definition: common/pdesolver.hh:26
Manages the handling of time dependent problems.
Definition: common/pdesolver.hh:29
typename VariablesChooser< Assembler >::Type AssemblerVariables
Definition: common/pdesolver.hh:42
typename Assembler::Variables AssemblerVariablesType
Definition: common/pdesolver.hh:32
constexpr bool assemblerExportsVariables
Definition: common/pdesolver.hh:35
Definition: adapt.hh:17
Definition: common/pdesolver.hh:24
typename A::SolutionVector Type
Definition: common/pdesolver.hh:39
AssemblerVariablesType< A > Type
Definition: common/pdesolver.hh:38
Definition: common/pdesolver.hh:37