Skip to content

Commit 85b1af4

Browse files
committed
add to_element(), a function to convert nuclide name to element name
1 parent 57fcb07 commit 85b1af4

6 files changed

Lines changed: 14 additions & 7 deletions

File tree

‎include/openmc/string_utils.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ std::string& strtrim(std::string& s);
1010

1111
char* strtrim(char* c_str);
1212

13+
std::string to_element(std::string const& name);
14+
1315
void to_lower(std::string& str);
1416

1517
int word_count(std::string const& str);

‎src/cross_sections.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ read_ce_cross_sections(const std::vector<std::vector<double>>& nuc_temps,
239239
already_read.insert(name);
240240

241241
// Check if elemental data has been read, if needed
242-
int pos = name.find_first_of("0123456789");
243-
std::string element = name.substr(0, pos);
242+
std::string element = to_element(name);
244243
if (settings::photon_transport) {
245244
if (already_read.find(element) == already_read.end()) {
246245
// Read photon interaction data from HDF5 photon library

‎src/material.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,7 @@ Material::Material(pugi::xml_node node)
227227
// If the corresponding element hasn't been encountered yet and photon
228228
// transport will be used, we need to add its symbol to the element_dict
229229
if (settings::photon_transport) {
230-
int pos = name.find_first_of("0123456789");
231-
std::string element = name.substr(0, pos);
230+
std::string element = to_element(name);
232231

233232
// Make sure photon cross section data is available
234233
LibraryKey key {Library::Type::photon, element};

‎src/physics.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "openmc/search.h"
1818
#include "openmc/settings.h"
1919
#include "openmc/simulation.h"
20+
#include "openmc/string_utils.h"
2021
#include "openmc/thermal.h"
2122
#include "openmc/tallies/tally.h"
2223

@@ -68,7 +69,7 @@ void collision(Particle* p)
6869
data::nuclides[p->event_nuclide_]->name_ << ". Energy = " << p->E_ << " eV.";
6970
} else if (p->type_ == Particle::Type::photon) {
7071
msg << " " << reaction_name(p->event_mt_) << " with " <<
71-
data::nuclides[p->event_nuclide_]->name_ << ". Energy = " << p->E_ << " eV.";
72+
to_element(data::nuclides[p->event_nuclide_]->name_) << ". Energy = " << p->E_ << " eV.";
7273
} else {
7374
msg << " Disappeared. Energy = " << p->E_ << " eV.";
7475
}

‎src/string_utils.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ char* strtrim(char* c_str)
2626
}
2727

2828

29+
std::string to_element(std::string const& name) {
30+
int pos = name.find_first_of("0123456789");
31+
return name.substr(0, pos);
32+
}
33+
34+
2935
void to_lower(std::string& str)
3036
{
3137
for (int i = 0; i < str.size(); i++) str[i] = std::tolower(str[i]);

‎src/tallies/tally_scoring.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "openmc/search.h"
1313
#include "openmc/settings.h"
1414
#include "openmc/simulation.h"
15+
#include "openmc/string_utils.h"
1516
#include "openmc/tallies/derivative.h"
1617
#include "openmc/tallies/filter.h"
1718
#include "openmc/tallies/filter_delayedgroup.h"
@@ -1274,8 +1275,7 @@ score_general_ce(Particle* p, int i_tally, int start_index,
12741275
if (i_nuclide >= 0) {
12751276
// Find the element corresponding to the nuclide
12761277
auto name = data::nuclides[i_nuclide]->name_;
1277-
int pos = name.find_first_of("0123456789");
1278-
std::string element = name.substr(0, pos);
1278+
std::string element = to_element(name);
12791279
int i_element = data::element_map[element];
12801280
auto& heating {data::elements[i_element].heating_};
12811281
auto i_grid = p->photon_xs_[i_element].index_grid;

0 commit comments

Comments
 (0)