3.4
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
discretization/fvgridvariables.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 *****************************************************************************/
25#ifndef DUMUX_FV_GRID_VARIABLES_HH
26#define DUMUX_FV_GRID_VARIABLES_HH
27
28#include <type_traits>
29#include <memory>
30
31namespace Dumux {
32
40template<class GG, class GVV, class GFVC>
42{
43public:
45 using GridGeometry = GG;
46
49
51 using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
52
54 using PrimaryVariables = typename VolumeVariables::PrimaryVariables;
55
57 using Scalar = std::decay_t<decltype(std::declval<PrimaryVariables>()[0])>;
58
61
62 template<class Problem>
63 FVGridVariables(std::shared_ptr<Problem> problem,
64 std::shared_ptr<const GridGeometry> gridGeometry)
66 , curGridVolVars_(*problem)
67 , prevGridVolVars_(*problem)
68 , gridFluxVarsCache_(*problem)
69 {}
70
72 template<class SolutionVector>
73 void init(const SolutionVector& curSol)
74 {
75 // resize and update the volVars with the initial solution
76 curGridVolVars_.update(*gridGeometry_, curSol);
77
78 // update the flux variables caches (always force flux cache update on initialization)
79 gridFluxVarsCache_.update(*gridGeometry_, curGridVolVars_, curSol, true);
80
81 // set the volvars of the previous time step in case we have an instationary problem
82 // note that this means some memory overhead in the case of enabled caching, however
83 // this it outweighted by the advantage of having a single grid variables object for
84 // stationary and instationary problems
85 prevGridVolVars_ = curGridVolVars_;
86 }
87
89 template<class SolutionVector>
90 void update(const SolutionVector& curSol, bool forceFluxCacheUpdate = false)
91 {
92 // resize and update the volVars with the initial solution
93 curGridVolVars_.update(*gridGeometry_, curSol);
94
95 // update the flux variables caches
96 gridFluxVarsCache_.update(*gridGeometry_, curGridVolVars_, curSol, forceFluxCacheUpdate);
97 }
98
100 template<class SolutionVector>
101 void updateAfterGridAdaption(const SolutionVector& curSol)
102 {
103 // update (always force flux cache update as the grid changed)
104 update(curSol, true);
105
106 // for instationary problems also update the variables
107 // for the previous time step to the new grid
108 prevGridVolVars_ = curGridVolVars_;
109 }
110
116 {
117 prevGridVolVars_ = curGridVolVars_;
118 }
119
121 template<class SolutionVector>
122 void resetTimeStep(const SolutionVector& solution)
123 {
124 // set the new time step vol vars to old vol vars
125 curGridVolVars_ = prevGridVolVars_;
126
127 // update the flux variables caches
128 gridFluxVarsCache_.update(*gridGeometry_, curGridVolVars_, solution);
129 }
130
133 { return gridFluxVarsCache_; }
134
137 { return gridFluxVarsCache_; }
138
141 { return curGridVolVars_; }
142
145 { return curGridVolVars_; }
146
149 { return prevGridVolVars_; }
150
153 { return prevGridVolVars_; }
154
157 { return *gridGeometry_; }
158
159protected:
160
161 std::shared_ptr<const GridGeometry> gridGeometry_;
162
163private:
164 GridVolumeVariables curGridVolVars_;
165 GridVolumeVariables prevGridVolVars_;
166
167 GridFluxVariablesCache gridFluxVarsCache_;
168};
169
170} // end namespace Dumux
171
173// Experimental implementation of new grid variables layout //
175
179
180namespace Dumux::Experimental {
181
187template<class GV>
189{
190 using GridGeometry = typename GV::GridGeometry;
191 using FVElementGeometry = typename GridGeometry::LocalView;
192
193 using GridView = typename GridGeometry::GridView;
194 using Element = typename GridView::template Codim<0>::Entity;
195
196 using ElementVolumeVariables = typename GV::GridVolumeVariables::LocalView;
197 using ElementFluxVariablesCache = typename GV::GridFluxVariablesCache::LocalView;
198
199public:
201 using GridVariables = GV;
202
205 : gridVariables_(&gridVariables)
206 , elemVolVars_(gridVariables.gridVolVars())
207 , elemFluxVarsCache_(gridVariables.gridFluxVarsCache())
208 {}
209
215 void bind(const Element& element,
216 const FVElementGeometry& fvGeometry)
217 {
218 const auto& x = gridVariables().dofs();
219 elemVolVars_.bind(element, fvGeometry, x);
220 elemFluxVarsCache_.bind(element, fvGeometry, elemVolVars_);
221 }
222
228 void bindElemVolVars(const Element& element,
229 const FVElementGeometry& fvGeometry)
230 {
231 elemVolVars_.bind(element, fvGeometry, gridVariables().dofs());
232
233 // unbind flux variables cache
234 elemFluxVarsCache_ = localView(gridVariables().gridFluxVarsCache());
235 }
236
238 const ElementVolumeVariables& elemVolVars() const { return elemVolVars_; }
239 ElementVolumeVariables& elemVolVars() { return elemVolVars_; }
240
242 const ElementFluxVariablesCache& elemFluxVarsCache() const { return elemFluxVarsCache_; }
243 ElementFluxVariablesCache& elemFluxVarsCache() { return elemFluxVarsCache_; }
244
247 { return *gridVariables_; }
248
249private:
250 const GridVariables* gridVariables_;
251 ElementVolumeVariables elemVolVars_;
252 ElementFluxVariablesCache elemFluxVarsCache_;
253};
254
263template<class GVV, class GFVC, class X>
265: public GridVariables<typename ProblemTraits<typename GVV::Problem>::GridGeometry, X>
266{
267 using Problem = typename GVV::Problem;
268 using GG = typename ProblemTraits<Problem>::GridGeometry;
269
272
273public:
274 using typename ParentType::SolutionVector;
275
277 using GridGeometry = GG;
278
281
283 using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
284
286 using PrimaryVariables = typename VolumeVariables::PrimaryVariables;
287
290
293
302 FVGridVariables(std::shared_ptr<Problem> problem,
303 std::shared_ptr<const GridGeometry> gridGeometry)
304 : ParentType(gridGeometry, [problem] (auto& x) { problem->applyInitialSolution(x); })
305 , gridVolVars_(*problem)
306 , gridFluxVarsCache_(*problem)
307 {}
308
317 template<class SolOrInitializer>
318 FVGridVariables(std::shared_ptr<Problem> problem,
319 std::shared_ptr<const GridGeometry> gridGeometry,
320 SolOrInitializer&& solOrInitializer)
321 : ParentType(gridGeometry, std::forward<SolOrInitializer>(solOrInitializer))
322 , gridVolVars_(*problem)
323 , gridFluxVarsCache_(*problem)
324 {
325 gridVolVars_.update(this->gridGeometry(), this->dofs());
326 gridFluxVarsCache_.update(this->gridGeometry(), gridVolVars_, this->dofs(), true);
327 }
328
330 void update(const SolutionVector& curSol)
331 {
332 ParentType::update(curSol);
333
334 // resize and update the volVars with the initial solution
335 gridVolVars_.update(this->gridGeometry(), curSol);
336
337 // update the flux variables caches
338 gridFluxVarsCache_.update(this->gridGeometry(), gridVolVars_, curSol);
339 }
340
342 void forceUpdateAll(const SolutionVector& curSol)
343 {
344 ParentType::update(curSol);
345
346 // resize and update the volVars with the initial solution
347 gridVolVars_.update(this->gridGeometry(), curSol);
348
349 // update the flux variables caches
350 gridFluxVarsCache_.update(this->gridGeometry(), gridVolVars_, curSol, true);
351 }
352
355 { return gridFluxVarsCache_; }
356
359 { return gridFluxVarsCache_; }
360
363 { return gridVolVars_; }
364
367 { return gridVolVars_; }
368
369private:
370 GridVolumeVariables gridVolVars_;
371 GridFluxVariablesCache gridFluxVarsCache_;
372};
373
374} // end namespace Dumux::Experimental
375
376#endif
Free function to get the local view of a grid cache object.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:38
Definition: adapt.hh:29
Definition: variables.hh:32
std::decay_t< decltype(std::declval< Problem >().gridGeometry())> GridGeometry
Definition: common/typetraits/problem.hh:45
void update(const SolutionVector &x)
Update the state to a new solution.
Definition: variables.hh:108
const SolutionVector & dofs() const
Return reference to the solution.
Definition: variables.hh:102
X SolutionVector
export the type of solution vector
Definition: variables.hh:64
The grid variable class for finite volume schemes storing variables on scv and scvf (volume and flux ...
Definition: discretization/fvgridvariables.hh:42
GridVolumeVariables & curGridVolVars()
return the current volume variables
Definition: discretization/fvgridvariables.hh:144
const GridFluxVariablesCache & gridFluxVarsCache() const
return the flux variables cache
Definition: discretization/fvgridvariables.hh:132
GG GridGeometry
export type of the finite volume grid geometry
Definition: discretization/fvgridvariables.hh:45
typename VolumeVariables::PrimaryVariables PrimaryVariables
export primary variable type
Definition: discretization/fvgridvariables.hh:54
std::shared_ptr< const GridGeometry > gridGeometry_
pointer to the constant grid geometry
Definition: discretization/fvgridvariables.hh:161
const GridVolumeVariables & curGridVolVars() const
return the current volume variables
Definition: discretization/fvgridvariables.hh:140
void advanceTimeStep()
Sets the current state as the previous for next time step.
Definition: discretization/fvgridvariables.hh:115
GVV GridVolumeVariables
export type of the finite volume grid geometry
Definition: discretization/fvgridvariables.hh:48
GridFluxVariablesCache & gridFluxVarsCache()
return the flux variables cache
Definition: discretization/fvgridvariables.hh:136
void init(const SolutionVector &curSol)
initialize all variables (stationary case)
Definition: discretization/fvgridvariables.hh:73
const GridVolumeVariables & prevGridVolVars() const
return the volume variables of the previous time step (for instationary problems)
Definition: discretization/fvgridvariables.hh:148
const GridGeometry & gridGeometry() const
return the finite volume grid geometry
Definition: discretization/fvgridvariables.hh:156
GridVolumeVariables & prevGridVolVars()
return the volume variables of the previous time step (for instationary problems)
Definition: discretization/fvgridvariables.hh:152
typename GridVolumeVariables::VolumeVariables VolumeVariables
export type of the volume variables
Definition: discretization/fvgridvariables.hh:51
GFVC GridFluxVariablesCache
export type of the finite volume grid geometry
Definition: discretization/fvgridvariables.hh:60
void updateAfterGridAdaption(const SolutionVector &curSol)
update all variables after grid adaption
Definition: discretization/fvgridvariables.hh:101
void resetTimeStep(const SolutionVector &solution)
resets state to the one before time integration
Definition: discretization/fvgridvariables.hh:122
FVGridVariables(std::shared_ptr< Problem > problem, std::shared_ptr< const GridGeometry > gridGeometry)
Definition: discretization/fvgridvariables.hh:63
std::decay_t< decltype(std::declval< PrimaryVariables >()[0])> Scalar
export scalar type (TODO get it directly from the volvars)
Definition: discretization/fvgridvariables.hh:57
void update(const SolutionVector &curSol, bool forceFluxCacheUpdate=false)
update all variables
Definition: discretization/fvgridvariables.hh:90
Finite volume-specific local view on grid variables.
Definition: discretization/fvgridvariables.hh:189
GV GridVariables
export corresponding grid-wide class
Definition: discretization/fvgridvariables.hh:201
ElementVolumeVariables & elemVolVars()
Definition: discretization/fvgridvariables.hh:239
FVGridVariablesLocalView(const GridVariables &gridVariables)
Constructor.
Definition: discretization/fvgridvariables.hh:204
const ElementVolumeVariables & elemVolVars() const
return reference to the elem vol vars
Definition: discretization/fvgridvariables.hh:238
void bindElemVolVars(const Element &element, const FVElementGeometry &fvGeometry)
Bind only the volume variables local view to a grid element.
Definition: discretization/fvgridvariables.hh:228
ElementFluxVariablesCache & elemFluxVarsCache()
Definition: discretization/fvgridvariables.hh:243
const ElementFluxVariablesCache & elemFluxVarsCache() const
return reference to the flux variables cache
Definition: discretization/fvgridvariables.hh:242
void bind(const Element &element, const FVElementGeometry &fvGeometry)
Bind this local view to a grid element.
Definition: discretization/fvgridvariables.hh:215
const GridVariables & gridVariables() const
Return reference to the grid variables.
Definition: discretization/fvgridvariables.hh:246
The grid variable class for finite volume schemes, storing variables on scv and scvf (volume and flux...
Definition: discretization/fvgridvariables.hh:266
GG GridGeometry
export type of the finite volume grid geometry
Definition: discretization/fvgridvariables.hh:277
void update(const SolutionVector &curSol)
Update all variables that may be affected by a change in solution.
Definition: discretization/fvgridvariables.hh:330
typename GridVolumeVariables::VolumeVariables VolumeVariables
export type of the volume variables
Definition: discretization/fvgridvariables.hh:283
GridFluxVariablesCache & gridFluxVarsCache()
return the flux variables cache
Definition: discretization/fvgridvariables.hh:358
GFVC GridFluxVariablesCache
export cache type for flux variables
Definition: discretization/fvgridvariables.hh:289
void forceUpdateAll(const SolutionVector &curSol)
Force the update of all variables.
Definition: discretization/fvgridvariables.hh:342
GVV GridVolumeVariables
export type of the grid volume variables
Definition: discretization/fvgridvariables.hh:280
FVGridVariables(std::shared_ptr< Problem > problem, std::shared_ptr< const GridGeometry > gridGeometry)
Constructor.
Definition: discretization/fvgridvariables.hh:302
GridVolumeVariables & gridVolVars()
return the current volume variables
Definition: discretization/fvgridvariables.hh:366
const GridFluxVariablesCache & gridFluxVarsCache() const
return the flux variables cache
Definition: discretization/fvgridvariables.hh:354
const GridVolumeVariables & gridVolVars() const
return the current volume variables
Definition: discretization/fvgridvariables.hh:362
typename VolumeVariables::PrimaryVariables PrimaryVariables
export primary variable type
Definition: discretization/fvgridvariables.hh:286
FVGridVariables(std::shared_ptr< Problem > problem, std::shared_ptr< const GridGeometry > gridGeometry, SolOrInitializer &&solOrInitializer)
Constructor with custom initialization of the solution.
Definition: discretization/fvgridvariables.hh:318
Base class for grid variables.
Definition: discretization/gridvariables.hh:43
const GridGeometry & gridGeometry() const
Return a reference to the grid geometry.
Definition: discretization/gridvariables.hh:62
Type traits for problem classes.
Base class for grid variables.