version 3.11-dev
experimental/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-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
14#ifndef DUMUX_EXPERIMENTAL_FV_GRID_VARIABLES_HH
15#define DUMUX_EXPERIMENTAL_FV_GRID_VARIABLES_HH
16
17#include <utility>
18#include <memory>
19
23
24namespace Dumux::Experimental {
25
32template<class GV>
34{
35 using GridGeometry = typename GV::GridGeometry;
36 using FVElementGeometry = typename GridGeometry::LocalView;
37
38 using GridView = typename GridGeometry::GridView;
39 using Element = typename GridView::template Codim<0>::Entity;
40
41 using ElementVolumeVariables = typename GV::GridVolumeVariables::LocalView;
42 using ElementFluxVariablesCache = typename GV::GridFluxVariablesCache::LocalView;
43
44public:
46 using GridVariables = GV;
47
50 : gridVariables_(&gridVariables)
51 , elemVolVars_(gridVariables.gridVolVars())
52 , elemFluxVarsCache_(gridVariables.gridFluxVarsCache())
53 {}
54
60 void bind(const Element& element,
61 const FVElementGeometry& fvGeometry)
62 {
63 const auto& x = gridVariables().dofs();
64 elemVolVars_.bind(element, fvGeometry, x);
65 elemFluxVarsCache_.bind(element, fvGeometry, elemVolVars_);
66 }
67
73 void bindElemVolVars(const Element& element,
74 const FVElementGeometry& fvGeometry)
75 {
76 elemVolVars_.bind(element, fvGeometry, gridVariables().dofs());
77
78 // unbind flux variables cache
79 elemFluxVarsCache_ = localView(gridVariables().gridFluxVarsCache());
80 }
81
83 const ElementVolumeVariables& elemVolVars() const { return elemVolVars_; }
84 ElementVolumeVariables& elemVolVars() { return elemVolVars_; }
85
87 const ElementFluxVariablesCache& elemFluxVarsCache() const { return elemFluxVarsCache_; }
88 ElementFluxVariablesCache& elemFluxVarsCache() { return elemFluxVarsCache_; }
89
92 { return *gridVariables_; }
93
94private:
95 const GridVariables* gridVariables_;
96 ElementVolumeVariables elemVolVars_;
97 ElementFluxVariablesCache elemFluxVarsCache_;
98};
99
114template<class GVV, class GFVC, class X>
116: public Variables<X>
117{
118 using Problem = typename GVV::Problem;
119 using GG = typename ProblemTraits<Problem>::GridGeometry;
120
121 using ParentType = Variables<X>;
123
124public:
125 using typename ParentType::SolutionVector;
126
128 using GridGeometry = GG;
129
132
134 using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
135
137 using PrimaryVariables = typename VolumeVariables::PrimaryVariables;
138
141
144
153 FVGridVariables(std::shared_ptr<Problem> problem,
154 std::shared_ptr<const GridGeometry> gridGeometry)
155 : ParentType([problem] (auto& x) { problem->applyInitialSolution(x); })
156 , gridGeometry_(gridGeometry)
157 , gridVolVars_(*problem)
158 , gridFluxVarsCache_(*problem)
159 {}
160
170 template<class SolOrInitializer>
171 FVGridVariables(std::shared_ptr<Problem> problem,
172 std::shared_ptr<const GridGeometry> gridGeometry,
173 SolOrInitializer&& solOrInitializer,
174 const typename ParentType::TimeLevel& timeLevel = typename ParentType::TimeLevel{0.0})
175 : ParentType(std::forward<SolOrInitializer>(solOrInitializer), timeLevel)
176 , gridGeometry_(gridGeometry)
177 , gridVolVars_(*problem)
178 , gridFluxVarsCache_(*problem)
179 {
180 gridVolVars_.update(this->gridGeometry(), this->dofs());
181 gridFluxVarsCache_.update(this->gridGeometry(), gridVolVars_, this->dofs(), true);
182 }
183
185 void update(const SolutionVector& curSol)
186 {
187 ParentType::update(curSol);
188
189 // resize and update the volVars with the initial solution
190 gridVolVars_.update(this->gridGeometry(), curSol);
191
192 // update the flux variables caches
193 gridFluxVarsCache_.update(this->gridGeometry(), gridVolVars_, curSol);
194 }
195
197 void forceUpdateAll(const SolutionVector& curSol)
198 {
199 ParentType::update(curSol);
200
201 // resize and update the volVars with the initial solution
202 gridVolVars_.update(this->gridGeometry(), curSol);
203
204 // update the flux variables caches
205 gridFluxVarsCache_.update(this->gridGeometry(), gridVolVars_, curSol, true);
206 }
207
210 { return gridFluxVarsCache_; }
211
214 { return gridFluxVarsCache_; }
215
218 { return gridVolVars_; }
219
222 { return gridVolVars_; }
223
226 { return *gridGeometry_; }
227
228private:
229 std::shared_ptr<const GridGeometry> gridGeometry_;
230 GridVolumeVariables gridVolVars_;
231 GridFluxVariablesCache gridFluxVarsCache_;
232};
233
234} // end namespace Dumux::Experimental
235
236#endif
The grid variable class for finite volume schemes, storing variables on scv and scvf (volume and flux...
Definition: experimental/discretization/fvgridvariables.hh:117
GG GridGeometry
export type of the finite volume grid geometry
Definition: experimental/discretization/fvgridvariables.hh:128
void update(const SolutionVector &curSol)
Update all variables that may be affected by a change in solution.
Definition: experimental/discretization/fvgridvariables.hh:185
typename GridVolumeVariables::VolumeVariables VolumeVariables
export type of the volume variables
Definition: experimental/discretization/fvgridvariables.hh:134
GridFluxVariablesCache & gridFluxVarsCache()
return the flux variables cache
Definition: experimental/discretization/fvgridvariables.hh:213
GFVC GridFluxVariablesCache
export cache type for flux variables
Definition: experimental/discretization/fvgridvariables.hh:140
void forceUpdateAll(const SolutionVector &curSol)
Force the update of all variables.
Definition: experimental/discretization/fvgridvariables.hh:197
GVV GridVolumeVariables
export type of the grid volume variables
Definition: experimental/discretization/fvgridvariables.hh:131
FVGridVariables(std::shared_ptr< Problem > problem, std::shared_ptr< const GridGeometry > gridGeometry)
Constructor.
Definition: experimental/discretization/fvgridvariables.hh:153
FVGridVariables(std::shared_ptr< Problem > problem, std::shared_ptr< const GridGeometry > gridGeometry, SolOrInitializer &&solOrInitializer, const typename ParentType::TimeLevel &timeLevel=typename ParentType::TimeLevel{0.0})
Constructor with custom initialization of the solution.
Definition: experimental/discretization/fvgridvariables.hh:171
GridVolumeVariables & gridVolVars()
return the current volume variables
Definition: experimental/discretization/fvgridvariables.hh:221
const GridFluxVariablesCache & gridFluxVarsCache() const
return the flux variables cache
Definition: experimental/discretization/fvgridvariables.hh:209
const GridVolumeVariables & gridVolVars() const
return the current volume variables
Definition: experimental/discretization/fvgridvariables.hh:217
typename VolumeVariables::PrimaryVariables PrimaryVariables
export primary variable type
Definition: experimental/discretization/fvgridvariables.hh:137
const GridGeometry & gridGeometry() const
Return a reference to the grid geometry.
Definition: experimental/discretization/fvgridvariables.hh:225
Finite volume-specific local view on grid variables.
Definition: experimental/discretization/fvgridvariables.hh:34
GV GridVariables
export corresponding grid-wide class
Definition: experimental/discretization/fvgridvariables.hh:46
ElementVolumeVariables & elemVolVars()
Definition: experimental/discretization/fvgridvariables.hh:84
FVGridVariablesLocalView(const GridVariables &gridVariables)
Constructor.
Definition: experimental/discretization/fvgridvariables.hh:49
const ElementVolumeVariables & elemVolVars() const
return reference to the elem vol vars
Definition: experimental/discretization/fvgridvariables.hh:83
void bindElemVolVars(const Element &element, const FVElementGeometry &fvGeometry)
Bind only the volume variables local view to a grid element.
Definition: experimental/discretization/fvgridvariables.hh:73
ElementFluxVariablesCache & elemFluxVarsCache()
Definition: experimental/discretization/fvgridvariables.hh:88
const ElementFluxVariablesCache & elemFluxVarsCache() const
return reference to the flux variables cache
Definition: experimental/discretization/fvgridvariables.hh:87
void bind(const Element &element, const FVElementGeometry &fvGeometry)
Bind this local view to a grid element.
Definition: experimental/discretization/fvgridvariables.hh:60
const GridVariables & gridVariables() const
Return reference to the grid variables.
Definition: experimental/discretization/fvgridvariables.hh:91
The grid variables class for general schemes, storing variables and data.
Definition: discretization/gridvariables.hh:27
Class that represents a time level during time integration.
Definition: timelevel.hh:22
Class that represents the variables of a model. We assume that models are formulated on the basis of ...
Definition: experimental/common/variables.hh:41
void update(const SolutionVector &x)
Update the state to a new solution.
Definition: experimental/common/variables.hh:98
const SolutionVector & dofs() const
Return reference to the solution.
Definition: experimental/common/variables.hh:92
const TimeLevel & timeLevel() const
Return the time level.
Definition: experimental/common/variables.hh:88
X SolutionVector
export the type of solution vector
Definition: experimental/common/variables.hh:54
Type traits for problem classes.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:26
Free function to get the local view of a grid cache object.
Definition: assembly/assembler.hh:44
std::decay_t< decltype(std::declval< Problem >().gridGeometry())> GridGeometry
Definition: common/typetraits/problem.hh:33