From 822adcf38181ee85a745b90dec39e194df508bf7 Mon Sep 17 00:00:00 2001 From: Ben Ryan Date: Fri, 6 Sep 2024 11:41:12 -0600 Subject: [PATCH] No testing for now --- src/interface/sparse_pack.hpp | 15 +++++++++++++++ src/interface/sparse_pack_base.cpp | 18 ++++++++++++++++++ src/interface/sparse_pack_base.hpp | 4 ++++ src/outputs/parthenon_xdmf.cpp | 1 - 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/interface/sparse_pack.hpp b/src/interface/sparse_pack.hpp index e939e3dc7004..123de3e6a705 100644 --- a/src/interface/sparse_pack.hpp +++ b/src/interface/sparse_pack.hpp @@ -189,6 +189,21 @@ class SparsePack : public SparsePackBase { return bounds_h_(1, b, vidx); } + KOKKOS_INLINE_FUNCTION int GetLevel(const int b, const int off3, const int off2, + const int off1) const { + return block_props_(b, 0, off3 - 1, off2 - 1, off1 - 1); + } + + KOKKOS_INLINE_FUNCTION int GetGID(const int b) const { + return block_props_(b, 1, 1, 1, 1); + } + + int GetLevelHost(const int b, const int off3, const int off2, const int off1) const { + return block_props_h_(b, 0, off3 - 1, off2 - 1, off1 - 1); + } + + int GetGIDHost(const int b) const { return block_props_h_(b, 1, 1, 1, 1); } + // Number of components of a variable on a block template KOKKOS_INLINE_FUNCTION int GetSize(const int b, const T &t) const { diff --git a/src/interface/sparse_pack_base.cpp b/src/interface/sparse_pack_base.cpp index d5a66db01498..1cdb3f03b805 100644 --- a/src/interface/sparse_pack_base.cpp +++ b/src/interface/sparse_pack_base.cpp @@ -165,6 +165,10 @@ SparsePackBase SparsePackBase::Build(T *pmd, const PackDescriptor &desc, pack.bounds_ = bounds_t("bounds", 2, nblocks, nvar + 1); pack.bounds_h_ = Kokkos::create_mirror_view(pack.bounds_); + // This array stores refinement levels of current block and all neighboring blocks. + pack.block_props_ = block_props_t("block_props", nblocks, 2, 3, 3, 3); + pack.block_props_h_ = Kokkos::create_mirror_view(pack.block_props_); + pack.coords_ = coords_t("coords", desc.flat ? max_size : nblocks); auto coords_h = Kokkos::create_mirror_view(pack.coords_); @@ -183,6 +187,19 @@ SparsePackBase SparsePackBase::Build(T *pmd, const PackDescriptor &desc, coords_h(b) = pmbd->GetBlockPointer()->coords_device; } + // This block's refinement level stored in central (0, 1,1,1) element of block + // properties + pack.block_props_h_(blidx, 0, 1, 1, 1) = pmbd->GetBlockPointer()->loc.level(); + // This block's gid stored in central (1, 1, 1, 1) element + pack.block_props_h_(blidx, 1, 1, 1, 1) = pmbd->GetBlockPointer()->gid; + for (auto &neighbor : pmbd->GetBlockPointer()->neighbors) { + // Multiple refined neighbors will write to the same index but they will always have + // the same refinement level. + pack.block_props_h_(blidx, 0, neighbor.offsets[2] + 1, neighbor.offsets[1] + 1, + neighbor.offsets[0] + 1) = neighbor.loc.level(); + // Currently not storing neighbor gids + } + for (int i = 0; i < nvar; ++i) { pack.bounds_h_(0, blidx, i) = idx; for (const auto &[var_name, uid] : desc.var_groups[i]) { @@ -281,6 +298,7 @@ SparsePackBase SparsePackBase::Build(T *pmd, const PackDescriptor &desc, }); Kokkos::deep_copy(pack.pack_, pack.pack_h_); Kokkos::deep_copy(pack.bounds_, pack.bounds_h_); + Kokkos::deep_copy(pack.block_props_, pack.block_props_h_); Kokkos::deep_copy(pack.coords_, coords_h); return pack; diff --git a/src/interface/sparse_pack_base.hpp b/src/interface/sparse_pack_base.hpp index 53fc4e37d0b1..05d3afe89b98 100644 --- a/src/interface/sparse_pack_base.hpp +++ b/src/interface/sparse_pack_base.hpp @@ -59,6 +59,8 @@ class SparsePackBase { using pack_h_t = typename pack_t::HostMirror; using bounds_t = ParArray3D; using bounds_h_t = typename bounds_t::HostMirror; + using block_props_t = ParArray5D; + using block_props_h_t = typename block_props_t::HostMirror; using coords_t = ParArray1D>; // Returns a SparsePackBase object that is either newly created or taken @@ -90,6 +92,8 @@ class SparsePackBase { pack_h_t pack_h_; bounds_t bounds_; bounds_h_t bounds_h_; + block_props_t block_props_; + block_props_h_t block_props_h_; coords_t coords_; int flx_idx_; diff --git a/src/outputs/parthenon_xdmf.cpp b/src/outputs/parthenon_xdmf.cpp index e9a596a7e28d..a5bdc34542b0 100644 --- a/src/outputs/parthenon_xdmf.cpp +++ b/src/outputs/parthenon_xdmf.cpp @@ -211,7 +211,6 @@ void genXDMF(std::string hdfFile, Mesh *pm, SimTime *tm, IndexDomain domain, int if (swarm_xdmf && all_swarm_info.all_info.size() > 0) { std::string sfilename_aux = hdfFile + ".swarm.xdmf"; std::ofstream pxdmf; - hsize_t dims[H5_NDIM] = {0}; // zero-initialized // open file pxdmf = std::ofstream(sfilename_aux.c_str(), std::ofstream::trunc);