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());
172 auto fvGeometry =
localView(gridGeometry);
173 for (
const auto& element : elements(gridGeometry.gridView()))
175 fvGeometry.bindElement(element);
176 for (
auto&& scv : scvs(fvGeometry))
179 const auto& cellCenterPriVars = sol[scv.dofIndex()];
180 PrimaryVariables priVars = makePriVarsFromCellCenterPriVars<PrimaryVariables>(cellCenterPriVars);
182 auto elemSol = elementSolution<typename GridGeometry::LocalView>(std::move(priVars));
183 volumeVariables_[scv.dofIndex()].update(elemSol, problem(), element, scv);
189 {
return volumeVariables_[scvIdx]; }
192 {
return volumeVariables_[scvIdx]; }
194 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value,
int> = 0>
196 {
return volumeVariables_[scv.dofIndex()]; }
198 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value,
int> = 0>
200 {
return volumeVariables_[scv.dofIndex()]; }
203 {
return *problemPtr_; }
207 template<
class... Args>
210 return Traits::getBoundaryPriVars(std::forward<Args>(args)...);
214 const Problem* problemPtr_;
215 std::vector<VolumeVariables> volumeVariables_;
224template<
class Traits>
228 using PrimaryVariables =
typename Traits::VolumeVariables::PrimaryVariables;
238 static constexpr bool cachingEnabled =
false;
245 template<
class Gr
idGeometry,
class SolutionVector>
246 void update(
const GridGeometry& gridGeometry,
const SolutionVector& sol)
248 if (sol.size() != gridGeometry.numScv())
249 DUNE_THROW(Dune::InvalidStateException,
"The solution vector passed to the GridVolumeVariables has the wrong size.\n"
250 <<
"Make sure to initialize the gridVariables correctly: \n\n"
251 <<
"auto ffSol = partial(sol, ffFaceIdx, ffCellCenterIdx); \n"
252 <<
"ffGridVariables->init(ffSol);\n\n");
256 {
return *problemPtr_;}
260 template<
class... Args>
263 return Traits::getBoundaryPriVars(std::forward<Args>(args)...);
268 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
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
Base class for the element volume variables vector for the staggered model.
Definition: staggered/freeflow/elementvolumevariables.hh:44
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:195
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:199
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:191
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:188
const Problem & problem() const
Definition: staggered/freeflow/gridvolumevariables.hh:202
PrimaryVariables getBoundaryPriVars(Args &&... args) const
Definition: staggered/freeflow/gridvolumevariables.hh:208
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:226
PrimaryVariables getBoundaryPriVars(Args &&... args) const
Definition: staggered/freeflow/gridvolumevariables.hh:261
void update(const GridGeometry &gridGeometry, const SolutionVector &sol)
Definition: staggered/freeflow/gridvolumevariables.hh:246
const Problem & problem() const
Definition: staggered/freeflow/gridvolumevariables.hh:255
typename Traits::VolumeVariables VolumeVariables
export the type of the VolumeVariables
Definition: staggered/freeflow/gridvolumevariables.hh:235
typename Traits::Problem Problem
export the problem type
Definition: staggered/freeflow/gridvolumevariables.hh:232
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: staggered/freeflow/gridvolumevariables.hh:241
StaggeredGridVolumeVariables(const Problem &problem)
Definition: staggered/freeflow/gridvolumevariables.hh:243
The local element solution class for staggered methods.