24#ifndef DUMUX_DISCRETIZATION_STAGGERED_FV_ELEMENT_GEOMETRY_HH
25#define DUMUX_DISCRETIZATION_STAGGERED_FV_ELEMENT_GEOMETRY_HH
42template<
class GG,
bool enableGr
idGeometryCache>
57 using GridView =
typename GG::GridView;
62 using Element =
typename GridView::template Codim<0>::Entity;
66 using ParentType::ParentType;
70 template<
class CellCenterOrFaceFVGr
idGeometry>
72 :
ParentType(gridGeometry.actualGridGeometry()) {}
75 using ParentType::scvf;
78 return this->gridGeometry().scvf(eIdx, localScvfIdx);
94 using GridView =
typename GG::GridView;
99 using Element =
typename GridView::template Codim<0>::Entity;
109 template<
class CellCenterOrFaceFVGr
idGeometry>
111 : gridGeometryPtr_(&gridGeometry.actualGridGeometry()) {}
115 : gridGeometryPtr_(&gridGeometry) {}
120 return scvf(this->gridGeometry().localToGlobalScvfIndex(eIdx, localScvfIdx));
127 if (scvIdx == scvIndices_[0])
130 return neighborScvs_[findLocalIndex_(scvIdx, neighborScvIndices_)];
137 auto it = std::find(scvfIndices_.begin(), scvfIndices_.end(), scvfIdx);
138 if (it != scvfIndices_.end())
141 return neighborScvfs_[findLocalIndex_(scvfIdx, neighborScvfIndices_)];
149 friend inline Dune::IteratorRange<typename std::array<SubControlVolume, 1>::const_iterator>
152 using IteratorType =
typename std::array<SubControlVolume, 1>::const_iterator;
153 return Dune::IteratorRange<IteratorType>(g.scvs_.begin(), g.scvs_.end());
161 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
164 using IteratorType =
typename std::vector<SubControlVolumeFace>::const_iterator;
165 return Dune::IteratorRange<IteratorType>(g.scvfs_.begin(), g.scvfs_.end());
170 {
return scvs_.size(); }
174 {
return scvfs_.size(); }
180 bindElement(element);
182 neighborScvs_.reserve(element.subEntities(1));
183 neighborScvfIndices_.reserve(element.subEntities(1));
184 neighborScvfs_.reserve(element.subEntities(1));
186 std::vector<GridIndexType> handledNeighbors;
187 handledNeighbors.reserve(element.subEntities(1));
188 for (
const auto& intersection : intersections(gridGeometry().gridView(), element))
190 if (intersection.neighbor())
192 const auto outside = intersection.outside();
193 const auto outsideIdx = gridGeometry().elementMapper().index(outside);
196 if ( std::find(handledNeighbors.begin(), handledNeighbors.end(), outsideIdx) == handledNeighbors.end() )
198 makeNeighborGeometries_(outside, outsideIdx);
199 handledNeighbors.push_back(outsideIdx);
210 scvfs_.reserve(element.subEntities(1));
211 scvfIndices_.reserve(element.subEntities(1));
212 makeElementGeometries_();
217 {
return static_cast<bool>(element_); }
221 {
return *element_; }
225 {
return *gridGeometryPtr_; }
229 {
return hasBoundaryScvf_; }
234 void makeElementGeometries_()
236 const auto& element = *element_;
237 const auto eIdx = gridGeometry().elementMapper().index(element);
238 scvs_[0] = SubControlVolume(element.geometry(), eIdx);
239 scvIndices_[0] = eIdx;
241 const auto& scvFaceIndices = gridGeometry().scvfIndicesOfScv(eIdx);
242 const auto& neighborVolVarIndices = gridGeometry().neighborVolVarIndices(eIdx);
244 typename GridGeometry::GeometryHelper geometryHelper(element, gridGeometry().gridView());
247 for (
const auto& intersection : intersections(gridGeometry().gridView(), element))
249 const auto& scvfNeighborVolVarIndex = neighborVolVarIndices[scvfCounter];
251 if (intersection.neighbor() || intersection.boundary())
253 geometryHelper.updateLocalFace(gridGeometry().intersectionMapper(), intersection);
254 std::vector<GridIndexType> scvIndices{eIdx, scvfNeighborVolVarIndex};
255 scvfs_.emplace_back(intersection,
256 intersection.geometry(),
257 scvFaceIndices[scvfCounter],
260 scvfIndices_.emplace_back(scvFaceIndices[scvfCounter]);
263 if (intersection.boundary())
264 hasBoundaryScvf_ =
true;
270 void makeNeighborGeometries_(
const Element& element,
const GridIndexType eIdx)
275 neighborScvs_.emplace_back(
element.geometry(), eIdx);
276 neighborScvIndices_.push_back(eIdx);
278 const auto& scvFaceIndices = gridGeometry().scvfIndicesOfScv(eIdx);
279 const auto& neighborVolVarIndices = gridGeometry().neighborVolVarIndices(eIdx);
281 typename GridGeometry::GeometryHelper geometryHelper(element, gridGeometry().gridView());
284 for (
const auto& intersection : intersections(gridGeometry().gridView(), element))
286 const auto& scvfNeighborVolVarIndex = neighborVolVarIndices[scvfCounter];
287 geometryHelper.updateLocalFace(gridGeometry().intersectionMapper(), intersection);
289 if (intersection.neighbor())
292 if (intersection.outside() == *element_)
294 std::vector<GridIndexType> scvIndices{eIdx, scvfNeighborVolVarIndex};
295 neighborScvfs_.emplace_back(intersection,
296 intersection.geometry(),
297 scvFaceIndices[scvfCounter],
301 neighborScvfIndices_.push_back(scvFaceIndices[scvfCounter]);
305 else if (intersection.boundary())
310 const LocalIndexType findLocalIndex_(
const GridIndexType idx,
311 const std::vector<GridIndexType>& indices)
const
313 auto it = std::find(indices.begin(), indices.end(), idx);
314 assert(it != indices.end() &&
"Could not find the scv/scvf! Make sure to properly bind this class!");
321 scvfIndices_.clear();
324 neighborScvIndices_.clear();
325 neighborScvfIndices_.clear();
326 neighborScvs_.clear();
327 neighborScvfs_.clear();
329 hasBoundaryScvf_ =
false;
332 std::optional<Element> element_;
333 const GridGeometry* gridGeometryPtr_;
336 std::array<GridIndexType, 1> scvIndices_;
337 std::array<SubControlVolume, 1> scvs_;
339 std::vector<GridIndexType> scvfIndices_;
340 std::vector<SubControlVolumeFace> scvfs_;
342 std::vector<GridIndexType> neighborScvIndices_;
343 std::vector<SubControlVolume> neighborScvs_;
345 std::vector<GridIndexType> neighborScvfIndices_;
346 std::vector<SubControlVolumeFace> neighborScvfs_;
348 bool hasBoundaryScvf_ =
false;
Defines the index types used for grid and local indices.
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
typename GridView::IndexSet::IndexType GridIndex
Definition: indextraits.hh:39
unsigned int LocalIndex
Definition: indextraits.hh:40
Stencil-local finite volume geometry (scvs and scvfs) for cell-centered TPFA models This builds up th...
Definition: discretization/cellcentered/tpfa/fvelementgeometry.hh:51
Stencil-local finite volume geometry (scvs and scvfs) for cell-centered TPFA models Specialization fo...
Definition: discretization/cellcentered/tpfa/fvelementgeometry.hh:61
typename GridView::template Codim< 0 >::Entity Element
export type of the element
Definition: discretization/cellcentered/tpfa/fvelementgeometry.hh:68
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: discretization/cellcentered/tpfa/fvelementgeometry.hh:72
Stencil-local finite volume geometry (scvs and scvfs) for staggered models This builds up the sub con...
Definition: discretization/staggered/fvelementgeometry.hh:43
const SubControlVolumeFace & scvf(GridIndexType eIdx, LocalIndexType localScvfIdx) const
Definition: discretization/staggered/fvelementgeometry.hh:76
StaggeredFVElementGeometry(const CellCenterOrFaceFVGridGeometry &gridGeometry)
Definition: discretization/staggered/fvelementgeometry.hh:71
Base class for the finite volume geometry vector for staggered models This locally builds up the sub ...
Definition: discretization/staggered/fvelementgeometry.hh:92
typename GridView::template Codim< 0 >::Entity Element
export type of the element
Definition: discretization/staggered/fvelementgeometry.hh:99
bool hasBoundaryScvf() const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition: discretization/staggered/fvelementgeometry.hh:228
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const ThisType &g)
Definition: discretization/staggered/fvelementgeometry.hh:162
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: discretization/staggered/fvelementgeometry.hh:101
const SubControlVolume & scv(GridIndexType scvIdx) const
Definition: discretization/staggered/fvelementgeometry.hh:125
StaggeredFVElementGeometry(const CellCenterOrFaceFVGridGeometry &gridGeometry)
Definition: discretization/staggered/fvelementgeometry.hh:110
std::size_t numScv() const
number of sub control volumes in this fv element geometry
Definition: discretization/staggered/fvelementgeometry.hh:169
const SubControlVolumeFace & scvf(GridIndexType eIdx, LocalIndexType localScvfIdx) const
Get a sub control volume face with an element index and a local scvf index.
Definition: discretization/staggered/fvelementgeometry.hh:118
const GridGeometry & gridGeometry() const
The grid finite volume geometry we are a restriction of.
Definition: discretization/staggered/fvelementgeometry.hh:224
std::size_t numScvf() const
number of sub control volumes in this fv element geometry
Definition: discretization/staggered/fvelementgeometry.hh:173
StaggeredFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: discretization/staggered/fvelementgeometry.hh:114
const Element & element() const
The bound element.
Definition: discretization/staggered/fvelementgeometry.hh:220
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition: discretization/staggered/fvelementgeometry.hh:216
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: discretization/staggered/fvelementgeometry.hh:103
friend Dune::IteratorRange< typename std::array< SubControlVolume, 1 >::const_iterator > scvs(const ThisType &g)
Definition: discretization/staggered/fvelementgeometry.hh:150
void bindElement(const Element &element)
Binding of an element preparing the geometries only inside the element.
Definition: discretization/staggered/fvelementgeometry.hh:206
const SubControlVolumeFace & scvf(GridIndexType scvfIdx) const
Definition: discretization/staggered/fvelementgeometry.hh:135
GG GridGeometry
export type of finite volume grid geometry
Definition: discretization/staggered/fvelementgeometry.hh:105
void bind(const Element &element)
Definition: discretization/staggered/fvelementgeometry.hh:178
Stencil-local finite volume geometry (scvs and scvfs) for cell-centered TPFA models This builds up th...