version 3.8
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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
13#ifndef DUMUX_FV_GRID_VARIABLES_HH
14#define DUMUX_FV_GRID_VARIABLES_HH
15
16#include <type_traits>
17#include <memory>
18
19namespace Dumux {
20
28template<class GG, class GVV, class GFVC>
30{
31public:
33 using GridGeometry = GG;
34
37
39 using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
40
42 using PrimaryVariables = typename VolumeVariables::PrimaryVariables;
43
45 using Scalar = std::decay_t<decltype(std::declval<PrimaryVariables>()[0])>;
46
49
50 template<class Problem>
51 FVGridVariables(std::shared_ptr<Problem> problem,
52 std::shared_ptr<const GridGeometry> gridGeometry)
54 , curGridVolVars_(*problem)
55 , prevGridVolVars_(*problem)
56 , gridFluxVarsCache_(*problem)
57 {}
58
60 template<class SolutionVector>
61 void init(const SolutionVector& curSol)
62 {
63 // resize and update the volVars with the initial solution
64 curGridVolVars_.update(*gridGeometry_, curSol);
65
66 // update the flux variables caches (always force flux cache update on initialization)
67 gridFluxVarsCache_.update(*gridGeometry_, curGridVolVars_, curSol, true);
68
69 // set the volvars of the previous time step in case we have an instationary problem
70 // note that this means some memory overhead in the case of enabled caching, however
71 // this it outweighted by the advantage of having a single grid variables object for
72 // stationary and instationary problems
73 prevGridVolVars_ = curGridVolVars_;
74 }
75
77 template<class SolutionVector>
78 void update(const SolutionVector& curSol, bool forceFluxCacheUpdate = false)
79 {
80 // resize and update the volVars with the initial solution
81 curGridVolVars_.update(*gridGeometry_, curSol);
82
83 // update the flux variables caches
84 gridFluxVarsCache_.update(*gridGeometry_, curGridVolVars_, curSol, forceFluxCacheUpdate);
85 }
86
88 template<class SolutionVector>
89 void updateAfterGridAdaption(const SolutionVector& curSol)
90 {
91 // update (always force flux cache update as the grid changed)
92 update(curSol, true);
93
94 // for instationary problems also update the variables
95 // for the previous time step to the new grid
96 prevGridVolVars_ = curGridVolVars_;
97 }
98
104 {
105 prevGridVolVars_ = curGridVolVars_;
106 }
107
109 template<class SolutionVector>
110 void resetTimeStep(const SolutionVector& solution)
111 {
112 // set the new time step vol vars to old vol vars
113 curGridVolVars_ = prevGridVolVars_;
114
115 // update the flux variables caches
116 gridFluxVarsCache_.update(*gridGeometry_, curGridVolVars_, solution);
117 }
118
121 { return gridFluxVarsCache_; }
122
125 { return gridFluxVarsCache_; }
126
129 { return curGridVolVars_; }
130
133 { return curGridVolVars_; }
134
137 { return prevGridVolVars_; }
138
141 { return prevGridVolVars_; }
142
145 { return *gridGeometry_; }
146
147protected:
148
149 std::shared_ptr<const GridGeometry> gridGeometry_;
150
151private:
152 GridVolumeVariables curGridVolVars_;
153 GridVolumeVariables prevGridVolVars_;
154
155 GridFluxVariablesCache gridFluxVarsCache_;
156};
157
158} // end namespace Dumux
159
160#endif
The grid variable class for finite volume schemes storing variables on scv and scvf (volume and flux ...
Definition: discretization/fvgridvariables.hh:30
GridVolumeVariables & curGridVolVars()
return the current volume variables
Definition: discretization/fvgridvariables.hh:132
const GridFluxVariablesCache & gridFluxVarsCache() const
return the flux variables cache
Definition: discretization/fvgridvariables.hh:120
GG GridGeometry
export type of the finite volume grid geometry
Definition: discretization/fvgridvariables.hh:33
typename VolumeVariables::PrimaryVariables PrimaryVariables
export primary variable type
Definition: discretization/fvgridvariables.hh:42
std::shared_ptr< const GridGeometry > gridGeometry_
pointer to the constant grid geometry
Definition: discretization/fvgridvariables.hh:149
const GridVolumeVariables & curGridVolVars() const
return the current volume variables
Definition: discretization/fvgridvariables.hh:128
void advanceTimeStep()
Sets the current state as the previous for next time step.
Definition: discretization/fvgridvariables.hh:103
GVV GridVolumeVariables
export type of the finite volume grid geometry
Definition: discretization/fvgridvariables.hh:36
GridFluxVariablesCache & gridFluxVarsCache()
return the flux variables cache
Definition: discretization/fvgridvariables.hh:124
void init(const SolutionVector &curSol)
initialize all variables (stationary case)
Definition: discretization/fvgridvariables.hh:61
const GridVolumeVariables & prevGridVolVars() const
return the volume variables of the previous time step (for instationary problems)
Definition: discretization/fvgridvariables.hh:136
const GridGeometry & gridGeometry() const
return the finite volume grid geometry
Definition: discretization/fvgridvariables.hh:144
GridVolumeVariables & prevGridVolVars()
return the volume variables of the previous time step (for instationary problems)
Definition: discretization/fvgridvariables.hh:140
typename GridVolumeVariables::VolumeVariables VolumeVariables
export type of the volume variables
Definition: discretization/fvgridvariables.hh:39
GFVC GridFluxVariablesCache
export type of the finite volume grid geometry
Definition: discretization/fvgridvariables.hh:48
void updateAfterGridAdaption(const SolutionVector &curSol)
update all variables after grid adaption
Definition: discretization/fvgridvariables.hh:89
void resetTimeStep(const SolutionVector &solution)
resets state to the one before time integration
Definition: discretization/fvgridvariables.hh:110
FVGridVariables(std::shared_ptr< Problem > problem, std::shared_ptr< const GridGeometry > gridGeometry)
Definition: discretization/fvgridvariables.hh:51
std::decay_t< decltype(std::declval< PrimaryVariables >()[0])> Scalar
export scalar type (TODO get it directly from the volvars)
Definition: discretization/fvgridvariables.hh:45
void update(const SolutionVector &curSol, bool forceFluxCacheUpdate=false)
update all variables
Definition: discretization/fvgridvariables.hh:78
Definition: adapt.hh:17