From 20331519beb2e940fff582f46423e4635bc61684 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Sat, 29 Jul 2017 15:15:39 -0500 Subject: [PATCH] Add TallyView.nuclides --- openmc/capi/tally.py | 12 ++++++++++++ src/api.F90 | 27 ++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/openmc/capi/tally.py b/openmc/capi/tally.py index f60d94e92..b7139bcb6 100644 --- a/openmc/capi/tally.py +++ b/openmc/capi/tally.py @@ -16,6 +16,10 @@ _dll.openmc_get_tally.errcheck = _error_handler _dll.openmc_tally_id.argtypes = [c_int32, POINTER(c_int32)] _dll.openmc_tally_id.restype = c_int _dll.openmc_tally_id.errcheck = _error_handler +_dll.openmc_tally_nuclides.argtypes = [ + c_int32, POINTER(POINTER(c_int)), POINTER(c_int)] +_dll.openmc_tally_nuclides.restype = c_int +_dll.openmc_tally_nuclides.errcheck = _error_handler _dll.openmc_tally_results.argtypes = [ c_int32, POINTER(POINTER(c_double)), POINTER(c_int*3)] _dll.openmc_tally_results.restype = c_int @@ -39,6 +43,14 @@ class TallyView(object): _dll.openmc_tally_id(self._index, tally_id) return tally_id.value + @property + def nuclides(self): + nucs = POINTER(c_int)() + n = c_int() + _dll.openmc_tally_nuclides(self._index, nucs, n) + return [NuclideView(nucs[i]).name if nucs[i] > 0 else 'total' + for i in range(n.value)] + @property def results(self): """Get tally results array diff --git a/src/api.F90 b/src/api.F90 index 6d50ca51e..cd8a8a064 100644 --- a/src/api.F90 +++ b/src/api.F90 @@ -44,6 +44,7 @@ module openmc_api public :: openmc_reset public :: openmc_run public :: openmc_tally_id + public :: openmc_tally_nuclides public :: openmc_tally_results ! Error codes @@ -335,7 +336,7 @@ contains end function openmc_get_tally !=============================================================================== -! OPENMC_LOAD_LOAD loads a nuclide from the cross section library +! OPENMC_LOAD_NUCLIDE loads a nuclide from the cross section library !=============================================================================== function openmc_load_nuclide(name) result(err) bind(C) @@ -657,6 +658,30 @@ contains end if end function openmc_tally_id +!=============================================================================== +! OPENMC_TALLY_NUCLIDES returns the list of nuclides assigned to a tally +!=============================================================================== + + function openmc_tally_nuclides(index, ptr, n) result(err) bind(C) + integer(C_INT32_T), value :: index + type(C_PTR), intent(out) :: ptr + integer(C_INT), intent(out) :: n + integer(C_INT) :: err + + err = E_UNASSIGNED + if (index >= 1 .and. index <= size(tallies)) then + associate (t => tallies(index)) + if (allocated(t % nuclide_bins)) then + ptr = C_LOC(t % nuclide_bins(1)) + n = size(t % nuclide_bins) + err = 0 + end if + end associate + else + err = E_OUT_OF_BOUNDS + end if + end function openmc_tally_nuclides + !=============================================================================== ! OPENMC_TALLY_RESULTS returns a pointer to a tally results array along with its ! shape. This allows a user to obtain in-memory tally results from Python