26#ifndef DUMUX_DISCRETIZATION_CCTPFA_FV_GRID_GEOMETRY_HH
27#define DUMUX_DISCRETIZATION_CCTPFA_FV_GRID_GEOMETRY_HH
50template<
class Gr
idView,
class MapperTraits = DefaultMapperTraits<Gr
idView>>
57 template<
class Gr
idGeometry>
60 template<
class Gr
idGeometry,
bool enableCache>
67 static constexpr int maxNumScvfNeighbors = int(GridView::dimension)<int(GridView::dimensionworld) ? 8 : 1<<(GridView::dimension-1);
76template<
class GridView,
77 bool enableGridGeometryCache =
false,
87template<
class GV,
class Traits>
93 using ConnectivityMap =
typename Traits::template ConnectivityMap<ThisType>;
95 using Element =
typename GV::template Codim<0>::Entity;
97 static const int dim = GV::dimension;
98 static const int dimWorld = GV::dimensionworld;
114 static constexpr int maxElementStencilSize = LocalView::maxNumElementScvfs*Traits::maxNumScvfNeighbors + 1;
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.");
132 {
return this->elementMapper(); }
143 return scvfs_.size();
149 return numBoundaryScvf_;
154 {
return this->gridView().size(0); }
159 ParentType::update();
164 scvfIndicesOfScv_.clear();
165 flipScvfIndices_.clear();
168 std::size_t numScvs = numDofs();
169 std::size_t numScvf = 0;
170 for (
const auto& element : elements(this->gridView()))
171 numScvf += element.subEntities(1);
174 scvs_.resize(numScvs);
175 scvfs_.reserve(numScvf);
176 scvfIndicesOfScv_.resize(numScvs);
177 hasBoundaryScvf_.resize(numScvs,
false);
180 GridIndexType scvfIdx = 0;
181 numBoundaryScvf_ = 0;
182 for (
const auto& element : elements(this->gridView()))
184 const auto eIdx = this->elementMapper().index(element);
188 std::vector<GridIndexType> scvfsIndexSet;
189 scvfsIndexSet.reserve(element.subEntities(1));
193 using ScvfGridIndexStorage =
typename SubControlVolumeFace::Traits::GridIndexStorage;
194 std::vector<ScvfGridIndexStorage> outsideIndices;
198 outsideIndices.resize(element.subEntities(1));
199 std::for_each(outsideIndices.begin(), outsideIndices.end(), [eIdx] (
auto& nIndices) { nIndices.push_back(eIdx); });
202 for (
const auto& intersection : intersections(this->gridView(), element))
204 if (intersection.neighbor())
206 const auto nIdx = this->elementMapper().index( intersection.outside() );
207 outsideIndices[intersection.indexInInside()].push_back(nIdx);
212 for (
const auto& intersection : intersections(this->gridView(), element))
215 if (intersection.neighbor())
218 if (intersection.boundary())
223 const auto nIdx = this->elementMapper().index(intersection.outside());
224 scvfs_.emplace_back(intersection,
225 intersection.geometry(),
227 ScvfGridIndexStorage({eIdx, nIdx}),
229 scvfsIndexSet.push_back(scvfIdx++);
235 auto indexInInside = intersection.indexInInside();
237 if (outsideIndices[indexInInside].empty())
241 scvfs_.emplace_back(intersection,
242 intersection.geometry(),
244 outsideIndices[indexInInside],
246 scvfsIndexSet.push_back(scvfIdx++);
247 outsideIndices[indexInInside].clear();
252 else if (intersection.boundary())
254 scvfs_.emplace_back(intersection,
255 intersection.geometry(),
257 ScvfGridIndexStorage({eIdx,
static_cast<GridIndexType
>(this->gridView().size(0) + numBoundaryScvf_++)}),
259 scvfsIndexSet.push_back(scvfIdx++);
261 hasBoundaryScvf_[eIdx] =
true;
266 scvfIndicesOfScv_[eIdx] = scvfsIndexSet;
270 if (dim < dimWorld || this->isPeriodic())
272 flipScvfIndices_.resize(scvfs_.size());
273 for (
auto&& scvf : scvfs_)
278 flipScvfIndices_[scvf.index()].resize(scvf.numOutsideScvs());
279 const auto insideScvIdx = scvf.insideScvIdx();
281 for (
unsigned int i = 0; i < scvf.numOutsideScvs(); ++i)
282 flipScvfIndices_[scvf.index()][i] = findFlippedScvfIndex_(insideScvIdx, scvf.outsideScvIdx(i));
287 connectivityMap_.update(*
this);
293 return scvs_[scvIdx];
299 return scvfs_[scvfIdx];
306 return scvfs_[flipScvfIndices_[scvfIdx][outsideScvfIdx]];
312 return scvfIndicesOfScv_[scvIdx];
320 {
return connectivityMap_; }
324 {
return hasBoundaryScvf_[eIdx]; }
328 GridIndexType findFlippedScvfIndex_(GridIndexType insideScvIdx, GridIndexType outsideScvIdx)
331 for (
auto outsideScvfIndex : scvfIndicesOfScv_[outsideScvIdx])
333 const auto& outsideScvf = this->scvf(outsideScvfIndex);
334 for (
unsigned int j = 0; j < outsideScvf.numOutsideScvs(); ++j)
335 if (outsideScvf.outsideScvIdx(j) == insideScvIdx)
336 return outsideScvf.index();
339 DUNE_THROW(Dune::InvalidStateException,
"No flipped version of this scvf found!");
343 ConnectivityMap connectivityMap_;
346 std::vector<SubControlVolume> scvs_;
347 std::vector<SubControlVolumeFace> scvfs_;
348 std::vector<std::vector<GridIndexType>> scvfIndicesOfScv_;
349 std::size_t numBoundaryScvf_;
350 std::vector<bool> hasBoundaryScvf_;
353 std::vector<std::vector<GridIndexType>> flipScvfIndices_;
363template<
class GV,
class Traits>
369 using ConnectivityMap =
typename Traits::template ConnectivityMap<ThisType>;
372 using Element =
typename GV::template Codim<0>::Entity;
374 static const int dim = GV::dimension;
375 static const int dimWorld = GV::dimensionworld;
377 using ScvfGridIndexStorage =
typename Traits::SubControlVolumeFace::Traits::GridIndexStorage;
378 using NeighborVolVarIndices =
typename std::conditional_t< (dim<dimWorld),
379 ScvfGridIndexStorage,
380 Dune::ReservedVector<GridIndexType, 1> >;
396 static constexpr int maxElementStencilSize = LocalView::maxNumElementScvfs*Traits::maxNumScvfNeighbors + 1;
407 DUNE_THROW(Dune::InvalidStateException,
"The cctpfa discretization method needs at least an overlap of 1 for parallel computations. "
408 <<
" Set the parameter \"Grid.Overlap\" in the input file.");
414 {
return this->elementMapper(); }
431 return numBoundaryScvf_;
436 {
return this->gridView().size(0); }
441 ParentType::update();
444 scvfIndicesOfScv_.clear();
445 neighborVolVarIndices_.clear();
448 numScvs_ = numDofs();
450 numBoundaryScvf_ = 0;
451 scvfIndicesOfScv_.resize(numScvs_);
452 neighborVolVarIndices_.resize(numScvs_);
455 for (
const auto& element : elements(this->gridView()))
457 const auto eIdx = this->elementMapper().index(element);
460 auto numLocalFaces = element.subEntities(1);
461 std::vector<GridIndexType> scvfsIndexSet;
462 std::vector<NeighborVolVarIndices> neighborVolVarIndexSet;
463 scvfsIndexSet.reserve(numLocalFaces);
464 neighborVolVarIndexSet.reserve(numLocalFaces);
468 std::vector<NeighborVolVarIndices> outsideIndices;
471 outsideIndices.resize(numLocalFaces);
472 for (
const auto& intersection : intersections(this->gridView(), element))
474 if (intersection.neighbor())
476 const auto nIdx = this->elementMapper().index(intersection.outside());
477 outsideIndices[intersection.indexInInside()].push_back(nIdx);
482 for (
const auto& intersection : intersections(this->gridView(), element))
485 if (intersection.neighbor())
488 if (intersection.boundary())
493 scvfsIndexSet.push_back(numScvf_++);
494 const auto nIdx = this->elementMapper().index(intersection.outside());
495 neighborVolVarIndexSet.emplace_back(NeighborVolVarIndices({nIdx}));
501 auto indexInInside = intersection.indexInInside();
503 if (outsideIndices[indexInInside].empty())
507 scvfsIndexSet.push_back(numScvf_++);
508 neighborVolVarIndexSet.emplace_back(std::move(outsideIndices[indexInInside]));
509 outsideIndices[indexInInside].clear();
514 else if (intersection.boundary())
516 scvfsIndexSet.push_back(numScvf_++);
517 neighborVolVarIndexSet.emplace_back(NeighborVolVarIndices({
static_cast<GridIndexType
>(numScvs_ + numBoundaryScvf_++)}));
522 scvfIndicesOfScv_[eIdx] = scvfsIndexSet;
523 neighborVolVarIndices_[eIdx] = neighborVolVarIndexSet;
527 connectivityMap_.update(*
this);
531 {
return scvfIndicesOfScv_[scvIdx]; }
535 {
return neighborVolVarIndices_[scvIdx]; }
542 {
return connectivityMap_; }
547 std::size_t numScvs_;
548 std::size_t numScvf_;
549 std::size_t numBoundaryScvf_;
552 ConnectivityMap connectivityMap_;
555 std::vector<std::vector<GridIndexType>> scvfIndicesOfScv_;
556 std::vector<std::vector<NeighborVolVarIndices>> neighborVolVarIndices_;
Defines the default element and vertex mapper types.
Defines the index types used for grid and local indices.
Check the overlap size for different discretization methods.
The available discretization methods in Dumux.
Base class for grid geometries.
DiscretizationMethod
The available discretization methods in Dumux.
Definition: method.hh:37
Struture to define the index types used for grid and local indices.
Definition: indextraits.hh:38
Base class for all finite volume grid geometries.
Definition: basegridgeometry.hh:49
GV GridView
export the grid view type
Definition: basegridgeometry.hh:64
A simple version of the connectivity map for cellcentered schemes. This implementation works for sche...
Definition: cellcentered/connectivitymap.hh:53
Sub control volumes for cell-centered discretization schemes.
Definition: discretization/cellcentered/subcontrolvolume.hh:63
Stencil-local finite volume geometry (scvs and scvfs) for cell-centered TPFA models This builds up th...
Definition: discretization/cellcentered/tpfa/fvelementgeometry.hh:50
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:53
static constexpr int maxNumScvfNeighbors
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:67
The finite volume geometry (scvs and scvfs) for cell-centered TPFA models on a grid view This builds ...
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:79
The finite volume geometry (scvs and scvfs) for cell-centered TPFA models on a grid view This builds ...
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:90
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:102
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:319
void update()
update all fvElementGeometries (do this again after grid adaption)
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:157
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:135
CCTpfaFVGridGeometry(const GridView &gridView)
Constructor.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:120
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:104
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:106
std::size_t numDofs() const
The total number of degrees of freedom.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:153
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:310
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:141
const SubControlVolumeFace & scvf(GridIndexType scvfIdx) const
Get a sub control volume face with a global scvf index.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:297
bool hasBoundaryScvf(GridIndexType eIdx) const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:323
std::size_t numBoundaryScvf() const
The total number of boundary sub control volume faces.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:147
const SubControlVolumeFace & flipScvf(GridIndexType scvfIdx, unsigned int outsideScvfIdx=0) const
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:304
typename Traits::ElementMapper DofMapper
export dof mapper type
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:108
const SubControlVolume & scv(GridIndexType scvIdx) const
Get a sub control volume with a global scv index.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:291
const DofMapper & dofMapper() const
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:131
The finite volume geometry (scvs and scvfs) for cell-centered TPFA models on a grid view This builds ...
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:366
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:384
const std::vector< GridIndexType > & scvfIndicesOfScv(GridIndexType scvIdx) const
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:530
typename Traits::ElementMapper DofMapper
export dof mapper type
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:390
const DofMapper & dofMapper() const
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:413
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:388
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:386
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:423
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:541
void update()
update all fvElementGeometries (do this again after grid adaption)
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:439
CCTpfaFVGridGeometry(const GridView &gridView)
Constructor.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:402
std::size_t numDofs() const
The total number of degrees of freedom.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:435
std::size_t numBoundaryScvf() const
The total number of boundary sub control volume faces.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:429
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:534
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/cellcentered/tpfa/fvgridgeometry.hh:417
The sub control volume face.
Definition: discretization/cellcentered/tpfa/subcontrolvolumeface.hh:90
Check if the overlap size is valid for a given discretization method.
Definition: checkoverlapsize.hh:40
Stencil-local finite volume geometry (scvs and scvfs) for cell-centered TPFA models This builds up th...
Sub control volumes for cell-centered discretization schemes.
The sub control volume face.
Stores the face indices corresponding to the neighbors of an element that contribute to the derivativ...