2020-06-01 21:19:06 -04:00
|
|
|
from ctypes import c_int, c_int32, c_int64, c_double, c_char_p, c_bool, POINTER
|
2017-09-15 14:04:31 -05:00
|
|
|
|
|
|
|
|
from . import _dll
|
2017-09-27 11:24:33 -05:00
|
|
|
from .core import _DLLGlobal
|
2020-06-01 18:06:31 -04:00
|
|
|
from .error import _error_handler
|
2017-09-15 14:04:31 -05:00
|
|
|
|
|
|
|
|
_RUN_MODES = {1: 'fixed source',
|
|
|
|
|
2: 'eigenvalue',
|
|
|
|
|
3: 'plot',
|
|
|
|
|
4: 'particle restart',
|
|
|
|
|
5: 'volume'}
|
|
|
|
|
|
2017-10-05 12:33:12 -05:00
|
|
|
_dll.openmc_set_seed.argtypes = [c_int64]
|
2018-01-31 17:52:52 -05:00
|
|
|
_dll.openmc_get_seed.restype = c_int64
|
2025-03-05 08:26:38 +09:00
|
|
|
_dll.openmc_set_stride.argtypes = [c_int64]
|
|
|
|
|
_dll.openmc_get_stride.restype = c_int64
|
2020-06-01 21:19:06 -04:00
|
|
|
_dll.openmc_get_n_batches.argtypes = [POINTER(c_int), c_bool]
|
|
|
|
|
_dll.openmc_get_n_batches.restype = c_int
|
|
|
|
|
_dll.openmc_get_n_batches.errcheck = _error_handler
|
|
|
|
|
_dll.openmc_set_n_batches.argtypes = [c_int32, c_bool, c_bool]
|
2020-06-01 18:06:31 -04:00
|
|
|
_dll.openmc_set_n_batches.restype = c_int
|
|
|
|
|
_dll.openmc_set_n_batches.errcheck = _error_handler
|
2017-10-05 12:33:12 -05:00
|
|
|
|
2017-09-15 14:04:31 -05:00
|
|
|
|
2020-03-19 15:21:15 -05:00
|
|
|
class _Settings:
|
2017-09-27 11:24:33 -05:00
|
|
|
# Attributes that are accessed through a descriptor
|
2019-04-11 12:38:36 -04:00
|
|
|
cmfd_run = _DLLGlobal(c_bool, 'cmfd_run')
|
2018-09-20 14:00:32 -04:00
|
|
|
entropy_on = _DLLGlobal(c_bool, 'entropy_on')
|
2017-09-27 11:24:33 -05:00
|
|
|
generations_per_batch = _DLLGlobal(c_int32, 'gen_per_batch')
|
|
|
|
|
inactive = _DLLGlobal(c_int32, 'n_inactive')
|
2020-02-13 14:46:34 +00:00
|
|
|
max_lost_particles = _DLLGlobal(c_int32, 'max_lost_particles')
|
2020-08-24 13:48:21 -05:00
|
|
|
need_depletion_rx = _DLLGlobal(c_bool, 'need_depletion_rx')
|
|
|
|
|
output_summary = _DLLGlobal(c_bool, 'output_summary')
|
2017-09-27 11:24:33 -05:00
|
|
|
particles = _DLLGlobal(c_int64, 'n_particles')
|
2020-08-24 13:48:21 -05:00
|
|
|
rel_max_lost_particles = _DLLGlobal(c_double, 'rel_max_lost_particles')
|
2019-03-06 13:16:34 -05:00
|
|
|
restart_run = _DLLGlobal(c_bool, 'restart_run')
|
2018-09-20 14:33:13 -04:00
|
|
|
run_CE = _DLLGlobal(c_bool, 'run_CE')
|
2018-08-24 11:04:17 -05:00
|
|
|
verbosity = _DLLGlobal(c_int, 'verbosity')
|
2021-09-30 16:34:58 -05:00
|
|
|
event_based = _DLLGlobal(c_bool, 'event_based')
|
2023-06-09 10:47:27 -05:00
|
|
|
weight_windows_on = _DLLGlobal(c_bool, 'weight_windows_on')
|
2017-09-15 14:04:31 -05:00
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def run_mode(self):
|
2018-08-24 11:04:17 -05:00
|
|
|
i = c_int.in_dll(_dll, 'run_mode').value
|
2017-09-15 14:04:31 -05:00
|
|
|
try:
|
|
|
|
|
return _RUN_MODES[i]
|
|
|
|
|
except KeyError:
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
@run_mode.setter
|
|
|
|
|
def run_mode(self, mode):
|
2018-08-24 11:04:17 -05:00
|
|
|
current_idx = c_int.in_dll(_dll, 'run_mode')
|
2017-09-15 14:04:31 -05:00
|
|
|
for idx, mode_value in _RUN_MODES.items():
|
|
|
|
|
if mode_value == mode:
|
|
|
|
|
current_idx.value = idx
|
|
|
|
|
break
|
|
|
|
|
else:
|
2024-04-29 22:45:37 +01:00
|
|
|
raise ValueError(f'Invalid run mode: {mode}')
|
2017-09-15 14:04:31 -05:00
|
|
|
|
2019-03-06 13:16:34 -05:00
|
|
|
@property
|
|
|
|
|
def path_statepoint(self):
|
2023-04-20 12:21:10 -04:00
|
|
|
path = c_char_p.in_dll(_dll, 'path_statepoint_c').value
|
2019-03-06 13:16:34 -05:00
|
|
|
return path.decode()
|
|
|
|
|
|
2017-10-05 12:33:12 -05:00
|
|
|
@property
|
|
|
|
|
def seed(self):
|
2018-01-31 17:52:52 -05:00
|
|
|
return _dll.openmc_get_seed()
|
2017-10-05 12:33:12 -05:00
|
|
|
|
|
|
|
|
@seed.setter
|
|
|
|
|
def seed(self, seed):
|
|
|
|
|
_dll.openmc_set_seed(seed)
|
|
|
|
|
|
2025-03-05 08:26:38 +09:00
|
|
|
@property
|
|
|
|
|
def stride(self):
|
|
|
|
|
return _dll.openmc_get_stride()
|
|
|
|
|
|
|
|
|
|
@stride.setter
|
|
|
|
|
def stride(self, stride):
|
|
|
|
|
_dll.openmc_set_stride(stride)
|
|
|
|
|
|
2020-06-01 21:19:06 -04:00
|
|
|
def set_batches(self, n_batches, set_max_batches=True, add_sp_batch=True):
|
2020-06-10 20:33:11 -04:00
|
|
|
"""Set number of batches or maximum number of batches
|
2020-06-01 18:06:31 -04:00
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
|
----------
|
|
|
|
|
n_batches : int
|
|
|
|
|
Number of batches to simulate
|
2020-06-10 20:33:11 -04:00
|
|
|
set_max_batches : bool
|
|
|
|
|
Whether to set maximum number of batches. If True, the value of
|
2020-06-01 21:19:06 -04:00
|
|
|
`n_max_batches` is overridden, otherwise the value of `n_batches`
|
|
|
|
|
is overridden. Only has an effect when triggers are used
|
2020-06-01 18:06:31 -04:00
|
|
|
add_sp_batch : bool
|
|
|
|
|
Whether to add `n_batches` as a statepoint batch
|
|
|
|
|
|
|
|
|
|
"""
|
2020-06-01 21:19:06 -04:00
|
|
|
_dll.openmc_set_n_batches(n_batches, set_max_batches, add_sp_batch)
|
|
|
|
|
|
|
|
|
|
def get_batches(self, get_max_batches=True):
|
2020-06-11 11:04:20 -04:00
|
|
|
"""Get number of batches or maximum number of batches
|
2020-06-01 21:19:06 -04:00
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
|
----------
|
|
|
|
|
get_max_batches : bool
|
|
|
|
|
Return `n_max_batches` if true, else return `n_batches`. Difference
|
|
|
|
|
arises only if triggers are used.
|
|
|
|
|
|
|
|
|
|
Returns
|
|
|
|
|
-------
|
|
|
|
|
int
|
|
|
|
|
Number of batches to simulate
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
n_batches = c_int()
|
|
|
|
|
_dll.openmc_get_n_batches(n_batches, get_max_batches)
|
|
|
|
|
|
|
|
|
|
return n_batches.value
|
2020-06-01 18:06:31 -04:00
|
|
|
|
2017-09-15 14:04:31 -05:00
|
|
|
|
|
|
|
|
settings = _Settings()
|