Remove nuclide_dict from Fortran side

This commit is contained in:
Paul Romano 2019-01-28 06:47:33 -06:00
parent b25feff0e7
commit 2ffbb6ea26
8 changed files with 39 additions and 28 deletions

View file

@ -163,7 +163,7 @@ class Material(_FortranObjectWithID):
_dll.openmc_material_get_densities(self._index, nuclides, densities, n)
# Convert to appropriate types and return
nuclide_list = [Nuclide(nuclides[i]).name for i in range(n.value)]
nuclide_list = [Nuclide(nuclides[i] + 1).name for i in range(n.value)]
density_array = as_array(densities, (n.value,))
return nuclide_list, density_array

View file

@ -731,14 +731,15 @@ contains
word = sarray(j)
! Search through nuclides
if (.not. nuclide_dict % has(word)) then
k = nuclide_map_get(to_c_string(word))
if (k == -1) then
call fatal_error("Could not find the nuclide " &
// trim(word) // " specified in tally " &
// trim(to_str(t % id)) // " in any material.")
end if
! Set bin to index in nuclides array
t % nuclide_bins(j) = nuclide_dict % get(word)
t % nuclide_bins(j) = k
end do
! Set number of nuclide bins

View file

@ -899,7 +899,7 @@ openmc_get_material_index(int32_t id, int32_t* index)
set_errmsg("No material exists with ID=" + std::to_string(id) + ".");
return OPENMC_E_INVALID_ID;
} else {
*index = it->second;
*index = it->second + 1;
return 0;
}
}
@ -1097,8 +1097,8 @@ openmc_material_set_volume(int32_t index, double volume)
extern "C" int
openmc_extend_materials(int32_t n, int32_t* index_start, int32_t* index_end)
{
if (index_start) *index_start = model::materials.size();
if (index_end) *index_end = model::materials.size() + n - 1;
if (index_start) *index_start = model::materials.size() + 1;
if (index_end) *index_end = model::materials.size() + n;
for (int32_t i = 0; i < n; i++) {
model::materials.push_back(new Material());
}

View file

@ -992,7 +992,17 @@ extern "C" bool multipole_in_range(Nuclide* nuc, double E)
E <= nuc->multipole_->E_max_;
}
extern "C" void nuclides_clear() { data::nuclides.clear(); }
extern "C" void nuclides_clear()
{
data::nuclides.clear();
data::nuclide_map.clear();
}
extern "C" int nuclide_map_get(const char* name)
{
auto it = data::nuclide_map.find(name);
return it == data::nuclide_map.end() ? -1 : it->second + 1;
}
extern "C" NuclideMicroXS* micro_xs_ptr();
extern "C" ElementMicroXS* micro_photon_xs_ptr();

View file

@ -5,7 +5,7 @@ module nuclide_header
use algorithm, only: sort, find, binary_search
use constants
use dict_header, only: DictIntInt, DictCharInt
use dict_header, only: DictIntInt
use endf, only: reaction_name, is_fission, is_disappearance, &
is_inelastic_scatter
use endf_header, only: Function1D, Polynomial, Tabulated1D
@ -150,7 +150,6 @@ module nuclide_header
! Nuclear data for each nuclide
type(Nuclide), allocatable, target :: nuclides(:)
integer(C_INT), bind(C) :: n_nuclides
type(DictCharInt) :: nuclide_dict
! Cross section caches
type(NuclideMicroXS), allocatable, target :: micro_xs(:) ! Cache for each nuclide
@ -213,6 +212,12 @@ module nuclide_header
real(C_DOUBLE), value :: E
real(C_DOUBLE) :: q
end function
function nuclide_map_get(name) result(idx) bind(C)
import C_CHAR, C_INT
character(kind=C_CHAR), intent(in) :: name(*)
integer(C_INT) :: idx
end function
end interface
contains
@ -650,7 +655,6 @@ contains
end if
n_nuclides = 0
call nuclide_dict % clear()
call library_clear()
end subroutine free_memory_nuclide
@ -670,11 +674,10 @@ contains
! Copy array of C_CHARs to normal Fortran string
name_ = to_f_string(name)
err = 0
if (allocated(nuclides)) then
if (nuclide_dict % has(name_)) then
index = nuclide_dict % get(name_)
err = 0
else
index = nuclide_map_get(name)
if (index == -1) then
err = E_DATA
call set_errmsg("No nuclide named '" // trim(name_) // &
"' has been loaded.")

View file

@ -3,12 +3,9 @@ module photon_header
use, intrinsic :: ISO_C_BINDING
use constants
use dict_header, only: DictCharInt
integer :: n_elements ! Number of photon cross section tables
type(DictCharInt) :: element_dict
!===============================================================================
! ELEMENTMICROXS contains cached microscopic photon cross sections for a
! particular element at the current energy
@ -42,7 +39,6 @@ contains
! Deallocate photon cross section data
n_elements = 0
call element_dict % clear()
end subroutine free_memory_photon
function micro_photon_xs_ptr() result(ptr) bind(C)

View file

@ -1,10 +1,10 @@
module tally_derivative_header
use constants
use dict_header, only: DictIntInt, EMPTY
use dict_header, only: DictIntInt
use error, only: fatal_error
use nuclide_header, only: nuclide_dict
use string, only: to_str, to_lower
use nuclide_header, only: nuclide_map_get
use string, only: to_str, to_lower, to_c_string
use xml_interface
implicit none
@ -74,9 +74,8 @@ contains
this % variable = DIFF_NUCLIDE_DENSITY
call get_node_value(node, "nuclide", word)
word = trim(to_lower(word))
val = nuclide_dict % get(word)
if (val == EMPTY) then
val = nuclide_map_get(to_c_string(word))
if (val == -1) then
call fatal_error("Could not find the nuclide " &
// trim(word) // " specified in derivative " &
// trim(to_str(this % id)) // " in any material.")

View file

@ -7,10 +7,10 @@ module tally_header
use dict_header, only: DictIntInt
use hdf5_interface, only: HID_T, HSIZE_T
use message_passing, only: n_procs, master
use nuclide_header, only: nuclide_dict
use nuclide_header, only: nuclide_map_get
use settings, only: reduce_tallies, run_mode
use stl_vector, only: VectorInt
use string, only: to_lower, to_f_string, str_to_int, to_str
use string, only: to_lower, to_f_string, str_to_int, to_str, to_c_string
use tally_filter_header, only: TallyFilterContainer, filters, n_filters
use tally_filter
use trigger_header, only: TriggerObject
@ -825,6 +825,7 @@ contains
integer(C_INT) :: err
integer :: i
integer :: idx
character(C_CHAR), pointer :: string(:)
character(len=:, kind=C_CHAR), allocatable :: nuclide_
@ -844,8 +845,9 @@ contains
case ('total')
t % nuclide_bins(i) = -1
case default
if (nuclide_dict % has(nuclide_)) then
t % nuclide_bins(i) = nuclide_dict % get(nuclide_)
idx = nuclide_map_get(to_c_string(nuclide_))
if (idx /= -1) then
t % nuclide_bins(i) = idx
else
err = E_DATA
call set_errmsg("Nuclide '" // trim(to_f_string(string)) // &