diff --git a/CHANGELOG.md b/CHANGELOG.md index 554debf3c568..1d361fc0567f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - [[PR 1172]](https://github.com/parthenon-hpc-lab/parthenon/pull/1172) Make parthenon manager robust against external MPI init and finalize calls ### Fixed (not changing behavior/API/variables/...) +- [[PR 1188]](https://github.com/parthenon-hpc-lab/parthenon/pull/1188) Fix hdf5 output issue for metadata none variables, update test. - [[PR 1170]](https://github.com/parthenon-hpc-lab/parthenon/pull/1170) Fixed incorrect initialization of array by a const not constexpr - [[PR 1189]](https://github.com/parthenon-hpc-lab/parthenon/pull/1189) Address CUDA MPI/ICP issue with Kokkos <=4.4.1 - [[PR 1178]](https://github.com/parthenon-hpc-lab/parthenon/pull/1178) Fix issue with mesh pointer when using relative residual tolerance in BiCGSTAB solver. diff --git a/CMakeLists.txt b/CMakeLists.txt index 61fd4fd3cfff..590f277ee8d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,9 +75,9 @@ include(cmake/Format.cmake) include(cmake/Lint.cmake) # regression test reference data -set(REGRESSION_GOLD_STANDARD_VER 24 CACHE STRING "Version of gold standard to download and use") +set(REGRESSION_GOLD_STANDARD_VER 25 CACHE STRING "Version of gold standard to download and use") set(REGRESSION_GOLD_STANDARD_HASH - "SHA512=e220df92a335131131e42ddb52dc221a6dbd6bb56361483b4af0292620eeb82ffb21ef3b95fd9a7c5cc158fb754da0bf1a1015bec98b5bbad05f4bceb1ee99bc" + "SHA512=314dc8312366d81ba33d1fde25812e9a7697b2f529de29e22662df0d458f1c4bc5b5bb4e649888170f66ffec0df1be20a9cf401944531c1c1ad835e26eaad28f" CACHE STRING "Hash of default gold standard file to download") option(REGRESSION_GOLD_STANDARD_SYNC "Automatically sync gold standard files." ON) diff --git a/example/advection/advection_package.cpp b/example/advection/advection_package.cpp index f799a2909262..64e4ea30712d 100644 --- a/example/advection/advection_package.cpp +++ b/example/advection/advection_package.cpp @@ -196,6 +196,20 @@ std::shared_ptr Initialize(ParameterInput *pin) { m = Metadata({Metadata::Cell, Metadata::OneCopy}, std::vector({1})); pkg->AddField("my_derived_var", m); + // Create a Metadata::None variable for IO testing purposes. + // Only load if test_metadata_none is specified in the Advection block + auto test_metadata_none = + pin->GetOrAddBoolean("Advection", "test_metadata_none", false); + pkg->AddParam("test_metadata_none", test_metadata_none); + if (test_metadata_none) { + const int nx1 = pin->GetOrAddInteger("parthenon/meshblock", "nx1", 1); + const int nx2 = pin->GetOrAddInteger("parthenon/meshblock", "nx2", 1); + const int nx3 = pin->GetOrAddInteger("parthenon/meshblock", "nx3", 1); + std::vector test_shape = {nx1 + 1, nx2 + 1, nx3 + 1, 3}; + m = Metadata({Metadata::OneCopy, Metadata::None}, test_shape); + pkg->AddField("metadata_none_var", m); + } + // List (vector) of HistoryOutputVar that will all be enrolled as output variables parthenon::HstVar_list hst_vars = {}; // Now we add a couple of callback functions @@ -281,6 +295,7 @@ AmrTag CheckRefinement(MeshBlockData *rc) { void PreFill(MeshBlockData *rc) { auto pmb = rc->GetBlockPointer(); auto pkg = pmb->packages.Get("advection_package"); + const bool test_metadata_none = pkg->Param("test_metadata_none"); bool fill_derived = pkg->Param("fill_derived"); if (fill_derived) { @@ -302,6 +317,24 @@ void PreFill(MeshBlockData *rc) { v(out + n, k, j, i) = 1.0 - v(in + n, k, j, i); }); } + + // Fill the metadata::None var with index gymnastics. + if (test_metadata_none) { + const int nx1 = pmb->cellbounds.ncellsi(IndexDomain::interior); + const int nx2 = pmb->cellbounds.ncellsj(IndexDomain::interior); + const int nx3 = pmb->cellbounds.ncellsk(IndexDomain::interior); + + // packing in principle unnecessary/convoluted here and just done for demonstration + std::vector vars({"metadata_none_var"}); + PackIndexMap imap; + const auto &v = rc->PackVariables(vars, imap); + + pmb->par_for( + PARTHENON_AUTO_LABEL, 0, 2, 0, nx3, 0, nx2, 0, nx1, + KOKKOS_LAMBDA(const int n, const int k, const int j, const int i) { + v(n, k, j, i) = n + k + j + i; + }); + } } // this is the package registered function to fill derived diff --git a/src/outputs/output_utils.hpp b/src/outputs/output_utils.hpp index 5c094ef688d7..e9fcee04c986 100644 --- a/src/outputs/output_utils.hpp +++ b/src/outputs/output_utils.hpp @@ -312,11 +312,11 @@ void PackOrUnpackVar(const VarInfo &info, bool do_ghosts, idx_t &idx, Function_t auto [kb, jb, ib] = info.GetPaddedBoundsKJI(domain); if (info.where == MetadataFlag({Metadata::None})) { kb.s = 0; - kb.e = shape[4]; + kb.e = std::max(0, shape[4] - 1); jb.s = 0; - jb.e = shape[5]; + jb.e = std::max(0, shape[5] - 1); ib.s = 0; - ib.e = shape[6]; + ib.e = std::max(0, shape[6] - 1); } for (int topo = 0; topo < shape[0]; ++topo) { for (int t = 0; t < shape[1]; ++t) { diff --git a/tst/regression/test_suites/output_hdf5/output_hdf5.py b/tst/regression/test_suites/output_hdf5/output_hdf5.py index cbef0aba2aa7..fd68c8e17851 100644 --- a/tst/regression/test_suites/output_hdf5/output_hdf5.py +++ b/tst/regression/test_suites/output_hdf5/output_hdf5.py @@ -190,6 +190,18 @@ def Analyse(self, parameters): ) analyze_status = False + # check contents of matadata_none_var + for dim in [2, 3]: + data = phdf.phdf(f"advection_{dim}d.out0.final.phdf") + profile = data.Get("metadata_none_var", flatten=False) + for index in np.ndindex(profile.shape): + ib, j, k, l, m = index + expected_value = l + k + j + m + actual_value = profile[ib, j, k, l, m] + if expected_value != actual_value: + print("metadata_none_var is incorrect") + analyze_status = False + # Checking Parthenon histograms versus numpy ones for dim in [2, 3]: # 1D histogram with binning of a variable with bins defined by a var diff --git a/tst/regression/test_suites/output_hdf5/parthinput.advection b/tst/regression/test_suites/output_hdf5/parthinput.advection index 3061d2bff961..118a82b58e56 100644 --- a/tst/regression/test_suites/output_hdf5/parthinput.advection +++ b/tst/regression/test_suites/output_hdf5/parthinput.advection @@ -54,6 +54,7 @@ vx = 1.0 vy = 1.0 vz = 1.0 profile = hard_sphere +test_metadata_none = true refine_tol = 0.3 # control the package specific refinement tagging function derefine_tol = 0.03 @@ -64,7 +65,8 @@ file_type = hdf5 dt = 1.0 variables = advected, one_minus_advected, & # comments are ok one_minus_advected_sq, & # on every (& characters are ok in comments) - one_minus_sqrt_one_minus_advected_sq # line + one_minus_sqrt_one_minus_advected_sq, & # line + metadata_none_var file_type = hst