Break up capi.find into find_cell and find_material

This commit is contained in:
Paul Romano 2017-08-03 07:12:37 -05:00
parent 745b0b2d83
commit cd8a297353
2 changed files with 28 additions and 19 deletions

View file

@ -14,7 +14,8 @@ Functions
openmc.capi.calculate_volumes
openmc.capi.finalize
openmc.capi.find
openmc.capi.find_cell
openmc.capi.find_material
openmc.capi.hard_reset
openmc.capi.init
openmc.capi.keff

View file

@ -33,39 +33,47 @@ def finalize():
_dll.openmc_finalize()
def find(xyz, rtype='cell'):
"""Find the cell or material at a given point
def find_cell(xyz):
"""Find the cell at a given point
Parameters
----------
xyz : iterable of float
Cartesian coordinates of position
rtype : {'cell', 'material'}
Whether to return the cell or material ID
Returns
-------
int or None
ID of the cell or material. If 'material' is requested and no
material exists at the given coordinate, None is returned.
int
ID of the cell.
int
If the cell at the given point is repeated in the geometry, this
indicates which instance it is, i.e., 0 would be the first instance.
"""
# Set second argument to openmc_find
if rtype == 'cell':
r_int = 1
elif rtype == 'material':
r_int = 2
else:
raise ValueError('Unknown return type: {}'.format(rtype))
# Call openmc_find
uid = c_int32()
instance = c_int32()
_dll.openmc_find((c_double*3)(*xyz), r_int, uid, instance)
return (uid.value if uid != 0 else None), instance.value
_dll.openmc_find((c_double*3)(*xyz), 1, uid, instance)
return uid.value, instance.value
def find_material(xyz):
"""Find the material at a given point
Parameters
----------
xyz : iterable of float
Cartesian coordinates of position
Returns
-------
int or None
ID of the material or None is no material is found
"""
uid = c_int32()
instance = c_int32()
_dll.openmc_find((c_double*3)(*xyz), 2, uid, instance)
return uid.value if uid != 0 else None
def hard_reset():