From 98e7396cbdc34303f1bc6ea65f110a8f984ae6b7 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 16 Jan 2019 16:12:49 -0600 Subject: [PATCH] Don't use lowercase nuclide/element names in maps --- src/cross_sections.cpp | 8 ++------ src/geometry_header.F90 | 4 ++-- src/input_xml.F90 | 34 +++++++++++++++++----------------- src/material.cpp | 1 + src/material_header.F90 | 4 ++-- src/nuclide_header.F90 | 12 ++++++------ src/tallies/tally_header.F90 | 2 +- 7 files changed, 31 insertions(+), 34 deletions(-) diff --git a/src/cross_sections.cpp b/src/cross_sections.cpp index ed963b23f1..08b4cbad2e 100644 --- a/src/cross_sections.cpp +++ b/src/cross_sections.cpp @@ -136,9 +136,7 @@ void read_cross_sections_xml() int i = 0; for (const auto& lib : data::libraries) { for (const auto& name : lib.materials_) { - std::string lower_name = name; - to_lower(lower_name); - LibraryKey key {lib.type_, lower_name}; + LibraryKey key {lib.type_, name}; data::library_map.insert({key, i}); } ++i; @@ -146,9 +144,7 @@ void read_cross_sections_xml() // Check that 0K nuclides are listed in the cross_sections.xml file for (const auto& name : settings::res_scat_nuclides) { - std::string lower_name = name; - to_lower(lower_name); - LibraryKey key {Library::Type::neutron, lower_name}; + LibraryKey key {Library::Type::neutron, name}; if (data::library_map.find(key) == data::library_map.end()) { fatal_error("Could not find resonant scatterer " + name + " in cross_sections.xml file!"); diff --git a/src/geometry_header.F90 b/src/geometry_header.F90 index 953360c0f3..379a80c72a 100644 --- a/src/geometry_header.F90 +++ b/src/geometry_header.F90 @@ -215,7 +215,7 @@ contains associate (mat => materials(i_material)) NUC_NAMES_LOOP: do k = 1, size(mat % names) ! Get index in nuc_temps array - i_nuclide = nuclide_dict % get(to_lower(mat % names(k))) + i_nuclide = nuclide_dict % get(mat % names(k)) ! Add temperature if it hasn't already been added if (find(nuc_temps(i_nuclide), temperature) == -1) then @@ -226,7 +226,7 @@ contains if (present(sab_temps) .and. mat % n_sab > 0) then SAB_NAMES_LOOP: do k = 1, size(mat % sab_names) ! Get index in nuc_temps array - i_sab = sab_dict % get(to_lower(mat % sab_names(k))) + i_sab = sab_dict % get(mat % sab_names(k)) ! Add temperature if it hasn't already been added if (find(sab_temps(i_sab), temperature) == -1) then diff --git a/src/input_xml.F90 b/src/input_xml.F90 index 0883776247..5a2c4263be 100644 --- a/src/input_xml.F90 +++ b/src/input_xml.F90 @@ -752,20 +752,20 @@ contains ALL_NUCLIDES: do j = 1, mat % n_nuclides ! Check that this nuclide is listed in the cross_sections.xml file name = trim(names % data(j)) - if (.not. library_present(LIBRARY_NEUTRON, (to_lower(name)))) then + if (.not. library_present(LIBRARY_NEUTRON, (name))) then call fatal_error("Could not find nuclide " // trim(name) & // " in cross_sections data file!") end if ! If this nuclide hasn't been encountered yet, we need to add its name ! and alias to the nuclide_dict - if (.not. nuclide_dict % has(to_lower(name))) then + if (.not. nuclide_dict % has(name)) then index_nuclide = index_nuclide + 1 mat % nuclide(j) = index_nuclide - call nuclide_dict % set(to_lower(name), index_nuclide) + call nuclide_dict % set(name, index_nuclide) else - mat % nuclide(j) = nuclide_dict % get(to_lower(name)) + mat % nuclide(j) = nuclide_dict % get(name) end if ! If the corresponding element hasn't been encountered yet and photon @@ -774,7 +774,7 @@ contains element = name(1:scan(name, '0123456789') - 1) ! Make sure photon cross section data is available - if (.not. library_present(LIBRARY_PHOTON, to_lower(element))) then + if (.not. library_present(LIBRARY_PHOTON, element)) then call fatal_error("Could not find element " // trim(element) & // " in cross_sections data file!") end if @@ -868,19 +868,19 @@ contains end if ! Check that this nuclide is listed in the cross_sections.xml file - if (.not. library_present(LIBRARY_THERMAL, to_lower(name))) then + if (.not. library_present(LIBRARY_THERMAL, name)) then call fatal_error("Could not find S(a,b) table " // trim(name) & // " in cross_sections.xml file!") end if ! If this S(a,b) table hasn't been encountered yet, we need to add its ! name and alias to the sab_dict - if (.not. sab_dict % has(to_lower(name))) then + if (.not. sab_dict % has(name)) then index_sab = index_sab + 1 mat % i_sab_tables(j) = index_sab - call sab_dict % set(to_lower(name), index_sab) + call sab_dict % set(name, index_sab) else - mat % i_sab_tables(j) = sab_dict % get(to_lower(name)) + mat % i_sab_tables(j) = sab_dict % get(name) end if end do end if @@ -1199,7 +1199,7 @@ contains end if ! If a specific nuclide was specified - word = to_lower(sarray(j)) + word = sarray(j) ! Search through nuclides if (.not. nuclide_dict % has(word)) then @@ -2052,8 +2052,8 @@ contains name = materials(i) % names(j) if (.not. already_read % contains(name)) then - filename = library_path(LIBRARY_NEUTRON, to_lower(name)) - i_nuclide = nuclide_dict % get(to_lower(name)) + filename = library_path(LIBRARY_NEUTRON, name) + i_nuclide = nuclide_dict % get(name) call write_message('Reading ' // trim(name) // ' from ' // & trim(filename), 6) @@ -2089,7 +2089,7 @@ contains if (photon_transport) then if (.not. element_already_read % contains(element)) then ! Read photon interaction data from HDF5 photon library - filename = library_path(LIBRARY_PHOTON, to_lower(element)) + filename = library_path(LIBRARY_PHOTON, element) i_element = element_dict % get(element) call write_message('Reading ' // trim(element) // ' from ' // & trim(filename), 6) @@ -2138,8 +2138,8 @@ contains name = materials(i) % sab_names(j) if (.not. already_read % contains(name)) then - filename = library_path(LIBRARY_THERMAL, to_lower(name)) - i_sab = sab_dict % get(to_lower(name)) + filename = library_path(LIBRARY_THERMAL, name) + i_sab = sab_dict % get(name) call write_message('Reading ' // trim(name) // ' from ' // & trim(filename), 6) @@ -2233,8 +2233,8 @@ contains associate (nuc => nuclides(i_table)) ! Look for WMP data in cross_sections.xml - if (library_present(LIBRARY_WMP, to_lower(nuc % name))) then - filename = library_path(LIBRARY_WMP, to_lower(nuc % name)) + if (library_present(LIBRARY_WMP, nuc % name)) then + filename = library_path(LIBRARY_WMP, nuc % name) else nuc % mp_present = .false. return diff --git a/src/material.cpp b/src/material.cpp index 802a7d495f..9a63760f9c 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -18,6 +18,7 @@ #include "openmc/search.h" #include "openmc/settings.h" #include "openmc/simulation.h" +#include "openmc/string_utils.h" #include "openmc/thermal.h" #include "openmc/xml_interface.h" diff --git a/src/material_header.F90 b/src/material_header.F90 index 0a14096123..0c5a2d7667 100644 --- a/src/material_header.F90 +++ b/src/material_header.F90 @@ -666,7 +666,7 @@ contains call move_alloc(FROM=new_density, TO=m % atom_density) ! Append new nuclide/density - k = nuclide_dict % get(to_lower(name_)) + k = nuclide_dict % get(name_) m % nuclide(n + 1) = k m % atom_density(n + 1) = density m % density = m % density + density @@ -810,7 +810,7 @@ contains do i = 1, n ! Convert C string to Fortran string call c_f_pointer(name(i), string, [10]) - name_ = to_lower(to_f_string(string)) + name_ = to_f_string(string) if (.not. nuclide_dict % has(name_)) then err = openmc_load_nuclide(string) diff --git a/src/nuclide_header.F90 b/src/nuclide_header.F90 index 75254cda1f..71cd3fba4a 100644 --- a/src/nuclide_header.F90 +++ b/src/nuclide_header.F90 @@ -707,8 +707,8 @@ contains name_ = to_f_string(name) if (allocated(nuclides)) then - if (nuclide_dict % has(to_lower(name_))) then - index = nuclide_dict % get(to_lower(name_)) + if (nuclide_dict % has(name_)) then + index = nuclide_dict % get(name_) err = 0 else err = E_DATA @@ -740,8 +740,8 @@ contains name_ = to_f_string(name) err = 0 - if (.not. nuclide_dict % has(to_lower(name_))) then - if (library_present(LIBRARY_NEUTRON, to_lower(name_))) then + if (.not. nuclide_dict % has(name_)) then + if (library_present(LIBRARY_NEUTRON, name_)) then ! allocate extra space in nuclides array n = n_nuclides allocate(new_nuclides(n + 1)) @@ -749,7 +749,7 @@ contains call move_alloc(FROM=new_nuclides, TO=nuclides) n = n + 1 - filename = library_path(LIBRARY_NEUTRON, to_lower(name_)) + filename = library_path(LIBRARY_NEUTRON, name_) ! Open file and make sure version is sufficient file_id = file_open(filename, 'r') @@ -764,7 +764,7 @@ contains call file_close(file_id) ! Add entry to nuclide dictionary - call nuclide_dict % set(to_lower(name_), n) + call nuclide_dict % set(name_, n) n_nuclides = n ! Initialize nuclide grid diff --git a/src/tallies/tally_header.F90 b/src/tallies/tally_header.F90 index f2339d85d5..e103189a2e 100644 --- a/src/tallies/tally_header.F90 +++ b/src/tallies/tally_header.F90 @@ -838,7 +838,7 @@ contains do i = 1, n ! Convert C string to Fortran string call c_f_pointer(nuclides(i), string, [10]) - nuclide_ = to_lower(to_f_string(string)) + nuclide_ = to_f_string(string) select case (nuclide_) case ('total')