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;
56 using Indices =
typename VolumeVariables::Indices;
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;
148 using Indices =
typename Traits::VolumeVariables::Indices;
154 static constexpr bool cachingEnabled =
true;
162 template<
class Gr
idGeometry,
class SolutionVector>
163 void update(
const GridGeometry& gridGeometry,
const SolutionVector& sol)
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");
171 volumeVariables_.resize(gridGeometry.numScv());
173 for (
const auto& element : elements(gridGeometry.gridView()))
175 auto fvGeometry =
localView(gridGeometry);
176 fvGeometry.bindElement(element);
178 for (
auto&& scv : scvs(fvGeometry))
181 const auto& cellCenterPriVars = sol[scv.dofIndex()];
182 PrimaryVariables priVars = makePriVarsFromCellCenterPriVars<PrimaryVariables>(cellCenterPriVars);
184 auto elemSol = elementSolution<typename GridGeometry::LocalView>(std::move(priVars));
185 volumeVariables_[scv.dofIndex()].update(elemSol, problem(), element, scv);
191 {
return volumeVariables_[scvIdx]; }
194 {
return volumeVariables_[scvIdx]; }
196 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value,
int> = 0>
198 {
return volumeVariables_[scv.dofIndex()]; }
200 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value,
int> = 0>
202 {
return volumeVariables_[scv.dofIndex()]; }
205 {
return *problemPtr_; }
209 template<
class... Args>
212 return Traits::getBoundaryPriVars(std::forward<Args>(args)...);
216 const Problem* problemPtr_;
217 std::vector<VolumeVariables> volumeVariables_;
226template<
class Traits>
230 using PrimaryVariables =
typename Traits::VolumeVariables::PrimaryVariables;
240 static constexpr bool cachingEnabled =
false;
247 template<
class Gr
idGeometry,
class SolutionVector>
248 void update(
const GridGeometry& gridGeometry,
const SolutionVector& sol)
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");
258 {
return *problemPtr_;}
262 template<
class... Args>
265 return Traits::getBoundaryPriVars(std::forward<Args>(args)...);
270 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
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.