mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
Add Python bindings to one_group_xs
This commit is contained in:
parent
e0bcfead80
commit
b615070ad9
2 changed files with 26 additions and 0 deletions
|
|
@ -2,6 +2,9 @@ from collections.abc import Mapping
|
|||
from ctypes import c_int, c_double, c_char_p, POINTER, c_size_t
|
||||
from weakref import WeakValueDictionary
|
||||
|
||||
from numpy.ctypeslib import ndpointer
|
||||
import numpy as np
|
||||
|
||||
from ..exceptions import DataError, AllocationError
|
||||
from . import _dll
|
||||
from .core import _FortranObject
|
||||
|
|
@ -10,6 +13,8 @@ from .error import _error_handler
|
|||
|
||||
__all__ = ['Nuclide', 'nuclides', 'load_nuclide']
|
||||
|
||||
_array_1d_dble = ndpointer(dtype=np.double, ndim=1, flags='CONTIGUOUS')
|
||||
|
||||
# Nuclide functions
|
||||
_dll.openmc_get_nuclide_index.argtypes = [c_char_p, POINTER(c_int)]
|
||||
_dll.openmc_get_nuclide_index.restype = c_int
|
||||
|
|
@ -20,6 +25,8 @@ _dll.openmc_load_nuclide.errcheck = _error_handler
|
|||
_dll.openmc_nuclide_name.argtypes = [c_int, POINTER(c_char_p)]
|
||||
_dll.openmc_nuclide_name.restype = c_int
|
||||
_dll.openmc_nuclide_name.errcheck = _error_handler
|
||||
_dll.openmc_nuclide_one_group_xs.argtypes = [c_int, c_int, _array_1d_dble,
|
||||
_array_1d_dble, c_int, POINTER(c_double)]
|
||||
_dll.nuclides_size.restype = c_size_t
|
||||
|
||||
|
||||
|
|
@ -70,6 +77,13 @@ class Nuclide(_FortranObject):
|
|||
_dll.openmc_nuclide_name(self._index, name)
|
||||
return name.value.decode()
|
||||
|
||||
def one_group_xs(self, MT, energy, flux):
|
||||
energy = np.asarray(energy, dtype=float)
|
||||
flux = np.asarray(flux, dtype=float)
|
||||
xs = c_double()
|
||||
_dll.openmc_nuclide_one_group_xs(self._index, MT, energy, flux, len(flux), xs)
|
||||
return xs.value
|
||||
|
||||
|
||||
class _NuclideMapping(Mapping):
|
||||
"""Provide mapping from nuclide name to index in nuclides array."""
|
||||
|
|
|
|||
|
|
@ -1043,6 +1043,18 @@ openmc_nuclide_name(int index, const char** name)
|
|||
}
|
||||
}
|
||||
|
||||
extern "C" int
|
||||
openmc_nuclide_one_group_xs(int index, int MT, const double* energy, const double* flux, int n, double* xs)
|
||||
{
|
||||
if (index < 0 || index >= data::nuclides.size()) {
|
||||
set_errmsg("Index in nuclides vector is out of bounds.");
|
||||
return OPENMC_E_OUT_OF_BOUNDS;
|
||||
}
|
||||
|
||||
*xs = data::nuclides[index]->one_group_xs(MT, {energy, energy + n + 1}, {flux, flux + n});
|
||||
return 0;
|
||||
}
|
||||
|
||||
void nuclides_clear()
|
||||
{
|
||||
data::nuclides.clear();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue