14#ifndef DUMUX_DISCRETIZATION_CCTPFA_FV_GRID_GEOMETRY_HH
15#define DUMUX_DISCRETIZATION_CCTPFA_FV_GRID_GEOMETRY_HH
42template<
class Gr
idView,
class MapperTraits = DefaultMapperTraits<Gr
idView>>
49 template<
class Gr
idGeometry>
52 template<
class Gr
idGeometry,
bool enableCache>
59 static constexpr int maxNumScvfNeighbors = int(GridView::dimension)<int(GridView::dimensionworld) ? 8 : 1<<(GridView::dimension-1);
68template<
class GridView,
69 bool enableGridGeometryCache =
false,
79template<
class GV,
class Traits>
85 using ConnectivityMap =
typename Traits::template ConnectivityMap<ThisType>;
87 using Element =
typename GV::template Codim<0>::Entity;
89 static const int dim = GV::dimension;
90 static const int dimWorld = GV::dimensionworld;
113 static constexpr int maxElementStencilSize = LocalView::maxNumElementScvfs*Traits::maxNumScvfNeighbors + 1;
121 , periodicGridTraits_(this->gridView().grid())
125 DUNE_THROW(Dune::InvalidStateException,
"The cctpfa discretization method needs at least an overlap of 1 for parallel computations. "
126 <<
" Set the parameter \"Grid.Overlap\" in the input file.");
139 {
return this->elementMapper(); }
150 return scvfs_.size();
156 return numBoundaryScvf_;
161 {
return this->gridView().size(0); }
167 ParentType::update(gridView);
174 ParentType::update(std::move(gridView));
181 return scvs_[scvIdx];
187 return scvfs_[scvfIdx];
194 return scvfs_[flipScvfIndices_[scvfIdx][outsideScvfIdx]];
200 return scvfIndicesOfScv_[scvIdx];
208 {
return connectivityMap_; }
212 {
return hasBoundaryScvf_[eIdx]; }
221 scvfIndicesOfScv_.clear();
222 flipScvfIndices_.clear();
225 std::size_t numScvs = numDofs();
226 std::size_t numScvf = 0;
227 for (
const auto& element : elements(this->gridView()))
228 numScvf += element.subEntities(1);
231 scvs_.resize(numScvs);
232 scvfs_.reserve(numScvf);
233 scvfIndicesOfScv_.resize(numScvs);
234 hasBoundaryScvf_.assign(numScvs,
false);
237 GridIndexType scvfIdx = 0;
238 numBoundaryScvf_ = 0;
239 for (
const auto& element : elements(this->gridView()))
241 const auto eIdx = this->elementMapper().index(element);
242 scvs_[eIdx] = SubControlVolume(element.geometry(), eIdx);
245 std::vector<GridIndexType> scvfsIndexSet;
246 scvfsIndexSet.reserve(element.subEntities(1));
250 using ScvfGridIndexStorage =
typename SubControlVolumeFace::Traits::GridIndexStorage;
251 std::vector<ScvfGridIndexStorage> outsideIndices;
255 outsideIndices.resize(element.subEntities(1));
256 std::for_each(outsideIndices.begin(), outsideIndices.end(), [eIdx] (
auto& nIndices) { nIndices.push_back(eIdx); });
259 for (
const auto& intersection : intersections(this->gridView(), element))
261 if (intersection.neighbor())
263 const auto nIdx = this->elementMapper().index( intersection.outside() );
264 outsideIndices[intersection.indexInInside()].push_back(nIdx);
269 for (
const auto& intersection : intersections(this->gridView(), element))
272 if (intersection.neighbor())
275 if (periodicGridTraits_.isPeriodic(intersection))
280 const auto nIdx = this->elementMapper().index(intersection.outside());
281 scvfs_.emplace_back(intersection,
282 intersection.geometry(),
284 ScvfGridIndexStorage({eIdx, nIdx}),
286 scvfsIndexSet.push_back(scvfIdx++);
292 auto indexInInside = intersection.indexInInside();
294 if (outsideIndices[indexInInside].empty())
298 scvfs_.emplace_back(intersection,
299 intersection.geometry(),
301 outsideIndices[indexInInside],
303 scvfsIndexSet.push_back(scvfIdx++);
304 outsideIndices[indexInInside].clear();
309 else if (intersection.boundary())
311 scvfs_.emplace_back(intersection,
312 intersection.geometry(),
314 ScvfGridIndexStorage({eIdx,
static_cast<GridIndexType
>(this->gridView().size(0) + numBoundaryScvf_++)}),
316 scvfsIndexSet.push_back(scvfIdx++);
318 hasBoundaryScvf_[eIdx] =
true;
323 scvfIndicesOfScv_[eIdx] = scvfsIndexSet;
327 if (dim < dimWorld || this->isPeriodic())
329 flipScvfIndices_.resize(scvfs_.size());
330 for (
auto&& scvf : scvfs_)
335 flipScvfIndices_[scvf.index()].resize(scvf.numOutsideScvs());
336 const auto insideScvIdx = scvf.insideScvIdx();
338 for (
unsigned int i = 0; i < scvf.numOutsideScvs(); ++i)
339 flipScvfIndices_[scvf.index()][i] = findFlippedScvfIndex_(insideScvIdx, scvf.outsideScvIdx(i));
344 connectivityMap_.update(*
this);
348 GridIndexType findFlippedScvfIndex_(GridIndexType insideScvIdx, GridIndexType outsideScvIdx)
351 for (
auto outsideScvfIndex : scvfIndicesOfScv_[outsideScvIdx])
353 const auto& outsideScvf = this->scvf(outsideScvfIndex);
354 for (
unsigned int j = 0; j < outsideScvf.numOutsideScvs(); ++j)
355 if (outsideScvf.outsideScvIdx(j) == insideScvIdx)
356 return outsideScvf.index();
359 DUNE_THROW(Dune::InvalidStateException,
"No flipped version of this scvf found!");
363 ConnectivityMap connectivityMap_;
366 std::vector<SubControlVolume> scvs_;
367 std::vector<SubControlVolumeFace> scvfs_;
368 std::vector<std::vector<GridIndexType>> scvfIndicesOfScv_;
369 std::size_t numBoundaryScvf_;
370 std::vector<bool> hasBoundaryScvf_;
373 std::vector<std::vector<GridIndexType>> flipScvfIndices_;
375 PeriodicGridTraits<typename GridView::Grid> periodicGridTraits_;
385template<
class GV,
class Traits>
391 using ConnectivityMap =
typename Traits::template ConnectivityMap<ThisType>;
394 using Element =
typename GV::template Codim<0>::Entity;
396 static const int dim = GV::dimension;
397 static const int dimWorld = GV::dimensionworld;
399 using ScvfGridIndexStorage =
typename Traits::SubControlVolumeFace::Traits::GridIndexStorage;
400 using NeighborVolVarIndices =
typename std::conditional_t< (dim<dimWorld),
401 ScvfGridIndexStorage,
402 Dune::ReservedVector<GridIndexType, 1> >;
425 static constexpr int maxElementStencilSize = LocalView::maxNumElementScvfs*Traits::maxNumScvfNeighbors + 1;
433 , periodicGridTraits_(this->gridView().grid())
437 DUNE_THROW(Dune::InvalidStateException,
"The cctpfa discretization method needs at least an overlap of 1 for parallel computations. "
438 <<
" Set the parameter \"Grid.Overlap\" in the input file.");
451 {
return this->elementMapper(); }
468 return numBoundaryScvf_;
473 {
return this->gridView().size(0); }
478 ParentType::update(gridView);
485 ParentType::update(std::move(gridView));
490 {
return scvfIndicesOfScv_[scvIdx]; }
494 {
return neighborVolVarIndices_[scvIdx]; }
501 {
return connectivityMap_; }
508 scvfIndicesOfScv_.clear();
509 neighborVolVarIndices_.clear();
512 numScvs_ = numDofs();
514 numBoundaryScvf_ = 0;
515 scvfIndicesOfScv_.resize(numScvs_);
516 neighborVolVarIndices_.resize(numScvs_);
519 for (
const auto& element : elements(this->gridView()))
521 const auto eIdx = this->elementMapper().index(element);
524 auto numLocalFaces = element.subEntities(1);
525 std::vector<GridIndexType> scvfsIndexSet;
526 std::vector<NeighborVolVarIndices> neighborVolVarIndexSet;
527 scvfsIndexSet.reserve(numLocalFaces);
528 neighborVolVarIndexSet.reserve(numLocalFaces);
532 std::vector<NeighborVolVarIndices> outsideIndices;
535 outsideIndices.resize(numLocalFaces);
536 for (
const auto& intersection : intersections(this->gridView(), element))
538 if (intersection.neighbor())
540 const auto nIdx = this->elementMapper().index(intersection.outside());
541 outsideIndices[intersection.indexInInside()].push_back(nIdx);
546 for (
const auto& intersection : intersections(this->gridView(), element))
549 if (intersection.neighbor())
552 if (periodicGridTraits_.isPeriodic(intersection))
557 scvfsIndexSet.push_back(numScvf_++);
558 const auto nIdx = this->elementMapper().index(intersection.outside());
559 neighborVolVarIndexSet.emplace_back(NeighborVolVarIndices({nIdx}));
565 auto indexInInside = intersection.indexInInside();
567 if (outsideIndices[indexInInside].empty())
571 scvfsIndexSet.push_back(numScvf_++);
572 neighborVolVarIndexSet.emplace_back(std::move(outsideIndices[indexInInside]));
573 outsideIndices[indexInInside].clear();
578 else if (intersection.boundary())
580 scvfsIndexSet.push_back(numScvf_++);
581 neighborVolVarIndexSet.emplace_back(NeighborVolVarIndices({
static_cast<GridIndexType
>(numScvs_ + numBoundaryScvf_++)}));
586 scvfIndicesOfScv_[eIdx] = scvfsIndexSet;
587 neighborVolVarIndices_[eIdx] = neighborVolVarIndexSet;
591 connectivityMap_.update(*
this);
595 std::size_t numScvs_;
596 std::size_t numScvf_;
597 std::size_t numBoundaryScvf_;
600 ConnectivityMap connectivityMap_;
603 std::vector<std::vector<GridIndexType>> scvfIndicesOfScv_;
604 std::vector<std::vector<NeighborVolVarIndices>> neighborVolVarIndices_;
606 PeriodicGridTraits<typename GridView::Grid> periodicGridTraits_;
Base class for grid geometries.
Stores the face indices corresponding to the neighbors of an element that contribute to the derivativ...
Check the overlap size for different discretization methods.
Base class for all grid geometries.
Definition: basegridgeometry.hh:52
typename BaseImplementation::GridView GridView
export the grid view type
Definition: basegridgeometry.hh:60
A simple version of the connectivity map for cellcentered schemes. This implementation works for sche...
Definition: cellcentered/connectivitymap.hh:41
Sub control volumes for cell-centered discretization schemes.
Definition: discretization/cellcentered/subcontrolvolume.hh:47
Stencil-local finite volume geometry (scvs and scvfs) for cell-centered TPFA models This builds up th...
Definition: discretization/cellcentered/tpfa/fvelementgeometry.hh:53
The finite volume geometry (scvs and scvfs) for cell-centered TPFA models on a grid view This builds ...
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:388
typename Traits::template LocalView< ThisType, false > LocalView
export the type of the fv element geometry (the local view type)
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:408
const std::vector< GridIndexType > & scvfIndicesOfScv(GridIndexType scvIdx) const
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:489
typename Traits::ElementMapper DofMapper
export dof mapper type
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:416
const DofMapper & dofMapper() const
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:450
CCTpfaFVGridGeometry(std::shared_ptr< BasicGridGeometry > gg)
Constructor with basic grid geometry used to share state with another grid geometry on the same grid ...
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:431
typename PeriodicGridTraits< typename GV::Grid >::SupportsPeriodicity SupportsPeriodicity
export whether the grid(geometry) supports periodicity
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:418
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:412
void update(GridView &&gridView)
update all fvElementGeometries (call this after grid adaption)
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:483
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:410
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:460
const ConnectivityMap & connectivityMap() const
Returns the connectivity map of which dofs have derivatives with respect to a given dof.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:500
BasicGridGeometry_t< GV, Traits > BasicGridGeometry
export basic grid geometry type for the alternative constructor
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:406
CCTpfaFVGridGeometry(const GridView &gridView)
Constructor from gridView.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:444
Extrusion_t< Traits > Extrusion
export the type of extrusion
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:414
void update(const GridView &gridView)
update all fvElementGeometries (call this after grid adaption)
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:476
std::size_t numDofs() const
The total number of degrees of freedom.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:472
std::size_t numBoundaryScvf() const
The total number of boundary sub control volume faces.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:466
const std::vector< NeighborVolVarIndices > & neighborVolVarIndices(GridIndexType scvIdx) const
Return the neighbor volVar indices for all scvfs in the scv with index scvIdx.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:493
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:454
The finite volume geometry (scvs and scvfs) for cell-centered TPFA models on a grid view This builds ...
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:82
typename Traits::template LocalView< ThisType, true > LocalView
export the type of the fv element geometry (the local view type)
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:96
const ConnectivityMap & connectivityMap() const
Returns the connectivity map of which dofs have derivatives with respect to a given dof.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:207
void update(const GridView &gridView)
update all fvElementGeometries (call this after grid adaption)
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:165
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:142
Extrusion_t< Traits > Extrusion
export the type of extrusion
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:102
BasicGridGeometry_t< GV, Traits > BasicGridGeometry
export basic grid geometry type for the alternative constructor
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:94
CCTpfaFVGridGeometry(const GridView &gridView)
Constructor from gridView.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:132
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:98
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:100
std::size_t numDofs() const
The total number of degrees of freedom.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:160
const std::vector< GridIndexType > & scvfIndicesOfScv(GridIndexType scvIdx) const
Get the sub control volume face indices of an scv by global index.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:198
typename PeriodicGridTraits< typename GV::Grid >::SupportsPeriodicity SupportsPeriodicity
export whether the grid(geometry) supports periodicity
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:106
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:148
const SubControlVolumeFace & scvf(GridIndexType scvfIdx) const
Get a sub control volume face with a global scvf index.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:185
void update(GridView &&gridView)
update all fvElementGeometries (call this after grid adaption)
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:172
bool hasBoundaryScvf(GridIndexType eIdx) const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:211
std::size_t numBoundaryScvf() const
The total number of boundary sub control volume faces.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:154
const SubControlVolumeFace & flipScvf(GridIndexType scvfIdx, unsigned int outsideScvfIdx=0) const
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:192
typename Traits::ElementMapper DofMapper
export dof mapper type
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:104
const SubControlVolume & scv(GridIndexType scvIdx) const
Get a sub control volume with a global scv index.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:179
CCTpfaFVGridGeometry(std::shared_ptr< BasicGridGeometry > gg)
Constructor with basic grid geometry used to share state with another grid geometry on the same grid ...
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:119
const DofMapper & dofMapper() const
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:138
The finite volume geometry (scvs and scvfs) for cell-centered TPFA models on a grid view This builds ...
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:71
The sub control volume face.
Definition: discretization/cellcentered/tpfa/subcontrolvolumeface.hh:78
Defines the default element and vertex mapper types.
Sub control volumes for cell-centered discretization schemes.
Stencil-local finite volume geometry (scvs and scvfs) for cell-centered TPFA models This builds up th...
The sub control volume face.
Helper classes to compute the integration elements.
Dune::Std::detected_or_t< Dumux::BasicGridGeometry< GV, typename T::ElementMapper, typename T::VertexMapper >, Detail::SpecifiesBaseGridGeometry, T > BasicGridGeometry_t
Type of the basic grid geometry implementation used as backend.
Definition: basegridgeometry.hh:42
The available discretization methods in Dumux.
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition: extrusion.hh:166
Grid properties related to periodicity.
The default traits for the tpfa finite volume grid geometry Defines the scv and scvf types and the ma...
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:45
static constexpr int maxNumScvfNeighbors
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:59
Check if the overlap size is valid for a given discretization method.
Definition: checkoverlapsize.hh:28
Structure to define the index types used for grid and local indices.
Definition: indextraits.hh:26
Definition: periodicgridtraits.hh:24