version 3.8
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-FileCopyrightInfo: 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
109template<class GVV, class GFVC, class X>
111: public GridVariables<typename ProblemTraits<typename GVV::Problem>::GridGeometry, X>
112{
113 using Problem = typename GVV::Problem;
114 using GG = typename ProblemTraits<Problem>::GridGeometry;
115
118
119public:
120 using typename ParentType::SolutionVector;
121
123 using GridGeometry = GG;
124
127
129 using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
130
132 using PrimaryVariables = typename VolumeVariables::PrimaryVariables;
133
136
139
148 FVGridVariables(std::shared_ptr<Problem> problem,
149 std::shared_ptr<const GridGeometry> gridGeometry)
150 : ParentType(gridGeometry, [problem] (auto& x) { problem->applyInitialSolution(x); })
151 , gridVolVars_(*problem)
152 , gridFluxVarsCache_(*problem)
153 {}
154
163 template<class SolOrInitializer>
164 FVGridVariables(std::shared_ptr<Problem> problem,
165 std::shared_ptr<const GridGeometry> gridGeometry,
166 SolOrInitializer&& solOrInitializer)
167 : ParentType(gridGeometry, std::forward<SolOrInitializer>(solOrInitializer))
168 , gridVolVars_(*problem)
169 , gridFluxVarsCache_(*problem)
170 {
171 gridVolVars_.update(this->gridGeometry(), this->dofs());
172 gridFluxVarsCache_.update(this->gridGeometry(), gridVolVars_, this->dofs(), true);
173 }
174
176 void update(const SolutionVector& curSol)
177 {
178 ParentType::update(curSol);
179
180 // resize and update the volVars with the initial solution
181 gridVolVars_.update(this->gridGeometry(), curSol);
182
183 // update the flux variables caches
184 gridFluxVarsCache_.update(this->gridGeometry(), gridVolVars_, curSol);
185 }
186
188 void forceUpdateAll(const SolutionVector& curSol)
189 {
190 ParentType::update(curSol);
191
192 // resize and update the volVars with the initial solution
193 gridVolVars_.update(this->gridGeometry(), curSol);
194
195 // update the flux variables caches
196 gridFluxVarsCache_.update(this->gridGeometry(), gridVolVars_, curSol, true);
197 }
198
201 { return gridFluxVarsCache_; }
202
205 { return gridFluxVarsCache_; }
206
209 { return gridVolVars_; }
210
213 { return gridVolVars_; }
214
215private:
216 GridVolumeVariables gridVolVars_;
217 GridFluxVariablesCache gridFluxVarsCache_;
218};
219
220} // end namespace Dumux::Experimental
221
222#endif
The grid variable class for finite volume schemes, storing variables on scv and scvf (volume and flux...
Definition: experimental/discretization/fvgridvariables.hh:112
GG GridGeometry
export type of the finite volume grid geometry
Definition: experimental/discretization/fvgridvariables.hh:123
void update(const SolutionVector &curSol)
Update all variables that may be affected by a change in solution.
Definition: experimental/discretization/fvgridvariables.hh:176
typename GridVolumeVariables::VolumeVariables VolumeVariables
export type of the volume variables
Definition: experimental/discretization/fvgridvariables.hh:129
GridFluxVariablesCache & gridFluxVarsCache()
return the flux variables cache
Definition: experimental/discretization/fvgridvariables.hh:204
GFVC GridFluxVariablesCache
export cache type for flux variables
Definition: experimental/discretization/fvgridvariables.hh:135
void forceUpdateAll(const SolutionVector &curSol)
Force the update of all variables.
Definition: experimental/discretization/fvgridvariables.hh:188
GVV GridVolumeVariables
export type of the grid volume variables
Definition: experimental/discretization/fvgridvariables.hh:126
FVGridVariables(std::shared_ptr< Problem > problem, std::shared_ptr< const GridGeometry > gridGeometry)
Constructor.
Definition: experimental/discretization/fvgridvariables.hh:148
GridVolumeVariables & gridVolVars()
return the current volume variables
Definition: experimental/discretization/fvgridvariables.hh:212
const GridFluxVariablesCache & gridFluxVarsCache() const
return the flux variables cache
Definition: experimental/discretization/fvgridvariables.hh:200
const GridVolumeVariables & gridVolVars() const
return the current volume variables
Definition: experimental/discretization/fvgridvariables.hh:208
typename VolumeVariables::PrimaryVariables PrimaryVariables
export primary variable type
Definition: experimental/discretization/fvgridvariables.hh:132
FVGridVariables(std::shared_ptr< Problem > problem, std::shared_ptr< const GridGeometry > gridGeometry, SolOrInitializer &&solOrInitializer)
Constructor with custom initialization of the solution.
Definition: experimental/discretization/fvgridvariables.hh:164
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
Base class for grid variables.
Definition: experimental/discretization/gridvariables.hh:33
const GridGeometry & gridGeometry() const
Return a reference to the grid geometry.
Definition: experimental/discretization/gridvariables.hh:52
void update(const SolutionVector &x)
Update the state to a new solution.
Definition: variables.hh:98
const SolutionVector & dofs() const
Return reference to the solution.
Definition: variables.hh:92
X SolutionVector
export the type of solution vector
Definition: variables.hh:54
Type traits for problem classes.
Base class for grid variables.
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: experimental/assembly/cclocalassembler.hh:36
std::decay_t< decltype(std::declval< Problem >().gridGeometry())> GridGeometry
Definition: common/typetraits/problem.hh:33