diff --git a/openmc/capi/__init__.py b/openmc/capi/__init__.py index b3b5731c1a..6ae49c4ff8 100644 --- a/openmc/capi/__init__.py +++ b/openmc/capi/__init__.py @@ -1,17 +1,19 @@ """Provides bindings to C functions defined by OpenMC shared library. When the :mod:`openmc` package is imported, the OpenMC shared library is -automatically loaded. Calls to the OpenMC library can then be made, for example: +automatically loaded. Calls to the OpenMC library can then be via functions or +objects in the :mod:`openmc.capi` subpackage, for example: .. code-block:: python openmc.capi.init() openmc.capi.run() + openmc.capi.finalize() """ from contextlib import contextmanager -from ctypes import CDLL, c_int, c_int32, c_double, c_char_p, POINTER +from ctypes import CDLL, c_int, c_int32, c_double, POINTER import sys from warnings import warn @@ -38,8 +40,6 @@ except OSError: _available = False - - class GeometryError(Exception): pass @@ -135,6 +135,10 @@ def find(xyz, rtype='cell'): return (uid.value if uid != 0 else None), instance.value +def hard_reset(): + _dll.openmc_hard_reset() + + def init(intracomm=None): """Initialize OpenMC @@ -185,7 +189,6 @@ def run(): _dll.openmc_run() - @contextmanager def run_in_memory(intracomm=None): """Provides context manager for calling OpenMC shared library functions. @@ -220,6 +223,7 @@ if _available: POINTER(c_double*3), c_int, POINTER(c_int32), POINTER(c_int32)] _dll.openmc_find.restype = c_int _dll.openmc_find.errcheck = _error_handler + _dll.openmc_hard_reset.restype = None _dll.openmc_init.argtypes = [POINTER(c_int)] _dll.openmc_init.restype = None _dll.openmc_get_keff.argtypes = [POINTER(c_double*2)] diff --git a/src/api.F90 b/src/api.F90 index 77b3dd576e..2c1fc968bc 100644 --- a/src/api.F90 +++ b/src/api.F90 @@ -15,7 +15,7 @@ module openmc_api use input_xml, only: assign_0K_elastic_scattering, check_data_version use particle_header, only: Particle use plot, only: openmc_plot_geometry - use random_lcg, only: seed + use random_lcg, only: seed, initialize_prng use simulation, only: openmc_run use volume_calc, only: openmc_calculate_volumes @@ -32,6 +32,7 @@ module openmc_api public :: openmc_get_material public :: openmc_get_nuclide public :: openmc_get_tally + public :: openmc_hard_reset public :: openmc_init public :: openmc_load_nuclide public :: openmc_material_add_nuclide @@ -334,6 +335,24 @@ contains end if end function openmc_get_tally +!=============================================================================== +! OPENMC_HARD_RESET reset tallies and timers as well as the pseudorandom +! generator state +!=============================================================================== + + subroutine openmc_hard_reset() bind(C) + ! Reset all tallies and timers + call openmc_reset() + + ! Reset total generations and keff guess + keff = ONE + total_gen = 0 + + ! Reset the random number generator state + seed = 1_8 + call initialize_prng() + end subroutine openmc_hard_reset + !=============================================================================== ! OPENMC_LOAD_NUCLIDE loads a nuclide from the cross section library !=============================================================================== @@ -602,7 +621,7 @@ contains end function openmc_nuclide_name !=============================================================================== -! OPENMC_RESET resets all tallies +! OPENMC_RESET resets tallies and timers !=============================================================================== subroutine openmc_reset() bind(C)