From a885e1d71a2ecdd29403b7dc489b42f2354b7dc7 Mon Sep 17 00:00:00 2001 From: Ben Ryan Date: Tue, 23 Apr 2024 03:28:43 -0600 Subject: [PATCH] Vector history not being output if no scalar history present (#1058) * Vector history not being output if no scalar history present * CHANGELOG * share md_base reset with both scalar and vector histories * Organize loop structure better --- CHANGELOG.md | 1 + src/outputs/history.cpp | 64 ++++++++++++++++++++--------------------- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e58da8591d5f..c81332b2d34e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 1058]](https://github.com/parthenon-hpc-lab/parthenon/pull/1058) Vector history not being output if no scalar history present - [[PR 1057]](https://github.com/parthenon-hpc-lab/parthenon/pull/1057) Fix history output after restarts - [[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 diff --git a/src/outputs/history.cpp b/src/outputs/history.cpp index eab7668d298d..2bd1f1b4fc3f 100644 --- a/src/outputs/history.cpp +++ b/src/outputs/history.cpp @@ -79,47 +79,45 @@ void HistoryOutput::WriteOutputFile(Mesh *pm, ParameterInput *pin, SimTime *tm, } } + // Get "base" MeshData, which always exists but may not be populated yet + auto &md_base = pm->mesh_data.Get(); + // Populated with all blocks + if (md_base->NumBlocks() == 0) { + md_base->Set(pm->block_list, pm); + } else if (md_base->NumBlocks() != pm->block_list.size()) { + PARTHENON_WARN( + "Resetting \"base\" MeshData to contain all blocks. This indicates that " + "the \"base\" MeshData container has been modified elsewhere. Double check " + "that the modification was intentional and is compatible with this reset.") + md_base->Set(pm->block_list, pm); + } + // Loop over all packages of the application for (const auto &pkg : packages) { - // Check if the package has enrolled scalar history functions which are stored in the - // Params under the `hist_param_key` name. const auto ¶ms = pkg.second->AllParams(); - if (!params.hasKey(hist_param_key)) { - continue; - } - const auto &hist_vars = params.Get(hist_param_key); - - // Get "base" MeshData, which always exists but may not be populated yet - auto &md_base = pm->mesh_data.Get(); - // Populated with all blocks - if (md_base->NumBlocks() == 0) { - md_base->Set(pm->block_list, pm); - } else if (md_base->NumBlocks() != pm->block_list.size()) { - PARTHENON_WARN( - "Resetting \"base\" MeshData to contain all blocks. This indicates that " - "the \"base\" MeshData container has been modified elsewhere. Double check " - "that the modification was intentional and is compatible with this reset.") - md_base->Set(pm->block_list, pm); - } - for (const auto &hist_var : hist_vars) { - auto result = hist_var.hst_fun(md_base.get()); - results[hist_var.hst_op].push_back(result); - labels[hist_var.hst_op].push_back(hist_var.label); + // Check if the package has enrolled scalar history functions which are stored in the + // Params under the `hist_param_key` name. + if (params.hasKey(hist_param_key)) { + const auto &hist_vars = params.Get(hist_param_key); + for (const auto &hist_var : hist_vars) { + auto result = hist_var.hst_fun(md_base.get()); + results[hist_var.hst_op].push_back(result); + labels[hist_var.hst_op].push_back(hist_var.label); + } } // Check if the package has enrolled vector history functions which are stored in the // Params under the `hist_vec_param_key` name. - if (!params.hasKey(hist_vec_param_key)) { - continue; - } - const auto &hist_vecs = params.Get(hist_vec_param_key); - for (const auto &hist_vec : hist_vecs) { - auto result = hist_vec.hst_vec_fun(md_base.get()); - for (int n = 0; n < result.size(); n++) { - std::string label = hist_vec.label + "_" + std::to_string(n); - results[hist_vec.hst_op].push_back(result[n]); - labels[hist_vec.hst_op].push_back(label); + if (params.hasKey(hist_vec_param_key)) { + const auto &hist_vecs = params.Get(hist_vec_param_key); + for (const auto &hist_vec : hist_vecs) { + auto result = hist_vec.hst_vec_fun(md_base.get()); + for (int n = 0; n < result.size(); n++) { + std::string label = hist_vec.label + "_" + std::to_string(n); + results[hist_vec.hst_op].push_back(result[n]); + labels[hist_vec.hst_op].push_back(label); + } } } }