Skip to content

Commit

Permalink
Merge pull request #1053 from parthenon-hpc-lab/lroberts36/fix-root-l…
Browse files Browse the repository at this point in the history
…evel

Set the correct root level on restart
  • Loading branch information
lroberts36 authored Apr 17, 2024
2 parents 91d2cdb + 46239a8 commit b2fb321
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [[PR 1004]](https://github.com/parthenon-hpc-lab/parthenon/pull/1004) Allow parameter modification from an input file for restarts

### Fixed (not changing behavior/API/variables/...)
- [[PR 1053]](https://github.com/parthenon-hpc-lab/parthenon/pull/1053) Set the correct root level on restart
- [[PR 1024]](https://github.com/parthenon-hpc-lab/parthenon/pull/1024) Add features to history output
- [[PR 1031]](https://github.com/parthenon-hpc-lab/parthenon/pull/1031) Fix bug in non-cell centered AMR

Expand Down
38 changes: 32 additions & 6 deletions src/mesh/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,10 @@ Mesh::Mesh(ParameterInput *pin, ApplicationInput *app_in, RestartReader &rr,
// Load balancing flag and parameters
RegisterLoadBalancing_(pin);

// Initialize the forest
forest = forest::Forest::HyperRectangular(mesh_size, block_size, mesh_bcs);
root_level = forest.root_level;

// SMR / AMR
if (adaptive) {
// read from file or from input? input for now.
Expand All @@ -584,27 +588,29 @@ Mesh::Mesh(ParameterInput *pin, ApplicationInput *app_in, RestartReader &rr,

InitUserMeshData(this, pin);

// Populate logical locations
// Populate legacy logical locations
auto lx123 = mesh_info.lx123;
auto locLevelGidLidCnghostGflag = mesh_info.level_gid_lid_cnghost_gflag;
current_level = -1;
for (int i = 0; i < nbtotal; i++) {
loclist[i] = LogicalLocation(locLevelGidLidCnghostGflag[5 * i], lx123[3 * i],
lx123[3 * i + 1], lx123[3 * i + 2]);

if (loclist[i].level() > current_level) {
current_level = loclist[i].level();
}
}

// rebuild the Block Tree
forest = forest::Forest::HyperRectangular(mesh_size, block_size, mesh_bcs);

for (int i = 0; i < nbtotal; i++) {
forest.AddMeshBlock(forest.GetForestLocationFromLegacyTreeLocation(loclist[i]),
false);
}

// Update the location list and levels to agree with forest levels
loclist = forest.GetMeshBlockListAndResolveGids();

current_level = std::numeric_limits<int>::min();
for (const auto &loc : loclist)
current_level = std::max(current_level, loc.level());

int nnb = loclist.size();
if (nnb != nbtotal) {
msg << "### FATAL ERROR in Mesh constructor" << std::endl
Expand Down Expand Up @@ -1341,4 +1347,24 @@ void Mesh::SetupMPIComms() {
#endif
}

// Return list of locations and levels for the legacy tree
// TODO(LFR): It doesn't make sense to offset the level by the
// legacy tree root level since the location indices are defined
// for loc.level(). It seems this level offset is required for
// the output to agree with the legacy output though.
std::pair<std::vector<std::int64_t>, std::vector<std::int64_t>>
Mesh::GetLevelsAndLogicalLocationsFlat() const noexcept {
std::vector<std::int64_t> levels, logicalLocations;
levels.reserve(nbtotal);
logicalLocations.reserve(nbtotal * 3);
for (auto loc : loclist) {
loc = forest.GetLegacyTreeLocation(loc);
levels.push_back(loc.level() - GetLegacyTreeRootLevel());
logicalLocations.push_back(loc.lx1());
logicalLocations.push_back(loc.lx2());
logicalLocations.push_back(loc.lx3());
}
return std::make_pair(levels, logicalLocations);
}

} // namespace parthenon
16 changes: 2 additions & 14 deletions src/mesh/mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,20 +205,8 @@ class Mesh {
std::vector<int> GetNbList() const noexcept { return nblist; }
std::vector<LogicalLocation> GetLocList() const noexcept { return loclist; }

// TODO(JMM): Put in implementation file?
auto GetLevelsAndLogicalLocationsFlat() const noexcept {
std::vector<std::int64_t> levels, logicalLocations;
levels.reserve(nbtotal);
logicalLocations.reserve(nbtotal * 3);
for (auto loc : loclist) {
loc = forest.GetLegacyTreeLocation(loc);
levels.push_back(loc.level() - GetLegacyTreeRootLevel());
logicalLocations.push_back(loc.lx1());
logicalLocations.push_back(loc.lx2());
logicalLocations.push_back(loc.lx3());
}
return std::make_pair(levels, logicalLocations);
}
std::pair<std::vector<std::int64_t>, std::vector<std::int64_t>>
GetLevelsAndLogicalLocationsFlat() const noexcept;

void OutputMeshStructure(const int dim, const bool dump_mesh_structure = true);

Expand Down

0 comments on commit b2fb321

Please sign in to comment.