Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vector history not being output if no scalar history present #1058

Merged
merged 5 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
38 changes: 18 additions & 20 deletions src/outputs/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,7 @@ void HistoryOutput::WriteOutputFile(Mesh *pm, ParameterInput *pin, SimTime *tm,

// 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();
Expand All @@ -102,24 +96,28 @@ void HistoryOutput::WriteOutputFile(Mesh *pm, ParameterInput *pin, SimTime *tm,
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)) {
Copy link
Collaborator Author

@brryan brryan Apr 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only potential change in behavior is that, even if no history vars are enrolled, we still update md_base if it was empty or if it had a different size than pm->block_list. I think this is fine because codes shouldn't be designed around not updating this variable during history output only if no history variables were requested.

I also now update md_base only once for all packages rather than inside the for (const auto &pkg : packages) loop.

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
Loading