177 using GridView =
typename GG::GridView;
178 using Element =
typename GridView::template Codim<0>::Entity;
180 using MpfaHelper =
typename GG::MpfaHelper;
182 static const int dim = GridView::dimension;
183 static const int dimWorld = GridView::dimensionworld;
184 using CoordScalar =
typename GridView::ctype;
185 using ReferenceElements =
typename Dune::ReferenceElements<CoordScalar, dim>;
207 if (scvIdx == scvIndices_[0])
210 return neighborScvs_[findLocalIndex(scvIdx, neighborScvIndices_)];
217 auto it = std::find(scvfIndices_.begin(), scvfIndices_.end(), scvfIdx);
218 if (it != scvfIndices_.end())
219 return scvfs_[std::distance(scvfIndices_.begin(), it)];
221 return neighborScvfs_[findLocalIndex(scvfIdx, neighborScvfIndices_)];
236 friend inline Dune::IteratorRange<typename std::array<SubControlVolume, 1>::const_iterator>
239 using IteratorType =
typename std::array<SubControlVolume, 1>::const_iterator;
240 return Dune::IteratorRange<IteratorType>(g.scvs_.begin(), g.scvs_.end());
248 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
251 using IteratorType =
typename std::vector<SubControlVolumeFace>::const_iterator;
252 return Dune::IteratorRange<IteratorType>(g.scvfs_.begin(), g.scvfs_.end());
257 {
return scvs_.size(); }
261 {
return scvfs_.size(); }
265 void bind(
const Element& element)
271 const auto globalI =
gridGeometry().elementMapper().index(element);
272 const auto& assemblyMapI =
gridGeometry().connectivityMap()[globalI];
275 const auto numNeighbors = assemblyMapI.size();
276 const auto numNeighborScvfs = numNeighborScvfs_(assemblyMapI);
277 neighborScvs_.reserve(numNeighbors);
278 neighborScvIndices_.reserve(numNeighbors);
279 neighborScvfIndices_.reserve(numNeighborScvfs);
280 neighborScvfs_.reserve(numNeighborScvfs);
284 for (
const auto& dataJ : assemblyMapI)
285 makeNeighborGeometries(
gridGeometry().element(dataJ.globalJ),
288 dataJ.additionalScvfs);
310 makeElementGeometries(element);
315 {
return *gridGeometryPtr_; }
319 {
return hasBoundaryScvf_; }
324 template<
class DataJContainer>
325 std::size_t numNeighborScvfs_(
const DataJContainer& dataJContainer)
327 std::size_t numNeighborScvfs = 0;
328 for (
const auto& dataJ : dataJContainer)
329 numNeighborScvfs += dataJ.scvfsJ.size() + dataJ.additionalScvfs.size();
330 return numNeighborScvfs;
334 void makeElementGeometries(
const Element& element)
337 const auto eIdx = gridGeometry().elementMapper().index(element);
338 scvs_[0] = SubControlVolume(element.geometry(), eIdx);
339 scvIndices_[0] = eIdx;
342 const auto& scvFaceIndices = gridGeometry().scvfIndicesOfScv(eIdx);
343 const auto& neighborVolVarIndices = gridGeometry().neighborVolVarIndices(eIdx);
346 static const auto q = []{
348 bool hasOldParamName =
hasParam(
"Mpfa.Q");
349 if (hasOldParamName) {
350 std::cerr <<
"Deprecation warning: Parameter Mpfa.Q is deprecated, use MPFA.Q (uppercase MPFA)" << std::endl;
353 bool hasNewParamName =
hasParam(
"MPFA.Q");
354 if (hasNewParamName) {
357 if (hasOldParamName | hasNewParamName)
364 const auto numLocalScvf = scvFaceIndices.size();
365 scvfIndices_.reserve(numLocalScvf);
366 scvfs_.reserve(numLocalScvf);
370 std::vector<bool> finishedFacets;
372 finishedFacets.resize(element.subEntities(1),
false);
375 for (
const auto& is : intersections(gridGeometry().gridView(), element))
381 const auto indexInInside = is.indexInInside();
382 if (finishedFacets[indexInInside])
385 finishedFacets[indexInInside] =
true;
389 bool useNeighbor = is.neighbor() && is.outside().level() > element.level();
390 const auto& e = useNeighbor ? is.outside() : element;
391 const auto indexInElement = useNeighbor ? is.indexInOutside() : is.indexInInside();
392 const auto eg = e.geometry();
393 const auto refElement = ReferenceElements::general(eg.type());
396 const auto numCorners = is.geometry().corners();
397 const auto isPositions = MpfaHelper::computeScvfCornersOnIntersection(eg,
403 for (
int c = 0; c < numCorners; ++c)
406 auto vIdxLocal = refElement.subEntity(indexInElement, 1, c, dim);
407 auto vIdxGlobal = gridGeometry().vertexMapper().subIndex(e, vIdxLocal, dim);
410 if (gridGeometry().isGhostVertex(vIdxGlobal))
413 hasBoundaryScvf_ = (hasBoundaryScvf_ || is.boundary());
415 scvfs_.emplace_back(MpfaHelper(),
416 MpfaHelper::getScvfCorners(isPositions, numCorners, c),
417 is.centerUnitOuterNormal(),
420 scvFaceIndices[scvfCounter],
422 neighborVolVarIndices[scvfCounter],
426 scvfIndices_.emplace_back(scvFaceIndices[scvfCounter]);
433 template<
typename IndexVector>
434 void makeNeighborGeometries(
const Element& element,
435 GridIndexType eIdxGlobal,
436 const IndexVector& scvfIndices,
437 const IndexVector& additionalScvfs)
440 neighborScvs_.emplace_back(element.geometry(), eIdxGlobal);
441 neighborScvIndices_.push_back(eIdxGlobal);
444 const auto& scvFaceIndices = gridGeometry().scvfIndicesOfScv(eIdxGlobal);
445 const auto& neighborVolVarIndices = gridGeometry().neighborVolVarIndices(eIdxGlobal);
448 static const auto q = []{
450 bool hasOldParamName =
hasParam(
"Mpfa.Q");
451 if (hasOldParamName) {
452 std::cerr <<
"Deprecation warning: Parameter Mpfa.Q is deprecated, use MPFA.Q (uppercase MPFA)" << std::endl;
455 bool hasNewParamName =
hasParam(
"MPFA.Q");
456 if (hasNewParamName) {
459 if (hasOldParamName | hasNewParamName)
467 std::vector<bool> finishedFacets;
469 finishedFacets.resize(element.subEntities(1),
false);
472 for (
const auto& is : intersections(gridGeometry().gridView(), element))
478 auto indexInInside = is.indexInInside();
479 if(finishedFacets[indexInInside])
482 finishedFacets[indexInInside] =
true;
486 bool useNeighbor = is.neighbor() && is.outside().level() > element.level();
487 const auto& e = useNeighbor ? is.outside() : element;
488 const auto indexInElement = useNeighbor ? is.indexInOutside() : is.indexInInside();
489 const auto eg = e.geometry();
490 const auto refElement = ReferenceElements::general(eg.type());
493 const auto numCorners = is.geometry().corners();
494 const auto isPositions = MpfaHelper::computeScvfCornersOnIntersection(eg,
500 for (
int c = 0; c < numCorners; ++c)
503 auto vIdxLocal = refElement.subEntity(indexInElement, 1, c, dim);
504 auto vIdxGlobal = gridGeometry().vertexMapper().subIndex(e, vIdxLocal, dim);
507 if (gridGeometry().isGhostVertex(vIdxGlobal))
511 if (!MpfaHelper::vectorContainsValue(scvfIndices, scvFaceIndices[scvfCounter])
512 && !MpfaHelper::vectorContainsValue(additionalScvfs, scvFaceIndices[scvfCounter]))
520 neighborScvfs_.emplace_back(MpfaHelper(),
521 MpfaHelper::getScvfCorners(isPositions, numCorners, c),
522 is.centerUnitOuterNormal(),
525 scvFaceIndices[scvfCounter],
527 neighborVolVarIndices[scvfCounter],
531 neighborScvfIndices_.emplace_back(scvFaceIndices[scvfCounter]);
540 unsigned int findLocalIndex(
const GridIndexType idx,
541 const std::vector<GridIndexType>& indices)
const
543 auto it = std::find(indices.begin(), indices.end(), idx);
544 assert(it != indices.end() &&
"Could not find the scv/scvf! Make sure to properly bind this class!");
545 return std::distance(indices.begin(), it);
551 scvfIndices_.clear();
554 neighborScvIndices_.clear();
555 neighborScvfIndices_.clear();
556 neighborScvs_.clear();
557 neighborScvfs_.clear();
559 hasBoundaryScvf_ =
false;
562 const GridGeometry* gridGeometryPtr_;
565 std::array<GridIndexType, 1> scvIndices_;
566 std::vector<GridIndexType> scvfIndices_;
567 std::array<SubControlVolume, 1> scvs_;
568 std::vector<SubControlVolumeFace> scvfs_;
570 std::vector<GridIndexType> neighborScvIndices_;
571 std::vector<GridIndexType> neighborScvfIndices_;
572 std::vector<SubControlVolume> neighborScvs_;
573 std::vector<SubControlVolumeFace> neighborScvfs_;
575 bool hasBoundaryScvf_ =
false;