3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_COMMON_PDESOLVER_HH
25#define DUMUX_COMMON_PDESOLVER_HH
26
27#include <memory>
28#include <utility>
29
30#include <dune/common/hybridutilities.hh>
31#include <dune/common/std/type_traits.hh>
32
34
35// forward declare
36namespace Dune {
37template <class FirstRow, class ... Args>
39} // end namespace Dune
40
41namespace Dumux {
42namespace Detail {
43
44template<class Assembler>
45using AssemblerVariablesType = typename Assembler::Variables;
46
47template<class Assembler>
48inline constexpr bool exportsVariables = Dune::Std::is_detected_v<AssemblerVariablesType, Assembler>;
49
50template<class A, bool exports = exportsVariables<A>> struct VariablesChooser;
51template<class A> struct VariablesChooser<A, true> { using Type = AssemblerVariablesType<A>; };
52template<class A> struct VariablesChooser<A, false> { using Type = typename A::ResidualType; };
53
54template<class Assembler>
56
57} // end namespace Detail
58
70template<class A, class LS>
72{
73 using Scalar = typename A::Scalar;
75
76public:
78 using Assembler = A;
79 using LinearSolver = LS;
80
83
89 PDESolver(std::shared_ptr<Assembler> assembler,
90 std::shared_ptr<LinearSolver> linearSolver)
91 : assembler_(assembler)
92 , linearSolver_(linearSolver)
93 {}
94
95 virtual ~PDESolver() = default;
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
165private:
166 std::shared_ptr<Assembler> assembler_;
167 std::shared_ptr<LinearSolver> linearSolver_;
168};
169
170} // namespace Dumux
171
172#endif
Definition: adapt.hh:29
constexpr bool exportsVariables
Definition: common/pdesolver.hh:48
typename Assembler::Variables AssemblerVariablesType
Definition: common/pdesolver.hh:45
typename VariablesChooser< Assembler >::Type AssemblerVariables
Definition: common/pdesolver.hh:55
Definition: common/pdesolver.hh:36
Definition: common/pdesolver.hh:38
Definition: common/pdesolver.hh:50
AssemblerVariablesType< A > Type
Definition: common/pdesolver.hh:51
typename A::ResidualType Type
Definition: common/pdesolver.hh:52
A high-level interface for a PDESolver.
Definition: common/pdesolver.hh:72
LS LinearSolver
Definition: common/pdesolver.hh:79
Detail::AssemblerVariables< Assembler > Variables
export the type of variables that represent a numerical solution
Definition: common/pdesolver.hh:82
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:78
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:89
LinearSolver & linearSolver()
Access the linear solver.
Definition: common/pdesolver.hh:141
virtual ~PDESolver()=default
Manages the handling of time dependent problems.
Definition: common/timeloop.hh:69
Manages the handling of time dependent problems.