Updating unstructured mesh writing to use the nuclide_score tally method and putting variable addition back into its own loop.

This commit is contained in:
Patrick Shriwise 2021-01-09 18:38:30 -06:00
parent 7b6bf93afd
commit 7a2f1d6d0a
3 changed files with 32 additions and 36 deletions

View file

@ -299,8 +299,8 @@ public:
//! Set the value of a bin for a variable on the internal
// mesh instance
virtual void set_score_data(const std::string& var_name,
std::vector<double> values,
std::vector<double> std_dev) = 0;
const std::vector<double>& values,
const std::vector<double>& std_dev) = 0;
//! Write the unstructured mesh to file
//
@ -373,8 +373,8 @@ public:
//! Set data for a score
void set_score_data(const std::string& score,
std::vector<double> values,
std::vector<double> std_dev) override;
const std::vector<double>& values,
const std::vector<double>& std_dev) override;
//! Write the mesh with any current tally data
void write(const std::string& base_filename) const;
@ -516,8 +516,8 @@ public:
void remove_scores() override;
void set_score_data(const std::string& var_name,
std::vector<double> values,
std::vector<double> std_dev) override;
const std::vector<double>& values,
const std::vector<double>& std_dev) override;
void write(const std::string& base_filename) const override;

View file

@ -2088,19 +2088,11 @@ void MOABMesh::remove_scores()
void
MOABMesh::set_score_data(const std::string& score,
std::vector<double> values,
std::vector<double> std_dev)
const std::vector<double>& values,
const std::vector<double>& std_dev)
{
auto score_tags = this->get_score_tags(score);
// normalize tally values by element volume
for (int i = 0; i < ehs_.size(); i++) {
auto eh = this->get_ent_handle_from_bin(i);
double volume = this->tet_volume(eh);
values[i] /= volume;
std_dev[i] /= volume;
}
moab::ErrorCode rval;
// set the score value
rval = mbi_->tag_set_data(score_tags.first, ehs_, values.data());
@ -2250,13 +2242,13 @@ LibMesh::remove_scores()
{
auto& eqn_sys = equation_systems_->get_system(eq_system_name_);
eqn_sys.clear();
eqn_sys.init();
variable_map_.clear();
}
void
LibMesh::set_score_data(const std::string& var_name,
std::vector<double> values,
std::vector<double> std_dev)
const std::vector<double>& values,
const std::vector<double>& std_dev)
{
auto& eqn_sys = equation_systems_->get_system(eq_system_name_);
@ -2278,14 +2270,13 @@ LibMesh::set_score_data(const std::string& var_name,
std::vector<libMesh::dof_id_type> value_dof_indices;
dof_map.dof_indices(e, value_dof_indices, value_num);
Ensures(value_dof_indices.size() == 1);
eqn_sys.solution->set(value_dof_indices[0], values[bin]);
eqn_sys.solution->set(value_dof_indices[0], values.at(bin));
// set std dev
std::vector<libMesh::dof_id_type> std_dev_dof_indices;
dof_map.dof_indices(e, std_dev_dof_indices, std_dev_num);
Ensures(std_dev_dof_indices.size() == 1);
eqn_sys.solution->set(std_dev_dof_indices[0], std_dev[bin]);
eqn_sys.solution->set(std_dev_dof_indices[0], std_dev.at(bin));
}
}

View file

@ -770,8 +770,6 @@ void read_source_bank(hid_t group_id, std::vector<Particle::Bank>& sites, bool d
H5Tclose(banktype);
}
void write_unstructured_mesh_results() {
#if !defined(LIBMESH) && !defined(DAGMC)
@ -807,18 +805,24 @@ void write_unstructured_mesh_results() {
for (int score_idx = 0; score_idx < tally->scores_.size(); score_idx++) {
for (int nuc_idx = 0; nuc_idx < tally->nuclides_.size(); nuc_idx++) {
// get the name for this nuclide
int nuclide = tally->nuclides_[nuc_idx];
std::string nuclide_name = "total"; // start with total by default
if (nuclide > -1) nuclide_name = data::nuclides[nuclide]->name_;
// get the name for this score
std::string score_name = tally->score_name(score_idx);
// combine the score and nuclide into a name for the value
auto score_str = fmt::format("{}_{}", score_name, nuclide_name);
auto score_str = fmt::format("{}_{}",
tally->score_name(score_idx),
tally->nuclide_name(nuc_idx));
// add this score to the mesh
// (this is in a separate loop because all variables need to be added
// to libMesh's equation system before any are initialized, which
// happens in set_score_data)
umesh->add_score(score_str);
}
}
for (int score_idx = 0; score_idx < tally->scores_.size(); score_idx++) {
for (int nuc_idx = 0; nuc_idx < tally->nuclides_.size(); nuc_idx++) {
// combine the score and nuclide into a name for the value
auto score_str = fmt::format("{}_{}",
tally->score_name(score_idx),
tally->nuclide_name(nuc_idx));
// index for this nuclide and score
int nuc_score_idx = score_idx + nuc_idx*tally->scores_.size();
@ -826,9 +830,11 @@ void write_unstructured_mesh_results() {
// construct result vectors
std::vector<double> mean_vec, std_dev_vec;
for (int j = 0; j < tally->results_.shape()[0]; j++) {
// get the volume for this bin
double volume = umesh->volume(j);
// compute the mean
double mean = tally->results_(j, nuc_score_idx, TallyResult::SUM) / n_realizations;
mean_vec.push_back(mean);
mean_vec.push_back(mean / volume);
// compute the standard deviation
double sum_sq = tally->results_(j , nuc_score_idx, TallyResult::SUM_SQ);
@ -837,9 +843,8 @@ void write_unstructured_mesh_results() {
std_dev = sum_sq/n_realizations - mean*mean;
std_dev = std::sqrt(std_dev / (n_realizations - 1));
}
std_dev_vec.push_back(std_dev);
std_dev_vec.push_back(std_dev / volume);
}
// set the data for this score
umesh->set_score_data(score_str, mean_vec, std_dev_vec);
}