Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/pythonapi/capi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Functions
current_batch
export_properties
export_weight_windows
feature_enabled
finalize
find_cell
find_material
Expand Down
9 changes: 9 additions & 0 deletions include/openmc/capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,15 @@ int openmc_properties_export(const char* filename);
// \return Error code
int openmc_properties_import(const char* filename);

//! Get whether an optional build feature is enabled.
//!
//! Supported feature names are ``dagmc``, ``libmesh``, ``strict_fp``, and
//! ``uwuw``.
//! \param feature Name of the feature to query
//! \param enabled Whether the feature is enabled
//! \return Error code
int openmc_get_feature_enabled(const char* feature, bool* enabled);

// Error codes
extern int OPENMC_E_UNASSIGNED;
extern int OPENMC_E_ALLOCATE;
Expand Down
5 changes: 0 additions & 5 deletions include/openmc/dagmc.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#ifndef OPENMC_DAGMC_H
#define OPENMC_DAGMC_H

namespace openmc {
extern "C" const bool DAGMC_ENABLED;
extern "C" const bool UWUW_ENABLED;
} // namespace openmc

// always include the XML interface header
#include "openmc/xml_interface.h"

Expand Down
2 changes: 0 additions & 2 deletions include/openmc/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ enum class ElementType { UNSUPPORTED = -1, LINEAR_TET, LINEAR_HEX };
// Global variables
//==============================================================================

extern "C" const bool LIBMESH_ENABLED;

class Mesh;

