20 #ifndef OPM_GRID_CPGRID_LGRHELPERS_HEADER_INCLUDED 21 #define OPM_GRID_CPGRID_LGRHELPERS_HEADER_INCLUDED 23 #include <dune/grid/common/mcmgmapper.hh> 24 #include <dune/common/version.hh> 26 #include <opm/grid/CpGrid.hpp> 33 #include <unordered_map> 48 template<
class Gr
id>
class LevelCartesianIndexMapper;
88 void refineAndProvideMarkedRefinedRelations(
const Dune::CpGrid& grid,
89 std::vector<std::shared_ptr<Dune::cpgrid::CpGridData>>& markedElem_to_itsLgr,
90 int& markedElem_count,
91 std::vector<std::vector<std::array<int,2>>>& cornerInMarkedElemWithEquivRefinedCorner,
92 std::map<std::array<int,2>,
int>& markedElemAndEquivRefinedCorn_to_corner,
93 std::vector<std::vector<std::pair<
int, std::vector<int>>>>& faceInMarkedElemAndRefinedFaces,
95 std::map<std::array<int,2>,std::array<int,2>>& elemLgrAndElemLgrCell_to_refinedLevelAdRefinedCell,
96 std::map<std::array<int,2>,std::array<int,2>>& refinedLevelAndRefinedCell_to_elemLgrAndElemLgrCell,
97 std::vector<int>& refined_cell_count_vec,
98 const std::vector<int>& assignRefinedLevel,
99 std::vector<std::vector<std::tuple<
int,std::vector<int>>>>& preAdapt_parent_to_children_cells_vec,
101 std::map<std::array<int,2>,
int>& elemLgrAndElemLgrCell_to_adaptedCell,
102 std::unordered_map<
int,std::array<int,2>>& adaptedCell_to_elemLgrAndElemLgrCell,
104 std::vector<std::vector<int>>& preAdapt_level_to_leaf_cells_vec,
106 const std::vector<std::array<int,3>>& cells_per_dim_vec);
126 std::tuple< std::vector<std::vector<std::array<int,2>>>,
127 std::vector<std::vector<int>>,
128 std::vector<std::array<int,2>>,
131 int preAdaptMaxLevel,
132 const std::map<std::array<int,2>,std::array<int,2>>& refinedLevelAndRefinedCell_to_elemLgrAndElemLgrCell,
133 const std::vector<int>& refined_cell_count_vec,
134 const std::unordered_map<
int,std::array<int,2>>& adaptedCell_to_elemLgrAndElemLgrCell,
135 const int& cell_count);
157 std::pair<std::vector<std::vector<int>>, std::vector<std::array<int,2>>>
159 int preAdaptMaxLevel,
160 const std::map<std::array<int,2>,std::array<int,2>>& elemLgrAndElemLgrCell_to_refinedLevelAndRefinedCell,
161 const std::map<std::array<int,2>,std::array<int,2>>& refinedLevelAndRefinedCell_to_elemLgrAndElemLgrCell,
162 const std::vector<int>& refined_cell_count_vec,
163 const std::map<std::array<int,2>,
int>& elemLgrAndElemLgrCell_to_adaptedCell,
164 const std::unordered_map<
int,std::array<int,2>>& adaptedCell_to_elemLgrAndElemLgrCell,
165 const int& cell_count);
187 int preAdaptMaxLevel,
188 std::map<std::array<int,2>,std::array<int,2>>& elemLgrAndElemLgrCorner_to_refinedLevelAndRefinedCorner,
189 std::map<std::array<int,2>,std::array<int,2>>& refinedLevelAndRefinedCorner_to_elemLgrAndElemLgrCorner,
190 std::vector<int>& refined_corner_count_vec,
191 std::map<std::array<int,2>, std::array<int,2>>& vanishedRefinedCorner_to_itsLastAppearance,
192 const std::vector<std::shared_ptr<Dune::cpgrid::CpGridData>>& markedElem_to_itsLgr,
193 const std::vector<int>& assignRefinedLevel,
194 const std::vector<std::vector<std::array<int,2>>>& cornerInMarkedElemWithEquivRefinedCorner,
195 const std::vector<std::vector<std::pair<
int, std::vector<int>>>>& faceInMarkedElemAndRefinedFaces,
196 const std::vector<std::array<int,3>>& cells_per_dim_vec);
203 bool isRefinedCornerInInteriorLgr(
const std::array<int,3>& cells_per_dim,
int cornerIdxInLgr);
217 std::array<int,3> getRefinedCornerIJK(
const std::array<int,3>& cells_per_dim,
int cornerIdxInLgr);
226 bool newRefinedCornerLiesOnEdge(
const std::array<int,3>& cells_per_dim,
int cornerIdxInLgr);
235 const std::array<int,3>& cells_per_dim,
245 bool isRefinedNewBornCornerOnLgrBoundary(
const std::array<int,3>& cells_per_dim,
int cornerIdxInLgr);
254 const std::array<int,3>& cells_per_dim,
267 int replaceLgr1CornerIdxByLgr2CornerIdx(
const std::array<int,3>& cells_per_dim_lgr1,
269 const std::array<int,3>& cells_per_dim_lgr2);
283 const std::array<int,3>& cells_per_dim_lgr1,
284 int cornerIdxLgr1,
int elemLgr1,
int parentFaceLastAppearanceIdx,
285 const std::array<int,3>& cells_per_dim_lgr2);
304 int preAdaptMaxLevel,
305 std::map<std::array<int,2>,
int>& elemLgrAndElemLgrCorner_to_adaptedCorner,
306 std::unordered_map<
int,std::array<int,2>>& adaptedCorner_to_elemLgrAndElemLgrCorner,
308 const std::vector<std::shared_ptr<Dune::cpgrid::CpGridData>>& markedElem_to_itsLgr,
309 const std::vector<int>& assignRefinedLevel,
310 const std::vector<std::vector<std::array<int,2>>>& cornerInMarkedElemWithEquivRefinedCorner,
311 std::map<std::array<int,2>, std::array<int,2>>& vanishedRefinedCorner_to_itsLastAppearance,
312 const std::vector<std::vector<std::pair<
int, std::vector<int>>>>& faceInMarkedElemAndRefinedFaces,
313 const std::vector<std::array<int,3>>& cells_per_dim_vec);
315 void markVanishedCorner(
const std::array<int,2>& vanished,
316 const std::array<int,2>& lastAppearance,
317 std::map<std::array<int,2>, std::array<int,2>>& vanishedRefinedCorner_to_itsLastAppearance);
319 void processInteriorCorners(
int elemIdx,
int shiftedLevel,
320 const std::shared_ptr<Dune::cpgrid::CpGridData>& lgr,
322 std::map<std::array<int,2>,
int>& elemLgrAndElemLgrCorner_to_adaptedCorner,
323 std::unordered_map<
int,std::array<int,2>>& adaptedCorner_to_elemLgrAndElemLgrCorner,
324 const std::vector<std::array<int,3>>& cells_per_dim_vec);
326 void processEdgeCorners(
int elemIdx,
int shiftedLevel,
327 const std::shared_ptr<Dune::cpgrid::CpGridData>& lgr,
329 std::map<std::array<int,2>,
int>& elemLgrAndElemLgrCorner_to_adaptedCorner,
330 std::unordered_map<
int,std::array<int,2>>& adaptedCorner_to_elemLgrAndElemLgrCorner,
331 std::map<std::array<int,2>, std::array<int,2>>& vanishedRefinedCorner_to_itsLastAppearance,
333 int preAdaptMaxLevel,
334 const std::vector<int>& assignRefinedLevel,
335 const std::vector<std::vector<std::pair<
int, std::vector<int>>>>& faceInMarkedElemAndRefinedFaces,
336 const std::vector<std::array<int,3>>& cells_per_dim_vec);
338 void processBoundaryCorners(
int elemIdx,
int shiftedLevel,
339 const std::shared_ptr<Dune::cpgrid::CpGridData>& lgr,
341 std::map<std::array<int,2>,
int>& elemLgrAndElemLgrCorner_to_adaptedCorner,
342 std::unordered_map<
int,std::array<int,2>>& adaptedCorner_to_elemLgrAndElemLgrCorner,
343 std::map<std::array<int,2>, std::array<int,2>>& vanishedRefinedCorner_to_itsLastAppearance,
345 int preAdaptMaxLevel,
346 const std::vector<int>& assignRefinedLevel,
347 const std::vector<std::vector<std::pair<
int, std::vector<int>>>>& faceInMarkedElemAndRefinedFaces,
348 const std::vector<std::array<int,3>>& cells_per_dim_vec);
352 void insertBidirectional(std::map<std::array<int,2>,
int>& a_to_b,
353 std::unordered_map<
int,std::array<int,2>>& b_to_a,
354 const std::array<int,2>& keyA,
358 void insertBidirectional(std::map<std::array<int,2>,std::array<int,2>>& a_to_b,
359 std::map<std::array<int,2>,std::array<int,2>>& b_to_a,
360 const std::array<int,2>& keyA,
361 const std::array<int,2>& keyB,
366 void insertBidirectional(std::map<std::array<int,2>,std::array<int,2>>& a_to_b,
367 std::map<std::array<int,2>,std::array<int,2>>& b_to_a,
368 const std::array<int,2>& keyA,
387 int preAdaptMaxLevel,
388 std::map<std::array<int,2>,std::array<int,2>>& elemLgrAndElemLgrFace_to_refinedLevelAndRefinedFace,
389 std::map<std::array<int,2>,std::array<int,2>>& refinedLevelAndRefinedFace_to_elemLgrAndElemLgrFace,
390 std::vector<int>& refined_face_count_vec,
391 const std::vector<std::shared_ptr<Dune::cpgrid::CpGridData>>& markedElem_to_itsLgr,
392 const std::vector<int>& assignRefinedLevel,
393 const std::vector<std::vector<std::pair<
int, std::vector<int>>>>& faceInMarkedElemAndRefinedFaces,
394 const std::vector<std::array<int,3>>& cells_per_dim_vec);
411 int preAdaptMaxLevel,
412 std::map<std::array<int,2>,
int>& elemLgrAndElemLgrFace_to_adaptedFace,
413 std::unordered_map<
int,std::array<int,2>>& adaptedFace_to_elemLgrAndElemLgrFace,
415 const std::vector<std::shared_ptr<Dune::cpgrid::CpGridData>>& markedElem_to_itsLgr,
416 const std::vector<int>& assignRefinedLevel,
417 const std::vector<std::vector<std::pair<
int, std::vector<int>>>>& faceInMarkedElemAndRefinedFaces,
418 const std::vector<std::array<int,3>>& cells_per_dim_vec);
434 std::array<int,3> getRefinedFaceIJK(
const std::array<int,3>& cells_per_dim,
int faceIdxInLgr,
435 const std::shared_ptr<Dune::cpgrid::CpGridData>& elemLgr_ptr);
443 bool isRefinedFaceInInteriorLgr(
const std::array<int,3>& cells_per_dim,
int faceIdxInLgr,
444 const std::shared_ptr<Dune::cpgrid::CpGridData>& elemLgr_ptr);
452 bool isRefinedFaceOnLgrBoundary(
const std::array<int,3>& cells_per_dim,
int faceIdxInLgr,
453 const std::shared_ptr<Dune::cpgrid::CpGridData>& elemLgr_ptr);
463 const std::array<int,3>& cells_per_dim,
465 const std::shared_ptr<Dune::cpgrid::CpGridData>& elemLgr_ptr,
470 const std::vector<int>& refined_corner_count_vec,
471 const std::vector<std::shared_ptr<Dune::cpgrid::CpGridData>>& markedElem_to_itsLgr,
472 const int& preAdaptMaxLevel,
473 const std::map<std::array<int,2>,std::array<int,2>>& refinedLevelAndRefinedCorner_to_elemLgrAndElemLgrCorner);
480 const std::vector<int>& refined_face_count_vec,
481 const std::map<std::array<int,2>,std::array<int,2>>& refinedLevelAndRefinedFace_to_elemLgrAndElemLgrFace,
482 const std::map<std::array<int,2>,std::array<int,2>>& elemLgrAndElemLgrCorner_to_refinedLevelAndRefinedCorner,
483 const std::map<std::array<int,2>, std::array<int,2>>& vanishedRefinedCorner_to_itsLastAppearance,
484 const std::vector<std::shared_ptr<Dune::cpgrid::CpGridData>>& markedElem_to_itsLgr,
485 const int& preAdaptMaxLevel,
486 const std::vector<std::vector<std::array<int,2>>>& cornerInMarkedElemWithEquivRefinedCorner,
487 const std::map<std::array<int,2>,
int>& markedElemAndEquivRefinedCorn_to_corner);
493 std::vector<std::vector<std::array<int,8>>>& refined_cell_to_point_vec,
494 std::vector<std::vector<int>>& refined_global_cell_vec,
495 const std::vector<int>& refined_cell_count_vec,
498 const std::map<std::array<int,2>,std::array<int,2>>& refinedLevelAndRefinedCell_to_elemLgrAndElemLgrCell,
499 const std::map<std::array<int,2>,std::array<int,2>>& elemLgrAndElemLgrFace_to_refinedLevelAndRefinedFace,
500 const std::vector<std::vector<std::pair<
int, std::vector<int>>>>& faceInMarkedElemAndRefinedFaces,
501 const std::vector<Dune::cpgrid::DefaultGeometryPolicy>& refined_geometries_vec,
502 const std::map<std::array<int,2>,std::array<int,2>>& elemLgrAndElemLgrCorner_to_refinedLevelAndRefinedCorner,
503 const std::map<std::array<int,2>, std::array<int,2>>& vanishedRefinedCorner_to_itsLastAppearance,
504 const std::vector<std::shared_ptr<Dune::cpgrid::CpGridData>>& markedElem_to_itsLgr,
505 const std::vector<int>& assignRefinedLevel,
506 const int& preAdaptMaxLevel,
507 const std::map<std::array<int,2>,
int>& markedElemAndEquivRefinedCorn_to_corner,
508 const std::vector<std::vector<std::array<int,2>>>& cornerInMarkedElemWithEquivRefinedCorner,
509 const std::vector<std::array<int,3>>& cells_per_dim_vec);
521 int replaceLgr1FaceIdxByLgr2FaceIdx(
const std::array<int,3>& cells_per_dim_lgr1,
int faceIdxInLgr1,
522 const std::shared_ptr<Dune::cpgrid::CpGridData>& elemLgr1_ptr,
523 const std::array<int,3>& cells_per_dim_lgr2);
528 const int& corners_count,
529 const std::vector<std::shared_ptr<Dune::cpgrid::CpGridData>>& markedElem_to_itsLgr,
530 const std::unordered_map<
int,std::array<int,2>>& adaptedCorner_to_elemLgrAndElemLgrCorner);
538 const int& face_count,
539 const std::unordered_map<
int,std::array<int,2>>& adaptedFace_to_elemLgrAndElemLgrFace,
540 const std::map<std::array<int,2>,
int>& elemLgrAndElemLgrCorner_to_adaptedCorner,
541 const std::map<std::array<int,2>, std::array<int,2>>& vanishedRefinedCorner_to_itsLastAppearance,
542 const std::vector<std::shared_ptr<Dune::cpgrid::CpGridData>>& markedElem_to_itsLgr,
543 const std::vector<int>& assignRefinedLevel,
544 const std::map<std::array<int,2>,
int>& markedElemAndEquivRefinedCorn_to_corner,
545 const std::vector<std::vector<std::array<int,2>>>& cornerInMarkedElemWithEquivRefinedCorner,
546 const std::vector<std::array<int,3>>& cells_per_dim_vec,
547 const int& preAdaptMaxLevel);
552 std::vector<std::array<int,8>>& adapted_cell_to_point,
553 const int& cell_count,
556 const std::unordered_map<
int,std::array<int,2>>& adaptedCell_to_elemLgrAndElemLgrCell,
557 const std::map<std::array<int,2>,
int>& elemLgrAndElemLgrFace_to_adaptedFace,
558 const std::vector<std::vector<std::pair<
int, std::vector<int>>>>& faceInMarkedElemAndRefinedFaces,
560 const std::map<std::array<int,2>,
int>& elemLgrAndElemLgrCorner_to_adaptedCorner,
561 const std::map<std::array<int,2>, std::array<int,2>>& vanishedRefinedCorner_to_itsLastAppearance,
562 const std::vector<std::shared_ptr<Dune::cpgrid::CpGridData>>& markedElem_to_itsLgr,
563 const std::vector<int>& assignRefinedLevel,
564 const std::map<std::array<int,2>,
int>& markedElemAndEquivRefinedCorn_to_corner,
565 const std::vector<std::vector<std::array<int,2>>>& cornerInMarkedElemWithEquivRefinedCorner,
566 const std::vector<std::array<int,3>>& cells_per_dim_vec,
567 const int& preAdaptMaxLevel);
577 const std::vector<std::array<int,3>>& startIJK_vec,
578 const std::vector<std::array<int,3>>& endIJK_vec,
582 for(
const auto& element: Dune::elements(grid.leafGridView())) {
583 std::array<int,3> ijk;
584 grid.
getIJK(element.index(), ijk);
585 for (std::size_t level = 0; level < startIJK_vec.size(); ++level) {
586 bool belongsToLevel =
true;
587 for (
int c = 0; c < 3; ++c) {
588 belongsToLevel = belongsToLevel && ( (ijk[c] >= startIJK_vec[level][c]) && (ijk[c] < endIJK_vec[level][c]) );
593 func(element, level);
609 const std::vector<std::array<int,3>>& startIJK_vec,
610 const std::vector<std::array<int,3>>& endIJK_vec,
611 std::vector<int>& lgr_with_at_least_one_active_cell);
626 void predictMinCellAndPointGlobalIdPerProcess(
const Dune::CpGrid& grid,
627 const std::vector<int>& assignRefinedLevel,
628 const std::vector<std::array<int,3>>& cells_per_dim_vec,
629 const std::vector<int>& lgr_with_at_least_one_active_cell,
630 int& min_globalId_cell_in_proc,
631 int& min_globalId_point_in_proc);
641 void assignCellIdsAndCandidatePointIds(
const Dune::CpGrid& grid,
642 std::vector<std::vector<int>>& localToGlobal_cells_per_level,
643 std::vector<std::vector<int>>& localToGlobal_points_per_level,
644 int min_globalId_cell_in_proc,
645 int min_globalId_point_in_proc,
646 const std::vector<std::array<int,3>>& cells_per_dim_vec);
662 std::vector<std::vector<int>>& localToGlobal_points_per_level,
663 const std::vector<std::tuple<
int,std::vector<int>>>& parent_to_children,
664 const std::vector<std::array<int,3>>& cells_per_dim_vec);
673 std::vector<int>& parentToFirstChildGlobalIds);
681 std::array<int,3> getIJK(
int idx_in_parent_cell,
const std::array<int,3>& cells_per_dim);
689 void validStartEndIJKs(
const std::vector<std::array<int,3>>& startIJK_vec,
690 const std::vector<std::array<int,3>>& endIJK_vec);
699 std::array<std::vector<int>,6> getBoundaryPatchFaces(
const std::array<int,3>& startIJK,
700 const std::array<int,3>& endIJK,
701 const std::array<int,3>& grid_dim);
710 std::array<int,3> getPatchDim(
const std::array<int,3>& startIJK,
const std::array<int,3>& endIJK);
717 bool patchesShareFace(
const std::vector<std::array<int,3>>& startIJK_vec,
718 const std::vector<std::array<int,3>>& endIJK_vec,
719 const std::array<int,3>& grid_dim);
721 int sharedFaceTag(
const std::vector<std::array<int,3>>& startIJK_2Patches,
722 const std::vector<std::array<int,3>>& endIJK_2Patches,
723 const std::array<int,3>& grid_dim);
744 std::tuple<std::vector<std::array<int,3>>,
745 std::vector<std::array<int,3>>,
746 std::vector<std::array<int,3>>,
747 std::vector<std::string>,
748 std::vector<std::string>>
749 excludeFakeSubdivisions(
const std::vector<std::array<int, 3>>& cells_per_dim_vec,
750 const std::vector<std::array<int, 3>>& startIJK_vec,
751 const std::vector<std::array<int, 3>>& endIJK_vec,
752 const std::vector<std::string>& lgr_name_vec,
753 const std::vector<std::string>& lgr_parent_grid_name_vec);
771 bool compatibleSubdivisions(
const std::vector<std::array<int,3>>& cells_per_dim_vec,
772 const std::vector<std::array<int,3>>& startIJK_vec,
773 const std::vector<std::array<int,3>>& endIJK_vec,
774 const std::array<int,3>& logicalCartesianSize);
776 void containsEightDifferentCorners(
const std::array<int,8>& cell_to_point);
786 void filterMarkedAquiferCellsAndConnections(
Dune::CpGrid& grid,
787 bool throwOnFailure);
788 template <
class LeafView>
789 bool throwIfIsCoarseAtLgrBoundary(
const LeafView& leafView,
793 for (
const auto& intersection : Dune::intersections(leafView, element)){
794 if (intersection.neighbor() && (intersection.outside().level() != element.
level()) && (element.
level() == 0)) {
797 OPM_THROW(std::invalid_argument,
"Refinement of cells at LGR boundaries is not supported, yet.");
809 #endif // OPM_GRID_CPGRID_LGRHELPERS_HEADER_INCLUDED
Base class for EntityVariable and SignedEntityVariable.
Definition: EntityRep.hpp:217
Definition: DefaultGeometryPolicy.hpp:52
int level() const
Return the level of the entity in the grid hierarchy. Level = 0 represents the coarsest grid...
Definition: Entity.hpp:473
The namespace Dune is the main namespace for all Dune code.
Definition: CartesianIndexMapper.hpp:9
[ provides Dune::Grid ]
Definition: CpGrid.hpp:201
This class encapsulates geometry for vertices, intersections, and cells.
Definition: CpGridData.hpp:94
Holds the implementation of the CpGrid as a pimple.
Definition: CellQuadrature.cpp:71
Struct that hods all the data needed to represent a Cpgrid.
Definition: CpGridData.hpp:117
void getIJK(const int c, std::array< int, 3 > &ijk) const
Extract Cartesian index triplet (i,j,k) of an active cell.
Definition: CpGrid.cpp:747