add_filters -> openmc_extend_filters

This commit is contained in:
Paul Romano 2017-08-10 21:53:24 -05:00
parent 6de7b8b130
commit c7985aa269
5 changed files with 58 additions and 45 deletions

View file

@ -18,6 +18,7 @@ module openmc_api
use plot, only: openmc_plot_geometry
use random_lcg, only: seed, initialize_prng
use tally_header
use tally_filter_header
use simulation, only: openmc_run
use string, only: to_f_string
use volume_calc, only: openmc_calculate_volumes
@ -28,6 +29,8 @@ module openmc_api
public :: openmc_calculate_volumes
public :: openmc_cell_get_id
public :: openmc_cell_set_temperature
public :: openmc_extend_filters
public :: openmc_extend_tallies
public :: openmc_finalize
public :: openmc_find
public :: openmc_get_cell

View file

@ -383,10 +383,10 @@ contains
n_cmfd_filters = merge(5, 3, energy_filters)
! Extend filters array so we can add CMFD filters
call add_filters(n_cmfd_filters)
err = openmc_extend_filters(n_cmfd_filters, i_start, i_end)
! Set up mesh filter
i_filt = n_user_filters + 1
i_filt = i_start
allocate(MeshFilter :: filters(i_filt) % obj)
select type (filt => filters(i_filt) % obj)
type is (MeshFilter)

View file

@ -2738,7 +2738,9 @@ contains
n_user_filters = size(node_filt_list)
! Allocate filters array
if (n_user_filters > 0) call add_filters(n_user_filters)
if (n_user_filters > 0) then
err = openmc_extend_filters(n_user_filters)
end if
! Check for user tallies
n_user_tallies = size(node_tal_list)
@ -3877,13 +3879,13 @@ contains
! Extend the filters array so we can add a surface filter and
! mesh filter
call add_filters(2)
err = openmc_extend_filters(2, i_start, i_end)
! Increment number of user filters
n_user_filters = n_user_filters + 2
! Get index of the new mesh filter
i_filt = n_user_filters - 1
i_filt = i_start
! Duplicate the mesh filter since other tallies might use this
! filter and we need to change the dimension
@ -3897,13 +3899,13 @@ contains
! currents coming into and out of the boundary mesh cells.
filt % n_bins = product(m % dimension + 1)
! Add filter to dictionary
call filter_dict % add_key(filt % id, i_filt)
! Add filter to dictionary
call filter_dict % add_key(filt % id, i_filt)
end select
t % filter(t % find_filter(FILTER_MESH)) = i_filt
! Get index of the new surface filter
i_filt = n_user_filters
i_filt = i_end
! Add surface filter
allocate(SurfaceFilter :: filters(i_filt) % obj)

View file

@ -1144,34 +1144,4 @@ contains
end do
end subroutine find_offset
!===============================================================================
! ADD_FILTERS creates or extends the filters array
!===============================================================================
subroutine add_filters(n)
integer, intent(in) :: n ! number of filters to add
integer :: i ! loop counter
type(TallyFilterContainer), allocatable :: temp(:) ! temporary filters
if (n_filters == 0) then
! Allocate filters array
allocate(filters(n))
else
! Move filters to temporary array
allocate(temp(n_filters + n))
do i = 1, n_filters
call move_alloc(filters(i) % obj, temp(i) % obj)
end do
! Move filters back from temporary array to filters array
call move_alloc(temp, filters)
end if
! Set n_filters
n_filters = size(filters)
end subroutine add_filters
end module tally_filter

View file

@ -10,12 +10,14 @@ module tally_filter_header
use hdf5
implicit none
private
public :: openmc_extend_filters
!===============================================================================
! TALLYFILTERMATCH stores every valid bin and weight for a filter
!===============================================================================
type TallyFilterMatch
type, public :: TallyFilterMatch
! Index of the bin and weight being used in the current filter combination
integer :: i_bin
type(VectorInt) :: bins
@ -31,7 +33,7 @@ module tally_filter_header
! should score to the tally.
!===============================================================================
type, abstract :: TallyFilter
type, public, abstract :: TallyFilter
integer :: id
integer :: n_bins = 0
contains
@ -93,18 +95,18 @@ module tally_filter_header
! TallyFilters
!===============================================================================
type TallyFilterContainer
type, public :: TallyFilterContainer
class(TallyFilter), allocatable :: obj
end type TallyFilterContainer
integer :: n_filters = 0 ! # of filters
integer(C_INT32_T), public, bind(C) :: n_filters = 0 ! # of filters
type(TallyFilterContainer), allocatable, target :: filters(:)
type(TallyFilterMatch), allocatable :: filter_matches(:)
type(TallyFilterContainer), public, allocatable, target :: filters(:)
type(TallyFilterMatch), public, allocatable :: filter_matches(:)
!$omp threadprivate(filter_matches)
! Dictionary that maps user IDs to indices in 'filters'
type(DictIntInt) :: filter_dict
type(DictIntInt), public :: filter_dict
contains
@ -116,4 +118,40 @@ contains
class(TallyFilter), intent(inout) :: this
end subroutine filter_initialize
!===============================================================================
! C API FUNCTIONS
!===============================================================================
function openmc_extend_filters(n, index_start, index_end) result(err) bind(C)
! Creates or extends the filters array
integer(C_INT32_T), value, intent(in) :: n
integer(C_INT32_T), optional, intent(out) :: index_start
integer(C_INT32_T), optional, intent(out) :: index_end
integer(C_INT) :: err
integer :: i ! loop counter
type(TallyFilterContainer), allocatable :: temp(:) ! temporary filters
if (n_filters == 0) then
! Allocate filters array
allocate(filters(n))
else
! Move filters to temporary array
allocate(temp(n_filters + n))
do i = 1, n_filters
call move_alloc(filters(i) % obj, temp(i) % obj)
end do
! Move filters back from temporary array to filters array
call move_alloc(temp, filters)
end if
! Return indices in filters array
if (present(index_start)) index_start = n_filters + 1
if (present(index_end)) index_end = n_filters + n
n_filters = n_filters + n
err = 0
end function openmc_extend_filters
end module tally_filter_header