3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
box/elementvolumevariables.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 *****************************************************************************/
24#ifndef DUMUX_DISCRETIZATION_BOX_ELEMENT_VOLUMEVARIABLES_HH
25#define DUMUX_DISCRETIZATION_BOX_ELEMENT_VOLUMEVARIABLES_HH
26
27#include <type_traits>
28#include <utility>
29
31
32namespace Dumux {
33
41template<class GVV, bool cachingEnabled>
43
49template<class GVV>
50class BoxElementVolumeVariables<GVV, /*cachingEnabled*/true>
51{
52public:
55
57 using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
58
61 : gridVolVarsPtr_(&gridVolVars) {}
62
63 const VolumeVariables& operator [](std::size_t scvIdx) const
64 { return gridVolVars().volVars(eIdx_, scvIdx); }
65
66 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0>
67 const VolumeVariables& operator [](const SubControlVolume& scv) const
68 { return gridVolVars().volVars(eIdx_, scv.indexInElement()); }
69
75 template<class FVElementGeometry, class SolutionVector>
76 BoxElementVolumeVariables bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
77 const FVElementGeometry& fvGeometry,
78 const SolutionVector& sol) &&
79 {
80 this->bindElement(element, fvGeometry, sol);
81 return std::move(*this);
82 }
83
84 // For compatibility reasons with the case of not storing the vol vars.
85 // function to be called before assembling an element, preparing the vol vars within the stencil
86 template<class FVElementGeometry, class SolutionVector>
87 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
88 const FVElementGeometry& fvGeometry,
89 const SolutionVector& sol) &
90 {
91 bindElement(element, fvGeometry, sol);
92 }
93
99 template<class FVElementGeometry, class SolutionVector>
100 BoxElementVolumeVariables bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
101 const FVElementGeometry& fvGeometry,
102 const SolutionVector& sol) &&
103 {
104 this->bindElement(element, fvGeometry, sol);
105 return std::move(*this);
106 }
107
108 // function to prepare the vol vars within the element
109 template<class FVElementGeometry, class SolutionVector>
110 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
111 const FVElementGeometry& fvGeometry,
112 const SolutionVector& sol) &
113 {
114 eIdx_ = fvGeometry.gridGeometry().elementMapper().index(element);
115 }
116
119 { return *gridVolVarsPtr_; }
120
121private:
122 const GridVolumeVariables* gridVolVarsPtr_;
123 std::size_t eIdx_;
124};
125
126
131template<class GVV>
132class BoxElementVolumeVariables<GVV, /*cachingEnabled*/false>
133{
134public:
137
139 using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
140
143 : gridVolVarsPtr_(&gridVolVars) {}
144
150 template<class FVElementGeometry, class SolutionVector>
151 BoxElementVolumeVariables bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
152 const FVElementGeometry& fvGeometry,
153 const SolutionVector& sol) &&
154 {
155 this->bindElement(element, fvGeometry, sol);
156 return std::move(*this);
157 }
158
159 // specialization for box models, simply forwards to the bindElement method
160 template<class FVElementGeometry, class SolutionVector>
161 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
162 const FVElementGeometry& fvGeometry,
163 const SolutionVector& sol) &
164 {
165 bindElement(element, fvGeometry, sol);
166 }
167
173 template<class FVElementGeometry, class SolutionVector>
174 BoxElementVolumeVariables bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
175 const FVElementGeometry& fvGeometry,
176 const SolutionVector& sol) &&
177 {
178 this->bindElement(element, fvGeometry, sol);
179 return std::move(*this);
180 }
181
182 // specialization for box models
183 template<class FVElementGeometry, class SolutionVector>
184 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
185 const FVElementGeometry& fvGeometry,
186 const SolutionVector& sol) &
187 {
188 // get the solution at the dofs of the element
189 auto elemSol = elementSolution(element, sol, fvGeometry.gridGeometry());
190
191 // resize volume variables to the required size
192 volumeVariables_.resize(fvGeometry.numScv());
193 for (auto&& scv : scvs(fvGeometry))
194 volumeVariables_[scv.indexInElement()].update(elemSol, gridVolVars().problem(), element, scv);
195 }
196
197 const VolumeVariables& operator [](std::size_t scvIdx) const
198 { return volumeVariables_[scvIdx]; }
199
200 VolumeVariables& operator [](std::size_t scvIdx)
201 { return volumeVariables_[scvIdx]; }
202
203 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0>
204 const VolumeVariables& operator [](const SubControlVolume& scv) const
205 { return volumeVariables_[scv.indexInElement()]; }
206
207 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0>
208 VolumeVariables& operator [](const SubControlVolume& scv)
209 { return volumeVariables_[scv.indexInElement()]; }
210
213 { return *gridVolVarsPtr_; }
214
215private:
216 const GridVolumeVariables* gridVolVarsPtr_;
217 std::vector<VolumeVariables> volumeVariables_;
218};
219
220} // end namespace Dumux
221
222#endif
auto elementSolution(const Element &element, const SolutionVector &sol, const GridGeometry &gg) -> std::enable_if_t< GridGeometry::discMethod==DiscretizationMethods::box, BoxElementSolution< typename GridGeometry::LocalView, std::decay_t< decltype(std::declval< SolutionVector >()[0])> > >
Make an element solution for box schemes.
Definition: box/elementsolution.hh:118
Definition: adapt.hh:29
The local (stencil) volume variables class for box models.
Definition: box/elementvolumevariables.hh:42
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: box/elementvolumevariables.hh:110
typename GridVolumeVariables::VolumeVariables VolumeVariables
export type of the volume variables
Definition: box/elementvolumevariables.hh:57
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: box/elementvolumevariables.hh:87
BoxElementVolumeVariables bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: box/elementvolumevariables.hh:100
GVV GridVolumeVariables
export type of the grid volume variables
Definition: box/elementvolumevariables.hh:54
const GridVolumeVariables & gridVolVars() const
The global volume variables object we are a restriction of.
Definition: box/elementvolumevariables.hh:118
BoxElementVolumeVariables(const GridVolumeVariables &gridVolVars)
Constructor.
Definition: box/elementvolumevariables.hh:60
BoxElementVolumeVariables bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: box/elementvolumevariables.hh:76
BoxElementVolumeVariables bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: box/elementvolumevariables.hh:151
BoxElementVolumeVariables bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: box/elementvolumevariables.hh:174
BoxElementVolumeVariables(const GridVolumeVariables &gridVolVars)
Constructor.
Definition: box/elementvolumevariables.hh:142
GVV GridVolumeVariables
export type of the grid volume variables
Definition: box/elementvolumevariables.hh:136
const GridVolumeVariables & gridVolVars() const
The global volume variables object we are a restriction of.
Definition: box/elementvolumevariables.hh:212
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: box/elementvolumevariables.hh:161
typename GridVolumeVariables::VolumeVariables VolumeVariables
export type of the volume variables
Definition: box/elementvolumevariables.hh:139
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: box/elementvolumevariables.hh:184
The local element solution class for the box method.