3.2-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
30
31namespace Dumux {
32
40template<class GVV, bool cachingEnabled>
42
48template<class GVV>
49class BoxElementVolumeVariables<GVV, /*cachingEnabled*/true>
50{
51public:
54
56 using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
57
60 : gridVolVarsPtr_(&gridVolVars) {}
61
62 const VolumeVariables& operator [](std::size_t scvIdx) const
63 { return gridVolVars().volVars(eIdx_, scvIdx); }
64
65 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0>
66 const VolumeVariables& operator [](const SubControlVolume& scv) const
67 { return gridVolVars().volVars(eIdx_, scv.indexInElement()); }
68
69 // For compatibility reasons with the case of not storing the vol vars.
70 // function to be called before assembling an element, preparing the vol vars within the stencil
71 template<class FVElementGeometry, class SolutionVector>
72 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
73 const FVElementGeometry& fvGeometry,
74 const SolutionVector& sol)
75 {
76 bindElement(element, fvGeometry, sol);
77 }
78
79 // function to prepare the vol vars within the element
80 template<class FVElementGeometry, class SolutionVector>
81 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
82 const FVElementGeometry& fvGeometry,
83 const SolutionVector& sol)
84 {
85 eIdx_ = fvGeometry.gridGeometry().elementMapper().index(element);
86 }
87
90 { return *gridVolVarsPtr_; }
91
92private:
93 const GridVolumeVariables* gridVolVarsPtr_;
94 std::size_t eIdx_;
95};
96
97
102template<class GVV>
103class BoxElementVolumeVariables<GVV, /*cachingEnabled*/false>
104{
105public:
108
110 using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
111
114 : gridVolVarsPtr_(&gridVolVars) {}
115
116 // specialization for box models, simply forwards to the bindElement method
117 template<class FVElementGeometry, class SolutionVector>
118 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
119 const FVElementGeometry& fvGeometry,
120 const SolutionVector& sol)
121 {
122 bindElement(element, fvGeometry, sol);
123 }
124
125 // specialization for box models
126 template<class FVElementGeometry, class SolutionVector>
127 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
128 const FVElementGeometry& fvGeometry,
129 const SolutionVector& sol)
130 {
131 // get the solution at the dofs of the element
132 auto elemSol = elementSolution(element, sol, fvGeometry.gridGeometry());
133
134 // resize volume variables to the required size
135 volumeVariables_.resize(fvGeometry.numScv());
136 for (auto&& scv : scvs(fvGeometry))
137 volumeVariables_[scv.indexInElement()].update(elemSol, gridVolVars().problem(), element, scv);
138 }
139
140 const VolumeVariables& operator [](std::size_t scvIdx) const
141 { return volumeVariables_[scvIdx]; }
142
143 VolumeVariables& operator [](std::size_t scvIdx)
144 { return volumeVariables_[scvIdx]; }
145
146 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0>
147 const VolumeVariables& operator [](const SubControlVolume& scv) const
148 { return volumeVariables_[scv.indexInElement()]; }
149
150 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0>
151 VolumeVariables& operator [](const SubControlVolume& scv)
152 { return volumeVariables_[scv.indexInElement()]; }
153
156 { return *gridVolVarsPtr_; }
157
158private:
159 const GridVolumeVariables* gridVolVarsPtr_;
160 std::vector<VolumeVariables> volumeVariables_;
161};
162
163} // end namespace Dumux
164
165#endif
auto elementSolution(const Element &element, const SolutionVector &sol, const GridGeometry &gg) -> std::enable_if_t< GridGeometry::discMethod==DiscretizationMethod::box, BoxElementSolution< typename GridGeometry::LocalView, std::decay_t< decltype(std::declval< SolutionVector >()[0])> > >
Make an element solution for box schemes.
Definition: box/elementsolution.hh:115
Definition: adapt.hh:29
The local (stencil) volume variables class for box models.
Definition: box/elementvolumevariables.hh:41
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol)
Definition: box/elementvolumevariables.hh:72
typename GridVolumeVariables::VolumeVariables VolumeVariables
export type of the volume variables
Definition: box/elementvolumevariables.hh:56
GVV GridVolumeVariables
export type of the grid volume variables
Definition: box/elementvolumevariables.hh:53
const GridVolumeVariables & gridVolVars() const
The global volume variables object we are a restriction of.
Definition: box/elementvolumevariables.hh:89
BoxElementVolumeVariables(const GridVolumeVariables &gridVolVars)
Constructor.
Definition: box/elementvolumevariables.hh:59
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol)
Definition: box/elementvolumevariables.hh:81
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol)
Definition: box/elementvolumevariables.hh:118
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol)
Definition: box/elementvolumevariables.hh:127
BoxElementVolumeVariables(const GridVolumeVariables &gridVolVars)
Constructor.
Definition: box/elementvolumevariables.hh:113
GVV GridVolumeVariables
export type of the grid volume variables
Definition: box/elementvolumevariables.hh:107
const GridVolumeVariables & gridVolVars() const
The global volume variables object we are a restriction of.
Definition: box/elementvolumevariables.hh:155
typename GridVolumeVariables::VolumeVariables VolumeVariables
export type of the volume variables
Definition: box/elementvolumevariables.hh:110
The local element solution class for the box method.