namespace model {
Expand Down
2 changes: 0 additions & 2 deletions include/openmc/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

namespace openmc {

extern "C" const bool STRICT_FP_ENABLED;

//! \brief Display the main title banner as well as information about the
//! program developers, version, and date/time which the problem was run.
void title();
Expand Down
39 changes: 28 additions & 11 deletions openmc/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

"""

from ctypes import CDLL, c_bool, c_int
from ctypes import CDLL, byref, c_bool, c_char_p, c_int, POINTER
import importlib.resources
import os
import sys
Expand All @@ -36,21 +36,38 @@
from unittest.mock import Mock
_dll = Mock()

from .error import _error_handler

def _dagmc_enabled():
return c_bool.in_dll(_dll, "DAGMC_ENABLED").value
_dll.openmc_get_feature_enabled.argtypes = [c_char_p, POINTER(c_bool)]
_dll.openmc_get_feature_enabled.restype = c_int
_dll.openmc_get_feature_enabled.errcheck = _error_handler

def _coord_levels():
return c_int.in_dll(_dll, "n_coord_levels").value
def feature_enabled(feature: str) -> bool:
"""Return whether OpenMC was built with an optional feature.

Parameters
----------
feature : {'dagmc', 'libmesh', 'strict_fp', 'uwuw'}
Feature to query.

Returns
-------
bool
Whether the feature is enabled.

def _libmesh_enabled():
return c_bool.in_dll(_dll, "LIBMESH_ENABLED").value
Raises
------
InvalidArgumentError
If *feature* is not recognized.

def _uwuw_enabled():
return c_bool.in_dll(_dll, "UWUW_ENABLED").value
"""
enabled = c_bool()
_dll.openmc_get_feature_enabled(feature.encode(), byref(enabled))
return enabled.value

def _strict_fp_enabled():
return c_bool.in_dll(_dll, "STRICT_FP_ENABLED").value

def _coord_levels():
return c_int.in_dll(_dll, "n_coord_levels").value


from .error import *
Expand Down
16 changes: 0 additions & 16 deletions src/dagmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,6 @@
#include <sstream>
#include <string>

namespace openmc {

#ifdef OPENMC_DAGMC_ENABLED
const bool DAGMC_ENABLED = true;
#else
const bool DAGMC_ENABLED = false;
#endif

#ifdef OPENMC_UWUW_ENABLED
const bool UWUW_ENABLED = true;
#else
const bool UWUW_ENABLED = false;
#endif

} // namespace openmc

#ifdef OPENMC_DAGMC_ENABLED

namespace openmc {
Expand Down
6 changes: 0 additions & 6 deletions src/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ namespace openmc {
// Global variables
//==============================================================================

#ifdef OPENMC_LIBMESH_ENABLED
const bool LIBMESH_ENABLED = true;
#else
const bool LIBMESH_ENABLED = false;
#endif

// Value used to indicate an empty slot in the hash table. We use -2 because
// the value -1 is used to indicate a void material.
constexpr int32_t EMPTY = -2;
Expand Down
37 changes: 35 additions & 2 deletions src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,44 @@

namespace openmc {

extern "C" int openmc_get_feature_enabled(const char* feature, bool* enabled)
{
if (!feature || !enabled) {
set_errmsg("Feature name and output pointer must not be null.");
return OPENMC_E_INVALID_ARGUMENT;
}

if (strcmp(feature, "dagmc") == 0) {
#ifdef OPENMC_DAGMC_ENABLED
*enabled = true;
#else
*enabled = false;
#endif
} else if (strcmp(feature, "libmesh") == 0) {
#ifdef OPENMC_LIBMESH_ENABLED
*enabled = true;
#else
*enabled = false;
#endif
} else if (strcmp(feature, "strict_fp") == 0) {
#ifdef OPENMC_ENABLE_STRICT_FP
const bool STRICT_FP_ENABLED = true;
*enabled = true;
#else
*enabled = false;
#endif
} else if (strcmp(feature, "uwuw") == 0) {
#ifdef OPENMC_UWUW_ENABLED
*enabled = true;
#else
const bool STRICT_FP_ENABLED = false;
*enabled = false;
#endif
} else {
set_errmsg(fmt::format("Unknown build feature '{}'.", feature));
return OPENMC_E_INVALID_ARGUMENT;
}

return 0;
}

//==============================================================================

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

def _check_build_environment():
"""Check STRICT_FP and cross section data, collecting any warnings."""
if not openmc.lib._strict_fp_enabled():
if not openmc.lib.feature_enabled('strict_fp'):
_environment_warnings.append(
"OpenMC was NOT built with -DOPENMC_ENABLE_STRICT_FP=on. "
"Regression test results may not match reference values due to "
Expand Down
2 changes: 1 addition & 1 deletion tests/regression_tests/dagmc/external/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from tests.testing_harness import PyAPITestHarness

pytestmark = pytest.mark.skipif(
not openmc.lib._dagmc_enabled(),
not openmc.lib.feature_enabled('dagmc'),
reason="DAGMC is not enabled.")

# Test that an external DAGMC instance can be passed in through the C API
Expand Down
2 changes: 1 addition & 1 deletion tests/regression_tests/dagmc/legacy/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from tests.testing_harness import PyAPITestHarness, config

pytestmark = pytest.mark.skipif(
not openmc.lib._dagmc_enabled(),
not openmc.lib.feature_enabled('dagmc'),
reason="DAGMC CAD geometry is not enabled.")

@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/regression_tests/dagmc/refl/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from tests.testing_harness import PyAPITestHarness

pytestmark = pytest.mark.skipif(
not openmc.lib._uwuw_enabled(),
not openmc.lib.feature_enabled('uwuw'),
reason="UWUW is not enabled.")

class UWUWTest(PyAPITestHarness):
Expand Down
2 changes: 1 addition & 1 deletion tests/regression_tests/dagmc/universes/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from tests.testing_harness import PyAPITestHarness

pytestmark = pytest.mark.skipif(
not openmc.lib._dagmc_enabled(),
not openmc.lib.feature_enabled('dagmc'),
reason="DAGMC CAD geometry is not enabled.")


Expand Down
2 changes: 1 addition & 1 deletion tests/regression_tests/dagmc/uwuw/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from tests.testing_harness import PyAPITestHarness

pytestmark = pytest.mark.skipif(
not openmc.lib._uwuw_enabled(),
not openmc.lib.feature_enabled('uwuw'),
reason="UWUW is not enabled.")

class UWUWTest(PyAPITestHarness):
Expand Down
2 changes: 1 addition & 1 deletion tests/regression_tests/external_moab/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from tests.testing_harness import PyAPITestHarness

pytestmark = pytest.mark.skipif(
not openmc.lib._dagmc_enabled(),
not openmc.lib.feature_enabled('dagmc'),
reason="DAGMC is not enabled.")

TETS_PER_VOXEL = 12
Expand Down
2 changes: 1 addition & 1 deletion tests/regression_tests/surface_source_write/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ def model_dagmc_2():


@pytest.mark.skipif(
not openmc.lib._dagmc_enabled(), reason="DAGMC CAD geometry is not enabled."
not openmc.lib.feature_enabled('dagmc'), reason="DAGMC CAD geometry is not enabled."
)
@pytest.mark.skipif(config["event"] is True, reason="Results from history-based mode.")
@pytest.mark.parametrize(
Expand Down
6 changes: 3 additions & 3 deletions tests/regression_tests/unstructured_mesh/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ def model():
@pytest.mark.parametrize("test_opts", test_cases)
def test_unstructured_mesh_tets(model, test_opts):
# skip the test if the library is not enabled
if test_opts['library'] == 'moab' and not openmc.lib._dagmc_enabled():
if test_opts['library'] == 'moab' and not openmc.lib.feature_enabled('dagmc'):
pytest.skip("DAGMC (and MOAB) mesh not enabled in this build.")

if test_opts['library'] == 'libmesh' and not openmc.lib._libmesh_enabled():
if test_opts['library'] == 'libmesh' and not openmc.lib.feature_enabled('libmesh'):
pytest.skip("LibMesh is not enabled in this build.")

# skip the tracklength test for libmesh
Expand Down Expand Up @@ -302,7 +302,7 @@ def test_unstructured_mesh_tets(model, test_opts):
harness.main()


@pytest.mark.skipif(not openmc.lib._libmesh_enabled(),
@pytest.mark.skipif(not openmc.lib.feature_enabled('libmesh'),
reason='LibMesh is not enabled in this build.')
def test_unstructured_mesh_hexes(model):
regular_mesh_tally = model.tallies[0]
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/dagmc/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from tests import cdtemp

pytestmark = pytest.mark.skipif(
not openmc.lib._dagmc_enabled(),
not openmc.lib.feature_enabled('dagmc'),
reason="DAGMC CAD geometry is not enabled.")


Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/dagmc/test_convert_to_multigroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import openmc.lib

pytestmark = pytest.mark.skipif(
not openmc.lib._dagmc_enabled(),
not openmc.lib.feature_enabled('dagmc'),
reason="DAGMC CAD geometry is not enabled.")


Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/dagmc/test_h5m_subdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest

pytestmark = pytest.mark.skipif(
not openmc.lib._dagmc_enabled(), reason="DAGMC CAD geometry is not enabled."
not openmc.lib.feature_enabled('dagmc'), reason="DAGMC CAD geometry is not enabled."
)


Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/dagmc/test_lost_particles.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest

pytestmark = pytest.mark.skipif(
not openmc.lib._dagmc_enabled(),
not openmc.lib.feature_enabled('dagmc'),
reason="DAGMC CAD geometry is not enabled.")


Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/dagmc/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from openmc.utility_funcs import change_directory

pytestmark = pytest.mark.skipif(
not openmc.lib._dagmc_enabled(),
not openmc.lib.feature_enabled('dagmc'),
reason="DAGMC CAD geometry is not enabled.")


Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/dagmc/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


pytestmark = pytest.mark.skipif(
not openmc.lib._dagmc_enabled(), reason="DAGMC CAD geometry is not enabled."
not openmc.lib.feature_enabled('dagmc'), reason="DAGMC CAD geometry is not enabled."
)

def test_plotting_dagmc_model(request):
Expand Down
9 changes: 9 additions & 0 deletions tests/unit_tests/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,15 @@ def test_settings(lib_init):
settings.seed = 11


def test_feature_enabled():
assert isinstance(openmc.lib.feature_enabled('dagmc'), bool)
assert isinstance(openmc.lib.feature_enabled('libmesh'), bool)
assert isinstance(openmc.lib.feature_enabled('strict_fp'), bool)
assert isinstance(openmc.lib.feature_enabled('uwuw'), bool)
with pytest.raises(exc.InvalidArgumentError, match="Unknown build feature"):
openmc.lib.feature_enabled('not-a-feature')


def test_tally_mapping(lib_init):
tallies = openmc.lib.tallies
assert isinstance(tallies, Mapping)
Expand Down
8 changes: 5 additions & 3 deletions tests/unit_tests/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,9 @@ def simple_umesh(request):
return sp.meshes[1]


@pytest.mark.skipif(not openmc.lib._dagmc_enabled(), reason="DAGMC not enabled.")
@pytest.mark.skipif(
not openmc.lib.feature_enabled('dagmc'), reason="DAGMC not enabled."
)
@pytest.mark.parametrize('export_type', ('.vtk', '.vtu'))
def test_umesh(run_in_tmpdir, simple_umesh, export_type):
"""Performs a minimal UnstructuredMesh simulation, reads in the resulting
Expand Down Expand Up @@ -507,9 +509,9 @@ def test_write_vtkhdf(mesh_file, mesh_library, request, run_in_tmpdir):
necessary to read in the unstructured mesh from a statepoint file to ensure
it has all the required attributes
"""
if mesh_library == 'moab' and not openmc.lib._dagmc_enabled():
if mesh_library == 'moab' and not openmc.lib.feature_enabled('dagmc'):
pytest.skip("DAGMC not enabled.")
if mesh_library == 'libmesh' and not openmc.lib._libmesh_enabled():
if mesh_library == 'libmesh' and not openmc.lib.feature_enabled('libmesh'):
pytest.skip("LibMesh not enabled.")

model = openmc.Model()
Expand Down
Loading
Loading