From 0bcc9f2c06f5673a95027fd493528f38ba4d7310 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 23 Jul 2020 13:47:57 -0500 Subject: [PATCH 1/3] Making sure score data is removed from the unstructured mesh. --- include/openmc/mesh.h | 3 +++ src/mesh.cpp | 24 ++++++++++++++++++++++++ src/state_point.cpp | 4 ++++ 3 files changed, 31 insertions(+) diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index a7160b0c8..d17f82023 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -298,6 +298,9 @@ public: //! Add a score to the mesh instance void add_score(std::string score) const; + //! Remove a score from the mesh instance + void remove_score(std::string score) const; + //! Set data for a score void set_score_data(const std::string& score, std::vector values, diff --git a/src/mesh.cpp b/src/mesh.cpp index b76be1ee8..5acfee44e 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -2015,6 +2015,30 @@ UnstructuredMesh::add_score(std::string score) const { auto score_tags = this->get_score_tags(score); } +void UnstructuredMesh::remove_score(std::string score) const { + moab::ErrorCode rval; + moab::Tag tag; + auto value_name = score + "_mean"; + rval = mbi_->tag_get_handle(value_name.c_str(), tag); + if (rval != moab::MB_SUCCESS) return; + + rval = mbi_->tag_delete(tag); + if (rval != moab::MB_SUCCESS) { + auto msg = fmt::format("Failed to delete mesh tag for the score {}" + " on unstructured mesh {}", score, id_); + fatal_error(msg); + } + + auto std_dev_name = score + "_std_dev"; + rval = mbi_->tag_get_handle(std_dev_name.c_str(), tag); + if (rval != moab::MB_SUCCESS) { + auto msg = fmt::format("Std. Dev. mesh tag does not exist for the score {}" + " on unstructured mesh {}", score, id_); + } + + +} + void UnstructuredMesh::set_score_data(const std::string& score, std::vector values, diff --git a/src/state_point.cpp b/src/state_point.cpp index bf249aa98..faf8071e7 100644 --- a/src/state_point.cpp +++ b/src/state_point.cpp @@ -687,6 +687,8 @@ void read_source_bank(hid_t group_id) void write_unstructured_mesh_results() { for (auto& tally : model::tallies) { + + std::vector tally_scores; for (auto filter_idx : tally->filters()) { auto& filter = model::tally_filters[filter_idx]; if (filter->type() != "mesh") continue; @@ -754,6 +756,8 @@ void write_unstructured_mesh_results() { w); // Write the unstructured mesh and data to file umesh->write(filename); + + for (const auto& score : tally_scores) { umesh->remove_score(score); } } } } From 7dbd211c534d2ad4044c68efb635343d7de5ec71 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 23 Jul 2020 16:31:47 -0500 Subject: [PATCH 2/3] Ensuring the data is deleted and scores for a given tally are tracked when writing the vtk file. --- src/mesh.cpp | 7 ++++++- src/state_point.cpp | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/mesh.cpp b/src/mesh.cpp index 5acfee44e..0cdd85631 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -2036,7 +2036,12 @@ void UnstructuredMesh::remove_score(std::string score) const { " on unstructured mesh {}", score, id_); } - + rval = mbi_->tag_delete(tag); + if (rval != moab::MB_SUCCESS) { + auto msg = fmt::format("Failed to delete mesh tag for the score {}" + " on unstructured mesh {}", score, id_); + fatal_error(msg); + } } void diff --git a/src/state_point.cpp b/src/state_point.cpp index faf8071e7..409a6ba7d 100644 --- a/src/state_point.cpp +++ b/src/state_point.cpp @@ -743,6 +743,7 @@ void write_unstructured_mesh_results() { std::string score_name = tally->score_name(i_score); auto score_str = fmt::format("{}_{}", score_name, nuclide_name); + tally_scores.push_back(score_str); umesh->set_score_data(score_str, mean_vec, std_dev_vec); } } From 6a446b6be5dcc58434c42da52362c4c6c1322188 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 26 Aug 2020 09:38:43 -0500 Subject: [PATCH 3/3] Apply suggestions from code review Including suggested change from @paulromano Co-authored-by: Paul Romano --- src/mesh.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/mesh.cpp b/src/mesh.cpp index 0cdd85631..2cd0fd77e 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -2016,10 +2016,9 @@ UnstructuredMesh::add_score(std::string score) const { } void UnstructuredMesh::remove_score(std::string score) const { - moab::ErrorCode rval; - moab::Tag tag; auto value_name = score + "_mean"; - rval = mbi_->tag_get_handle(value_name.c_str(), tag); + moab::Tag tag; + moab::ErrorCode rval = mbi_->tag_get_handle(value_name.c_str(), tag); if (rval != moab::MB_SUCCESS) return; rval = mbi_->tag_delete(tag);