mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 13:45:36 -04:00
Expand C API, targeting FETs
This commit is contained in:
parent
e3f0bff0f0
commit
411fd288ea
4 changed files with 127 additions and 5 deletions
|
|
@ -17,6 +17,7 @@ extern "C" {
|
|||
};
|
||||
|
||||
int openmc_calculate_volumes();
|
||||
int openmc_cell_filter_get_bins(int32_t index, int32_t** cells, int32_t* n);
|
||||
int openmc_cell_get_fill(int32_t index, int* type, int32_t** indices, int32_t* n);
|
||||
int openmc_cell_get_id(int32_t index, int32_t* id);
|
||||
int openmc_cell_set_fill(int32_t index, int type, int32_t n, const int32_t* indices);
|
||||
|
|
|
|||
|
|
@ -17,11 +17,16 @@ from .mesh import Mesh
|
|||
__all__ = ['Filter', 'AzimuthalFilter', 'CellFilter',
|
||||
'CellbornFilter', 'CellfromFilter', 'DistribcellFilter',
|
||||
'DelayedGroupFilter', 'EnergyFilter', 'EnergyoutFilter',
|
||||
'EnergyFunctionFilter', 'MaterialFilter', 'MeshFilter',
|
||||
'MeshSurfaceFilter', 'MuFilter', 'PolarFilter', 'SurfaceFilter',
|
||||
'UniverseFilter', 'filters']
|
||||
'EnergyFunctionFilter', 'LegendreFilter', 'MaterialFilter', 'MeshFilter',
|
||||
'MeshSurfaceFilter', 'MuFilter', 'PolarFilter', 'SphericalHarmonicsFilter',
|
||||
'SpatialLegendreFilter', 'SurfaceFilter',
|
||||
'UniverseFilter', 'ZernikeFilter', 'filters']
|
||||
|
||||
# Tally functions
|
||||
_dll.openmc_cell_filter_get_bins.argtypes = [
|
||||
c_int32, POINTER(POINTER(c_int32)), POINTER(c_int32)]
|
||||
_dll.openmc_cell_filter_get_bins.restype = c_int
|
||||
_dll.openmc_cell_filter_get_bins.errcheck = _error_handler
|
||||
_dll.openmc_energy_filter_get_bins.argtypes = [
|
||||
c_int32, POINTER(POINTER(c_double)), POINTER(c_int32)]
|
||||
_dll.openmc_energy_filter_get_bins.restype = c_int
|
||||
|
|
@ -47,6 +52,12 @@ _dll.openmc_filter_set_type.errcheck = _error_handler
|
|||
_dll.openmc_get_filter_index.argtypes = [c_int32, POINTER(c_int32)]
|
||||
_dll.openmc_get_filter_index.restype = c_int
|
||||
_dll.openmc_get_filter_index.errcheck = _error_handler
|
||||
_dll.openmc_legendre_filter_get_order.argtypes = [c_int32, POINTER(c_int)]
|
||||
_dll.openmc_legendre_filter_get_order.restype = c_int
|
||||
_dll.openmc_legendre_filter_get_order.errcheck = _error_handler
|
||||
_dll.openmc_legendre_filter_set_order.argtypes = [c_int32, c_int]
|
||||
_dll.openmc_legendre_filter_set_order.restype = c_int
|
||||
_dll.openmc_legendre_filter_set_order.errcheck = _error_handler
|
||||
_dll.openmc_material_filter_get_bins.argtypes = [
|
||||
c_int32, POINTER(POINTER(c_int32)), POINTER(c_int32)]
|
||||
_dll.openmc_material_filter_get_bins.restype = c_int
|
||||
|
|
@ -66,7 +77,24 @@ _dll.openmc_meshsurface_filter_get_mesh.errcheck = _error_handler
|
|||
_dll.openmc_meshsurface_filter_set_mesh.argtypes = [c_int32, c_int32]
|
||||
_dll.openmc_meshsurface_filter_set_mesh.restype = c_int
|
||||
_dll.openmc_meshsurface_filter_set_mesh.errcheck = _error_handler
|
||||
|
||||
_dll.openmc_spatial_legendre_filter_get_order.argtypes = [c_int32, POINTER(c_int)]
|
||||
_dll.openmc_spatial_legendre_filter_get_order.restype = c_int
|
||||
_dll.openmc_spatial_legendre_filter_get_order.errcheck = _error_handler
|
||||
_dll.openmc_spatial_legendre_filter_set_order.argtypes = [c_int32, c_int]
|
||||
_dll.openmc_spatial_legendre_filter_set_order.restype = c_int
|
||||
_dll.openmc_spatial_legendre_filter_set_order.errcheck = _error_handler
|
||||
_dll.openmc_sphharm_filter_get_order.argtypes = [c_int32, POINTER(c_int)]
|
||||
_dll.openmc_sphharm_filter_get_order.restype = c_int
|
||||
_dll.openmc_sphharm_filter_get_order.errcheck = _error_handler
|
||||
_dll.openmc_sphharm_filter_set_order.argtypes = [c_int32, c_int]
|
||||
_dll.openmc_sphharm_filter_set_order.restype = c_int
|
||||
_dll.openmc_sphharm_filter_set_order.errcheck = _error_handler
|
||||
_dll.openmc_zernike_filter_get_order.argtypes = [c_int32, POINTER(c_int)]
|
||||
_dll.openmc_zernike_filter_get_order.restype = c_int
|
||||
_dll.openmc_zernike_filter_get_order.errcheck = _error_handler
|
||||
_dll.openmc_zernike_filter_set_order.argtypes = [c_int32, c_int]
|
||||
_dll.openmc_zernike_filter_set_order.restype = c_int
|
||||
_dll.openmc_zernike_filter_set_order.errcheck = _error_handler
|
||||
|
||||
class Filter(_FortranObjectWithID):
|
||||
__instances = WeakValueDictionary()
|
||||
|
|
@ -150,6 +178,13 @@ class AzimuthalFilter(Filter):
|
|||
class CellFilter(Filter):
|
||||
filter_type = 'cell'
|
||||
|
||||
@property
|
||||
def bins(self):
|
||||
cells = POINTER(c_int32)()
|
||||
n = c_int32()
|
||||
_dll.openmc_cell_filter_get_bins(self._index, cells, n)
|
||||
return as_array(cells, (n.value,))
|
||||
|
||||
|
||||
class CellbornFilter(Filter):
|
||||
filter_type = 'cellborn'
|
||||
|
|
@ -171,6 +206,20 @@ class EnergyFunctionFilter(Filter):
|
|||
filter_type = 'energyfunction'
|
||||
|
||||
|
||||
class LegendreFilter(Filter):
|
||||
filter_type = 'legendre'
|
||||
|
||||
@property
|
||||
def order(self):
|
||||
temp_order = c_int()
|
||||
_dll.openmc_legendre_filter_get_order(self._index, temp_order)
|
||||
return temp_order.value
|
||||
|
||||
@order.setter
|
||||
def order(self, order):
|
||||
_dll.openmc_legendre_filter_set_order(self._index, order)
|
||||
|
||||
|
||||
class MaterialFilter(Filter):
|
||||
filter_type = 'material'
|
||||
|
||||
|
|
@ -241,6 +290,34 @@ class PolarFilter(Filter):
|
|||
filter_type = 'polar'
|
||||
|
||||
|
||||
class SphericalHarmonicsFilter(Filter):
|
||||
filter_type = 'sphericalharmonics'
|
||||
|
||||
@property
|
||||
def order(self):
|
||||
temp_order = c_int()
|
||||
_dll.openmc_sphharm_filter_get_order(self._index, temp_order)
|
||||
return temp_order.value
|
||||
|
||||
@order.setter
|
||||
def order(self, order):
|
||||
_dll.openmc_sphharm_filter_set_order(self._index, order)
|
||||
|
||||
|
||||
class SpatialLegendreFilter(Filter):
|
||||
filter_type = 'spatiallegendre'
|
||||
|
||||
@property
|
||||
def order(self):
|
||||
temp_order = c_int()
|
||||
_dll.openmc_spatial_legendre_filter_get_order(self._index, temp_order)
|
||||
return temp_order.value
|
||||
|
||||
@order.setter
|
||||
def order(self, order):
|
||||
_dll.openmc_spatial_legendre_filter_set_order(self._index, order)
|
||||
|
||||
|
||||
class SurfaceFilter(Filter):
|
||||
filter_type = 'surface'
|
||||
|
||||
|
|
@ -249,6 +326,20 @@ class UniverseFilter(Filter):
|
|||
filter_type = 'universe'
|
||||
|
||||
|
||||
class ZernikeFilter(Filter):
|
||||
filter_type = 'zernike'
|
||||
|
||||
@property
|
||||
def order(self):
|
||||
temp_order = c_int()
|
||||
_dll.openmc_zernike_filter_get_order(self._index, temp_order)
|
||||
return temp_order.value
|
||||
|
||||
@order.setter
|
||||
def order(self, order):
|
||||
_dll.openmc_zernike_filter_set_order(self._index, order)
|
||||
|
||||
|
||||
_FILTER_TYPE_MAP = {
|
||||
'azimuthal': AzimuthalFilter,
|
||||
'cell': CellFilter,
|
||||
|
|
@ -259,13 +350,17 @@ _FILTER_TYPE_MAP = {
|
|||
'energy': EnergyFilter,
|
||||
'energyout': EnergyoutFilter,
|
||||
'energyfunction': EnergyFunctionFilter,
|
||||
'legendre': LegendreFilter,
|
||||
'material': MaterialFilter,
|
||||
'mesh': MeshFilter,
|
||||
'meshsurface': MeshSurfaceFilter,
|
||||
'mu': MuFilter,
|
||||
'polar': PolarFilter,
|
||||
'sphericalharmoics': SphericalHarmonicsFilter,
|
||||
'spatiallegendre': SpatialLegendreFilter,
|
||||
'surface': SurfaceFilter,
|
||||
'universe': UniverseFilter,
|
||||
'zernike': ZernikeFilter
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ module openmc_api
|
|||
|
||||
private
|
||||
public :: openmc_calculate_volumes
|
||||
public :: openmc_cell_filter_get_bins
|
||||
public :: openmc_cell_get_id
|
||||
public :: openmc_cell_get_fill
|
||||
public :: openmc_cell_set_fill
|
||||
|
|
|
|||
|
|
@ -14,13 +14,14 @@ module tally_filter_cell
|
|||
|
||||
implicit none
|
||||
private
|
||||
public :: openmc_cell_filter_get_bins
|
||||
|
||||
!===============================================================================
|
||||
! CELLFILTER specifies which geometric cells tally events reside in.
|
||||
!===============================================================================
|
||||
|
||||
type, public, extends(TallyFilter) :: CellFilter
|
||||
integer, allocatable :: cells(:)
|
||||
integer(C_INT32_T), allocatable :: cells(:)
|
||||
type(DictIntInt) :: map
|
||||
contains
|
||||
procedure :: from_xml
|
||||
|
|
@ -116,4 +117,28 @@ contains
|
|||
label = "Cell " // to_str(cells(this % cells(bin)) % id)
|
||||
end function text_label_cell
|
||||
|
||||
!===============================================================================
|
||||
! C API FUNCTIONS
|
||||
!===============================================================================
|
||||
|
||||
function openmc_cell_filter_get_bins(index, cells, n) result(err) bind(C)
|
||||
! Return the cells associated with a cell filter
|
||||
integer(C_INT32_T), value :: index
|
||||
type(C_PTR), intent(out) :: cells
|
||||
integer(C_INT32_T), intent(out) :: n
|
||||
integer(C_INT) :: err
|
||||
|
||||
err = verify_filter(index)
|
||||
if (err == 0) then
|
||||
select type (f => filters(index) % obj)
|
||||
type is (CellFilter)
|
||||
cells = C_LOC(f % cells)
|
||||
n = size(f % cells)
|
||||
class default
|
||||
err = E_INVALID_TYPE
|
||||
call set_errmsg("Tried to get cells from a non-cell filter.")
|
||||
end select
|
||||
end if
|
||||
end function openmc_cell_filter_get_bins
|
||||
|
||||
end module tally_filter_cell
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue