From 6749f72fecbf8c42b55cc2e093bc5e9bb039bed3 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 28 Feb 2020 16:24:34 -0600 Subject: [PATCH] Moving tally writing into the statepoint function. Should write anytime a statepoint file is asked for. --- include/openmc/state_point.h | 4 +++ src/state_point.cpp | 48 ++++++++++++++++++++++++++++++++++++ src/tallies/tally.cpp | 32 ------------------------ 3 files changed, 52 insertions(+), 32 deletions(-) diff --git a/include/openmc/state_point.h b/include/openmc/state_point.h index e44c57f1a4..4a901ac2a2 100644 --- a/include/openmc/state_point.h +++ b/include/openmc/state_point.h @@ -16,5 +16,9 @@ void read_source_bank(hid_t group_id); void write_tally_results_nr(hid_t file_id); void restart_set_keff(); +#ifdef DAGMC +void write_unstructured_mesh_results(); +#endif + } // namespace openmc #endif // OPENMC_STATE_POINT_H diff --git a/src/state_point.cpp b/src/state_point.cpp index c8c3c87bd8..465bab506d 100644 --- a/src/state_point.cpp +++ b/src/state_point.cpp @@ -24,6 +24,7 @@ #include "openmc/simulation.h" #include "openmc/tallies/derivative.h" #include "openmc/tallies/filter.h" +#include "openmc/tallies/filter_mesh.h" #include "openmc/tallies/tally.h" #include "openmc/timer.h" @@ -164,6 +165,10 @@ openmc_statepoint_write(const char* filename, bool* write_source) tally_ids.push_back(tally->id_); write_attribute(tallies_group, "ids", tally_ids); +#ifdef DAGMC + write_unstructured_mesh_results(); +#endif + // Write all tally information except results for (const auto& tally : model::tallies) { hid_t tally_group = create_group(tallies_group, @@ -677,6 +682,49 @@ void read_source_bank(hid_t group_id) H5Tclose(banktype); } +#ifdef DAGMC +void write_unstructured_mesh_results() { + for (auto& tally : model::tallies) { + for (auto filter_idx : tally->filters()) { + auto& filter = model::tally_filters[filter_idx]; + if (filter->type() == "mesh") { + auto mesh_filter = dynamic_cast(filter.get()); + auto& mesh = model::meshes[mesh_filter->mesh()]; + auto umesh = dynamic_cast(mesh.get()); + if (umesh) { + for (auto score : tally->scores_) { + // get values for this score and create vectors for marking + // up the mesh + auto values = xt::view(tally->results_, xt::all(), 0, static_cast(TallyResult::SUM)); + auto sum_sq = xt::view(tally->results_, xt::all(), 0, TallyResult::SUM_SQ); + std::vector vals_vec, sum_sq_vec; + for (int i = 0; i < tally->results_.shape()[0]; i++) { + vals_vec.push_back(tally->results_(i, 0, TallyResult::SUM) / tally->n_realizations_); + sum_sq_vec.push_back(tally->results_(i, 0, TallyResult::SUM_SQ) - std::pow(vals_vec[i], 2)/ tally->n_realizations_); + } + + // set the score data on the mesh + umesh->set_score_data(std::to_string(score), + vals_vec, + sum_sq_vec); + } + + // Determine width for zero padding + int w = std::to_string(settings::n_max_batches).size(); + + std::string umesh_filename = fmt::format("{0}tally_{1}.{2:0{3}}", + settings::path_output, + tally->id_, + simulation::current_batch, + w); + umesh->write(umesh_filename); + } + } + } + } +} +#endif + void write_tally_results_nr(hid_t file_id) { // ========================================================================== diff --git a/src/tallies/tally.cpp b/src/tallies/tally.cpp index f8bf4f1115..b63128dc04 100644 --- a/src/tallies/tally.cpp +++ b/src/tallies/tally.cpp @@ -831,38 +831,6 @@ void Tally::accumulate() } } } - -#ifdef DAGMC - for (auto filter_idx : filters_) { - auto& filter = model::tally_filters[filter_idx]; - if (filter->type() == "mesh") { - auto mesh_filter = dynamic_cast(filter.get()); - auto& mesh = model::meshes[mesh_filter->mesh()]; - auto umesh = dynamic_cast(mesh.get()); - if (umesh) { - for (auto score : scores_) { - // get values for this score and create vectors for marking - // up the mesh - auto values = xt::view(results_, xt::all(), 0, static_cast(TallyResult::SUM)); - auto sum_sq = xt::view(results_, xt::all(), 0, TallyResult::SUM_SQ); - std::vector vals_vec, sum_sq_vec; - for (int i = 0; i < results_.shape()[0]; i++) { - vals_vec.push_back(results_(i, 0, TallyResult::SUM) / n_realizations_); - sum_sq_vec.push_back(results_(i, 0, TallyResult::SUM_SQ) - std::pow(vals_vec[i], 2)/ n_realizations_); - } - - // set the score data on the mesh - umesh->set_score_data(std::to_string(score), - vals_vec, - sum_sq_vec); - } - std::stringstream output_filename; - output_filename << "tally_" << id_ << "_umesh"; - umesh->write(output_filename.str()); - } - } - } -#endif } //==============================================================================