From aac774ee750193083ae20ec04a4698760af722c8 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 17 Feb 2020 20:36:00 -0600 Subject: [PATCH] Writing scores between each batch. --- include/openmc/mesh.h | 7 ++---- src/mesh.cpp | 53 ++++++++++++++++--------------------------- src/tallies/tally.cpp | 4 ++-- 3 files changed, 24 insertions(+), 40 deletions(-) diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index 29d1a0e4dd..b1b815528d 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -356,6 +356,8 @@ intersect_track(const moab::CartVect& start, //! \param[in] all_tets MOAB Range of tetrahedra for the tree void build_kdtree(const moab::Range& all_tets); + //! Get the tags for a score from the mesh instance + //! or create them if they are not there std::pair get_score_tags(std::string score) const; @@ -391,11 +393,6 @@ public: std::string bin_label(int bin) const override; - //! Get the tags for a score from the mesh instance - moab::ErrorCode get_score_tags(std::string score, - moab::Tag& val_tag, - moab::Tag& err_tag) const; - //! Add a score to the mesh instance void add_score(std::string score) const; diff --git a/src/mesh.cpp b/src/mesh.cpp index e7aaa59222..0c296ec9f7 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -2013,58 +2013,50 @@ UnstructuredMesh::bin_label(int bin) const { return out.str(); }; -moab::ErrorCode -UnstructuredMesh::get_score_tags(std::string score, - moab::Tag& val_tag, - moab::Tag& err_tag) const { +std::pair +UnstructuredMesh::get_score_tags(std::string score) const { moab::ErrorCode rval; // add a tag to the mesh // all scores are treated as a single value // with an uncertainty - moab::Tag score_val; + moab::Tag value_tag; double default_val = 0.0; - rval = mbi_->tag_get_handle(score.c_str(), + auto val_string = score + "_value"; + rval = mbi_->tag_get_handle(val_string.c_str(), 1, moab::MB_TYPE_DOUBLE, - score_val, + value_tag, moab::MB_TAG_DENSE|moab::MB_TAG_CREAT, &default_val); if (rval != moab::MB_SUCCESS) { std::stringstream msg; msg << "Could not create or retrieve the value tag for the score " << score << " on unstructured mesh " << id_; - warning(msg); - return rval; + fatal_error(msg); } - moab::Tag score_err; - rval = mbi_->tag_get_handle(score.c_str(), + moab::Tag error_tag; + std::string err_string = score + "_error"; + rval = mbi_->tag_get_handle(err_string.c_str(), 1, moab::MB_TYPE_DOUBLE, - score_err, + error_tag, moab::MB_TAG_DENSE|moab::MB_TAG_CREAT, &default_val); - if (rval != moab::MB_SUCCESS) { std::stringstream msg; msg << "Could not create or retrieve the error tag for the score " << score << " on unstructured mesh " << id_; - warning(msg); - return rval; + fatal_error(msg); } - return moab::MB_SUCCESS; + + return {value_tag, error_tag}; } void UnstructuredMesh::add_score(std::string score) const { - moab::Tag score_val, score_err; - moab::ErrorCode rval = get_score_tags(score, score_val, score_err); - if (rval != moab::MB_SUCCESS) { - std::stringstream msg; - msg << "Failed to add score '" << score << "' to unstructured mesh" << id_; - fatal_error(msg); - } + auto score_tags = get_score_tags(score); } void @@ -2072,27 +2064,22 @@ UnstructuredMesh::set_score(const std::string& score, int bin, double val, double err) const { - moab::Tag score_val, score_err; - moab::ErrorCode rval = get_score_tags(score, score_val, score_err); - if (rval != moab::MB_SUCCESS) { - std::stringstream msg; - msg << "Failed to get tags for the score '" << score << "' on " - << "unstructured mesh " << id_; - warning(msg); - } + auto score_tags = get_score_tags(score); moab::EntityHandle eh = get_ent_handle_from_bin(bin); + moab::ErrorCode rval; // set the score value - rval = mbi_->tag_set_data(score_val, &eh, 1, &val); + rval = mbi_->tag_set_data(score_tags.first, &eh, 1, &val); if (rval != moab::MB_SUCCESS) { std::stringstream msg; msg << "Failed to set the tally value for score '" << score << "' " << " on unstructured mesh " << id_; warning(msg); } + // set the error value - rval = mbi_->tag_set_data(score_err, &eh, 1, &err); + rval = mbi_->tag_set_data(score_tags.second, &eh, 1, &err); if (rval != moab::MB_SUCCESS) { std::stringstream msg; msg << "Failed to set the tally value for score '" << score << "' " diff --git a/src/tallies/tally.cpp b/src/tallies/tally.cpp index 6a9c1455fd..54b77ee980 100644 --- a/src/tallies/tally.cpp +++ b/src/tallies/tally.cpp @@ -842,7 +842,7 @@ void Tally::accumulate() if (umesh) { for (auto score : scores_) { umesh->add_score(std::to_string(score)); - for (int i = 0; i < results_.shape()[0]; i ++) { + for (int i = 0; i < results_.shape()[0]; i++) { umesh->set_score(std::to_string(score), i, results_(i, 0, RESULT_SUM), @@ -850,7 +850,7 @@ void Tally::accumulate() } } std::stringstream output_filename; - output_filename << "tally_" << id_ << "umesh"; + output_filename << "tally_" << id_ << "_umesh"; umesh->write(output_filename.str()); } }