3.1-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
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
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 auto numScv = gridGeometry.numScv();
166 volumeVariables_.resize(numScv);
167
168 for (const auto& element : elements(gridGeometry.gridView()))
169 {
170 auto fvGeometry = localView(gridGeometry);
171 fvGeometry.bindElement(element);
172
173 for (auto&& scv : scvs(fvGeometry))
174 {
175 // construct a privars object from the cell center solution vector
176 const auto& cellCenterPriVars = sol[scv.dofIndex()];
177 PrimaryVariables priVars = makePriVarsFromCellCenterPriVars<PrimaryVariables>(cellCenterPriVars);
178
179 auto elemSol = elementSolution<typename GridGeometry::LocalView>(std::move(priVars));
180 volumeVariables_[scv.dofIndex()].update(elemSol, problem(), element, scv);
181 }
182 }
183 }
184
185 const VolumeVariables& volVars(const std::size_t scvIdx) const
186 { return volumeVariables_[scvIdx]; }
187
188 VolumeVariables& volVars(const std::size_t scvIdx)
189 { return volumeVariables_[scvIdx]; }
190
191 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0>
192 const VolumeVariables& volVars(const SubControlVolume& scv) const
193 { return volumeVariables_[scv.dofIndex()]; }
194
195 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0>
196 VolumeVariables& volVars(const SubControlVolume& scv)
197 { return volumeVariables_[scv.dofIndex()]; }
198
199 const Problem& problem() const
200 { return *problemPtr_; }
201
204 template<class... Args>
205 PrimaryVariables getBoundaryPriVars(Args&&... args) const
206 {
207 return Traits::getBoundaryPriVars(std::forward<Args>(args)...);
208 }
209
210private:
211 const Problem* problemPtr_;
212 std::vector<VolumeVariables> volumeVariables_;
213};
214
215
221template<class Traits>
222class StaggeredGridVolumeVariables<Traits, /*cachingEnabled*/false>
223{
225 using PrimaryVariables = typename Traits::VolumeVariables::PrimaryVariables;
226
227public:
229 using Problem = typename Traits::Problem;
230
232 using VolumeVariables = typename Traits::VolumeVariables;
233
235 static constexpr bool cachingEnabled = false;
236
238 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
239
240 StaggeredGridVolumeVariables(const Problem& problem) : problemPtr_(&problem) {}
241
242 template<class GridGeometry, class SolutionVector>
243 void update(const GridGeometry& gridGeometry, const SolutionVector& sol) {}
244
245 const Problem& problem() const
246 { return *problemPtr_;}
247
250 template<class... Args>
251 PrimaryVariables getBoundaryPriVars(Args&&... args) const
252 {
253 return Traits::getBoundaryPriVars(std::forward<Args>(args)...);
254 }
255
256private:
257
258 const Problem* problemPtr_;
259};
260
261} // end namespace Dumux
262
263#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
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
Property tag Indices
Definition: porousmediumflow/sequential/properties.hh:59
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:192
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:196
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:188
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:185
const Problem & problem() const
Definition: staggered/freeflow/gridvolumevariables.hh:199
PrimaryVariables getBoundaryPriVars(Args &&... args) const
Definition: staggered/freeflow/gridvolumevariables.hh:205
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:223
PrimaryVariables getBoundaryPriVars(Args &&... args) const
Definition: staggered/freeflow/gridvolumevariables.hh:251
void update(const GridGeometry &gridGeometry, const SolutionVector &sol)
Definition: staggered/freeflow/gridvolumevariables.hh:243
const Problem & problem() const
Definition: staggered/freeflow/gridvolumevariables.hh:245
typename Traits::VolumeVariables VolumeVariables
export the type of the VolumeVariables
Definition: staggered/freeflow/gridvolumevariables.hh:232
typename Traits::Problem Problem
export the problem type
Definition: staggered/freeflow/gridvolumevariables.hh:229
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: staggered/freeflow/gridvolumevariables.hh:238
StaggeredGridVolumeVariables(const Problem &problem)
Definition: staggered/freeflow/gridvolumevariables.hh:240
The local element solution class for staggered methods.