Adding umesh tally write between batches when accumulating.

This commit is contained in:
Patrick Shriwise 2020-02-17 17:18:35 -06:00
parent 862c20752e
commit 3f2556aa9c
3 changed files with 146 additions and 0 deletions

View file

@ -356,6 +356,9 @@ 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);
std::pair<moab::Tag, moab::Tag>
get_score_tags(std::string score) const;
public:
std::pair<std::vector<double>, std::vector<double>>
@ -388,6 +391,22 @@ 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;
//! Set data for a score
void set_score(const std::string& score,
int bin,
double val,
double err) const;
//! Write the mesh with any current tally data
void write(std::string base_filename) const;
std::string filename_; //<! Path to unstructured mesh file
private:

View file

@ -2013,6 +2013,108 @@ 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 {
moab::ErrorCode rval;
// add a tag to the mesh
// all scores are treated as a single value
// with an uncertainty
moab::Tag score_val;
double default_val = 0.0;
rval = mbi_->tag_get_handle(score.c_str(),
1,
moab::MB_TYPE_DOUBLE,
score_val,
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;
}
moab::Tag score_err;
rval = mbi_->tag_get_handle(score.c_str(),
1,
moab::MB_TYPE_DOUBLE,
score_err,
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;
}
return moab::MB_SUCCESS;
}
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);
}
}
void
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);
}
moab::EntityHandle eh = get_ent_handle_from_bin(bin);
// set the score value
rval = mbi_->tag_set_data(score_val, &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);
if (rval != moab::MB_SUCCESS) {
std::stringstream msg;
msg << "Failed to set the tally value for score '" << score << "' "
<< " on unstructured mesh " << id_;
warning(msg);
}
}
void
UnstructuredMesh::write(std::string base_filename) const {
// add extension to the base name
base_filename += ".h5m";
moab::ErrorCode rval;
rval = mbi_->write_mesh(base_filename.c_str());
if (rval != moab::MB_SUCCESS) {
std::stringstream msg;
msg << "Failed to write unstructured mesh " << id_;
warning(msg);
}
}
#endif

View file

@ -831,6 +831,31 @@ 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<MeshFilter*>(filter.get());
auto& mesh = model::meshes[mesh_filter->mesh()];
auto umesh = dynamic_cast<UnstructuredMesh*>(mesh.get());
if (umesh) {
for (auto score : scores_) {
umesh->add_score(std::to_string(score));
for (int i = 0; i < results_.shape()[0]; i ++) {
umesh->set_score(std::to_string(score),
i,
results_(i, 0, RESULT_SUM),
results_(i, 0, RESULT_SUM_SQ));
}
}
std::stringstream output_filename;
output_filename << "tally_" << id_ << "umesh";
umesh->write(output_filename.str());
}
}
}
#endif
}
//==============================================================================