From 9d737ea69e1973b5bf1469235ff815847aafef13 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 14 Aug 2017 14:53:57 -0500 Subject: [PATCH] Add filter get/set id C API functions --- openmc/capi/filter.py | 6 +++++ src/api.F90 | 2 ++ src/tallies/tally_filter_header.F90 | 37 +++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/openmc/capi/filter.py b/openmc/capi/filter.py index aea968dad..0525378f9 100644 --- a/openmc/capi/filter.py +++ b/openmc/capi/filter.py @@ -13,6 +13,12 @@ _dll.openmc_energy_filter_set_bins.errcheck = _error_handler _dll.openmc_extend_filters.argtypes = [c_int32, POINTER(c_int32), POINTER(c_int32)] _dll.openmc_extend_filters.restype = c_int _dll.openmc_extend_filters.errcheck = _error_handler +_dll.openmc_filter_get_id.argtypes = [c_int32, POINTER(c_int32)] +_dll.openmc_filter_get_id.restype = c_int +_dll.openmc_filter_get_id.errcheck = _error_handler +_dll.openmc_filter_set_id.argtypes = [c_int32, c_int32] +_dll.openmc_filter_set_id.restype = c_int +_dll.openmc_filter_set_id.errcheck = _error_handler _dll.openmc_filter_set_type.argtypes = [c_int32, c_char_p] _dll.openmc_filter_set_type.restype = c_int _dll.openmc_filter_set_type.errcheck = _error_handler diff --git a/src/api.F90 b/src/api.F90 index a6dc6aba8..200d3704c 100644 --- a/src/api.F90 +++ b/src/api.F90 @@ -33,6 +33,8 @@ module openmc_api public :: openmc_energy_filter_set_bins public :: openmc_extend_filters public :: openmc_extend_tallies + public :: openmc_filter_get_id + public :: openmc_filter_set_id public :: openmc_filter_set_type public :: openmc_finalize public :: openmc_find diff --git a/src/tallies/tally_filter_header.F90 b/src/tallies/tally_filter_header.F90 index b499a74ab..f87101dfc 100644 --- a/src/tallies/tally_filter_header.F90 +++ b/src/tallies/tally_filter_header.F90 @@ -4,6 +4,7 @@ module tally_filter_header use constants, only: MAX_LINE_LEN use dict_header, only: DictIntInt + use error use particle_header, only: Particle use stl_vector, only: VectorInt, VectorReal @@ -12,6 +13,8 @@ module tally_filter_header implicit none private public :: openmc_extend_filters + public :: openmc_filter_get_id + public :: openmc_filter_set_id !=============================================================================== ! TALLYFILTERMATCH stores every valid bin and weight for a filter @@ -154,4 +157,38 @@ contains err = 0 end function openmc_extend_filters + + function openmc_filter_get_id(index, id) result(err) bind(C) + ! Return the ID of a filter + integer(C_INT32_T), value :: index + integer(C_INT32_T), intent(out) :: id + integer(C_INT) :: err + + if (index >= 1 .and. index <= n_filters) then + id = filters(index) % obj % id + err = 0 + else + err = E_OUT_OF_BOUNDS + end if + end function openmc_filter_get_id + + + function openmc_filter_set_id(index, id) result(err) bind(C) + ! Set the ID of a filter + integer(C_INT32_T), value, intent(in) :: index + integer(C_INT32_T), value, intent(in) :: id + integer(C_INT) :: err + + if (index >= 1 .and. index <= n_filters) then + if (allocated(filters(index) % obj)) then + filters(index) % obj % id = id + err = 0 + else + err = E_FILTER_NOT_ALLOCATED + end if + else + err = E_OUT_OF_BOUNDS + end if + end function openmc_filter_set_id + end module tally_filter_header