3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * 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 *****************************************************************************/
26#ifndef DUMUX_EXPERIMENTAL_FV_GRID_VARIABLES_HH
27#define DUMUX_EXPERIMENTAL_FV_GRID_VARIABLES_HH
28
29#include <utility>
30#include <memory>
31
35
36namespace Dumux::Experimental {
37
44template<class GV>
46{
47 using GridGeometry = typename GV::GridGeometry;
48 using FVElementGeometry = typename GridGeometry::LocalView;
49
50 using GridView = typename GridGeometry::GridView;
51 using Element = typename GridView::template Codim<0>::Entity;
52
53 using ElementVolumeVariables = typename GV::GridVolumeVariables::LocalView;
54 using ElementFluxVariablesCache = typename GV::GridFluxVariablesCache::LocalView;
55
56public:
58 using GridVariables = GV;
59
62 : gridVariables_(&gridVariables)
63 , elemVolVars_(gridVariables.gridVolVars())
64 , elemFluxVarsCache_(gridVariables.gridFluxVarsCache())
65 {}
66
72 void bind(const Element& element,
73 const FVElementGeometry& fvGeometry)
74 {
75 const auto& x = gridVariables().dofs();
76 elemVolVars_.bind(element, fvGeometry, x);
77 elemFluxVarsCache_.bind(element, fvGeometry, elemVolVars_);
78 }
79
85 void bindElemVolVars(const Element& element,
86 const FVElementGeometry& fvGeometry)
87 {
88 elemVolVars_.bind(element, fvGeometry, gridVariables().dofs());
89
90 // unbind flux variables cache
91 elemFluxVarsCache_ = localView(gridVariables().gridFluxVarsCache());
92 }
93
95 const ElementVolumeVariables& elemVolVars() const { return elemVolVars_; }
96 ElementVolumeVariables& elemVolVars() { return elemVolVars_; }
97
99 const ElementFluxVariablesCache& elemFluxVarsCache() const { return elemFluxVarsCache_; }
100 ElementFluxVariablesCache& elemFluxVarsCache() { return elemFluxVarsCache_; }
101
104 { return *gridVariables_; }
105
106private:
107 const GridVariables* gridVariables_;
108 ElementVolumeVariables elemVolVars_;
109 ElementFluxVariablesCache elemFluxVarsCache_;
110};
111
121template<class GVV, class GFVC, class X>
123: public GridVariables<typename ProblemTraits<typename GVV::Problem>::GridGeometry, X>
124{
125 using Problem = typename GVV::Problem;
126 using GG = typename ProblemTraits<Problem>::GridGeometry;
127
130
131public:
132 using typename ParentType::SolutionVector;
133
135 using GridGeometry = GG;
136
139
141 using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
142
144 using PrimaryVariables = typename VolumeVariables::PrimaryVariables;
145
148
151
160 FVGridVariables(std::shared_ptr<Problem> problem,
161 std::shared_ptr<const GridGeometry> gridGeometry)
162 : ParentType(gridGeometry, [problem] (auto& x) { problem->applyInitialSolution(x); })
163 , gridVolVars_(*problem)
164 , gridFluxVarsCache_(*problem)
165 {}
166
175 template<class SolOrInitializer>
176 FVGridVariables(std::shared_ptr<Problem> problem,
177 std::shared_ptr<const GridGeometry> gridGeometry,
178 SolOrInitializer&& solOrInitializer)
179 : ParentType(gridGeometry, std::forward<SolOrInitializer>(solOrInitializer))
180 , gridVolVars_(*problem)
181 , gridFluxVarsCache_(*problem)
182 {
183 gridVolVars_.update(this->gridGeometry(), this->dofs());
184 gridFluxVarsCache_.update(this->gridGeometry(), gridVolVars_, this->dofs(), true);
185 }
186
188 void update(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);
197 }
198
200 void forceUpdateAll(const SolutionVector& curSol)
201 {
202 ParentType::update(curSol);
203
204 // resize and update the volVars with the initial solution
205 gridVolVars_.update(this->gridGeometry(), curSol);
206
207 // update the flux variables caches
208 gridFluxVarsCache_.update(this->gridGeometry(), gridVolVars_, curSol, true);
209 }
210
213 { return gridFluxVarsCache_; }
214
217 { return gridFluxVarsCache_; }
218
221 { return gridVolVars_; }
222
225 { return gridVolVars_; }
226
227private:
228 GridVolumeVariables gridVolVars_;
229 GridFluxVariablesCache gridFluxVarsCache_;
230};
231
232} // end namespace Dumux::Experimental
233
234#endif
Free function to get the local view of a grid cache object.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:38
Definition: variables.hh:33
std::decay_t< decltype(std::declval< Problem >().gridGeometry())> GridGeometry
Definition: common/typetraits/problem.hh:45
void update(const SolutionVector &x)
Update the state to a new solution.
Definition: variables.hh:110
const SolutionVector & dofs() const
Return reference to the solution.
Definition: variables.hh:104
X SolutionVector
export the type of solution vector
Definition: variables.hh:66
Finite volume-specific local view on grid variables.
Definition: experimental/discretization/fvgridvariables.hh:46
GV GridVariables
export corresponding grid-wide class
Definition: experimental/discretization/fvgridvariables.hh:58
ElementVolumeVariables & elemVolVars()
Definition: experimental/discretization/fvgridvariables.hh:96
FVGridVariablesLocalView(const GridVariables &gridVariables)
Constructor.
Definition: experimental/discretization/fvgridvariables.hh:61
const ElementVolumeVariables & elemVolVars() const
return reference to the elem vol vars
Definition: experimental/discretization/fvgridvariables.hh:95
void bindElemVolVars(const Element &element, const FVElementGeometry &fvGeometry)
Bind only the volume variables local view to a grid element.
Definition: experimental/discretization/fvgridvariables.hh:85
ElementFluxVariablesCache & elemFluxVarsCache()
Definition: experimental/discretization/fvgridvariables.hh:100
const ElementFluxVariablesCache & elemFluxVarsCache() const
return reference to the flux variables cache
Definition: experimental/discretization/fvgridvariables.hh:99
void bind(const Element &element, const FVElementGeometry &fvGeometry)
Bind this local view to a grid element.
Definition: experimental/discretization/fvgridvariables.hh:72
const GridVariables & gridVariables() const
Return reference to the grid variables.
Definition: experimental/discretization/fvgridvariables.hh:103
The grid variable class for finite volume schemes, storing variables on scv and scvf (volume and flux...
Definition: experimental/discretization/fvgridvariables.hh:124
GG GridGeometry
export type of the finite volume grid geometry
Definition: experimental/discretization/fvgridvariables.hh:135
void update(const SolutionVector &curSol)
Update all variables that may be affected by a change in solution.
Definition: experimental/discretization/fvgridvariables.hh:188
typename GridVolumeVariables::VolumeVariables VolumeVariables
export type of the volume variables
Definition: experimental/discretization/fvgridvariables.hh:141
GridFluxVariablesCache & gridFluxVarsCache()
return the flux variables cache
Definition: experimental/discretization/fvgridvariables.hh:216
GFVC GridFluxVariablesCache
export cache type for flux variables
Definition: experimental/discretization/fvgridvariables.hh:147
void forceUpdateAll(const SolutionVector &curSol)
Force the update of all variables.
Definition: experimental/discretization/fvgridvariables.hh:200
GVV GridVolumeVariables
export type of the grid volume variables
Definition: experimental/discretization/fvgridvariables.hh:138
FVGridVariables(std::shared_ptr< Problem > problem, std::shared_ptr< const GridGeometry > gridGeometry)
Constructor.
Definition: experimental/discretization/fvgridvariables.hh:160
GridVolumeVariables & gridVolVars()
return the current volume variables
Definition: experimental/discretization/fvgridvariables.hh:224
const GridFluxVariablesCache & gridFluxVarsCache() const
return the flux variables cache
Definition: experimental/discretization/fvgridvariables.hh:212
const GridVolumeVariables & gridVolVars() const
return the current volume variables
Definition: experimental/discretization/fvgridvariables.hh:220
typename VolumeVariables::PrimaryVariables PrimaryVariables
export primary variable type
Definition: experimental/discretization/fvgridvariables.hh:144
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:176
Base class for grid variables.
Definition: experimental/discretization/gridvariables.hh:45
const GridGeometry & gridGeometry() const
Return a reference to the grid geometry.
Definition: experimental/discretization/gridvariables.hh:64
Type traits for problem classes.
Base class for grid variables.