12#ifndef DUMUX_DISCRETIZATION_STAGGERED_ELEMENT_VOLUMEVARIABLES_HH
13#define DUMUX_DISCRETIZATION_STAGGERED_ELEMENT_VOLUMEVARIABLES_HH
20#include <dune/common/exceptions.hh>
30template<
class GVV,
bool cachingEnabled>
51 : gridVolVarsPtr_(&gridVolVars)
52 , numScv_(gridVolVars.problem().gridGeometry().numScv())
56 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value,
int> = 0>
59 if (scv.dofIndex() < numScv_)
60 return gridVolVars().volVars(scv.dofIndex());
62 return boundaryVolumeVariables_[getLocalIdx_(scv.dofIndex())];
70 return gridVolVars().volVars(scvIdx);
72 return boundaryVolumeVariables_[getLocalIdx_(scvIdx)];
80 template<
class FVElementGeometry,
class SolutionVector>
82 const FVElementGeometry& fvGeometry,
83 const SolutionVector& sol) &&
85 this->bind_(element, fvGeometry, sol);
86 return std::move(*
this);
89 template<
class FVElementGeometry,
class SolutionVector>
90 void bind(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
91 const FVElementGeometry& fvGeometry,
92 const SolutionVector& sol) &
93 { this->bind_(element, fvGeometry, sol); }
100 template<
class FVElementGeometry,
class SolutionVector>
102 const FVElementGeometry& fvGeometry,
103 const SolutionVector& sol) &&
105 this->bindElement_(element, fvGeometry, sol);
106 return std::move(*
this);
109 template<
class FVElementGeometry,
class SolutionVector>
110 void bindElement(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
111 const FVElementGeometry& fvGeometry,
112 const SolutionVector& sol) &
113 { this->bindElement_(element, fvGeometry, sol); }
117 {
return *gridVolVarsPtr_; }
124 boundaryVolVarIndices_.clear();
125 boundaryVolumeVariables_.clear();
130 template<class FVElementGeometry, class SolutionVector, typename std::enable_if_t<isMultiTypeBlockVector<SolutionVector>::value,
int> = 0>
131 void bind_(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
132 const FVElementGeometry& fvGeometry,
133 const SolutionVector& sol)
136 bind_(element, fvGeometry, sol[FVElementGeometry::GridGeometry::cellCenterIdx()]);
141 template<class FVElementGeometry, class SolutionVector, typename std::enable_if_t<!isMultiTypeBlockVector<SolutionVector>::value,
int> = 0>
142 void bind_(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
143 const FVElementGeometry& fvGeometry,
144 const SolutionVector& sol)
146 if (!fvGeometry.hasBoundaryScvf())
150 boundaryVolVarIndices_.reserve(fvGeometry.numScvf());
151 boundaryVolumeVariables_.reserve(fvGeometry.numScvf());
154 for (
auto&& scvf : scvfs(fvGeometry))
157 if (!scvf.boundary())
160 const auto& problem = gridVolVars().problem();
161 auto boundaryPriVars = gridVolVars().getBoundaryPriVars(problem, sol, element, scvf);
162 const auto elemSol = elementSolution<FVElementGeometry>(std::move(boundaryPriVars));
163 auto&& scvI = fvGeometry.scv(scvf.insideScvIdx());
165 VolumeVariables volVars;
166 volVars.update(elemSol,
171 boundaryVolumeVariables_.emplace_back(std::move(volVars));
172 boundaryVolVarIndices_.push_back(scvf.outsideScvIdx());
177 template<
class FVElementGeometry,
class SolutionVector>
178 void bindElement_(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
179 const FVElementGeometry& fvGeometry,
180 const SolutionVector& sol)
183 const GridVolumeVariables* gridVolVarsPtr_;
186 int getLocalIdx_(
const int volVarIdx)
const
188 auto it = std::find(boundaryVolVarIndices_.begin(), boundaryVolVarIndices_.end(), volVarIdx);
189 assert(it != boundaryVolVarIndices_.end() &&
"Could not find the current volume variables for volVarIdx!");
193 std::vector<std::size_t> boundaryVolVarIndices_;
194 std::vector<VolumeVariables> boundaryVolumeVariables_;
195 const std::size_t numScv_;
207 using PrimaryVariables =
typename GVV::VolumeVariables::PrimaryVariables;
218 : gridVolVarsPtr_(&gridVolVars) {}
225 template<
class FVElementGeometry,
class SolutionVector>
227 const FVElementGeometry& fvGeometry,
228 const SolutionVector& sol) &&
230 this->bind_(element, fvGeometry, sol);
231 return std::move(*
this);
234 template<
class FVElementGeometry,
class SolutionVector>
235 void bind(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
236 const FVElementGeometry& fvGeometry,
237 const SolutionVector& sol) &
238 { this->bind_(element, fvGeometry, sol); }
245 template<
class FVElementGeometry,
class SolutionVector>
247 const FVElementGeometry& fvGeometry,
248 const SolutionVector& sol) &&
250 this->bindElement_(element, fvGeometry, sol);
251 return std::move(*
this);
254 template<
class FVElementGeometry,
class SolutionVector>
255 void bindElement(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
256 const FVElementGeometry& fvGeometry,
257 const SolutionVector& sol) &
258 { this->bindElement_(element, fvGeometry, sol); }
261 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value,
int> = 0>
263 {
return volumeVariables_[getLocalIdx_(scv.dofIndex())]; }
266 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value,
int> = 0>
268 {
return volumeVariables_[getLocalIdx_(scv.dofIndex())]; }
272 {
return volumeVariables_[getLocalIdx_(scvIdx)]; }
276 {
return volumeVariables_[getLocalIdx_(scvIdx)]; }
280 {
return *gridVolVarsPtr_; }
285 template<class FVElementGeometry, class SolutionVector, typename std::enable_if_t<isMultiTypeBlockVector<SolutionVector>::value,
int> = 0>
286 void bind_(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
287 const FVElementGeometry& fvGeometry,
288 const SolutionVector& sol)
291 bind_(element, fvGeometry, sol[FVElementGeometry::GridGeometry::cellCenterIdx()]);
296 template<class FVElementGeometry, class SolutionVector, typename std::enable_if_t<!isMultiTypeBlockVector<SolutionVector>::value,
int> = 0>
297 void bind_(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
298 const FVElementGeometry& fvGeometry,
299 const SolutionVector& sol)
303 const auto& problem = gridVolVars().problem();
304 const auto& gridGeometry = fvGeometry.gridGeometry();
305 const auto globalI = gridGeometry.elementMapper().index(element);
306 const auto& map = gridGeometry.connectivityMap();
307 constexpr auto cellCenterIdx = FVElementGeometry::GridGeometry::cellCenterIdx();
308 const auto& connectivityMapI = map(cellCenterIdx, cellCenterIdx, globalI);
309 const auto numDofs = connectivityMapI.size();
311 auto&& scvI = fvGeometry.scv(globalI);
314 volumeVariables_.resize(numDofs+1);
315 volVarIndices_.resize(numDofs+1);
319 auto doVolVarUpdate = [&](
int globalJ)
321 const auto& elementJ = gridGeometry.element(globalJ);
322 auto&& scvJ = fvGeometry.scv(globalJ);
323 const auto elemSol = makeElementSolutionFromCellCenterPrivars<PrimaryVariables>(sol[globalJ]);
324 volumeVariables_[localIdx].update(elemSol,
328 volVarIndices_[localIdx] = scvJ.dofIndex();
333 doVolVarUpdate(globalI);
336 for (
const auto& globalJ : connectivityMapI)
337 doVolVarUpdate(globalJ);
339 if (fvGeometry.hasBoundaryScvf())
342 for (
auto&& scvf : scvfs(fvGeometry))
345 if (!scvf.boundary())
348 volumeVariables_.resize(localIdx+1);
349 volVarIndices_.resize(localIdx+1);
351 auto boundaryPriVars = gridVolVars().getBoundaryPriVars(problem, sol, element, scvf);
352 auto elemSol = elementSolution<FVElementGeometry>(std::move(boundaryPriVars));
353 volumeVariables_[localIdx].update(elemSol,
357 volVarIndices_[localIdx] = scvf.outsideScvIdx();
365 template<class FVElementGeometry, class SolutionVector, typename std::enable_if_t<isMultiTypeBlockVector<SolutionVector>::value,
int> = 0>
366 void bindElement_(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
367 const FVElementGeometry& fvGeometry,
368 const SolutionVector& sol)
371 bindElement_(element, fvGeometry, sol[FVElementGeometry::GridGeometry::cellCenterIdx()]);
376 template<class FVElementGeometry, class SolutionVector, typename std::enable_if_t<!isMultiTypeBlockVector<SolutionVector>::value,
int> = 0>
377 void bindElement_(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
378 const FVElementGeometry& fvGeometry,
379 const SolutionVector& sol)
383 const auto globalI = fvGeometry.gridGeometry().elementMapper().index(element);
384 volumeVariables_.resize(1);
385 volVarIndices_.resize(1);
388 auto&& scv = fvGeometry.scv(globalI);
390 const auto elemSol = makeElementSolutionFromCellCenterPrivars<PrimaryVariables>(sol[globalI]);
391 volumeVariables_[0].update(elemSol,
392 gridVolVars().problem(),
395 volVarIndices_[0] = scv.dofIndex();
401 volVarIndices_.clear();
402 volumeVariables_.clear();
405 const GridVolumeVariables* gridVolVarsPtr_;
407 int getLocalIdx_(
const int volVarIdx)
const
409 auto it = std::find(volVarIndices_.begin(), volVarIndices_.end(), volVarIdx);
410 assert(it != volVarIndices_.end() &&
"Could not find the current volume variables for volVarIdx!");
414 std::vector<std::size_t> volVarIndices_;
415 std::vector<VolumeVariables> volumeVariables_;
GVV GridVolumeVariables
export type of the grid volume variables
Definition: staggered/freeflow/elementvolumevariables.hh:211
StaggeredElementVolumeVariables bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: staggered/freeflow/elementvolumevariables.hh:226
StaggeredElementVolumeVariables bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: staggered/freeflow/elementvolumevariables.hh:246
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: staggered/freeflow/elementvolumevariables.hh:235
StaggeredElementVolumeVariables(const GridVolumeVariables &gridVolVars)
Constructor.
Definition: staggered/freeflow/elementvolumevariables.hh:217
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: staggered/freeflow/elementvolumevariables.hh:255
typename GridVolumeVariables::VolumeVariables VolumeVariables
export type of the volume variables
Definition: staggered/freeflow/elementvolumevariables.hh:214
const GridVolumeVariables & gridVolVars() const
The global volume variables object we are a restriction of.
Definition: staggered/freeflow/elementvolumevariables.hh:279
typename GridVolumeVariables::VolumeVariables VolumeVariables
export type of the volume variables
Definition: staggered/freeflow/elementvolumevariables.hh:47
const GridVolumeVariables & gridVolVars() const
The global volume variables object we are a restriction of.
Definition: staggered/freeflow/elementvolumevariables.hh:116
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: staggered/freeflow/elementvolumevariables.hh:110
GVV GridVolumeVariables
export type of the grid volume variables
Definition: staggered/freeflow/elementvolumevariables.hh:44
StaggeredElementVolumeVariables bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: staggered/freeflow/elementvolumevariables.hh:101
StaggeredElementVolumeVariables(const GridVolumeVariables &gridVolVars)
Constructor.
Definition: staggered/freeflow/elementvolumevariables.hh:50
StaggeredElementVolumeVariables bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: staggered/freeflow/elementvolumevariables.hh:81
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: staggered/freeflow/elementvolumevariables.hh:90
Base class for the element volume variables vector for the staggered model.
Definition: staggered/freeflow/elementvolumevariables.hh:32
static ctype distance(const Dune::FieldVector< ctype, dimWorld > &a, const Dune::FieldVector< ctype, dimWorld > &b)
Compute the shortest distance between two points.
Definition: distance.hh:282
The local element solution class for staggered methods.
Type traits to be used with vector types.