3.4
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
elementfacevariables.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_STAGGERED_ELEMENTFACEVARIABLES_HH
25#define DUMUX_DISCRETIZATION_STAGGERED_ELEMENTFACEVARIABLES_HH
26
27#include <algorithm>
28#include <cassert>
29#include <vector>
30
31namespace Dumux {
32
37template<class GridFaceVariables, bool cachingEnabled>
39{};
40
45template<class GFV>
46class StaggeredElementFaceVariables<GFV, /*cachingEnabled*/true>
47{
48public:
50 using GridFaceVariables = GFV;
51
53 using FaceVariables = typename GridFaceVariables::FaceVariables;
54
55 StaggeredElementFaceVariables(const GridFaceVariables& gridFaceVariables) : gridFaceVariablesPtr_(&gridFaceVariables) {}
56
58 template<class SubControlVolumeFace, typename std::enable_if_t<!std::is_integral<SubControlVolumeFace>::value, int> = 0>
59 const FaceVariables& operator [](const SubControlVolumeFace& scvf) const
60 { return gridFaceVariables().faceVars(scvf.index()); }
61
64 const FaceVariables& operator [](const std::size_t scvfIdx) const
65 { return gridFaceVariables().faceVars(scvfIdx); }
66
67
70 template<class FVElementGeometry, class SolutionVector>
71 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
72 const FVElementGeometry& fvGeometry,
73 const SolutionVector& sol)
74 {}
75
78 template<class FVElementGeometry, class SolutionVector>
79 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
80 const FVElementGeometry& fvGeometry,
81 const SolutionVector& sol)
82 {}
83
84
87 { return *gridFaceVariablesPtr_; }
88
89
90private:
91 const GridFaceVariables* gridFaceVariablesPtr_;
92};
93
98template<class GFV>
99class StaggeredElementFaceVariables<GFV, /*cachingEnabled*/false>
100{
101public:
103 using GridFaceVariables = GFV;
104
106 using FaceVariables = typename GridFaceVariables::FaceVariables;
107
108 StaggeredElementFaceVariables(const GridFaceVariables& globalFacesVars) : gridFaceVariablesPtr_(&globalFacesVars) {}
109
111 template<class SubControlVolumeFace, typename std::enable_if_t<!std::is_integral<SubControlVolumeFace>::value, int> = 0>
112 const FaceVariables& operator [](const SubControlVolumeFace& scvf) const
113 { return faceVariables_[scvf.localFaceIdx()]; }
114
116 const FaceVariables& operator [](const std::size_t scvfIdx) const
117 { return faceVariables_[getLocalIdx_(scvfIdx)]; }
118
120 template<class SubControlVolumeFace, typename std::enable_if_t<!std::is_integral<SubControlVolumeFace>::value, int> = 0>
121 FaceVariables& operator [](const SubControlVolumeFace& scvf)
122 { return faceVariables_[scvf.localFaceIdx()]; }
123
124 // operator for the access with an index
125 FaceVariables& operator [](const std::size_t scvfIdx)
126 { return faceVariables_[getLocalIdx_(scvfIdx)]; }
127
130 template<class FVElementGeometry, class SolutionVector>
131 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
132 const FVElementGeometry& fvGeometry,
133 const SolutionVector& sol)
134 {
135 faceVariables_.resize(fvGeometry.numScvf());
136 faceVarIndices_.resize(fvGeometry.numScvf());
137
138 constexpr auto faceIdx = FVElementGeometry::GridGeometry::faceIdx();
139
140 for(auto&& scvf : scvfs(fvGeometry))
141 {
142 faceVariables_[scvf.localFaceIdx()].update(sol[faceIdx], gridFaceVariables().problem(), element, fvGeometry, scvf);
143 faceVarIndices_[scvf.localFaceIdx()] = scvf.index();
144 }
145 }
146
149 template<class FVElementGeometry, class SolutionVector>
150 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
151 const FVElementGeometry& fvGeometry,
152 const SolutionVector& sol)
153 {
154 faceVariables_.resize(fvGeometry.numScvf());
155 faceVarIndices_.resize(fvGeometry.numScvf());
156
157 constexpr auto faceIdx = FVElementGeometry::GridGeometry::faceIdx();
158
159 for(auto&& scvf : scvfs(fvGeometry))
160 {
161 faceVariables_[scvf.localFaceIdx()].updateOwnFaceOnly(sol[faceIdx][scvf.dofIndex()]);
162 faceVarIndices_[scvf.localFaceIdx()] = scvf.index();
163 }
164 }
165
168 { return *gridFaceVariablesPtr_; }
169
170private:
171
172 int getLocalIdx_(const int scvfIdx) const
173 {
174 auto it = std::find(faceVarIndices_.begin(), faceVarIndices_.end(), scvfIdx);
175 assert(it != faceVarIndices_.end() && "Could not find the current face variables for scvfIdx!");
176 return std::distance(faceVarIndices_.begin(), it);
177 }
178
179 const GridFaceVariables* gridFaceVariablesPtr_;
180 std::vector<std::size_t> faceVarIndices_;
181 std::vector<FaceVariables> faceVariables_;
182};
183
184} // end namespace
185
186#endif
ctype distance(const Dune::FieldVector< ctype, dimWorld > &a, const Dune::FieldVector< ctype, dimWorld > &b)
Compute the shortest distance between two points.
Definition: distance.hh:138
Definition: adapt.hh:29
Base class for the face variables vector.
Definition: elementfacevariables.hh:39
typename GridFaceVariables::FaceVariables FaceVariables
export type of the volume variables
Definition: elementfacevariables.hh:53
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol)
Definition: elementfacevariables.hh:71
StaggeredElementFaceVariables(const GridFaceVariables &gridFaceVariables)
Definition: elementfacevariables.hh:55
const GridFaceVariables & gridFaceVariables() const
The global volume variables object we are a restriction of.
Definition: elementfacevariables.hh:86
GFV GridFaceVariables
export type of the grid volume variables
Definition: elementfacevariables.hh:50
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol)
Definition: elementfacevariables.hh:79
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol)
Definition: elementfacevariables.hh:131
StaggeredElementFaceVariables(const GridFaceVariables &globalFacesVars)
Definition: elementfacevariables.hh:108
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol)
Definition: elementfacevariables.hh:150
typename GridFaceVariables::FaceVariables FaceVariables
export type of the volume variables
Definition: elementfacevariables.hh:106
const GridFaceVariables & gridFaceVariables() const
The global volume variables object we are a restriction of.
Definition: elementfacevariables.hh:167
GFV GridFaceVariables
export type of the grid volume variables
Definition: elementfacevariables.hh:103