24#ifndef DUMUX_DISCRETIZATION_STAGGERED_GRID_VOLUMEVARIABLES_HH
25#define DUMUX_DISCRETIZATION_STAGGERED_GRID_VOLUMEVARIABLES_HH
27#include <dune/common/exceptions.hh>
28#include <dune/common/rangeutilities.hh>
37template<
class P,
class VV>
44 template<
class Gr
idVolumeVariables,
bool cachingEnabled>
49 template<
class Problem,
class SolutionVector,
class Element,
class SubControlVolumeFace>
51 const SolutionVector& sol,
52 const Element& element,
53 const SubControlVolumeFace& scvf)
55 using CellCenterPrimaryVariables =
typename SolutionVector::value_type;
57 static constexpr auto dim = PrimaryVariables::dimension - CellCenterPrimaryVariables::dimension;
58 static constexpr auto offset = dim;
60 const auto bcTypes = problem.boundaryTypes(element, scvf);
64 for(
int i = 0; i < dim; ++i)
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.");
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.");
75 if(bcTypes.isDirichlet(Indices::velocity(scvf.directionIndex())))
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");
80 boundaryPriVars[Indices::pressureIdx] = sol[scvf.insideScvIdx()][Indices::pressureIdx - offset];
86 if(bcTypes.isDirichlet(Indices::pressureIdx))
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");
91 boundaryPriVars[Indices::pressureIdx] = problem.dirichlet(element, scvf)[Indices::pressureIdx];
95 if(CellCenterPrimaryVariables::dimension == 1)
96 return boundaryPriVars;
99 for(
int eqIdx = offset; eqIdx < PrimaryVariables::dimension; ++eqIdx)
101 if(eqIdx == Indices::pressureIdx)
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];
111 std::array<bool, VolumeVariables::numFluidComponents() - 1> isComponentOutflow;
112 for(
int compIdx = 1; compIdx < VolumeVariables::numFluidComponents(); ++compIdx)
114 const auto eqIdx = VolumeVariables::Indices::conti0EqIdx + compIdx;
115 isComponentOutflow[compIdx -1] = bcTypes.isOutflow(eqIdx);
118 if(Dune::any_true(isComponentOutflow) && !Dune::all_true(isComponentOutflow))
119 DUNE_THROW(Dune::InvalidStateException,
"Outflow condition must be set for all components!");
121 return boundaryPriVars;
129template<
class Traits,
bool cachingEnabled>
137template<
class Traits>
141 using PrimaryVariables =
typename Traits::VolumeVariables::PrimaryVariables;
154 static constexpr bool cachingEnabled =
true;
162 template<
class Gr
idGeometry,
class SolutionVector>
163 void update(
const GridGeometry& gridGeometry,
const SolutionVector& sol)
165 auto numScv = gridGeometry.numScv();
166 volumeVariables_.resize(numScv);
168 for (
const auto& element : elements(gridGeometry.gridView()))
170 auto fvGeometry =
localView(gridGeometry);
171 fvGeometry.bindElement(element);
173 for (
auto&& scv : scvs(fvGeometry))
176 const auto& cellCenterPriVars = sol[scv.dofIndex()];
177 PrimaryVariables priVars = makePriVarsFromCellCenterPriVars<PrimaryVariables>(cellCenterPriVars);
179 auto elemSol = elementSolution<typename GridGeometry::LocalView>(std::move(priVars));
180 volumeVariables_[scv.dofIndex()].update(elemSol, problem(), element, scv);
186 {
return volumeVariables_[scvIdx]; }
189 {
return volumeVariables_[scvIdx]; }
191 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value,
int> = 0>
193 {
return volumeVariables_[scv.dofIndex()]; }
195 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value,
int> = 0>
197 {
return volumeVariables_[scv.dofIndex()]; }
200 {
return *problemPtr_; }
204 template<
class... Args>
207 return Traits::getBoundaryPriVars(std::forward<Args>(args)...);
211 const Problem* problemPtr_;
212 std::vector<VolumeVariables> volumeVariables_;
221template<
class Traits>
225 using PrimaryVariables =
typename Traits::VolumeVariables::PrimaryVariables;
235 static constexpr bool cachingEnabled =
false;
242 template<
class Gr
idGeometry,
class SolutionVector>
243 void update(
const GridGeometry& gridGeometry,
const SolutionVector& sol) {}
246 {
return *problemPtr_;}
250 template<
class... Args>
253 return Traits::getBoundaryPriVars(std::forward<Args>(args)...);
258 const Problem* problemPtr_;
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.