OpenMC/openmc/lib/__init__.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
2 KiB
Python
Raw Permalink Normal View History

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:
.. code-block:: python
2019-09-05 07:31:13 -05:00
openmc.lib.init()
openmc.lib.run()
openmc.lib.finalize()
"""
from ctypes import CDLL, c_bool, c_int
import importlib.resources
import os
import sys
# Determine shared-library suffix
if sys.platform == 'darwin':
_suffix = 'dylib'
else:
_suffix = 'so'
if os.environ.get('READTHEDOCS', None) != 'True':
# Open shared library
_filename = importlib.resources.files(__name__) / f'libopenmc.{_suffix}'
_dll = CDLL(str(_filename)) # TODO: Remove str() when Python 3.12+
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
# values for symbols, no errors occur
2018-02-21 07:00:20 -06:00
from unittest.mock import Mock
_dll = Mock()
2017-08-03 06:33:46 -05:00
2018-11-26 23:01:13 -06:00
def _dagmc_enabled():
return c_bool.in_dll(_dll, "DAGMC_ENABLED").value
2018-11-26 23:01:13 -06:00
def _coord_levels():
return c_int.in_dll(_dll, "n_coord_levels").value
def _libmesh_enabled():
return c_bool.in_dll(_dll, "LIBMESH_ENABLED").value
2024-04-24 12:05:11 -04:00
def _uwuw_enabled():
return c_bool.in_dll(_dll, "UWUW_ENABLED").value
def _strict_fp_enabled():
return c_bool.in_dll(_dll, "STRICT_FP_ENABLED").value
2017-08-03 06:33:46 -05:00
from .error import *
from .core import *
from .nuclide import *
from .material import *
from .cell import *
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 *
from .settings import settings
from .math import *
from .plot import *
from .weight_windows import *
from .dagmc import *
# Flag to denote whether or not openmc.lib.init has been called
# TODO: Establish and use a flag in the C++ code to represent the status of the
# openmc_init and openmc_finalize methods
is_initialized = False