add to_element(), a function to convert nuclide name to element name

This commit is contained in:
liangjg 2019-04-11 13:59:11 -04:00
parent 57fcb078d3
commit 85b1af458a
6 changed files with 14 additions and 7 deletions

View file

@ -10,6 +10,8 @@ std::string& strtrim(std::string& s);
char* strtrim(char* c_str);
std::string to_element(std::string const& name);
void to_lower(std::string& str);
int word_count(std::string const& str);

View file

@ -239,8 +239,7 @@ read_ce_cross_sections(const std::vector<std::vector<double>>& nuc_temps,
already_read.insert(name);
// Check if elemental data has been read, if needed
int pos = name.find_first_of("0123456789");
std::string element = name.substr(0, pos);
std::string element = to_element(name);
if (settings::photon_transport) {
if (already_read.find(element) == already_read.end()) {
// Read photon interaction data from HDF5 photon library

View file

@ -227,8 +227,7 @@ Material::Material(pugi::xml_node node)
// If the corresponding element hasn't been encountered yet and photon
// transport will be used, we need to add its symbol to the element_dict
if (settings::photon_transport) {
int pos = name.find_first_of("0123456789");
std::string element = name.substr(0, pos);
std::string element = to_element(name);
// Make sure photon cross section data is available
LibraryKey key {Library::Type::photon, element};

View file

@ -17,6 +17,7 @@
#include "openmc/search.h"
#include "openmc/settings.h"
#include "openmc/simulation.h"
#include "openmc/string_utils.h"
#include "openmc/thermal.h"
#include "openmc/tallies/tally.h"
@ -68,7 +69,7 @@ void collision(Particle* p)
data::nuclides[p->event_nuclide_]->name_ << ". Energy = " << p->E_ << " eV.";
} else if (p->type_ == Particle::Type::photon) {
msg << " " << reaction_name(p->event_mt_) << " with " <<
data::nuclides[p->event_nuclide_]->name_ << ". Energy = " << p->E_ << " eV.";
to_element(data::nuclides[p->event_nuclide_]->name_) << ". Energy = " << p->E_ << " eV.";
} else {
msg << " Disappeared. Energy = " << p->E_ << " eV.";
}

View file

@ -26,6 +26,12 @@ char* strtrim(char* c_str)
}
std::string to_element(std::string const& name) {
int pos = name.find_first_of("0123456789");
return name.substr(0, pos);
}
void to_lower(std::string& str)
{
for (int i = 0; i < str.size(); i++) str[i] = std::tolower(str[i]);

View file

@ -12,6 +12,7 @@
#include "openmc/search.h"
#include "openmc/settings.h"
#include "openmc/simulation.h"
#include "openmc/string_utils.h"
#include "openmc/tallies/derivative.h"
#include "openmc/tallies/filter.h"
#include "openmc/tallies/filter_delayedgroup.h"
@ -1274,8 +1275,7 @@ score_general_ce(Particle* p, int i_tally, int start_index,
if (i_nuclide >= 0) {
// Find the element corresponding to the nuclide
auto name = data::nuclides[i_nuclide]->name_;
int pos = name.find_first_of("0123456789");
std::string element = name.substr(0, pos);
std::string element = to_element(name);
int i_element = data::element_map[element];
auto& heating {data::elements[i_element].heating_};
auto i_grid = p->photon_xs_[i_element].index_grid;