24#ifndef DUMUX_DISCRETIZATION_CCTPFA_ELEMENT_VOLUMEVARIABLES_HH
25#define DUMUX_DISCRETIZATION_CCTPFA_ELEMENT_VOLUMEVARIABLES_HH
42template<
class GVV,
bool cachingEnabled>
63 : gridVolVarsPtr_(&gridVolVars)
64 , numScv_(gridVolVars.problem().gridGeometry().numScv())
68 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value,
int> = 0>
71 if (scv.dofIndex() < numScv_)
72 return gridVolVars().volVars(scv.dofIndex());
74 return boundaryVolumeVariables_[getLocalIdx_(scv.dofIndex())];
81 return gridVolVars().volVars(scvIdx);
83 return boundaryVolumeVariables_[getLocalIdx_(scvIdx)];
87 template<
class FVElementGeometry,
class SolutionVector>
88 void bind(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
89 const FVElementGeometry& fvGeometry,
90 const SolutionVector& sol)
92 if (!fvGeometry.hasBoundaryScvf())
96 boundaryVolVarIndices_.reserve(fvGeometry.numScvf());
97 boundaryVolumeVariables_.reserve(fvGeometry.numScvf());
99 for (
const auto& scvf : scvfs(fvGeometry))
101 if (!scvf.boundary())
105 const auto& problem = gridVolVars().problem();
106 const auto bcTypes = problem.boundaryTypes(element, scvf);
107 if (bcTypes.hasOnlyDirichlet())
109 const auto dirichletPriVars = elementSolution<FVElementGeometry>(problem.dirichlet(element, scvf));
110 auto&& scvI = fvGeometry.scv(scvf.insideScvIdx());
113 volVars.update(dirichletPriVars,
118 boundaryVolumeVariables_.emplace_back(std::move(volVars));
119 boundaryVolVarIndices_.push_back(scvf.outsideScvIdx());
125 template<
class FVElementGeometry,
class SolutionVector>
126 void bindElement(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
127 const FVElementGeometry& fvGeometry,
128 const SolutionVector& sol)
133 {
return *gridVolVarsPtr_; }
139 boundaryVolVarIndices_.clear();
140 boundaryVolumeVariables_.clear();
143 const GridVolumeVariables* gridVolVarsPtr_;
146 int getLocalIdx_(
const int volVarIdx)
const
148 auto it = std::find(boundaryVolVarIndices_.begin(), boundaryVolVarIndices_.end(), volVarIdx);
149 assert(it != boundaryVolVarIndices_.end() &&
"Could not find the current volume variables for volVarIdx!");
153 std::vector<std::size_t> boundaryVolVarIndices_;
154 std::vector<VolumeVariables> boundaryVolumeVariables_;
155 const std::size_t numScv_;
174 : gridVolVarsPtr_(&gridVolVars) {}
177 template<
class FVElementGeometry,
class SolutionVector>
178 void bind(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
179 const FVElementGeometry& fvGeometry,
180 const SolutionVector& sol)
184 const auto& problem = gridVolVars().problem();
185 const auto& gridGeometry = fvGeometry.gridGeometry();
186 const auto globalI = gridGeometry.elementMapper().index(element);
187 const auto& connectivityMapI = gridGeometry.connectivityMap()[globalI];
188 const auto numDofs = connectivityMapI.size() + 1;
191 volumeVariables_.resize(numDofs);
192 volVarIndices_.resize(numDofs);
196 auto&& scvI = fvGeometry.scv(globalI);
197 volumeVariables_[localIdx].update(
elementSolution(element, sol, gridGeometry),
201 volVarIndices_[localIdx] = scvI.dofIndex();
205 for (
const auto& dataJ : connectivityMapI)
207 const auto& elementJ = gridGeometry.element(dataJ.globalJ);
208 auto&& scvJ = fvGeometry.scv(dataJ.globalJ);
209 volumeVariables_[localIdx].update(
elementSolution(elementJ, sol, gridGeometry),
213 volVarIndices_[localIdx] = scvJ.dofIndex();
217 if (fvGeometry.hasBoundaryScvf())
220 for (
auto&& scvf : scvfs(fvGeometry))
223 if (!scvf.boundary())
227 const auto bcTypes = problem.boundaryTypes(element, scvf);
228 if (bcTypes.hasOnlyDirichlet())
230 const auto dirichletPriVars = elementSolution<FVElementGeometry>(problem.dirichlet(element, scvf));
232 volumeVariables_.resize(localIdx+1);
233 volVarIndices_.resize(localIdx+1);
234 volumeVariables_[localIdx].update(dirichletPriVars,
238 volVarIndices_[localIdx] = scvf.outsideScvIdx();
266 template<
class FVElementGeometry,
class SolutionVector>
267 void bindElement(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
268 const FVElementGeometry& fvGeometry,
269 const SolutionVector& sol)
273 const auto eIdx = fvGeometry.gridGeometry().elementMapper().index(element);
274 volumeVariables_.resize(1);
275 volVarIndices_.resize(1);
278 auto&& scv = fvGeometry.scv(eIdx);
279 volumeVariables_[0].update(
elementSolution(element, sol, fvGeometry.gridGeometry()),
280 gridVolVars().problem(),
283 volVarIndices_[0] = scv.dofIndex();
287 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value,
int> = 0>
289 {
return volumeVariables_[getLocalIdx_(scv.dofIndex())]; }
292 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value,
int> = 0>
294 {
return volumeVariables_[getLocalIdx_(scv.dofIndex())]; }
298 {
return volumeVariables_[getLocalIdx_(scvIdx)]; }
302 {
return volumeVariables_[getLocalIdx_(scvIdx)]; }
306 {
return *gridVolVarsPtr_; }
312 volVarIndices_.clear();
313 volumeVariables_.clear();
316 const GridVolumeVariables* gridVolVarsPtr_;
319 int getLocalIdx_(
const int volVarIdx)
const
321 auto it = std::find(volVarIndices_.begin(), volVarIndices_.end(), volVarIdx);
322 assert(it != volVarIndices_.end() &&
"Could not find the current volume variables for volVarIdx!");
326 std::vector<std::size_t> volVarIndices_;
327 std::vector<VolumeVariables> volumeVariables_;
ctype distance(const Dune::FieldVector< ctype, dimWorld > &a, const Dune::FieldVector< ctype, dimWorld > &b)
Compute the shortest distance between two points.
Definition: distance.hh:138
auto elementSolution(const Element &element, const SolutionVector &sol, const GridGeometry &gg) -> std::enable_if_t< GridGeometry::discMethod==DiscretizationMethod::box, BoxElementSolution< typename GridGeometry::LocalView, std::decay_t< decltype(std::declval< SolutionVector >()[0])> > >
Make an element solution for box schemes.
Definition: box/elementsolution.hh:118
The local (stencil) volume variables class for cell centered tpfa models.
Definition: cellcentered/tpfa/elementvolumevariables.hh:44
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol)
precompute the volume variables of an element - do nothing: volVars are cached
Definition: cellcentered/tpfa/elementvolumevariables.hh:126
CCTpfaElementVolumeVariables(const GridVolumeVariables &gridVolVars)
Constructor.
Definition: cellcentered/tpfa/elementvolumevariables.hh:62
const GridVolumeVariables & gridVolVars() const
The global volume variables object we are a restriction of.
Definition: cellcentered/tpfa/elementvolumevariables.hh:132
GVV GridVolumeVariables
export type of the grid volume variables
Definition: cellcentered/tpfa/elementvolumevariables.hh:56
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol)
precompute all boundary volume variables in a stencil of an element, the remaining ones are cached
Definition: cellcentered/tpfa/elementvolumevariables.hh:88
typename GridVolumeVariables::VolumeVariables VolumeVariables
export type of the volume variables
Definition: cellcentered/tpfa/elementvolumevariables.hh:59
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol)
Prepares the volume variables within the element stencil.
Definition: cellcentered/tpfa/elementvolumevariables.hh:178
typename GridVolumeVariables::VolumeVariables VolumeVariables
export type of the volume variables
Definition: cellcentered/tpfa/elementvolumevariables.hh:170
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol)
Definition: cellcentered/tpfa/elementvolumevariables.hh:267
GVV GridVolumeVariables
export type of the grid volume variables
Definition: cellcentered/tpfa/elementvolumevariables.hh:167
CCTpfaElementVolumeVariables(const GridVolumeVariables &gridVolVars)
Constructor.
Definition: cellcentered/tpfa/elementvolumevariables.hh:173
const GridVolumeVariables & gridVolVars() const
The global volume variables object we are a restriction of.
Definition: cellcentered/tpfa/elementvolumevariables.hh:305
The local element solution class for cell-centered methods.