19#include <unordered_map>
37template <
typename Gr
id>
52 template <MInt nDim_,
class SysEqn>
56 template <MInt nDim_,
class SysEqn>
58 template <MInt nDim_,
class SysEqn>
60 template <MInt nDim_,
class SysEqn>
62 template <MInt nDim_,
class SysEqn>
66#if not defined(MAIA_MS_COMPILER)
67 template <MInt nDim_,
class SysEqn>
221 std::cerr <<
"mis " << cellId <<
" " << dir <<
" " <<
m_tree.
neighbor(cellId, dir) <<
" " << solverId <<
" "
251 maia::grid::tree::SolverBitsetType::reference
a_solver(
const MInt cellId,
const MInt solverId) {
298 mAlloc(
minPer3, perSize1 * perSize2,
"minPer3", std::numeric_limits<MFloat>::max(), AT_);
299 mAlloc(
maxPer3, perSize1 * perSize2,
"maxPer3", -std::numeric_limits<MFloat>::max(), AT_);
317 MInt ind1_ = ind1 + i;
319 MInt ind2_ = ind2 + i;
321 minPhi =
mMin(minPhi,
minPer3[ind1 * perSize2 + ind2_]);
322 minPhi =
mMin(minPhi,
minPer3[ind1_ * perSize2 + ind2]);
325 }
else if(side > 0) {
328 MInt ind1_ = ind1 + i;
330 MInt ind2_ = ind2 + i;
332 maxPhi =
mMax(maxPhi,
maxPer3[ind1 * perSize2 + ind2_]);
333 maxPhi =
mMax(maxPhi,
maxPer3[ind1_ * perSize2 + ind2]);
337 mTerm(1, AT_,
"side = 0?");
345 else if(ind >=
nBins[dir])
346 ind =
nBins[dir] - 1;
493 if(periodicCells || !
a_hasProperty(cellId, Cell::IsPeriodic)) ++cnt;
806 template <MBool t_correct = false>
830 template <MBool t_correct = false>
835 template <MBool t_correct = false>
838 const MInt solverId = -1);
840 template <MBool t_correct = false>
843 const MInt solverId = -1,
const MBool allowNonLeafHalo =
false) {
844 return findContainingLeafCell<t_correct>(&coord[0], startId, correctCellCoord, solverId, allowNonLeafHalo);
846 template <MBool t_correct = false>
849 const MInt solverId = -1,
const MBool allowNonLeafHalo =
false);
851 template <MBool t_correct = false, MBool ins
ideLimit>
853 std::function<
MFloat*(
MInt,
MFloat*
const)> correctCellCoord =
nullptr)
const {
854 return pointWthCell<t_correct, insideLimit>(&coord[0], cellId, correctCellCoord);
857 template <MBool t_correct = false, MBool ins
ideLimit>
859 std::function<
MFloat*(
MInt,
MFloat*
const)> correctCellCoord =
nullptr)
const;
875 template <
typename DATATYPE>
877 template <
typename DATATYPE>
879 const MInt* noCellsSendPerDom,
const MInt* cellIdsSend,
MInt noDomRecv,
MInt* domRecv,
880 const MInt* noCellsRecvPerDom,
const MInt* cellIdsRecv);
885 MInt*
const noSliceCellIds,
MInt*
const sliceCellIds,
MInt*
const noSliceHilbertIds =
nullptr,
886 MInt*
const sliceHilbertInfo =
nullptr,
MInt*
const noSliceContHilbertIds =
nullptr,
887 MInt*
const sliceContiguousHilbertInfo =
nullptr);
897 std::vector<std::vector<MInt>>& partLvlAncestorWindowCells);
899 void balance(
const MInt*
const noCellsToReceiveByDomain,
const MInt*
const noCellsToSendByDomain,
900 const MInt*
const sortedCellId,
const MLong*
const offset,
const MLong*
const globalIdOffsets);
912 void refineCell(
const MInt cellId,
const MLong*
const refineChildIds =
nullptr,
const MBool mayHaveChildren =
false,
918 template <MBool removeChilds>
929 const MInt baseLevel)
const;
937 template <
class ITERATOR,
typename U>
939 template <
typename TA,
typename TB,
typename TC>
941 template <
typename TA,
typename TB>
947 template <std::
size_t N>
952 void saveGrid(
const MChar*,
const std::vector<std::vector<MInt>>&,
const std::vector<std::vector<MInt>>&,
953 const std::vector<std::vector<MInt>>&,
const std::vector<MInt>&,
const std::vector<std::vector<MInt>>&,
954 MInt* recalcIdTree =
nullptr);
968 MBool allChilds =
false);
981 template <
typename CELLTYPE>
984 const MLong*
const partitionCellsGlobalId,
const MFloat totalWorkload,
985 MLong* partitionCellOffsets,
MLong* globalIdOffsets,
MBool computeOnlyPartition =
false);
992 const std::vector<std::function<
void(
const MInt)>>& = std::vector<std::function<
void(
const MInt)>>());
995 template <MBool finer, MBool coarser>
997 const MBool diagonalNeighbors =
true);
998 template <MBool finer, MBool coarser>
1000 const MInt dimNextNext = -1,
const uint_fast8_t childCodes = (uint_fast8_t)~0);
1004 const MInt onlyLevel = -1,
const MBool duringMeshAdaptation =
false,
1005 const std::vector<std::function<
void(
const MInt)>>& = std::vector<std::function<
void(
const MInt)>>(),
1006 const std::vector<std::function<
void(
const MInt)>>& = std::vector<std::function<
void(
const MInt)>>(),
1007 const MBool forceLeafLvlCorrection =
false);
1009 const MInt onlyLevel = -1,
1010 const std::vector<std::function<
void(
const MInt)>>& = std::vector<std::function<
void(
const MInt)>>());
1012 const MFloat*,
MInt*
const, std::vector<std::vector<MInt>>&,
1013 std::vector<std::vector<MLong>>&);
1015 const MFloat*,
MInt*
const, std::vector<std::vector<MInt>>&,
1016 std::vector<std::vector<MLong>>&);
1017 void meshAdaptation(std::vector<std::vector<MFloat>>&, std::vector<MFloat>&, std::vector<std::bitset<64>>&,
1018 std::vector<MInt>&,
const std::vector<std::function<
void(
const MInt)>>&,
1019 const std::vector<std::function<
void(
const MInt)>>&,
1020 const std::vector<std::function<
void(
const MInt)>>&,
1021 const std::vector<std::function<
void(
const MInt,
const MInt)>>&,
1023 const std::vector<std::function<
void()>>&);
1024 void meshAdaptationLowMem(std::vector<std::vector<MFloat>>&, std::vector<MFloat>&, std::vector<std::bitset<64>>&,
1025 std::vector<MInt>&,
const std::vector<std::function<
void(
const MInt)>>&,
1026 const std::vector<std::function<
void(
const MInt)>>&,
1027 const std::vector<std::function<
void(
const MInt)>>&,
1028 const std::vector<std::function<
void(
const MInt,
const MInt)>>&,
1030 const std::vector<std::function<
void()>>&);
1032 void meshAdaptationDefault(std::vector<std::vector<MFloat>>&, std::vector<MFloat>&, std::vector<std::bitset<64>>&,
1033 std::vector<MInt>&,
const std::vector<std::function<
void(
const MInt)>>&,
1034 const std::vector<std::function<
void(
const MInt)>>&,
1035 const std::vector<std::function<
void(
const MInt)>>&,
1036 const std::vector<std::function<
void(
const MInt,
const MInt)>>&,
1038 const std::vector<std::function<
void()>>&);
1042 std::vector<std::function<
void(
const MInt,
const MInt)>>());
1045 const std::vector<std::function<
MInt(
const MFloat*,
const MInt,
const MInt)>>& cellOutsideSolver);
1049 const std::function<
MInt(
const MFloat*,
const MInt,
const MInt)>& cellOutsideSolver);
1096 std::vector<std::vector<MInt>> old_globalhaloCells, old_globalwindowCells;
1098 for(
MInt i = 0; i < noNeighborDomains(); i++) {
1099 std::vector<MInt> tmp_halo;
1100 std::vector<MInt> tmp_window;
1101 for(
MInt j = 0; j < (signed)m_haloCells[i].size(); j++) {
1102 tmp_halo.push_back(a_globalId(m_haloCells[i][j]));
1104 for(
MInt j = 0; j < (signed)m_windowCells[i].size(); j++) {
1105 tmp_window.push_back(a_globalId(m_windowCells[i][j]));
1107 old_globalhaloCells.push_back(tmp_halo);
1108 old_globalwindowCells.push_back(tmp_window);
1113 m_haloCells.clear();
1114 m_windowCells.clear();
1115 m_haloCells.resize(noDomains());
1116 m_windowCells.resize(noDomains());
1120 for(
MInt level = m_maxLevel; level > reductionLevel; level--) {
1121 interpolateToParentCells(level - 1);
1122 for(
MInt c = m_tree.
size() - 1; c >= 0; c--) {
1123 if(a_level(c) == level) {
1128 m_noInternalCells = m_tree.
size();
1132 for(
MInt c = 0; c < m_tree.
size(); c++) {
1133 if(a_hasProperty(c, Cell::IsHalo)) {
1135 for(
MInt i = 0; i < noNeighborDomains(); i++) {
1136 for(std::size_t j = 0; j < old_globalhaloCells[i].size(); j++)
1137 if(a_globalId(c) == old_globalhaloCells[i][j]) {
1145 m_haloCells[m_nghbrDomains[nghr]].push_back(c);
1147 }
else if(a_hasProperty(c, Cell::IsWindow)) {
1149 std::vector<MInt> t;
1150 for(
MInt i = 0; i < noNeighborDomains(); i++) {
1151 for(std::size_t j = 0; j < old_globalwindowCells[i].size(); j++)
1152 if(a_globalId(c) == old_globalwindowCells[i][j]) {
1162 m_windowCells[m_nghbrDomains[i]].push_back(c);
1169 for(
MInt i = 0; i < noDomains(); i++) {
1170 m_noInternalCells -= (signed)m_haloCells[i].size();
1177 MPI_Allgather(&(m_noInternalCells), 1, MPI_INT, rcvBufRed.
begin(), 1, MPI_INT, mpiComm(), AT_,
"(m_noInternalCells)",
1178 "rcvBufRed.begin()");
1182 for(
MInt i = 0; i < noDomains(); i++) {
1183 m_domainOffsets[i] = offset;
1184 offset += rcvBufRed[i];
1187 m_domainOffsets[noDomains()] = offset;
1189 return rcvBufRed[domainId()];
void mAlloc(T *&a, const MLong N, const MString &objectName, MString function)
allocates memory for one-dimensional array 'a' of size N
MBool mDeallocate(T *&a)
deallocates the memory previously allocated for element 'a'
void a_resetProperties(const MInt cellId)
Returns property p of the cell cellId.
void refineCell(const MInt cellId, const MLong *const refineChildIds=nullptr, const MBool mayHaveChildren=false, const std::vector< std::function< MInt(const MFloat *, const MInt, const MInt)> > &=std::vector< std::function< MInt(const MFloat *, const MInt, const MInt)> >(), const std::bitset< maia::grid::tree::Tree< nDim >::maxNoSolvers()> refineFlag=std::bitset< maia::grid::tree::Tree< nDim >::maxNoSolvers()>(1ul))
MFloat gridCellVolume(const MInt level) const
MInt * m_identicalSolverLvlJumps
const MBool m_paraViewPlugin
MInt m_maxLevel
The max Level of refinement of the solver length.
static constexpr const auto WINDOWLAYER_MAX
MInt createAzimuthalHaloCell(const MInt, const MInt, const MLong *, std::unordered_multimap< MLong, MInt > &, const MFloat *, MInt *const, std::vector< std::vector< MInt > > &, std::vector< std::vector< MLong > > &)
Create a new azimuthal halo cell as neighbor of cellId in direction dir and find matching neighbor do...
MBool checkOutsideAzimuthalDomain(MFloat *)
void getAdjacentGridCells1d5(std::set< MInt > &, const MInt, const MInt, const MInt dimNext=-1, const MInt dimNextNext=-1, const uint_fast8_t childCodes=(uint_fast8_t)~0)
MLong a_neighborId(const MInt cellId, const MInt dir, const MInt solverId) const
Returns the neighbor id of the cell cellId dir.
MInt noHaloCells(const MInt domainId) const
Return number of halo cells for given domain.
std::vector< MInt > m_azimuthalNghbrDomainIndex
MBool hollowBoxSphereIntersection(const MFloat *bMin, const MFloat *bMax, const MFloat *const sphereCenter, MFloat const radius)
MFloat cellVolumeAtLevel(const MInt level) const
MInt maxUniformRefinementLevel() const
Return maximum homogeneously-refined level.
MBool a_isToDelete(const MInt cellId) const
Returns the delete of the cell cellId.
MInt findIndex(ITERATOR, ITERATOR, const U &)
Find index in array [first,last) with matching entry 'val'.
MLong noPartitionCellsGlobal() const
static constexpr MInt nDim_()
MLong a_neighborId(const MInt cellId, const MInt dir) const
Returns the neighbor id of the cell cellId dir.
std::vector< MInt > m_azimuthalUnmappedHaloDomains
MLong a_childId(const MInt cellId, const MInt pos, const MInt solverId) const
Returns the child id of the cell cellId at position pos.
MFloat m_partitionCellWorkloadThreshold
std::array< MInt, 3 > m_periodicCartesianDir
void tagActiveWindowsOnLeafLvl3(const MInt maxLevel, const MBool duringMeshAdaptation, const std::vector< std::function< void(const MInt)> > &=std::vector< std::function< void(const MInt)> >())
Don't touch this function, because you don't know what you are doing NOTE: Actually the most clever w...
MBool a_hasParent(const MInt cellId) const
Returns if the cell cellId has a parent.
void rotateCartesianCoordinates(MFloat *, MFloat)
Rotate caresian coordinates by angle. Azimuthal periodic center is used.
void restorePeriodicConnection()
Delete the Connection of periodic-Halo-Cells at the bounding box.
void calculateNoOffspringsAndWorkload(Collector< CELLTYPE > *input_cells, MInt input_noCells)
Caluclate the number of offsprings and the workload for each cell.
void checkWindowHaloConsistency(const MBool fullCheck=false, const MString a="")
Checks consistency of window/halo cells.
static constexpr MInt m_maxNoSensors
const std::vector< std::vector< MInt > > & azimuthalWindowCells() const
MString m_gridInputFileName
MInt periodicCartesianDir(const MInt dir) const
MBool m_allowInterfaceRefinement
void tagAzimuthalUnmappedHaloCells(std::vector< std::vector< MLong > > &, std::vector< MLong > &, std::vector< MInt > &, MInt)
Tag azimuthal halo cells for refinement.
MInt m_maxUniformRefinementLevel
void computeGlobalIds()
Update number of internal cells, recalculate domain offsets, recalculate global ids for all internal ...
void meshAdaptation(std::vector< std::vector< MFloat > > &, std::vector< MFloat > &, std::vector< std::bitset< 64 > > &, std::vector< MInt > &, const std::vector< std::function< void(const MInt)> > &, const std::vector< std::function< void(const MInt)> > &, const std::vector< std::function< void(const MInt)> > &, const std::vector< std::function< void(const MInt, const MInt)> > &, const std::vector< std::function< MInt(const MFloat *, const MInt, const MInt)> > &, const std::vector< std::function< void()> > &)
MInt ancestorPartitionCellId(const MInt cellId) const
Return the cell Id of the partition cell that has the given cellId as a descendant.
MInt a_noChildren(const MInt cellId) const
Returns the no. of children of the cell cellId.
MFloat & a_weight(const MInt cellId)
Returns the weight of the cell cellId.
MFloat * dummyCorrect(const MInt cellId, MFloat *coords)
MInt * m_identicalSolvers
void loadGridFile(const MInt, const MInt)
Load grid from disk and setup communication.
MString gridInputFileName() const
Return grid file name.
void updateHaloCellCollectors()
Fill m_nghbrDomains, m_haloCells and m_windowCells with data from temporary buffers.
MInt * m_noSolverHaloLayers
void determineNoPartitionCellsAndOffsets(MLong *const noPartitionCells, MLong *const partitionCellOffsets)
Determine the number of partition cells on each domain and the corresponding offsets.
friend class FvBndryCnd2D
MInt m_noPartitionLevelAncestors
Local number of partition level ancestors on this domain (without halos)
MInt maxPartitionLevelShift() const
MInt windowCell(const MInt domainId, const MInt cellId) const
Return window cell id.
constexpr MInt noHaloLayers(const MInt solverId) const
std::vector< MLong > m_partitionLevelAncestorChildIds
MInt noAzimuthalNeighborDomains() const
Return number of azimuthal neighbor domains.
MInt minCell(const MInt id) const
Return min-level cell id.
std::vector< MInt > m_gridBndryCells
MInt noWindowCells(const MInt domainId) const
Return number of window cells for given domain.
MFloat a_weight(const MInt cellId) const
Returns the weight of the cell cellId.
maia::grid::cell::BitsetType::reference a_hasProperty(const MInt cellId, const Cell p)
Returns property p of the cell cellId.
MString a_propertiesToString(const MInt cellId)
constexpr MInt noPartitionCells() const
MInt m_partitionCellOffspringThreshold
MInt m_noIdenticalSolvers
MLong a_parentId(const MInt cellId, const MInt solverId) const
Returns the parent of the cell cellId.
const MInt & neighborDomain(const MInt id) const
Return neighbor domain.
MBool pointInLocalBoundingBox(const MFloat *coord)
Check if the given point lies in the local bounding box.
MBool m_hasMultiSolverBoundingBox
MBool wasBalancedAtLeastOnce() const
std::vector< std::vector< MInt > > m_azimuthalWindowCells
MInt m_noMinLevelCellsGlobal
MInt noNeighborDomains() const
Return number of neighbor domains.
MBool m_localBoundingBoxInit
MInt globalIdToLocalId(const MLong &globalId, const MBool termIfNotExisting=false)
Global to local id mapping.
MInt * m_identicalSolverMaxLvl
MLong generateHilbertIndex(const MInt cellId, const MInt targetMinLevel)
MLong generateHilbertIndex(const MInt cellId)
void savePartitionCellWorkloadsGridFile()
Update the partition cell workloads in the grid file.
void descendStoreGlobalId(MInt cellId, MInt &localCnt)
Recursively descend subtree to reset global id for internal cells.
MInt * m_localPartitionCellLocalIdsRestart
std::vector< std::vector< MInt > > m_windowCells
MInt findContainingPartitionCell(const MFloat *const coord, const MInt solverId=-1, std::function< MFloat *(MInt, MFloat *const)> correctCellCoord=nullptr)
Return the cell Id of the partition cell containing the coords.
void meshAdaptationDefault(std::vector< std::vector< MFloat > > &, std::vector< MFloat > &, std::vector< std::bitset< 64 > > &, std::vector< MInt > &, const std::vector< std::function< void(const MInt)> > &, const std::vector< std::function< void(const MInt)> > &, const std::vector< std::function< void(const MInt)> > &, const std::vector< std::function< void(const MInt, const MInt)> > &, const std::vector< std::function< MInt(const MFloat *, const MInt, const MInt)> > &, const std::vector< std::function< void()> > &)
Performs mesh adaptation and continuously updates the window/halo cells.
MLong m_localPartitionCellOffsetsRestart[3]
friend class FvBndryCnd3D
maia::grid::tree::SolverBitsetType::reference a_solver(const MInt cellId, const MInt solverId)
Returns if cell cellId is used by solver solverId.
MLong m_localPartitionCellOffsets[3]
void tagActiveWindows(std::vector< MLong > &, MInt)
Flag m_noHaloLayers layers of halo cells adjacent to internal cells on this domain.
MLong hilbertIndexGeneric(const MFloat *const coords, const MFloat *const center, const MFloat length0, const MInt baseLevel) const
Return the hilbert index for the given coordinates in 2D/3D.
std::vector< std::vector< MInt > > m_partitionLevelAncestorWindowCells
MBool intersectingWithLocalBoundingBox(MFloat *const center, MFloat const radius)
const MInt & azimuthalNeighborDomain(const MInt id) const
Return azimuthal neighbor domain.
MBool pointWthCell(const std::array< MFloat, nDim > &coord, const MInt cellId, std::function< MFloat *(MInt, MFloat *const)> correctCellCoord=nullptr) const
void determinePartLvlAncestorHaloWindowCells(std::vector< std::vector< MInt > > &partLvlAncestorHaloCells, std::vector< std::vector< MInt > > &partLvlAncestorWindowCells)
Store partition level ancestor window/halo cells.
void tagActiveWindowsAtMinLevel(const MInt)
Actually the most clever way of tagging is to go from highest level to lower levels,...
void compactCells(const std::vector< std::function< void(const MInt, const MInt)> > &=std::vector< std::function< void(const MInt, const MInt)> >())
Removes all holes in the cell collector and moves halo cells to the back of the collector.
std::vector< MInt > m_azimuthalNghbrDomains
void computeLocalBoundingBox(MFloat *const bbox)
Compute the bounding box of all local cells.
MInt noSolverHaloCells(const MInt domainId, const MInt solverId, const MBool periodicCells) const
MBool a_hasNeighbor(const MInt cellId, const MInt dir, const MInt solverId) const
Returns noNeighborIds of the cell CellId.
const std::vector< MInt > & azimuthalNeighborDomains() const
Return vector of azimuthal neighbor domains.
MBool m_wasBalancedAtLeastOnce
MInt findNeighborDomainId(const MLong globalId)
MBool a_isLeafCell(const MInt cellId) const
Returns whether cell is leaf cellId.
void saveGrid(const MChar *, const std::vector< std::vector< MInt > > &, const std::vector< std::vector< MInt > > &, const std::vector< std::vector< MInt > > &, const std::vector< MInt > &, const std::vector< std::vector< MInt > > &, MInt *recalcIdTree=nullptr)
MBool m_updatePartitionCellsOnRestart
void exchangeNotInPlace(DATATYPE *exchangeVar, DATATYPE *recvMem)
communicates a variable from windows to halos but does not overwrite halo values. Window values are s...
void changeGlobalToLocalIds()
Change global child/neighbor/parent cell ids into local cell ids. Requires that m_globalToLocalId con...
void centerOfGravity(MFloat *const center) const
MInt noMinCells() const
Return the number of Cells on the minLevel.
maia::grid::cell::BitsetType::reference a_isToDelete(const MInt cellId)
Returns the delete of the cell cellId.
MInt centerOfGravity(MInt dir) const
Return the center of gravity.
MPI_Comm mpiComm() const
Return the MPI communicator used by this grid.
void saveDonorGridPartition(const MString &gridMapFileName, const MString &gridPartitionFileName)
Create and store donor grid partition for volume-coupled simulations.
void balance(const MInt *const noCellsToReceiveByDomain, const MInt *const noCellsToSendByDomain, const MInt *const sortedCellId, const MLong *const offset, const MLong *const globalIdOffsets)
Balance the grid according to the given cell send/recv counts.
MInt a_noOffsprings(const MInt cellId) const
Returns the noOffsprings of the cell .
MLong noCellsGlobal() const
Return the Global-noCells.
void setGridInputFilename(MBool=false)
Read grid file name from properties or restart files.
MInt m_maxPartitionLevelShift
void createMinLevelExchangeCells()
Create window-halo-connectivity based on hilbertIndex matching for regular and periodic exchange cell...
MInt findContainingHaloCell(const MFloat *const coord, const MInt solverId, MInt domainId, MBool onlyPartitionCells, std::function< MFloat *(MInt, MFloat *const)> correctCellCoord=nullptr)
Return the cell id of the halo partition cell containing the coords.
MInt findContainingLeafCell(const std::array< MFloat, nDim > &coord, const MInt startId, std::function< MFloat *(MInt, MFloat *const)> *correctCellCoord=nullptr, const MInt solverId=-1, const MBool allowNonLeafHalo=false)
MFloat m_targetGridCenterOfGravity[3]
void correctAzimuthalSolverBits()
Corrects solver bits on azimuthal halo cells Ensure that azimuthal halo cells have all children or ar...
MFloat m_centerOfGravity[3]
coordinates of the root cell
std::vector< std::tuple< MInt, MInt, MInt > > m_neighborBackup
MInt noHaloLayers() const
Return noHalo-a_noHaloLayers.
void boundingBox(MFloat *const box) const
MLong m_noPartitionLevelAncestorsGlobal
void createHigherLevelExchangeCells_old(const MInt onlyLevel=-1, const std::vector< std::function< void(const MInt)> > &=std::vector< std::function< void(const MInt)> >())
Iteratively create window and halo cells on levels m_minLevel+1...m_maxLevel, starting from m_minLeve...
void createPaths()
Necessary for extractPointIdsFromGrid function.
MInt & a_level(const MInt cellId)
Returns the level of the cell cellId.
MInt haloCell(const MInt domainId, const MInt cellId) const
Return halo cell id.
MInt a_level(const MInt cellId) const
Returns the level of the cell cellId.
MLong a_globalId(const MInt cellId) const
Returns the globalId of the cell cellId in collector cells_.
void descendNoOffsprings(const MLong cellId, const MLong offset=0)
void generalExchange(MInt noVars, const MInt *vars, DATATYPE **exchangeVar, MInt noDomSend, MInt *domSend, const MInt *noCellsSendPerDom, const MInt *cellIdsSend, MInt noDomRecv, MInt *domRecv, const MInt *noCellsRecvPerDom, const MInt *cellIdsRecv)
void exchangeProperties()
Exchange properties of window/halo cells.
std::vector< MInt > m_nghbrDomainIndex
MInt noAzimuthalHaloCells(const MInt domainId) const
Return number of azimuthal Halo cells for given domain.
MBool isSolverWindowCell(const MInt domainId, const MInt cellId, const MInt solverId) const
MBool coarsenCheck(const MInt cellId, const MInt solverId)
checks if the given cell's children may be removed
MBool boxSphereIntersection(const MFloat *bMin, const MFloat *bMax, const MFloat *const sphereCenter, MFloat const radius)
MBool hasCutOff() const
Returns weather the grid has a cutOff.
MFloat m_periodicCartesianLength[3]
MFloat * m_gridCellVolume
void propagateDistance(std::vector< MInt > &list, MIntScratchSpace &distMem, MInt dist)
propagates a given distance from a given list of cells on equal level neighbours
void savePartitionFile()
Save current grid partitioning to file.
std::vector< MInt > m_nghbrDomains
std::vector< std::vector< MInt > > m_haloCells
std::vector< std::vector< MInt > > m_azimuthalHaloCells
void storeMinLevelCells(const MBool updateMinlevel=false)
Store cell ids of all min-level cells.
const MLong & domainOffset(const MInt id) const
Return domain offset.
MFloat m_lengthLevel0
The initial length of the solver.
MInt intersectingWithHaloCells(MFloat *const center, MFloat const radius, MInt domainId, MBool onlyPartition)
MBool m_updatedPartitionCells
void removeChilds(const MInt cellId)
removes the children of the given cell
MLong localPartitionCellOffsets(const MInt index) const
const std::vector< std::vector< MInt > > & azimuthalHaloCells() const
MInt a_hasChildren(const MInt cellId, const MInt solverId) const
Returns if the cell cellId has children.
MInt m_newMinLevel
The new min Level which has been increased at the restart!
MInt setNeighborDomainIndex(const MInt, std::vector< TA > &, std::vector< TB > &, std::vector< TC > &)
Find neighbor domain index or create new if not existing.
MBool a_isHalo(const MInt cellId) const
Returns property p of the cell cellId.
std::vector< MInt > m_partitionLevelAncestorNghbrDomains
std::array< MFloat, 3 > m_azimuthalPerCenter
MBool a_isLeafCell(const MInt cellId, const MInt solverId) const
Returns whether cell is leaf cellId.
const std::vector< std::vector< MInt > > & haloCells() const
void setUpdatedPartitionCells(const MBool flag)
void setLevel()
Set minimum und maximum cell levels.
std::vector< std::unordered_map< MInt, M32X4bit< true > > > m_windowLayer_
void setSolver(const MInt cellId, const MInt solverId, MBool flag)
Sets if cell is used by solver.
MInt m_minLevel
The min Level of refinement of the solver length.
MBool m_updatingPartitionCells
MInt windowLayer(const MInt domainId, const MInt cellId, const MInt solverId) const
MInt m_noPeriodicCartesianDirs
MInt azimuthalHaloCell(const MInt domainId, const MInt cellId) const
Return azimuthal Halo cell id.
MLong & a_childId(const MInt cellId, const MInt pos)
Returns the child id of the cell cellId at position pos.
MLong bitOffset() const
Return the 32-BitOffset.
void setupWindowHaloCellConnectivity()
Create window and halo cell connectivity between domains.
void tagActiveWindows2_(std::vector< MLong > &, const MInt)
NOTE: Actually the most clever way of tagging is to go from highest level to lower levels,...
MInt getAdjacentGridCells5(const MInt, MInt *const, const MInt level=-1, const MBool diagonalNeighbors=true)
MFloat halfCellLength(const MInt cellId) const
Returns the half cell length of cell cellId.
MLong m_noPartitionCellsGlobal
MFloat a_coordinate(Collector< U > *NotUsed(cells_), const MInt cellId, const MInt dir) const
Returns the coordinate of the cell cellId in collector cells_ for direction dir.
void cartesianToCylindric(const MFloat *, MFloat *)
Transform cartesian cell coordinate to cylindrcal coordinats using the / using the azimuthal periodic...
MInt noAzimuthalUnmappedHaloCells() const
constexpr MBool paraViewPlugin() const
MInt intersectingWithPartitioncells(MFloat *const center, MFloat const radius)
MLong a_parentId(const MInt cellId) const
Returns the parent of the cell cellId.
MInt findContainingHaloPartitionCell(const MFloat *const coors, const MInt solverId=-1)
Return the cell id of the halo partition cell containing the coords.
MInt targetGridMinLevel() const
MBool updatePartitionCells(MInt offspringThreshold, MFloat workloadThreshold)
Determine new partition cells (i.e. in/decrease the partition level shifts) and change the grid accor...
void a_copyProperties(const MInt fromCellId, const MInt toCellId)
Returns property p of the cell cellId.
void meshAdaptationLowMem(std::vector< std::vector< MFloat > > &, std::vector< MFloat > &, std::vector< std::bitset< 64 > > &, std::vector< MInt > &, const std::vector< std::function< void(const MInt)> > &, const std::vector< std::function< void(const MInt)> > &, const std::vector< std::function< void(const MInt)> > &, const std::vector< std::function< void(const MInt, const MInt)> > &, const std::vector< std::function< MInt(const MFloat *, const MInt, const MInt)> > &, const std::vector< std::function< void()> > &)
Performs mesh adaptation and continuously updates the window/halo cells.
MFloat a_workload(const MInt cellId) const
Returns the workload of the cell cellId.
const Tree & treeb() const
MInt * m_localPartitionCellLocalIds
std::map< MLong, MInt > m_globalToLocalId
Mapping: global cell id -> local cell id.
void propagationStep(MInt cellId, MInt dist, MInt *distMem, MInt endDist)
starts the propagation on a cell and continues calling the function for the neighbours
void setChildSolverFlag(const MInt cellId, const MInt solver, const std::function< MInt(const MFloat *, const MInt, const MInt)> &cellOutsideSolver)
const MFloat * globalBoundingBox() const
return global Bounding box
MLong a_childId(const MInt cellId, const MInt pos) const
Returns the child id of the cell cellId at position pos.
MFloat cellLengthAtCell(const MInt cellId) const
Returns the cell length of cell cellId.
void deletePeriodicConnection(const MBool=true)
Delete the Connection of periodic-Halo-Cells at the bounding box.
MInt a_hasChild(const MInt cellId, const MInt pos) const
Returns if the cell cellId has a child at position pos.
MBool a_hasNeighbor(const MInt cellId, const MInt dir) const
Returns noNeighborIds of the cell CellId.
void partitionParallel(const MInt tmpCount, const MLong tmpOffset, const MFloat *const partitionCellsWorkload, const MLong *const partitionCellsGlobalId, const MFloat totalWorkload, MLong *partitionCellOffsets, MLong *globalIdOffsets, MBool computeOnlyPartition=false)
MInt createAdjacentHaloCell(const MInt, const MInt, const MLong *, std::unordered_multimap< MLong, MInt > &, const MFloat *, MInt *const, std::vector< std::vector< MInt > > &, std::vector< std::vector< MLong > > &)
Create a new halo cell (candidate) as neighbor of cellId in direction dir and find matching neighbor ...
MBool updatedPartitionCells() const
MBool wasBalanced() const
void createGridMap(const MString &donorGridFileName, const MString &gridMapFileName)
Create file that contains mapping from donor to target cell.
MFloat lengthLevel0() const
Return the length of the level 0 cell.
MFloat m_boundingBoxBackup[6]
MLong * m_localPartitionCellGlobalIds
MBool refineCheck(const MInt cellId, const MInt solverId, const std::vector< std::function< MInt(const MFloat *, const MInt, const MInt)> > &cellOutsideSolver)
checks if the given cell may be refined
MInt deleteCell(const MInt cellId)
Deletes a cell (without collector fragmentation) and returns new collector size.
void createGridSlice(const MString &axis, const MFloat intercept, const MString &fileName)
Overload method of createGridSlice to provide usage with or without return of cellIds which are in th...
std::vector< MInt > m_partitionLevelAncestorIds
Partition level shift.
MFloat & a_coordinate(const MInt cellId, const MInt dir)
Returns the coordinate of the cell cellId for direction dir.
void exchangeSolverBitset(std::bitset< N > *const data, const MBool defaultVal=false)
MInt & a_noOffsprings(const MInt cellId)
Returns the noOffsprings of the cell .
const std::vector< std::vector< MInt > > & windowCells() const
Tree & treeb()
Full access to tree (for now)
azimuthalBbox m_azimuthalBbox
MFloat periodicCartesianLength(const MInt dir) const
MInt azimuthalUnmappedHaloCell(const MInt cellId) const
MInt findContainingLeafCell(const MFloat *coord, std::function< MFloat *(MInt, MFloat *const)> correctCellCoord=nullptr, const MInt solverId=-1)
Return the cell Id of the leaf cell containing the coords.
MBool a_hasParent(const MInt cellId, const MInt solverId) const
Returns if the cell cellId has a parent.
void computeLeafLevel()
Compute distance to leaf level.
MBool m_partitionParallelSplit
std::set< MInt > m_freeIndices
MLong & a_globalId(const MInt cellId)
Returns the globalId of the cell cellId in collector cells_.
std::vector< MInt > m_azimuthalUnmappedHaloCells
std::vector< std::vector< MInt > > m_partitionLevelAncestorHaloCells
Tree m_tree
Store the tree.
static constexpr MInt m_noDirs
MLong hilbertIndexGeneric(const MFloat *const coords) const
MFloat & a_workload(const MInt cellId)
Returns the workload of the cell cellId.
void dumpCellData(const MString name)
Write the cell data of the local tree to some file for debugging purposes.
MBool * m_checkRefinementHoles
void checkAzimuthalWindowHaloConsistency()
Checks consistency of aimuthal window/halo cells.
MFloat m_localBoundingBox[6]
Local bounding box for fast checking if a point lies outside the local domain.
MInt a_hasChildren(const MInt cellId) const
Returns if the cell cellId has children.
void removeCell(const MInt cellId)
removes the children of the given cell
MInt azimuthalWindowCell(const MInt domainId, const MInt cellId) const
Return azimuthal window cell id.
MFloat m_targetGridLengthLevel0
MInt getAdjacentGridCells(MInt, MIntScratchSpace &, MInt, MBool diagonalNeighbors=true)
Retrieves all direct and diagonal neighboring cells of the given cell on the child level if available...
void swapCells(const MInt cellId, const MInt otherId)
swap two cells; the window/halo cell arrays have to be update elsewhere for performance reasons
void createGlobalToLocalIdMapping()
Create the mapping from global to local cell ids.
MInt maxRefinementLevel() const
Return maximum possible refinement level.
MLong & a_parentId(const MInt cellId)
Returns the parent of the cell cellId.
void tagAzimuthalHigherLevelExchangeCells(std::vector< MLong > &, std::vector< MLong > &, MInt)
Tag azimuthal halo cells for refinement.
void gridSanityChecks()
Perform grid sanity checks.
std::vector< std::vector< MInt > > m_azimuthalHigherLevelConnectivity
MInt domainId() const
Return the domainId (rank)
MInt noSolverWindowCells(const MInt domainId, const MInt solverId) const
MInt noAzimuthalWindowCells(const MInt domainId) const
Return number of azimuthal window cells for given domain.
void localToGlobalIds()
Convert parent ids, neighbor ids, and child ids from local to global cell ids.
MInt localPartitionCellLocalIds(const MInt id) const
MBool m_loadGridPartition
std::array< MInt, 2 > m_azimuthalPeriodicDir
MLong & a_neighborId(const MInt cellId, const MInt dir)
Returns the neighbor id of the cell cellId dir.
void resetCell(const MInt &cellId)
Reset cell to default values.
MFloat m_targetGridBoundingBox[6]
Multisolver grid information.
MBool isMpiRoot() const
Return true if this is domain zero (a.k.a. as the root domain)
static constexpr MInt m_maxNoChilds
CartesianGrid(MInt maxCells, const MFloat *const bBox, const MPI_Comm comm, const MString &fileName="")
MInt findContainingLeafCell(const MFloat *const coord, const MInt startId, std::function< MFloat *(MInt, MFloat *const)> correctCellCoord=nullptr, const MInt solverId=-1, const MBool allowNonLeafHalo=false)
std::vector< MInt > m_minLevelCells
void loadDonorGridPartition(const MLong *const partitionCellsId, const MInt noPartitionCells)
Return partition cell offsets based on grid partition file.
void updatePartitionCellInformation()
Update the partition cell local/global ids and the partition cell global offsets.
MInt noInternalCells() const
Return number of internal cells (i.e., excluding halo cells)
MFloat cellLengthAtLevel(const MInt level) const
Returns cell length at cell level level.
MInt reduceToLevel(const MInt reductionLevel, F interpolateToParentCells)
Reduces the current grid to a certain level.
MInt m_noHaloPartitionLevelAncestors
MInt m_targetGridMinLevel
MInt a_hasChild(const MInt cellId, const MInt pos, const MInt solverId) const
Returns if the cell cellId has a child at position pos.
MInt setAzimuthalNeighborDomainIndex(const MInt, std::vector< std::vector< MInt > > &, std::vector< std::vector< MInt > > &)
Find azimuthal neighbor domain index or create new if not existing.
void createLeafCellMapping(const MInt donorSolverId, const MInt gridCellId, std::vector< MInt > &mappedLeafCells, MBool allChilds=false)
Identify all leaf cells of one solver which are mapped to a given grid cell.
MBool a_hasProperty(const MInt cellId, const Cell p) const
Returns property p of the cell cellId.
MFloat a_coordinate(const MInt cellId, const MInt dir) const
Returns the coordinate of the cell cellId for direction dir.
const std::vector< MInt > & neighborDomains() const
Return vector of neighbor domains.
void createHigherLevelExchangeCells(const MInt onlyLevel=-1, const MBool duringMeshAdaptation=false, const std::vector< std::function< void(const MInt)> > &=std::vector< std::function< void(const MInt)> >(), const std::vector< std::function< void(const MInt)> > &=std::vector< std::function< void(const MInt)> >(), const MBool forceLeafLvlCorrection=false)
Iteratively create window and halo cells on levels m_minLevel+1...m_maxLevel, starting from m_minLeve...
constexpr MBool allowInterfaceRefinement() const
void loadGrid(const MString &fileName)
Load a grid file writen with saveGridDomainPar.
void checkWindowLayer(const MString a)
Checks variable m_windowLayer_.
MInt azimuthalUnmappedHaloDomain(const MInt cellId) const
void loadPartitionFile(const MString &partitionFileName, MLong *partitionCellOffsets)
Load a grid partitioning from a file.
MFloat reductionFactor() const
Return the reductionFactor.
std::array< MInt, 11+(nDim - 2) *32 > m_neighborCode
maia::grid::tree::SolverBitsetType::reference a_isLeafCell(const MInt cellId, const MInt solverId)
Returns whether cell is leaf cellId.
This class is a ScratchSpace.
constexpr MInt size() const
Return size (i.e., currently used number of nodes)
Grid controller manages adaptation and load balancing in multi-solver environment.
Class that represents grid tree and contains all relevant per-node data.
MBool hasChild(const MInt id, const MInt pos) const
Return whether node has child at given position.
MInt noChildren(const MInt id) const
Return number of children of given node.
SolverBitsetType::reference solver(const MInt id, const MInt solverId)
Accessor for solver usage.
MFloat & weight(const MInt id)
Accessor for weight.
MString propertiesToString(const MInt id) const
Convert properties to string.
MBool hasParent(const MInt id) const
Return whether node has parent.
MInt & noOffsprings(const MInt id)
Accessor for noOffsprings.
MLong & globalId(const MInt id)
Accessor for global id.
MLong & neighbor(const MInt id, const MInt dir)
Accessor for neighbor node.
PropertyBitsetType & properties(const MInt id)
Accessor for properties.
MLong & parent(const MInt id)
Accessor for parent node.
MBool hasNeighbor(const MInt id, const MInt dir) const
Return whether node has same-level neighbor in given direction.
MFloat & workload(const MInt id)
Accessor for workload.
MInt & level(const MInt id)
Accessor for level.
MBool isLeafCell(const MInt id) const
Accessor for isLeafCell usage (const version).
PropertyBitsetType::reference hasProperty(const MInt id, const Cell p)
Accessor for properties.
MLong & child(const MInt id, const MInt pos)
Accessor for child node.
void resetProperties(const MInt id)
Reset all properties.
maia::grid::tree::Cell Cell
MFloat & coordinate(const MInt id, const MInt dim)
Accessor for coordinates.
MBool hasChildren(const MInt id) const
Return whether node has any children.
void mTerm(const MInt errorCode, const MString &location, const MString &message)
constexpr Real POW3(const Real x)
constexpr Real POW2(const Real x)
constexpr T mMin(const T &x, const T &y)
constexpr T mMax(const T &x, const T &y)
constexpr MLong IPOW2(MInt x)
constexpr MFloat FFPOW2(MInt x)
std::basic_string< char > MString
int MPI_Allgather(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm, const MString &name, const MString &sndvarname, const MString &rcvvarname)
same as MPI_Allgather
Namespace for auxiliary functions/classes.
MFloat dist(const Point< DIM > &p, const Point< DIM > &q)
MFloat azimuthalBoundary(const MFloat *coords, MInt side)
MInt index(const MFloat *coord, MInt dir)
MInt azimuthalSide(const MFloat phi)
void init(MFloat angle, MInt periodicDir1, MInt periodicDir2, MInt noLayers)