3.2-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
33
34// forward declare
35namespace Dune {
36template <class FirstRow, class ... Args>
38}
39
40namespace Dumux {
41
53template<class Assembler, class LinearSolver>
55{
56 using SolutionVector = typename Assembler::ResidualType;
57 using Scalar = typename Assembler::Scalar;
59
60public:
61 PDESolver(std::shared_ptr<Assembler> assembler,
62 std::shared_ptr<LinearSolver> linearSolver)
63 : assembler_(assembler)
64 , linearSolver_(linearSolver)
65 {}
66
67 virtual ~PDESolver() = default;
68
73 virtual void solve(SolutionVector& sol) = 0;
74
82 virtual void solve(SolutionVector& sol, TimeLoop& timeLoop)
83 {
84 // per default we just forward to the method without time step control
85 solve(sol);
86 }
87
88protected:
92 const Assembler& assembler() const
93 { return *assembler_; }
94
98 Assembler& assembler()
99 { return *assembler_; }
100
105 { return *linearSolver_; }
106
111 { return *linearSolver_; }
112
116 template <class FirstRow, class ... Args>
118 {
119 bool matrixHasCorrectSize = true;
120 using namespace Dune::Hybrid;
121 forEach(std::make_index_sequence<Dune::MultiTypeBlockMatrix<FirstRow, Args...>::N()>(), [&](const auto i)
122 {
123 const auto& row = matrix[i];
124 const auto numRowsLeftMostBlock = row[Dune::index_constant<0>{}].N();
125 forEach(row, [&](const auto& subBlock)
126 {
127 if (subBlock.N() != numRowsLeftMostBlock)
128 matrixHasCorrectSize = false;
129 });
130 });
131 return matrixHasCorrectSize;
132 }
133
134private:
135 std::shared_ptr<Assembler> assembler_;
136 std::shared_ptr<LinearSolver> linearSolver_;
137};
138
139} // namespace Dumux
140
141#endif
Manages the handling of time dependent problems.
Definition: adapt.hh:29
Definition: common/pdesolver.hh:35
Definition: common/pdesolver.hh:37
A high-level interface for a PDESolver.
Definition: common/pdesolver.hh:55
virtual ~PDESolver()=default
virtual void solve(SolutionVector &sol, TimeLoop &timeLoop)
Solve the given PDE system with time step control.
Definition: common/pdesolver.hh:82
LinearSolver & linearSolver()
Access the linear solver.
Definition: common/pdesolver.hh:110
const Assembler & assembler() const
Access the assembler.
Definition: common/pdesolver.hh:92
const LinearSolver & linearSolver() const
Access the linear solver.
Definition: common/pdesolver.hh:104
virtual void solve(SolutionVector &sol)=0
Solve the given PDE system (usually assemble + solve linear system + update)
Assembler & assembler()
Access the assembler.
Definition: common/pdesolver.hh:98
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:117
PDESolver(std::shared_ptr< Assembler > assembler, std::shared_ptr< LinearSolver > linearSolver)
Definition: common/pdesolver.hh:61
Manages the handling of time dependent problems.
Definition: timeloop.hh:72
Base class for linear solvers.
Definition: solver.hh:37