3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
staggered/freeflow/gridvolumevariables.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_GRID_VOLUMEVARIABLES_HH
25#define DUMUX_DISCRETIZATION_STAGGERED_GRID_VOLUMEVARIABLES_HH
26
27#include <dune/common/exceptions.hh>
28#include <dune/common/rangeutilities.hh>
29
30// make the local view function available whenever we use this class
34
35namespace Dumux {
36
37template<class P, class VV>
39{
40 using Problem = P;
41 using VolumeVariables = VV;
42 using PrimaryVariables = typename VV::PrimaryVariables;
43
44 template<class GridVolumeVariables, bool cachingEnabled>
46
49 template<class Problem, class SolutionVector, class Element, class SubControlVolumeFace>
51 const SolutionVector& sol,
52 const Element& element,
53 const SubControlVolumeFace& scvf)
54 {
55 using CellCenterPrimaryVariables = typename SolutionVector::value_type;
56 using Indices = typename VolumeVariables::Indices;
57 static constexpr auto dim = PrimaryVariables::dimension - CellCenterPrimaryVariables::dimension;
58 static constexpr auto offset = dim;
59
60 const auto bcTypes = problem.boundaryTypes(element, scvf);
61 PrimaryVariables boundaryPriVars(0.0);
62
63 // make sure to not use outflow BC for momentum balance
64 for(int i = 0; i < dim; ++i)
65 {
66 if(bcTypes.isOutflow(Indices::velocity(i)))
67 DUNE_THROW(Dune::InvalidStateException, "Outflow condition cannot be used for velocity. Set only a Dirichlet value for pressure instead.");
68 }
69
70 if(bcTypes.isOutflow(Indices::pressureIdx))
71 DUNE_THROW(Dune::InvalidStateException, "Outflow condition cannot be used for pressure. Set only a Dirichlet value for velocity instead.");
72
73 // Determine the pressure value at a boundary with a Dirichlet condition for velocity.
74 // This just takes the value of the adjacent inner cell.
75 if(bcTypes.isDirichlet(Indices::velocity(scvf.directionIndex())))
76 {
77 if(bcTypes.isDirichlet(Indices::pressureIdx))
78 DUNE_THROW(Dune::InvalidStateException, "A Dirichlet condition for velocity must not be combined with a Dirichlet condition for pressure");
79 else
80 boundaryPriVars[Indices::pressureIdx] = sol[scvf.insideScvIdx()][Indices::pressureIdx - offset];
81 // TODO: pressure could be extrapolated to the boundary
82 }
83
84 // Determine the pressure value for a boundary with a Dirichlet condition for pressure.
85 // Takes a value specified in the problem.
86 if(bcTypes.isDirichlet(Indices::pressureIdx))
87 {
88 if(bcTypes.isDirichlet(Indices::velocity(scvf.directionIndex())))
89 DUNE_THROW(Dune::InvalidStateException, "A Dirichlet condition for velocity must not be combined with a Dirichlet condition for pressure");
90 else
91 boundaryPriVars[Indices::pressureIdx] = problem.dirichlet(element, scvf)[Indices::pressureIdx];
92 }
93
94 // Return for isothermal single-phase systems ...
95 if(CellCenterPrimaryVariables::dimension == 1)
96 return boundaryPriVars;
97
98 // ... or handle values for components, temperature, etc.
99 for(int eqIdx = offset; eqIdx < PrimaryVariables::dimension; ++eqIdx)
100 {
101 if(eqIdx == Indices::pressureIdx)
102 continue;
103
104 if(bcTypes.isDirichlet(eqIdx))
105 boundaryPriVars[eqIdx] = problem.dirichlet(element, scvf)[eqIdx];
106 else if(bcTypes.isOutflow(eqIdx) || bcTypes.isSymmetry() || bcTypes.isNeumann(eqIdx))
107 boundaryPriVars[eqIdx] = sol[scvf.insideScvIdx()][eqIdx - offset];
108 }
109
110 // make sure that a potential outflow condition is set for all components
111 std::array<bool, VolumeVariables::numFluidComponents() - 1> isComponentOutflow;
112 for(int compIdx = 1; compIdx < VolumeVariables::numFluidComponents(); ++compIdx)
113 {
114 const auto eqIdx = VolumeVariables::Indices::conti0EqIdx + compIdx;
115 isComponentOutflow[compIdx -1] = bcTypes.isOutflow(eqIdx);
116 }
117
118 if(Dune::any_true(isComponentOutflow) && !Dune::all_true(isComponentOutflow))
119 DUNE_THROW(Dune::InvalidStateException, "Outflow condition must be set for all components!");
120
121 return boundaryPriVars;
122 }
123};
124
129template<class Traits, bool cachingEnabled>
131
137template<class Traits>
138class StaggeredGridVolumeVariables<Traits, /*cachingEnabled*/true>
139{
141 using PrimaryVariables = typename Traits::VolumeVariables::PrimaryVariables;
142
143public:
145 using Problem = typename Traits::Problem;
146
148 using Indices = typename Traits::VolumeVariables::Indices;
149
151 using VolumeVariables = typename Traits::VolumeVariables;
152
154 static constexpr bool cachingEnabled = true;
155
157 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
158
159 StaggeredGridVolumeVariables(const Problem& problem) : problemPtr_(&problem) {}
160
162 template<class GridGeometry, class SolutionVector>
163 void update(const GridGeometry& gridGeometry, const SolutionVector& sol)
164 {
165 if (sol.size() != gridGeometry.numScv())
166 DUNE_THROW(Dune::InvalidStateException, "The solution vector passed to the GridVolumeVariables has the wrong size.\n"
167 << "Make sure to initialize the gridVariables correctly: \n\n"
168 << "auto ffSol = partial(sol, ffFaceIdx, ffCellCenterIdx); \n"
169 << "ffGridVariables->init(ffSol);\n\n");
170
171 volumeVariables_.resize(gridGeometry.numScv());
172
173 for (const auto& element : elements(gridGeometry.gridView()))
174 {
175 auto fvGeometry = localView(gridGeometry);
176 fvGeometry.bindElement(element);
177
178 for (auto&& scv : scvs(fvGeometry))
179 {
180 // construct a privars object from the cell center solution vector
181 const auto& cellCenterPriVars = sol[scv.dofIndex()];
182 PrimaryVariables priVars = makePriVarsFromCellCenterPriVars<PrimaryVariables>(cellCenterPriVars);
183
184 auto elemSol = elementSolution<typename GridGeometry::LocalView>(std::move(priVars));
185 volumeVariables_[scv.dofIndex()].update(elemSol, problem(), element, scv);
186 }
187 }
188 }
189
190 const VolumeVariables& volVars(const std::size_t scvIdx) const
191 { return volumeVariables_[scvIdx]; }
192
193 VolumeVariables& volVars(const std::size_t scvIdx)
194 { return volumeVariables_[scvIdx]; }
195
196 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0>
197 const VolumeVariables& volVars(const SubControlVolume& scv) const
198 { return volumeVariables_[scv.dofIndex()]; }
199
200 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0>
201 VolumeVariables& volVars(const SubControlVolume& scv)
202 { return volumeVariables_[scv.dofIndex()]; }
203
204 const Problem& problem() const
205 { return *problemPtr_; }
206
209 template<class... Args>
210 PrimaryVariables getBoundaryPriVars(Args&&... args) const
211 {
212 return Traits::getBoundaryPriVars(std::forward<Args>(args)...);
213 }
214
215private:
216 const Problem* problemPtr_;
217 std::vector<VolumeVariables> volumeVariables_;
218};
219
220
226template<class Traits>
227class StaggeredGridVolumeVariables<Traits, /*cachingEnabled*/false>
228{
230 using PrimaryVariables = typename Traits::VolumeVariables::PrimaryVariables;
231
232public:
234 using Problem = typename Traits::Problem;
235
237 using VolumeVariables = typename Traits::VolumeVariables;
238
240 static constexpr bool cachingEnabled = false;
241
243 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
244
245 StaggeredGridVolumeVariables(const Problem& problem) : problemPtr_(&problem) {}
246
247 template<class GridGeometry, class SolutionVector>
248 void update(const GridGeometry& gridGeometry, const SolutionVector& sol)
249 {
250 if (sol.size() != gridGeometry.numScv())
251 DUNE_THROW(Dune::InvalidStateException, "The solution vector passed to the GridVolumeVariables has the wrong size.\n"
252 << "Make sure to initialize the gridVariables correctly: \n\n"
253 << "auto ffSol = partial(sol, ffFaceIdx, ffCellCenterIdx); \n"
254 << "ffGridVariables->init(ffSol);\n\n");
255 }
256
257 const Problem& problem() const
258 { return *problemPtr_;}
259
262 template<class... Args>
263 PrimaryVariables getBoundaryPriVars(Args&&... args) const
264 {
265 return Traits::getBoundaryPriVars(std::forward<Args>(args)...);
266 }
267
268private:
269
270 const Problem* problemPtr_;
271};
272
273} // end namespace Dumux
274
275#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: adapt.hh:29
Base class for the element volume variables vector for the staggered model.
Definition: staggered/freeflow/elementvolumevariables.hh:43
Definition: staggered/freeflow/gridvolumevariables.hh:39
VV VolumeVariables
Definition: staggered/freeflow/gridvolumevariables.hh:41
P Problem
Definition: staggered/freeflow/gridvolumevariables.hh:40
static PrimaryVariables getBoundaryPriVars(const Problem &problem, const SolutionVector &sol, const Element &element, const SubControlVolumeFace &scvf)
Definition: staggered/freeflow/gridvolumevariables.hh:50
typename VV::PrimaryVariables PrimaryVariables
Definition: staggered/freeflow/gridvolumevariables.hh:42
Grid volume variables class for staggered models.
Definition: staggered/freeflow/gridvolumevariables.hh:130
Grid volume variables class for staggered models. Specialization in case of storing the volume variab...
Definition: staggered/freeflow/gridvolumevariables.hh:139
typename Traits::VolumeVariables::Indices Indices
export the type of the indices
Definition: staggered/freeflow/gridvolumevariables.hh:148
typename Traits::Problem Problem
export the problem type
Definition: staggered/freeflow/gridvolumevariables.hh:145
const VolumeVariables & volVars(const SubControlVolume &scv) const
Definition: staggered/freeflow/gridvolumevariables.hh:197
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: staggered/freeflow/gridvolumevariables.hh:157
VolumeVariables & volVars(const SubControlVolume &scv)
Definition: staggered/freeflow/gridvolumevariables.hh:201
typename Traits::VolumeVariables VolumeVariables
export the type of the VolumeVariables
Definition: staggered/freeflow/gridvolumevariables.hh:151
VolumeVariables & volVars(const std::size_t scvIdx)
Definition: staggered/freeflow/gridvolumevariables.hh:193
void update(const GridGeometry &gridGeometry, const SolutionVector &sol)
Update all volume variables.
Definition: staggered/freeflow/gridvolumevariables.hh:163
const VolumeVariables & volVars(const std::size_t scvIdx) const
Definition: staggered/freeflow/gridvolumevariables.hh:190
const Problem & problem() const
Definition: staggered/freeflow/gridvolumevariables.hh:204
PrimaryVariables getBoundaryPriVars(Args &&... args) const
Definition: staggered/freeflow/gridvolumevariables.hh:210
StaggeredGridVolumeVariables(const Problem &problem)
Definition: staggered/freeflow/gridvolumevariables.hh:159
Grid volume variables class for staggered models. Specialization in case of not storing the volume va...
Definition: staggered/freeflow/gridvolumevariables.hh:228
PrimaryVariables getBoundaryPriVars(Args &&... args) const
Definition: staggered/freeflow/gridvolumevariables.hh:263
void update(const GridGeometry &gridGeometry, const SolutionVector &sol)
Definition: staggered/freeflow/gridvolumevariables.hh:248
const Problem & problem() const
Definition: staggered/freeflow/gridvolumevariables.hh:257
typename Traits::VolumeVariables VolumeVariables
export the type of the VolumeVariables
Definition: staggered/freeflow/gridvolumevariables.hh:237
typename Traits::Problem Problem
export the problem type
Definition: staggered/freeflow/gridvolumevariables.hh:234
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: staggered/freeflow/gridvolumevariables.hh:243
StaggeredGridVolumeVariables(const Problem &problem)
Definition: staggered/freeflow/gridvolumevariables.hh:245
The local element solution class for staggered methods.