3.1-git
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 *****************************************************************************/
24#ifndef DUMUX_FV_GRID_VARIABLES_HH
25#define DUMUX_FV_GRID_VARIABLES_HH
26
27#include <type_traits>
28#include <memory>
29#include <cassert>
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 [[deprecated("Use init(sol) instead. The class now works without modification for stationary and instationary cases.")]]
91 void init(const SolutionVector& curSol, const SolutionVector& initSol)
92 {
93 // initialize current volvars and the flux var cache
94 init(initSol);
95 }
96
98 template<class SolutionVector>
99 void update(const SolutionVector& curSol, bool forceFluxCacheUpdate = false)
100 {
101 // resize and update the volVars with the initial solution
102 curGridVolVars_.update(*gridGeometry_, curSol);
103
104 // update the flux variables caches
105 gridFluxVarsCache_.update(*gridGeometry_, curGridVolVars_, curSol, forceFluxCacheUpdate);
106 }
107
109 template<class SolutionVector>
110 void updateAfterGridAdaption(const SolutionVector& curSol)
111 {
112 // update (always force flux cache update as the grid changed)
113 update(curSol, true);
114
115 // for instationary problems also update the variables
116 // for the previous time step to the new grid
117 prevGridVolVars_ = curGridVolVars_;
118 }
119
125 {
126 prevGridVolVars_ = curGridVolVars_;
127 }
128
130 template<class SolutionVector>
131 void resetTimeStep(const SolutionVector& solution)
132 {
133 // set the new time step vol vars to old vol vars
134 curGridVolVars_ = prevGridVolVars_;
135
136 // update the flux variables caches
137 gridFluxVarsCache_.update(*gridGeometry_, curGridVolVars_, solution);
138 }
139
142 { return gridFluxVarsCache_; }
143
146 { return gridFluxVarsCache_; }
147
150 { return curGridVolVars_; }
151
154 { return curGridVolVars_; }
155
158 { return prevGridVolVars_; }
159
162 { return prevGridVolVars_; }
163
165 [[deprecated("Use gridGeometry() instead. fvGridGeometry() will be removed after 3.1!")]]
167 { return gridGeometry(); }
168
171 { return *gridGeometry_; }
172
173protected:
174
175 std::shared_ptr<const GridGeometry> gridGeometry_;
176
177private:
178 GridVolumeVariables curGridVolVars_;
179 GridVolumeVariables prevGridVolVars_;
180
181 GridFluxVariablesCache gridFluxVarsCache_;
182};
183
184} // end namespace Dumux
185
186#endif
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
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:153
const GridFluxVariablesCache & gridFluxVarsCache() const
return the flux variables cache
Definition: discretization/fvgridvariables.hh:141
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:175
const GridVolumeVariables & curGridVolVars() const
return the current volume variables
Definition: discretization/fvgridvariables.hh:149
void advanceTimeStep()
Sets the current state as the previous for next time step.
Definition: discretization/fvgridvariables.hh:124
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:145
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:157
const GridGeometry & fvGridGeometry() const
return the finite volume grid geometry
Definition: discretization/fvgridvariables.hh:166
const GridGeometry & gridGeometry() const
return the finite volume grid geometry
Definition: discretization/fvgridvariables.hh:170
void init(const SolutionVector &curSol, const SolutionVector &initSol)
initialize all variables (instationary case)
Definition: discretization/fvgridvariables.hh:91
GridVolumeVariables & prevGridVolVars()
return the volume variables of the previous time step (for instationary problems)
Definition: discretization/fvgridvariables.hh:161
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:110
void resetTimeStep(const SolutionVector &solution)
resets state to the one before time integration
Definition: discretization/fvgridvariables.hh:131
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:99