OpenMC/openmc/lib/__init__.py

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

75 lines
1.9 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 os
import sys
import pkg_resources
# Determine shared-library suffix
if sys.platform == 'darwin':
_suffix = 'dylib'
else:
_suffix = 'so'
if os.environ.get('READTHEDOCS', None) != 'True':
# Open shared library
_filename = pkg_resources.resource_filename(
__name__, 'libopenmc.{}'.format(_suffix))
_dll = CDLL(_filename)
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
2022-11-18 18:26:31 +01:00
def _ncrystal_enabled():
return c_bool.in_dll(_dll, "NCRYSTAL_ENABLED").value
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
def _mcpl_enabled():
return c_bool.in_dll(_dll, "MCPL_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 *
# 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