Skip to content

Commit

Permalink
Vector history not being output if no scalar history present (#1058)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
brryan committed Apr 23, 2024
1 parent 25f4e27 commit a885e1d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 33 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 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
Expand Down
64 changes: 31 additions & 33 deletions src/outputs/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &params = pkg.second->AllParams();
if (!params.hasKey(hist_param_key)) {
continue;
}
const auto &hist_vars = params.Get<HstVar_list>(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<HstVar_list>(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<HstVec_list>(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<HstVec_list>(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);
}
}
}
}
Expand Down

0 comments on commit a885e1d

Please sign in to comment.