1"""
2This module provides bindings to C/C++ functions defined by OpenMC shared
3library. When the :mod:`openmc.lib` package is imported, the OpenMC shared
4library is automatically loaded. Calls to the OpenMC library can then be via
5functions or objects in :mod:`openmc.lib`, for example:
6
7.. code-block:: python
8
9    openmc.lib.init()
10    openmc.lib.run()
11    openmc.lib.finalize()
12
13"""
14
15from ctypes import CDLL, c_bool, c_int
16import os
17import sys
18
19import pkg_resources
20
21
22# Determine shared-library suffix
23if sys.platform == 'darwin':
24    _suffix = 'dylib'
25else:
26    _suffix = 'so'
27
28if os.environ.get('READTHEDOCS', None) != 'True':
29    # Open shared library
30    _filename = pkg_resources.resource_filename(
31        __name__, 'libopenmc.{}'.format(_suffix))
32    _dll = CDLL(_filename)
33else:
34    # For documentation builds, we don't actually have the shared library
35    # available. Instead, we create a mock object so that when the modules
36    # within the openmc.lib package try to configure arguments and return
37    # values for symbols, no errors occur
38    from unittest.mock import Mock
39    _dll = Mock()
40
41
42def _dagmc_enabled():
43    return c_bool.in_dll(_dll, "DAGMC_ENABLED").value
44
45def _coord_levels():
46    return c_int.in_dll(_dll, "n_coord_levels").value
47
48def _libmesh_enabled():
49    return c_bool.in_dll(_dll, "LIBMESH_ENABLED").value
50
51from .error import *
52from .core import *
53from .nuclide import *
54from .material import *
55from .cell import *
56from .mesh import *
57from .filter import *
58from .tally import *
59from .settings import settings
60from .math import *
61from .plot import *
62