2017-07-31 08:18:55 -05:00
|
|
|
"""
|
2019-09-05 07:31:13 -05:00
|
|
|
This module provides bindings to C/C++ functions defined by OpenMC shared
|
|
|
|
|
library. When the :mod:`openmc.lib` package is imported, the OpenMC shared
|
|
|
|
|
library is automatically loaded. Calls to the OpenMC library can then be via
|
|
|
|
|
functions or objects in :mod:`openmc.lib`, for example:
|
2017-07-28 15:46:35 -05:00
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
2019-09-05 07:31:13 -05:00
|
|
|
openmc.lib.init()
|
|
|
|
|
openmc.lib.run()
|
|
|
|
|
openmc.lib.finalize()
|
2017-07-28 15:46:35 -05:00
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
2020-09-02 15:41:03 -05:00
|
|
|
from ctypes import CDLL, c_bool, c_int
|
2024-07-18 11:54:06 -05:00
|
|
|
import importlib.resources
|
2017-10-05 10:52:29 -05:00
|
|
|
import os
|
2017-06-09 11:58:14 -05:00
|
|
|
import sys
|
|
|
|
|
|
2017-07-29 08:43:48 -05:00
|
|
|
|
|
|
|
|
# Determine shared-library suffix
|
|
|
|
|
if sys.platform == 'darwin':
|
|
|
|
|
_suffix = 'dylib'
|
|
|
|
|
else:
|
|
|
|
|
_suffix = 'so'
|
|
|
|
|
|
2017-10-05 10:52:29 -05:00
|
|
|
if os.environ.get('READTHEDOCS', None) != 'True':
|
|
|
|
|
# Open shared library
|
2024-07-18 11:54:06 -05:00
|
|
|
_filename = importlib.resources.files(__name__) / f'libopenmc.{_suffix}'
|
|
|
|
|
_dll = CDLL(str(_filename)) # TODO: Remove str() when Python 3.12+
|
2017-10-05 10:52:29 -05:00
|
|
|
else:
|
|
|
|
|
# For documentation builds, we don't actually have the shared library
|
|
|
|
|
# available. Instead, we create a mock object so that when the modules
|
2019-09-05 07:31:13 -05:00
|
|
|
# within the openmc.lib package try to configure arguments and return
|
2017-10-05 10:52:29 -05:00
|
|
|
# values for symbols, no errors occur
|
2018-02-21 07:00:20 -06:00
|
|
|
from unittest.mock import Mock
|
2017-10-05 10:52:29 -05:00
|
|
|
_dll = Mock()
|
2017-08-03 06:33:46 -05:00
|
|
|
|
2018-11-26 23:01:13 -06:00
|
|
|
|
|
|
|
|
def _dagmc_enabled():
|
2021-01-05 22:23:19 -06:00
|
|
|
return c_bool.in_dll(_dll, "DAGMC_ENABLED").value
|
2018-11-26 23:01:13 -06:00
|
|
|
|
2020-09-02 15:41:03 -05:00
|
|
|
def _coord_levels():
|
|
|
|
|
return c_int.in_dll(_dll, "n_coord_levels").value
|
|
|
|
|
|
2020-04-09 12:37:33 -05:00
|
|
|
def _libmesh_enabled():
|
2021-01-05 22:23:19 -06:00
|
|
|
return c_bool.in_dll(_dll, "LIBMESH_ENABLED").value
|
2020-04-09 12:37:33 -05:00
|
|
|
|
2024-04-24 12:05:11 -04:00
|
|
|
def _uwuw_enabled():
|
|
|
|
|
return c_bool.in_dll(_dll, "UWUW_ENABLED").value
|
|
|
|
|
|
2026-02-25 17:12:18 -06:00
|
|
|
def _strict_fp_enabled():
|
|
|
|
|
return c_bool.in_dll(_dll, "STRICT_FP_ENABLED").value
|
|
|
|
|
|
2023-06-09 10:47:27 -05:00
|
|
|
|
2017-08-03 06:33:46 -05:00
|
|
|
from .error import *
|
|
|
|
|
from .core import *
|
|
|
|
|
from .nuclide import *
|
|
|
|
|
from .material import *
|
|
|
|
|
from .cell import *
|
2018-04-01 07:50:14 -05:00
|
|
|
from .mesh import *
|
2017-08-11 11:08:13 -05:00
|
|
|
from .filter import *
|
2017-08-03 06:33:46 -05:00
|
|
|
from .tally import *
|
2017-09-15 14:04:31 -05:00
|
|
|
from .settings import settings
|
2018-04-29 06:35:56 -04:00
|
|
|
from .math import *
|
2019-02-26 07:50:03 -06:00
|
|
|
from .plot import *
|
2023-06-09 10:47:27 -05:00
|
|
|
from .weight_windows import *
|
2025-01-07 22:50:02 +01:00
|
|
|
from .dagmc import *
|
2021-09-23 16:22:42 -05:00
|
|
|
|
2021-09-29 18:51:00 -05:00
|
|
|
# Flag to denote whether or not openmc.lib.init has been called
|
2021-09-30 16:34:58 -05:00
|
|
|
# TODO: Establish and use a flag in the C++ code to represent the status of the
|
|
|
|
|
# openmc_init and openmc_finalize methods
|
2021-09-29 18:51:00 -05:00
|
|
|
is_initialized = False
|