Add openmc_filter_set_type

This commit is contained in:
Paul Romano 2017-08-11 11:08:13 -05:00
parent 22f3e0d30e
commit 0b112820c8
5 changed files with 80 additions and 1 deletions

View file

@ -35,4 +35,5 @@ from .core import *
from .nuclide import *
from .material import *
from .cell import *
from .filter import *
from .tally import *

15
openmc/capi/filter.py Normal file
View file

@ -0,0 +1,15 @@
from ctypes import c_int, c_int32, c_double, c_char_p, POINTER
from . import _dll
from .error import _error_handler
__all__ = []
# Tally functions
_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_set_type.argtypes = [c_int32, c_char_p]
_dll.openmc_filter_set_type.restype = c_int
_dll.openmc_filter_set_type.errcheck = _error_handler

View file

@ -19,6 +19,7 @@ module openmc_api
use random_lcg, only: seed, initialize_prng
use tally_header
use tally_filter_header
use tally_filter, only: openmc_filter_set_type
use simulation, only: openmc_run
use string, only: to_f_string
use volume_calc, only: openmc_calculate_volumes
@ -31,6 +32,7 @@ module openmc_api
public :: openmc_cell_set_temperature
public :: openmc_extend_filters
public :: openmc_extend_tallies
public :: openmc_filter_set_type
public :: openmc_finalize
public :: openmc_find
public :: openmc_get_cell

View file

@ -27,6 +27,7 @@ module error
integer(C_INT), public, bind(C) :: E_TALLY_INVALID_ID = -12
integer(C_INT), public, bind(C) :: E_INVALID_SIZE = -13
integer(C_INT), public, bind(C) :: E_CELL_NO_MATERIAL = -14
integer(C_INT), public, bind(C) :: E_ALREADY_ALLOCATED = -15
! Warning codes
integer(C_INT), public, bind(C) :: W_BELOW_MIN_BOUND = 1

View file

@ -5,11 +5,12 @@ module tally_filter
use algorithm, only: binary_search
use constants, only: ONE, NO_BIN_FOUND, FP_PRECISION, ERROR_REAL
use dict_header, only: DictIntInt
use error
use geometry_header
use hdf5_interface
use particle_header, only: Particle
use surface_header
use string, only: to_str
use string, only: to_str, to_f_string
use tally_filter_header
! Inherit other filters
@ -1144,4 +1145,63 @@ contains
end do
end subroutine find_offset
!===============================================================================
! C API FUNCTIONS
!===============================================================================
function openmc_filter_set_type(index, type) result(err) bind(C)
! Set the type of a filter
integer(C_INT32_T), value, intent(in) :: index
character(kind=C_CHAR), intent(in) :: type(*)
integer(C_INT) :: err
character(:), allocatable :: type_
type_ = to_f_string(type)
err = 0
if (index >= 1 .and. index <= n_filters) then
if (allocated(filters(index) % obj)) then
err = E_ALREADY_ALLOCATED
else
select case (type_)
case ('azimuthal')
allocate(AzimuthalFilter :: filters(index) % obj)
case ('cell')
allocate(CellFilter :: filters(index) % obj)
case ('cellborn')
allocate(CellbornFilter :: filters(index) % obj)
case ('cellfrom')
allocate(CellfromFilter :: filters(index) % obj)
case ('delayedgroup')
allocate(DelayedGroupFilter :: filters(index) % obj)
case ('distribcell')
allocate(DistribcellFilter :: filters(index) % obj)
case ('energy')
allocate(EnergyFilter :: filters(index) % obj)
case ('energyout')
allocate(EnergyoutFilter :: filters(index) % obj)
case ('energyfunction')
allocate(EnergyFunctionFilter :: filters(index) % obj)
case ('material')
allocate(MaterialFilter :: filters(index) % obj)
case ('mesh')
allocate(MeshFilter :: filters(index) % obj)
case ('mu')
allocate(MuFilter :: filters(index) % obj)
case ('polar')
allocate(PolarFilter :: filters(index) % obj)
case ('surface')
allocate(SurfaceFilter :: filters(index) % obj)
case ('universe')
allocate(UniverseFilter :: filters(index) % obj)
case default
err = E_UNASSIGNED
end select
end if
else
err = E_OUT_OF_BOUNDS
end if
end function openmc_filter_set_type
end module tally_filter