MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
cartesiangridproxy.h
Go to the documentation of this file.
1// Copyright (C) 2024 The m-AIA AUTHORS
2//
3// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
4//
5// SPDX-License-Identifier: LGPL-3.0-only
6
7#ifndef GRIDPROXY_H_
8#define GRIDPROXY_H_
9
10#include <algorithm>
11#include <bitset>
12#include <type_traits>
13#include <vector>
14#include "COMM/mpiexchange.h"
15#include "COMM/mpioverride.h"
16#include "cartesiangrid.h"
17#include "cartesiangridtree.h"
18#include "typetraits.h"
19
20#include "GEOM/geometry.h"
21
22namespace maia {
23namespace grid {
24
25// Forward declare tree proxy
26namespace tree {
27template <MInt nDim>
28class TreeProxy;
29}
30
35template <MInt nDim>
36class Proxy {
37 public:
38 // Types
44
45 // Methods
46 // Constructor
47 Proxy(const MInt solverId, Grid& grid_, Geometry<nDim>& geometry_);
48 Proxy(const MInt solverId, Grid& grid_); // ParaView plugin
49
50 // Destructor
51 ~Proxy();
52
53 // Add this accessor in case the full grid access is needed
54 Grid& raw() { return m_grid; }
55 const Grid& raw() const { return m_grid; }
56
57 // Return proxy grid tree
58 const TreeProxy& tree() const { return m_tree; }
59
60 // Other methods
61 void update();
62 void updateOther();
64 void initGridMap();
65 void updateGridMap();
66 void resizeGridMap(const MInt solverSize);
68 void findDirectNghbrs(const MInt, std::vector<MInt>&);
69 void findNeighborHood(const MInt, const MInt, std::vector<MInt>&);
70 void getAllLeafChilds(const MInt, std::vector<MInt>&);
72 MInt domainContainingCell(MInt globalId) const;
73
74 private:
75 // Internal methods for updating the proxy class and its tree proxy
77 void checkOffsetConsistency() const;
78 void checkNeighborConsistency() const;
79 void setupWindowHaloConnectivityOnLeafLvl(std::map<MInt, MInt>&);
80 void checkWindowHaloConsistency() const;
83 void descendStoreGlobalId(MInt cellId, MInt& localCnt);
85 void updateTreeData();
86
87 void getLocalSameLevelCellIds(std::vector<MInt>& levelCellId, const MInt level);
88
90
91 public:
92 void updateGridInfo();
93 void findEqualLevelNeighborsParDiagonal(MBool idsAreGlobal = true);
96 MInt cellId, MInt noLayers, MIntScratchSpace& adjacentCells, MInt level, MInt diagonalNeighbors = 0);
97 MInt getNghbrCells(MInt cellId, MInt level, MInt* nghbrs, MInt dir0, MInt dir1 = -1, MInt dir2 = -1);
98 MInt findNeighborDomainId(const MLong globalId);
99 MInt globalToLocalId(const MLong globalId) const { return tree().localId(globalId); }
100 void smoothFilter(const MInt level, MFloat** value);
101
103 const MInt gridCellId = raw().findContainingLeafCell(coord, nullptr, solverId());
104 if(gridCellId < 0) return gridCellId;
105 ASSERT(solverFlag(gridCellId, solverId()), "");
106 return tree().grid2solver(gridCellId);
107 }
108 MInt findContainingLeafCell(const MFloat* coord, const MInt startId, const MBool allowNonLeafHalo = false) {
109 const MInt startGridId = tree().solver2grid(startId);
110 const MInt gridCellId = raw().findContainingLeafCell(coord, startGridId, nullptr, solverId(), allowNonLeafHalo);
111 if(gridCellId < 0) return gridCellId;
112 ASSERT(solverFlag(gridCellId, solverId()), "");
113 return tree().grid2solver(gridCellId);
114 }
115
117 MBool isActive() const { return m_isActive; }
118
121
123 MInt solverId() const { return m_solverId; }
124
125 MBool wasAdapted() const { return raw().wasAdapted(); }
126 MBool wasBalanced() const { return raw().wasBalanced(); }
127
128 // General grid & parallelization information
129 MInt noCells() const { return tree().size(); }
131
132 MInt noNeighborDomains() const { return m_neighborDomains.size(); }
133 MInt neighborDomain(const MInt id) const { return m_neighborDomains[id]; }
134 const std::vector<MInt>& neighborDomains() const { return m_neighborDomains; }
135
136 MInt noWindowCells(const MInt domainId) const { return m_windowCells[domainId].size(); }
137 const MInt& windowCell(const MInt domainId, const MInt id) const { return m_windowCells[domainId][id]; }
138 const std::vector<std::vector<MInt>>& windowCells() const { return m_windowCells; };
139
140 MInt noHaloCells(const MInt domainId) const { return m_haloCells[domainId].size(); }
141 const MInt& haloCell(const MInt domainId, const MInt id) const { return m_haloCells[domainId][id]; }
142 const std::vector<std::vector<MInt>>& haloCells() const { return m_haloCells; };
143
146
149
151 const MInt& leafWindowCell(const MInt domainId, const MInt id) const { return m_leafWindowCells[domainId][id]; }
152 const std::vector<std::vector<MInt>>& leafWindowCells() const { return m_leafWindowCells; };
153
154 MInt noLeafHaloCells(const MInt domainId) const { return m_leafHaloCells[domainId].size(); }
155 const MInt& leafHaloCell(const MInt domainId, const MInt id) const { return m_leafHaloCells[domainId][id]; }
156 const std::vector<std::vector<MInt>>& leafHaloCells() const { return m_leafHaloCells; };
157
158 MInt leafRecSize() const { return m_leafRecvSize; }
159 MInt leafSendSize() const { return m_leafSendSize; }
160
161 // Azimuthal periodicity
163 MInt azimuthalNeighborDomain(const MInt azimuthalId) const { return m_azimuthalNeighborDomains[azimuthalId]; }
164 const std::vector<MInt>& azimuthalNeighborDomains() const { return m_azimuthalNeighborDomains; }
165
166 // Window cells
167 MInt noAzimuthalWindowCells(const MInt azimuthalDomainId) const {
168 return m_azimuthalWindowCells[azimuthalDomainId].size();
169 }
170 const MInt& azimuthalWindowCell(const MInt azimuthalDomainId, const MInt id) const {
171 return m_azimuthalWindowCells[azimuthalDomainId][id];
172 }
173 const std::vector<std::vector<MInt>>& azimuthalWindowCells() const { return m_azimuthalWindowCells; };
174
175 // Halo cells
176 MInt noAzimuthalHaloCells(const MInt azimuthalDomainId) const {
177 return m_azimuthalHaloCells[azimuthalDomainId].size();
178 }
179 const MInt& azimuthalHaloCell(const MInt azimuthalDomainId, const MInt id) const {
180 return m_azimuthalHaloCells[azimuthalDomainId][id];
181 }
182 const std::vector<std::vector<MInt>>& azimuthalHaloCells() const { return m_azimuthalHaloCells; };
183
187
188 MInt noDomains() const { return m_noDomains; }
189 MInt domainId() const { return m_domainId; }
190 MPI_Comm mpiComm() const { return m_mpiComm; }
191
192 const MLong& domainOffset(const MInt id) const { return m_domainOffsets[id]; }
193 MInt maxLevel() const { return m_maxLevel; }
194
195 // Methods that are just pass-through to the original grid
199 MFloat lengthLevel0() const { return raw().lengthLevel0(); }
200 MInt minLevel() const { return raw().minLevel(); }
201 MInt newMinLevel() const { return raw().m_newMinLevel; }
202 MInt centerOfGravity(MInt dir) const { return raw().centerOfGravity(dir); }
204 MFloat cellLengthAtLevel(const MInt level) const { return raw().cellLengthAtLevel(level); }
205 MFloat cellLengthAtCell(const MInt cellId) const { return raw().cellLengthAtCell(m_tree.solver2grid(cellId)); }
206 MFloat halfCellLength(const MInt cellId) const { return raw().halfCellLength(m_tree.solver2grid(cellId)); }
207 MFloat cellVolumeAtLevel(const MInt level) const { return raw().cellVolumeAtLevel(level); }
208 constexpr MBool hasCutOff() const { return raw().hasCutOff(); }
209
210 static constexpr MInt m_maxNoChilds = IPOW2(nDim);
211 MLong bitOffset() const { return raw().bitOffset(); }
213 MLong noCellsGlobal() const { return raw().noCellsGlobal(); }
214 MInt minCell(const MInt id) const {
215 if(raw().minCell(id) > -1 && solverFlag(raw().minCell(id), solverId())) {
216 return m_tree.grid2solver(raw().minCell(id));
217 }
218 return -1;
219 }
220 // NOTE: The number of min-cells is the same in the solver and the grid.
221 // But the ids might have changed during adaptation/balance!
222 MInt noMinCells() const { return raw().noMinCells(); }
223 MBool isPeriodic(const MInt cellId) {
224 const MInt gridCellId = tree().solver2grid(cellId);
225 return raw().treeb().hasProperty(gridCellId, Cell::IsPeriodic);
226 }
227 MInt periodicCartesianDir(const MInt dir) const { return raw().periodicCartesianDir(dir); }
229 MInt maxNoCells() const { return m_maxNoCells; }
230 MFloat gridCellVolume(const MInt level) const { return raw().gridCellVolume(level); }
236 void rotateCartesianCoordinates(MFloat* coords, MFloat angle) { raw().rotateCartesianCoordinates(coords, angle); }
237 MInt neighborList(const MInt cellId, const MInt dir) const { return m_neighborList[cellId][dir]; }
238 MInt& neighborList(const MInt cellId, const MInt dir) { return m_neighborList[cellId][dir]; }
239 MLong localPartitionCellOffsets(const MInt index) const { return raw().localPartitionCellOffsets(index); }
241
244 }
246 // NOTE: solver based globalId
248 }
249
250 // restart-file versions
252 /*if(!raw().updatedPartitionCells() && !hasInactiveRanks()) {
253 return raw().m_localPartitionCellOffsetsRestart[index];
254 } else if (!hasInactiveRanks()) {
255 return localPartitionCellOffsets(index);
256 } else {*/
257 return m_localPartitionCellOffsets[index];
258 //}
259 }
261 /*if(!raw().updatedPartitionCells() && !hasInactiveRanks()) {
262 return m_tree.grid2solver(raw().m_localPartitionCellLocalIdsRestart[id]) > -1 ?
263 m_tree.globalId(m_tree.grid2solver(raw().m_localPartitionCellLocalIdsRestart[id])): -1;
264 } else if (!hasInactiveRanks()) {
265 return localPartitionCellGlobalIds(id);
266 } else {*/
268 //}
269 }
270
271 MBool isPeriodic(const MInt cellId) const {
272 return raw().a_hasProperty(m_tree.solver2grid(cellId), Cell::IsPeriodic);
273 }
274 MBool solverFlag(const MInt gridId, const MInt solverId) const { return raw().treeb().solver(gridId, solverId); }
275
276 MLong generateHilbertIndex(const MInt cellId, const MInt refLevel = -1) {
277 const MInt level = refLevel > -1 ? refLevel : minLevel();
278 return raw().generateHilbertIndex(m_tree.solver2grid(cellId), level);
279 }
280
282 if(!g_multiSolverGrid && noDomains() > 1) {
283 ASSERT(m_neighborDomainIndex[id] == raw().m_nghbrDomainIndex[id], "");
284 }
286 }
288
289 MInt a_storeNghbrIds(const MInt id) const { return m_storeNghbrIds[id]; }
290 MInt a_identNghbrIds(const MInt id) const { return m_identNghbrIds[id]; }
291 MInt a_neighborList(const MInt cellId, const MInt dir) const { return m_neighborList[cellId][dir]; }
292
293 MBool checkNghbrIds() { return m_storeNghbrIds != nullptr && m_identNghbrIds != nullptr; }
294
295 // constexpr MInt noHaloLayers() const { return raw().noHaloLayers(); }
296 constexpr MInt noHaloLayers() const { return raw().noHaloLayers(solverId()); }
297
298 // Methods modifying the tree proxy directly (use with care!)
299 void setSolver2grid(const MInt solverId, const MInt treeId) { m_tree.setSolver2grid(solverId, treeId); }
300 void setGrid2solver(const MInt treeId, const MInt solverId) { m_tree.setGrid2solver(treeId, solverId); }
301 void swapSolverIds(const MInt id0, const MInt id1) { m_tree.swapSolverIds(id0, id1); }
302 void swapGridIds(const MInt id0, const MInt id1) { m_tree.swapGridIds(id0, id1); }
303
304
311 template <typename U>
313 if(noNeighborDomains() > 0) {
315 }
316 }
317 void exchangeHaloCellsForVisualizationDG(MFloat* data, const MInt* const polyDegs, const MInt* const dataOffsets);
318 void exchangeHaloCellsForVisualizationSBP(MFloat* data, const MInt* const noNodes1D, const MInt* const dataOffsets);
319
320 // Check wether cell is located outside geometry
321 // Necessary for azimuthal periodicity to check if azimuthal halo cell is requiered
323
324 private:
325 // Data
327 const MInt m_solverId = -1;
328
329 static constexpr const MInt m_noDirs = 2 * nDim;
330
333
336
339
340 // Parallelization-related data
342 MPI_Comm m_mpiComm = MPI_COMM_NULL;
347 std::vector<MLong> m_domainOffsets;
348
349 // Neighbor/window/halo data
350 std::vector<MInt> m_neighborDomains;
351 std::vector<MInt> m_neighborDomainIndex;
352 std::vector<std::vector<MInt>> m_windowCells;
353 std::vector<std::vector<MInt>> m_haloCells;
354 std::vector<MInt> m_leafSendNeighborDomains;
355 std::vector<MInt> m_leafRecvNeighborDomains;
356 std::vector<std::vector<MInt>> m_leafWindowCells;
357 std::vector<std::vector<MInt>> m_leafHaloCells;
360 std::map<MInt, MInt> m_global2solver;
361
362 // Azimuthal periodicity window/halo data
363 std::vector<MInt> m_azimuthalNeighborDomains;
365 std::vector<std::vector<MInt>> m_azimuthalWindowCells;
366 std::vector<std::vector<MInt>> m_azimuthalHaloCells;
369 std::vector<MInt> m_isOutsideHalo;
370 std::vector<MInt> m_isOutsideWindow;
371
372 // Other grid information
376
377 // Holds the reverse-direction-Information
378 const MInt m_revDir[6] = {1, 0, 3, 2, 5, 4};
379
383
385 MLong m_localPartitionCellOffsets[3] = {static_cast<MLong>(-1), static_cast<MLong>(-1), static_cast<MLong>(-1)};
386};
387
388
389namespace tree {
390
395template <MInt nDim>
397 // Friends & family
398 // Grid proxy must be declared as template friend as otherwise classes deriving from this tree
399 // proxy do not work
400 template <MInt nDim_>
401 friend class maia::grid::Proxy;
402
403 public:
404 // Types
407
409 TreeProxy(const MInt solverId_, Tree& tree_) : m_tree(tree_), m_solverId(solverId_) {
410 m_solver2grid.reserve(m_tree.capacity());
411 m_grid2solver.reserve(m_tree.capacity());
412 m_globalIds.reserve(m_tree.capacity());
413 m_isCutOffCell.reserve(m_tree.capacity());
414 }
415
417 MInt solver2grid(const MInt id) const {
418 // TODO labels:GRID c++14
419 //#ifndef NDEBUG
420 // ASSERT(id >= 0 && id < m_solver2grid.size(), "id in solver2grid is out of bounds");
421 //#endif
422 return m_solver2grid[id];
423 }
425 MInt grid2solver(const MInt id) const {
426 // TODO labels:GRID c++14
427 //#ifndef NDEBUG
428 // ASSERT(id+1 >= 0 && id+1 < m_grid2solver.size(), "id in grid2solver is out of bounds");
429 //#endif
430 return m_grid2solver[id + 1];
431 }
432
433 void setSolver2grid(const MInt solverId, const MInt treeId) {
434 ASSERT(solverId > -1 && solverId < (signed)m_solver2grid.size(),
435 "id, size: " << solverId << " " << m_solver2grid.size());
436 m_solver2grid[solverId] = treeId;
437 }
438 void setGrid2solver(const MInt treeId, const MInt solverId) {
439 ASSERT((treeId + 1) > -1 && (treeId + 1) < (signed)m_grid2solver.size(),
440 "id size: " << treeId + 1 << " " << m_grid2solver.size());
441 m_grid2solver[treeId + 1] = solverId;
442 }
443
444 void swapSolverIds(const MInt id0, const MInt id1) {
445 ASSERT(id0 > -1 && id1 > -1 && id0 < size() && id1 < size(),
446 "id0, id1, size: " << id0 << " , " << id1 << " , " << size());
447 const MInt g0 = m_solver2grid[id0];
448 const MInt g1 = m_solver2grid[id1];
449 if(g0 > -1) m_grid2solver[g0 + 1] = id1;
450 if(g1 > -1) m_grid2solver[g1 + 1] = id0;
451 std::swap(m_solver2grid[id0], m_solver2grid[id1]);
452 }
453
454 void swapGridIds(const MInt id0, const MInt id1) {
455 ASSERT(id0 > -1 && id1 > -1 && id0 < m_tree.size() && id1 < m_tree.size()
456 && (id0 + 1) < (signed)m_grid2solver.size() && (id1 + 1) < (signed)m_grid2solver.size(),
457 "");
458 const MInt b0 = m_grid2solver[id0 + 1];
459 const MInt b1 = m_grid2solver[id1 + 1];
460 if(b0 > -1) m_solver2grid[b0] = id1;
461 if(b1 > -1) m_solver2grid[b1] = id0;
462 std::swap(m_grid2solver[id0 + 1], m_grid2solver[id1 + 1]);
463 }
464
466 MInt size() const { return m_solver2grid.size(); }
467
468 // Parent-child relationship
469 MInt parent(const MInt id) const;
470 MBool hasParent(const MInt id) const;
471 MInt child(const MInt id, const MInt pos) const;
472 MBool hasChild(const MInt id, const MInt pos) const;
473 MBool hasChildren(const MInt id) const;
474 MInt noChildren(const MInt id) const;
475 MBool isLeafCell(const MInt id) const;
476
477 // Neighbors
478 MInt neighbor(const MInt id, const MInt dir) const;
479 MBool hasNeighbor(const MInt id, const MInt dir) const;
480 MBool hasAnyNeighbor(const MInt id, const MInt dir) const;
481
482 // // Other data fields
483 MLong globalId(const MInt id) const;
484 MInt localId(const MLong id) const;
485 MInt cutOff(const MInt id) const;
486 MInt level(const MInt id) const;
487 const MFloat& coordinate(const MInt id, const MInt dir) const;
488 // MFloat& weight(const MInt id);
489 MFloat weight(const MInt id) const;
490 MBool hasProperty(const MInt id, const Cell p) const;
491 // MUlong propertiesToBits(const MInt id) const;
492 // MString propertiesToString(const MInt id) const;
493 // auto properties(const MInt id) -> decltype(tree().properties(solver2grid(id))) & ;
494
495 // // Other data fields (subject to change)
496 // MInt& noOffsprings(const MInt id);
497 // MInt noOffsprings(const MInt id) const;
498 // MFloat& workload(const MInt id);
499 // MFloat workload(const MInt id) const;
500
501 // Entries per tree node
503 static constexpr MInt noChildrenPerNode() { return 4 * nDim - 4; }
505 static constexpr MInt noNeighborsPerNode() { return 2 * nDim; }
506
508 static constexpr MInt oppositeNeighborDir(const MInt dir) { return dir + 1 - 2 * (dir % 2); }
509
511 static constexpr MInt noProperties() { return maia::grid::cell::p(Cell::NumProperties); }
512
513 private:
515 MInt solverId() const { return m_solverId; }
516
518 void update(const Proxy<nDim>& NotUsed(gridProxy_)) {}
519
522
523 // Data
526
528 const MInt m_solverId = -1;
529
530 // Grid cell <-> solver cell mappings
531 std::vector<MInt> m_solver2grid;
532 std::vector<MInt> m_grid2solver;
533 std::vector<MLong> m_globalIds;
534 std::map<MLong, MInt> m_globalToLocalId{};
535 std::vector<MInt> m_isCutOffCell;
536};
537
538
540template <MInt nDim>
542 return grid2solver(m_tree.parent(solver2grid(id)));
543}
544
545
547template <MInt nDim>
549 return parent(id) > -1;
550}
551
552
554template <MInt nDim>
555MInt TreeProxy<nDim>::child(const MInt id, const MInt pos) const {
556 return grid2solver(m_tree.child(solver2grid(id), pos));
557}
558
559
561template <MInt nDim>
562MBool TreeProxy<nDim>::hasChild(const MInt id, const MInt pos) const {
563 return child(id, pos) > -1;
564}
565
566
568template <MInt nDim>
570 return noChildren(id) > 0;
571}
572
573
575template <MInt nDim>
577 MInt count = 0;
578 for(MInt pos = 0; pos < noChildrenPerNode(); pos++) {
579 count += hasChild(id, pos);
580 }
581 return count;
582}
583
585template <MInt nDim>
587 return m_tree.isLeafCell(solver2grid(id), solverId());
588}
589
590
592template <MInt nDim>
593MInt TreeProxy<nDim>::neighbor(const MInt id, const MInt dir) const {
594 return grid2solver(m_tree.neighbor(solver2grid(id), dir));
595}
596
597
599template <MInt nDim>
600MBool TreeProxy<nDim>::hasNeighbor(const MInt id, const MInt dir) const {
601 return neighbor(id, dir) > -1;
602}
604template <MInt nDim>
605MBool TreeProxy<nDim>::hasAnyNeighbor(const MInt id, const MInt dir) const {
606 return hasNeighbor(id, dir) || (hasParent(id) && hasNeighbor(parent(id), dir));
607}
608
609
611template <MInt nDim>
613 return m_globalIds[id];
614}
615
617template <MInt nDim>
619 return m_isCutOffCell[id];
620}
621
623template <MInt nDim>
625 return m_tree.level(solver2grid(id));
626}
627
628
630template <MInt nDim>
631const MFloat& TreeProxy<nDim>::coordinate(const MInt id, const MInt dir) const {
632 return m_tree.coordinate(solver2grid(id), dir);
633}
634
635
636// /// Accessor for weight.
637// template <MInt nDim> MFloat& TreeProxy<nDim>::weight(const MInt id) {
638// return m_tree.weight(solver2grid(id));
639// }
641template <MInt nDim>
643 return m_tree.weight(solver2grid(id));
644}
645//
646//
647// /// Accessor for noOffsprings.
648// template <MInt nDim> MInt& TreeProxy<nDim>::noOffsprings(const MInt id) {
649// return m_tree.noOffsprings(solver2grid(id));
650// }
651// /// Accessor for noOffsprings (const version).
652// template <MInt nDim> MInt TreeProxy<nDim>::noOffsprings(const MInt id) const {
653// return m_tree.noOffsprings(solver2grid(id));
654// }
655//
656//
657// /// Accessor for workload.
658// template <MInt nDim> MFloat& TreeProxy<nDim>::workload(const MInt id) {
659// return m_tree.workload(solver2grid(id));
660// }
661// /// Accessor for workload (const version).
662// template <MInt nDim> MFloat TreeProxy<nDim>::workload(const MInt id) const {
663// return m_tree.workload(solver2grid(id));
664// }
665
666
668template <MInt nDim>
669MBool TreeProxy<nDim>::hasProperty(const MInt id, const Cell p) const {
670 ASSERT(p != Cell::IsWindow, "Query for IsWindow won't give solver-specific information!");
671 return m_tree.hasProperty(solver2grid(id), p);
672}
673
674// /// Convert properties to string.
675// template <MInt nDim> MString TreeProxy<nDim>::propertiesToString(const MInt id) const {
676// return m_tree.propertiesToString(solver2grid(id));
677// }
678// /// Accessor for properties.
679// template <MInt nDim>
680// auto TreeProxy<nDim>::properties(const MInt id) ->
681// decltype(m_tree.properties(solver2grid(id))) & {
682// return m_tree.properties(solver2grid(id));
683// }
684
686template <MInt nDim>
688 TRACE();
689
690 std::map<MLong, MInt>().swap(m_globalToLocalId);
691 std::set<MInt> periodicCells;
692 for(MInt cellId = 0; cellId < size(); cellId++) {
693 if(hasProperty(cellId, Cell::IsPeriodic)) {
694 periodicCells.insert(cellId);
695 continue;
696 }
697 ASSERT(m_globalToLocalId.count(globalId(cellId)) == 0, "Global id already in map");
698 m_globalToLocalId[globalId(cellId)] = cellId;
699 }
700
701 for(auto it = periodicCells.begin(); it != periodicCells.end(); it++) {
702 if(m_globalToLocalId.count(globalId(*it)) == 0) {
703 m_globalToLocalId[globalId(*it)] = *it;
704 }
705 }
706}
707
709template <MInt nDim>
711 TRACE();
712
713 if(m_globalToLocalId.count(id) > 0) {
714 return m_globalToLocalId.at(id);
715 } else {
716 return -1;
717 }
718}
719
720} // namespace tree
721
722} // namespace grid
723} // namespace maia
724
725#endif // ifndef GRIDPROXY_H_
GridCell
Grid cell Property Labels.
MFloat gridCellVolume(const MInt level) const
MFloat cellVolumeAtLevel(const MInt level) const
MInt maxUniformRefinementLevel() const
Return maximum homogeneously-refined level.
void rotateCartesianCoordinates(MFloat *, MFloat)
Rotate caresian coordinates by angle. Azimuthal periodic center is used.
MInt periodicCartesianDir(const MInt dir) const
MString gridInputFileName() const
Return grid file name.
maia::grid::cell::BitsetType::reference a_hasProperty(const MInt cellId, const Cell p)
Returns property p of the cell cellId.
MLong generateHilbertIndex(const MInt cellId, const MInt targetMinLevel)
void centerOfGravity(MFloat *const center) const
MInt noMinCells() const
Return the number of Cells on the minLevel.
MLong noCellsGlobal() const
Return the Global-noCells.
MFloat m_azimuthalAngle
MInt noHaloLayers() const
Return noHalo-a_noHaloLayers.
MBool hasCutOff() const
Returns weather the grid has a cutOff.
Definition: cartesiangrid.h:83
MLong localPartitionCellOffsets(const MInt index) const
MInt m_newMinLevel
The new min Level which has been increased at the restart!
MLong bitOffset() const
Return the 32-BitOffset.
MFloat halfCellLength(const MInt cellId) const
Returns the half cell length of cell cellId.
MInt minLevel() const
MFloat cellLengthAtCell(const MInt cellId) const
Returns the cell length of cell cellId.
MBool wasBalanced() const
MFloat lengthLevel0() const
Return the length of the level 0 cell.
Tree & treeb()
Full access to tree (for now)
azimuthalBbox m_azimuthalBbox
MFloat periodicCartesianLength(const MInt dir) 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 m_azimuthalPer
std::array< MInt, 2 > m_azimuthalPeriodicDir
MFloat cellLengthAtLevel(const MInt level) const
Returns cell length at cell level level.
constexpr MBool allowInterfaceRefinement() const
MBool wasAdapted() const
MFloat reductionFactor() const
Return the reductionFactor.
This class is a ScratchSpace.
Definition: scratch.h:758
constexpr MInt size() const
Return size (i.e., currently used number of nodes)
Definition: container.h:89
const MInt & leafHaloCell(const MInt domainId, const MInt id) const
void getLocalSameLevelCellIds(std::vector< MInt > &levelCellId, const MInt level)
find all cells on the same level used by the smoothFilter!
MInt domainContainingCell(MInt globalId) const
domain id containing a given global cell id
MBool allowInterfaceRefinement() const
const std::vector< std::vector< MInt > > & windowCells() const
std::vector< MInt > m_leafSendNeighborDomains
MInt leafRecvNeighborDomain(const MInt id) const
void setGrid2solver(const MInt treeId, const MInt solverId)
void swapGridIds(const MInt id0, const MInt id1)
MInt determineAzimuthalBoundarySide(const MFloat *coords)
MLong generateHilbertIndex(const MInt cellId, const MInt refLevel=-1)
MFloat cellVolumeAtLevel(const MInt level) const
MInt noAzimuthalUnmappedHaloCells() const
void checkWindowHaloConsistency() const
std::vector< MInt > m_azimuthalNeighborDomainIndex
const std::vector< std::vector< MInt > > & leafWindowCells() const
MInt noAzimuthalWindowCells(const MInt azimuthalDomainId) const
MFloat cellLengthAtCell(const MInt cellId) const
std::map< MInt, MInt > m_global2solver
MLong bitOffset() const
static constexpr const MInt m_noDirs
MInt findContainingLeafCell(const MFloat *coord)
std::vector< MInt > m_azimuthalNeighborDomains
MBool isPeriodic(const MInt cellId) const
MPI_Comm mpiComm() const
MInt solverId() const
Return solver id.
MInt leafRecSize() const
MInt maxUniformRefinementLevel() const
MBool hasInactiveRanks() const
Return whether this solver is inactive on one of the global domains.
void updatePartitionCellOffsets()
updates solver-grid partition cell offsets and globalIds!
const MInt & azimuthalUnmappedHaloCell(const MInt id) const
void setupWindowHaloConnectivityOnLeafLvl(std::map< MInt, MInt > &)
void setSolver2grid(const MInt solverId, const MInt treeId)
MInt noLeafHaloCells(const MInt domainId) const
MFloat lengthLevel0() const
std::vector< std::vector< MInt > > m_windowCells
void findEqualLevelNeighborsParDiagonal(MBool idsAreGlobal=true)
std::vector< MInt > m_azimuthalUnmappedHaloDomains
const MInt & azimuthalUnmappedHaloDomain(const MInt id) const
MLong m_localPartitionCellOffsets[3]
MInt getNghbrCells(MInt cellId, MInt level, MInt *nghbrs, MInt dir0, MInt dir1=-1, MInt dir2=-1)
const MInt m_revDir[6]
void descendStoreGlobalId(MInt cellId, MInt &localCnt)
MInt noAzimuthalHaloCells(const MInt azimuthalDomainId) const
MInt globalToLocalId(const MLong globalId) const
const std::vector< MInt > & neighborDomains() const
MInt noLeafSendNeighborDomains() const
std::vector< std::vector< MInt > > m_haloCells
MFloat halfCellLength(const MInt cellId) const
void checkNeighborConsistency() const
MInt noWindowCells(const MInt domainId) const
MLong localPartitionCellOffsetsRestart(const MInt index) const
MInt azimuthalDomainIndex(const MInt id)
MInt minCell(const MInt id) const
void exchangeHaloCellsForVisualizationDG(MFloat *data, const MInt *const polyDegs, const MInt *const dataOffsets)
Exchange DG halo/window cell data for visualization with ParaView.
MInt centerOfGravity(MInt dir) const
void exchangeHaloCellsForVisualizationSBP(MFloat *data, const MInt *const noNodes1D, const MInt *const dataOffsets)
Exchange DG-SBP halo/window cell data for visualization with ParaView.
MInt getAdjacentGridCells(MInt cellId, MInt noLayers, MIntScratchSpace &adjacentCells, MInt level, MInt diagonalNeighbors=0)
Retrieves all direct and diagonal neighboring cells of the given cell on the child level if available...
std::vector< MInt > m_neighborDomainIndex
MInt neighborDomain(const MInt id) const
std::vector< MInt > m_isOutsideWindow
MBool wasAdapted() const
const MLong & domainOffset(const MInt id) const
MInt maxRefinementLevel() const
MString gridInputFileName() const
MInt leafSendNeighborDomain(const MInt id) const
Grid & m_grid
Reference to actual grid.
MInt & neighborList(const MInt cellId, const MInt dir)
MFloat cellLengthAtLevel(const MInt level) const
constexpr MInt noHaloLayers() const
constexpr MBool hasCutOff() const
const MInt & leafWindowCell(const MInt domainId, const MInt id) const
void resizeGridMap(const MInt solverSize)
std::vector< MInt > m_isOutsideHalo
MInt noHaloCells(const MInt domainId) const
void rotateCartesianCoordinates(MFloat *coords, MFloat angle)
MInt noAzimuthalNeighborDomains() const
void exchangeHaloCellsForVisualization(U *data)
Exchange Halo/Window data in a general way for ParaView or other external visuliazation software.
MInt neighborList(const MInt cellId, const MInt dir) const
void setSolverFlagsForAddedSolver()
Set solver flags for newly added solver.
std::vector< MInt > m_neighborDomains
MBool azimuthalPeriodicity() const
MInt periodicCartesianDir(const MInt dir) const
MLong noCellsGlobal() const
const MInt & windowCell(const MInt domainId, const MInt id) const
MInt findNeighborDomainId(const MLong globalId)
Find neighbor domain id corresponding to given solver-specific globalId.
MBool checkOutsideGeometry(MInt gridId)
MInt a_neighborList(const MInt cellId, const MInt dir) const
void smoothFilter(const MInt level, MFloat **value)
smooth the grid-based values over neighboring leaf cell asure conservation of the total value
std::vector< std::vector< MInt > > m_leafWindowCells
std::vector< MInt > m_leafRecvNeighborDomains
static constexpr MInt m_maxNoChilds
TreeProxy m_tree
Tree proxy object.
MInt a_storeNghbrIds(const MInt id) const
std::vector< std::vector< MInt > > m_azimuthalWindowCells
MInt localPartitionCellLocalIds(const MInt id) const
void checkWindowHaloConsistencyAzimuthal() const
MInt a_identNghbrIds(const MInt id) const
MFloat gridCellVolume(const MInt level) const
std::vector< std::vector< MInt > > m_leafHaloCells
MInt findContainingLeafCell(const MFloat *coord, const MInt startId, const MBool allowNonLeafHalo=false)
void findNeighborHood(const MInt, const MInt, std::vector< MInt > &)
Obtain list of neighbors for the given extend, using m_storeNghbrIds and m_identNghbrIds.
std::vector< MInt > m_azimuthalUnmappedHaloCells
MBool isActive() const
Return whether the solver is active on the current domain.
MLong localPartitionCellGlobalIdsRestart(const MInt id) const
const MInt & azimuthalWindowCell(const MInt azimuthalDomainId, const MInt id) const
MLong localPartitionCellGlobalIds(const MInt id) const
const MInt & azimuthalHaloCell(const MInt azimuthalDomainId, const MInt id) const
std::vector< std::vector< MInt > > m_azimuthalHaloCells
Geom * m_geometry
Reference to solver geometry.
MInt noLeafWindowCells(const MInt domainId) const
MBool solverFlag(const MInt gridId, const MInt solverId) const
void checkOffsetConsistency() const
MInt azimuthalDir(MInt dir)
MFloat reductionFactor() const
void getAllLeafChilds(const MInt, std::vector< MInt > &)
gathers all leaf child cells for a given parentId
MInt noInternalCells() const
void checkNeighborConsistencyAzimuthal() const
std::vector< MLong > m_domainOffsets
const TreeProxy & tree() const
MInt leafSendSize() const
MBool isPeriodic(const MInt cellId)
MInt noNeighborDomains() const
void findDirectNghbrs(const MInt, std::vector< MInt > &)
Obtain list of direct neighbors of given cell. Requires m_identNghbrIds, as such findCartesianNghbIds...
const std::vector< MInt > & azimuthalNeighborDomains() const
const std::vector< std::vector< MInt > > & leafHaloCells() const
const Grid & raw() const
const std::vector< std::vector< MInt > > & azimuthalWindowCells() const
MInt newMinLevel() const
const std::vector< std::vector< MInt > > & haloCells() const
const MInt & haloCell(const MInt domainId, const MInt id) const
const std::vector< std::vector< MInt > > & azimuthalHaloCells() const
const MInt m_solverId
Solver id.
void swapSolverIds(const MInt id0, const MInt id1)
MInt noLeafRecvNeighborDomains() const
MFloat periodicCartesianLength(const MInt dir) const
MLong localPartitionCellOffsets(const MInt index) const
MInt azimuthalNeighborDomain(const MInt azimuthalId) const
MBool wasBalanced() const
MInt domainIndex(const MInt id)
Class that represents grid tree and contains all relevant per-node data.
SolverBitsetType::reference solver(const MInt id, const MInt solverId)
Accessor for solver usage.
PropertyBitsetType::reference hasProperty(const MInt id, const Cell p)
Accessor for properties.
MInt noChildren(const MInt id) const
Return number of children of given node.
MBool hasParent(const MInt id) const
Return whether node has parent.
MInt neighbor(const MInt id, const MInt dir) const
Accessor for neighbor node.
TreeProxy(const MInt solverId_, Tree &tree_)
Constructor does nothing but pass arguments to members.
MBool hasAnyNeighbor(const MInt id, const MInt dir) const
Return whether node or its parent has neighbor in given direction.
MInt solver2grid(const MInt id) const
Convert solver cell id to grid cell id.
MLong globalId(const MInt id) const
Accessor for global id.
MBool isLeafCell(const MInt id) const
Accessor for isLeafCell.
std::vector< MInt > m_solver2grid
std::vector< MInt > m_isCutOffCell
const MFloat & coordinate(const MInt id, const MInt dir) const
Accessor for coordinates.
MBool hasNeighbor(const MInt id, const MInt dir) const
Return whether node has same-level neighbor in given direction.
MBool hasChildren(const MInt id) const
Return whether node has any children.
Tree & m_tree
Reference to actual grid tree.
void createGlobalToLocalIdMapping()
Create global to local id mapping.
void swapGridIds(const MInt id0, const MInt id1)
MInt size() const
Return tree size (= number of cells)
MInt parent(const MInt id) const
Accessor for parent node.
const MInt m_solverId
Solver id.
MBool hasChild(const MInt id, const MInt pos) const
Return whether node has child at given position.
void setGrid2solver(const MInt treeId, const MInt solverId)
MInt cutOff(const MInt id) const
Accessor for cutOff dir.
void setSolver2grid(const MInt solverId, const MInt treeId)
std::vector< MInt > m_grid2solver
MInt localId(const MLong id) const
Accesor for local id.
MBool hasProperty(const MInt id, const Cell p) const
Accessor for properties.
MFloat weight(const MInt id) const
Accessor for weight (const version).
MInt level(const MInt id) const
Accessor for level.
void update(const Proxy< nDim > &NotUsed(gridProxy_))
Default implementation does nothing as everything relevant is set by grid proxy class.
MInt solverId() const
Return solver id.
static constexpr MInt noNeighborsPerNode()
Return maximum number of same-level neighbors per node.
MInt child(const MInt id, const MInt pos) const
Accessor for child node.
std::map< MLong, MInt > m_globalToLocalId
static constexpr MInt oppositeNeighborDir(const MInt dir)
Return opposite direction for given neighbor direction.
static constexpr MInt noChildrenPerNode()
Return maximum number of children per node.
void swapSolverIds(const MInt id0, const MInt id1)
static constexpr MInt noProperties()
Return number of properties defined for each node.
std::vector< MLong > m_globalIds
MInt grid2solver(const MInt id) const
Convert grid cell id to solver cell id (+1 in size is to map "-1" to "-1")
MBool g_multiSolverGrid
constexpr MLong IPOW2(MInt x)
int32_t MInt
Definition: maiatypes.h:62
std::basic_string< char > MString
Definition: maiatypes.h:55
double MFloat
Definition: maiatypes.h:52
int64_t MLong
Definition: maiatypes.h:64
bool MBool
Definition: maiatypes.h:58
MInt id
Definition: maiatypes.h:71
constexpr std::underlying_type< GridCell >::type p(const GridCell property)
Converts property name to underlying integer value.
GridCell Cell
Underlying enum type for property access.
void exchangeData(const MInt noNghbrDomains, const MInt *const nghbrDomains, const MInt *const noHaloCells, const MInt **const, const MInt *const noWindowCells, const MInt **const windowCells, const MPI_Comm comm, const U *const data, U *const haloBuffer, const MInt noDat=1)
Generic exchange of data.
Definition: mpiexchange.h:295
Namespace for auxiliary functions/classes.