version 3.11-dev
discretization/gridvariables.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-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_GRID_VARIABLES_HH
13#define DUMUX_GRID_VARIABLES_HH
14
15#include <memory>
16
17namespace Dumux::Experimental {
18
25template<class GG, class GVC>
27{
28public:
30 using GridGeometry = GG;
31
33 using GridVariablesCache = GVC;
34
36 using Variables = typename GridVariablesCache::Variables;
37
39 using PrimaryVariables = typename Variables::PrimaryVariables;
40
42 using Scalar = typename PrimaryVariables::value_type;
43
44 template<class Problem>
45 GridVariables(std::shared_ptr<Problem> problem,
46 std::shared_ptr<const GridGeometry> gridGeometry)
48 , curGridVars_(*problem)
49 , prevGridVars_(*problem)
50 {}
51
53 template<class SolutionVector>
54 void init(const SolutionVector& curSol)
55 {
56 // initialize and update the current grid variables with a given solution
57 curGridVars_.init(*gridGeometry_, curSol);
58
59 // set the variables of the previous time step in case we have an instationary problem
60 // note that this means some memory overhead in the case of enabled caching, however
61 // this is outweighed by the advantage of having a single grid variables object for
62 // stationary and instationary problems
63 prevGridVars_ = curGridVars_;
64 }
65
67 template<class SolutionVector>
68 void update(const SolutionVector& curSol)
69 {
70 // update the current grid variables for the given solution
71 curGridVars_.update(*gridGeometry_, curSol);
72 }
73
75 template<class SolutionVector>
76 void updateAfterGridAdaption(const SolutionVector& curSol)
77 {
78 // update (always force data cache update as the grid changed)
79 curGridVars_.init(*gridGeometry_, curSol);
80
81 // for instationary problems also update the variables
82 // for the previous time step to the new grid
83 prevGridVars_ = curGridVars_;
84 }
85
91 {
92 prevGridVars_ = curGridVars_;
93 }
94
96 template<class SolutionVector>
97 void resetTimeStep(const SolutionVector& solution)
98 {
99 // set the new time step variables to old variables
100 curGridVars_ = prevGridVars_;
101 }
102
105 { return curGridVars_; }
106
109 { return curGridVars_; }
110
113 { return prevGridVars_; }
114
117 { return prevGridVars_; }
118
121 { return *gridGeometry_; }
122
123protected:
124 std::shared_ptr<const GridGeometry> gridGeometry_;
125
126private:
127 GridVariablesCache curGridVars_;
128 GridVariablesCache prevGridVars_;
129};
130
131} // end namespace Dumux::Experimental
132
133#endif
The grid variables class for general schemes, storing variables and data.
Definition: discretization/gridvariables.hh:27
const GridVariablesCache & curGridVars() const
return the current variables
Definition: discretization/gridvariables.hh:104
void resetTimeStep(const SolutionVector &solution)
resets state to the one before time integration
Definition: discretization/gridvariables.hh:97
const GridGeometry & gridGeometry() const
return the grid discretization
Definition: discretization/gridvariables.hh:120
GG GridGeometry
export type of the grid discretization
Definition: discretization/gridvariables.hh:30
GridVariables(std::shared_ptr< Problem > problem, std::shared_ptr< const GridGeometry > gridGeometry)
Definition: discretization/gridvariables.hh:45
void update(const SolutionVector &curSol)
update all variables
Definition: discretization/gridvariables.hh:68
typename PrimaryVariables::value_type Scalar
export scalar
Definition: discretization/gridvariables.hh:42
std::shared_ptr< const GridGeometry > gridGeometry_
pointer to the constant grid geometry
Definition: discretization/gridvariables.hh:124
const GridVariablesCache & prevGridVars() const
return the variables of the previous time step (for instationary problems)
Definition: discretization/gridvariables.hh:112
GridVariablesCache & curGridVars()
return the current variables
Definition: discretization/gridvariables.hh:108
typename Variables::PrimaryVariables PrimaryVariables
export primary variable type
Definition: discretization/gridvariables.hh:39
GridVariablesCache & prevGridVars()
return the variables of the previous time step (for instationary problems)
Definition: discretization/gridvariables.hh:116
void advanceTimeStep()
Sets the current state as the previous for next time step.
Definition: discretization/gridvariables.hh:90
typename GridVariablesCache::Variables Variables
export type of the variables
Definition: discretization/gridvariables.hh:36
GVC GridVariablesCache
export type of the grid variables cache
Definition: discretization/gridvariables.hh:33
void updateAfterGridAdaption(const SolutionVector &curSol)
update all variables after grid adaption
Definition: discretization/gridvariables.hh:76
void init(const SolutionVector &curSol)
initialize all variables (stationary case)
Definition: discretization/gridvariables.hh:54
Definition: assembly/assembler.hh:44