Skip to content

Commit

Permalink
Break up capi.find into find_cell and find_material
Browse files Browse the repository at this point in the history
  • Loading branch information
paulromano committed Aug 3, 2017
1 parent 745b0b2 commit cd8a297
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
3 changes: 2 additions & 1 deletion docs/source/pythonapi/capi.rst
Expand Up @@ -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
Expand Down
42 changes: 25 additions & 17 deletions openmc/capi/core.py
Expand Up @@ -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))
uid = c_int32()
instance = c_int32()
_dll.openmc_find((c_double*3)(*xyz), 1, uid, instance)
return uid.value, instance.value

# Call openmc_find

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), r_int, uid, instance)
return (uid.value if uid != 0 else None), instance.value
_dll.openmc_find((c_double*3)(*xyz), 2, uid, instance)
return uid.value if uid != 0 else None


def hard_reset():
Expand Down

0 comments on commit cd8a297

Please sign in to comment.