3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
variablesbackend.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 *****************************************************************************/
26#ifndef DUMUX_COMMON_VARIABLES_BACKEND_HH
27#define DUMUX_COMMON_VARIABLES_BACKEND_HH
28
29#include <array>
30#include <utility>
31#include <type_traits>
32
33#include <dune/common/indices.hh>
34#include <dune/common/typetraits.hh>
35#include <dune/common/hybridutilities.hh>
36#include <dune/common/std/type_traits.hh>
37#include <dune/istl/bvector.hh>
38
39// forward declaration
40namespace Dune {
41
42template<class... Args>
44
45} // end namespace Dune
46
47namespace Dumux {
48
53template<class DofVector, bool isScalar = Dune::IsNumber<DofVector>::value>
55
60template<class Scalar>
61class DofBackend<Scalar, true>
62{
63public:
64 using DofVector = Scalar;
65 using SizeType = std::size_t;
66
68 static SizeType size(const DofVector& d)
69 { return 1; }
70
73 { return 0.0; }
74
76 static void axpy(Scalar a, const DofVector& x, DofVector& y)
77 { y += a*x; }
78};
79
89template<class Vector>
90class DofBackend<Vector, false>
91{
92public:
93 using DofVector = Vector;
94 using SizeType = std::size_t;
95
97 static SizeType size(const DofVector& d)
98 { return d.size(); }
99
102 { DofVector d; d.resize(size); return d; }
103
105 static void axpy(typename DofVector::field_type a, const DofVector& x, DofVector& y)
106 { y.axpy(a, x); }
107};
108
113template<class... Blocks>
114class DofBackend<Dune::MultiTypeBlockVector<Blocks...>, false>
115{
116 using DV = Dune::MultiTypeBlockVector<Blocks...>;
117 static constexpr auto numBlocks = DV::size();
118
119 using VectorSizeInfo = std::array<std::size_t, numBlocks>;
120
121public:
122 using DofVector = DV;
123 using SizeType = VectorSizeInfo;
124
126 static SizeType size(const DofVector& d)
127 {
128 VectorSizeInfo result;
129 using namespace Dune::Hybrid;
130 forEach(std::make_index_sequence<numBlocks>{}, [&](auto i) {
131 result[i] = d[Dune::index_constant<i>{}].size();
132 });
133 return result;
134 }
135
137 static DofVector zeros(const SizeType& size)
138 {
139 DofVector result;
140 using namespace Dune::Hybrid;
141 forEach(std::make_index_sequence<numBlocks>{}, [&](auto i) {
142 result[Dune::index_constant<i>{}].resize(size[i]);
143 });
144 return result;
145 }
146
148 template<class Scalar, std::enable_if_t< Dune::IsNumber<Scalar>::value, int> = 0>
149 static void axpy(Scalar a, const DofVector& x, DofVector& y)
150 { y.axpy(a, x); }
151};
152
153namespace Detail {
154
155template<class Vars>
156using SolutionVectorType = typename Vars::SolutionVector;
157
158template<class Vars, bool varsExportSolution>
160
167template<class Vars>
168class VariablesBackend<Vars, false>
169: public DofBackend<Vars>
170{
172
173public:
174 using Variables = Vars;
175 using typename ParentType::DofVector;
176
178 static void update(Variables& v, const DofVector& dofs)
179 { v = dofs; }
180
182 static const DofVector& dofs(const Variables& v)
183 { return v; }
184
186 static DofVector& dofs(Variables& v)
187 { return v; }
188};
189
196template<class Vars>
197class VariablesBackend<Vars, true>
198: public DofBackend<typename Vars::SolutionVector>
199{
200public:
201 using DofVector = typename Vars::SolutionVector;
202 using Variables = Vars;
203
205 static void update(Variables& v, const DofVector& dofs)
206 { v.update(dofs); }
207
209 static const DofVector& dofs(const Variables& v)
210 { return v.dofs(); }
211
214 { return v.dofs(); }
215};
216} // end namespace Detail
217
225template<class Vars>
227
228} // end namespace Dumux
229
230#endif
Definition: adapt.hh:29
typename Vars::SolutionVector SolutionVectorType
Definition: variablesbackend.hh:156
Definition: common/pdesolver.hh:36
Definition: variablesbackend.hh:43
Class providing operations with primary variable vectors.
Definition: variablesbackend.hh:54
static void axpy(Scalar a, const DofVector &x, DofVector &y)
Perform axpy operation (y += a * x)
Definition: variablesbackend.hh:76
static SizeType size(const DofVector &d)
Return the number of entries in the dof vector.
Definition: variablesbackend.hh:68
static DofVector zeros(SizeType size)
Make a zero-initialized dof vector instance.
Definition: variablesbackend.hh:72
std::size_t SizeType
Definition: variablesbackend.hh:65
Scalar DofVector
the type of the dofs parametrizing the variables object
Definition: variablesbackend.hh:64
static SizeType size(const DofVector &d)
Return the number of entries in the dof vector.
Definition: variablesbackend.hh:97
std::size_t SizeType
Definition: variablesbackend.hh:94
Vector DofVector
the type of the dofs parametrizing the variables object
Definition: variablesbackend.hh:93
static DofVector zeros(SizeType size)
Make a zero-initialized dof vector instance.
Definition: variablesbackend.hh:101
static void axpy(typename DofVector::field_type a, const DofVector &x, DofVector &y)
Perform axpy operation (y += a * x)
Definition: variablesbackend.hh:105
static SizeType size(const DofVector &d)
Return the number of entries in the sub-dof-vectors.
Definition: variablesbackend.hh:126
static void axpy(Scalar a, const DofVector &x, DofVector &y)
Perform axpy operation (y += a * x)
Definition: variablesbackend.hh:149
VectorSizeInfo SizeType
Definition: variablesbackend.hh:123
static DofVector zeros(const SizeType &size)
Make a zero-initialized dof vector instance.
Definition: variablesbackend.hh:137
Definition: variablesbackend.hh:159
static void update(Variables &v, const DofVector &dofs)
update to new solution vector
Definition: variablesbackend.hh:178
Vars Variables
Definition: variablesbackend.hh:174
static const DofVector & dofs(const Variables &v)
return const reference to dof vector
Definition: variablesbackend.hh:182
static DofVector & dofs(Variables &v)
return reference to dof vector
Definition: variablesbackend.hh:186
static void update(Variables &v, const DofVector &dofs)
update to new solution vector
Definition: variablesbackend.hh:205
Vars Variables
the type of the variables object
Definition: variablesbackend.hh:202
static DofVector & dofs(Variables &v)
return reference to dof vector
Definition: variablesbackend.hh:213
static const DofVector & dofs(const Variables &v)
return const reference to dof vector
Definition: variablesbackend.hh:209
typename Vars::SolutionVector DofVector
Definition: variablesbackend.hh:201