From ca72b1e971e56042da31436f76d2fd80961925f8 Mon Sep 17 00:00:00 2001 From: Luke Labrie-Cleary Date: Wed, 24 Apr 2024 12:05:11 -0400 Subject: [PATCH] make uwuw optional (#2965) --- CMakeLists.txt | 17 ++++-- cmake/OpenMCConfig.cmake.in | 4 ++ include/openmc/dagmc.h | 9 +++- openmc/lib/__init__.py | 3 ++ src/dagmc.cpp | 66 ++++++++++++++++------- src/output.cpp | 5 ++ tests/regression_tests/dagmc/refl/test.py | 4 +- tests/regression_tests/dagmc/uwuw/test.py | 4 +- 8 files changed, 86 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b08914ac64..1841251ff5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,7 @@ option(OPENMC_USE_LIBMESH "Enable support for libMesh unstructured mesh tall option(OPENMC_USE_MPI "Enable MPI" OFF) option(OPENMC_USE_MCPL "Enable MCPL" OFF) option(OPENMC_USE_NCRYSTAL "Enable support for NCrystal scattering" OFF) +option(OPENMC_USE_UWUW "Enable UWUW" OFF) # Warnings for deprecated options foreach(OLD_OPT IN ITEMS "openmp" "profile" "coverage" "dagmc" "libmesh") @@ -125,10 +126,15 @@ endif() if(OPENMC_USE_DAGMC) find_package(DAGMC REQUIRED PATH_SUFFIXES lib/cmake) if (${DAGMC_VERSION} VERSION_LESS 3.2.0) - message(FATAL_ERROR "Discovered DAGMC Version: ${DAGMC_VERSION}. \ - Please update DAGMC to version 3.2.0 or greater.") + message(FATAL_ERROR "Discovered DAGMC Version: ${DAGMC_VERSION}." + "Please update DAGMC to version 3.2.0 or greater.") endif() message(STATUS "Found DAGMC: ${DAGMC_DIR} (version ${DAGMC_VERSION})") + + # Check if UWUW is needed and available + if(OPENMC_USE_UWUW AND NOT DAGMC_BUILD_UWUW) + message(FATAL_ERROR "UWUW is enabled but DAGMC was not configured with UWUW.") + endif() endif() #=============================================================================== @@ -510,7 +516,7 @@ endif() if(OPENMC_USE_DAGMC) target_compile_definitions(libopenmc PRIVATE DAGMC) - target_link_libraries(libopenmc dagmc-shared uwuw-shared) + target_link_libraries(libopenmc dagmc-shared) endif() if(OPENMC_USE_LIBMESH) @@ -547,6 +553,11 @@ if(OPENMC_USE_NCRYSTAL) target_link_libraries(libopenmc NCrystal::NCrystal) endif() +if (OPENMC_USE_UWUW) + target_compile_definitions(libopenmc PRIVATE UWUW) + target_link_libraries(libopenmc uwuw-shared) +endif() + #=============================================================================== # Log build info that this executable can report later #=============================================================================== diff --git a/cmake/OpenMCConfig.cmake.in b/cmake/OpenMCConfig.cmake.in index 1305ad3edf5..44a5e0d5a3f 100644 --- a/cmake/OpenMCConfig.cmake.in +++ b/cmake/OpenMCConfig.cmake.in @@ -38,3 +38,7 @@ endif() if(@OPENMC_USE_MCPL@) find_package(MCPL REQUIRED) endif() + +if(@OPENMC_USE_UWUW@) + find_package(UWUW REQUIRED) +endif() diff --git a/include/openmc/dagmc.h b/include/openmc/dagmc.h index 0b23e567abc..2facf4fc05e 100644 --- a/include/openmc/dagmc.h +++ b/include/openmc/dagmc.h @@ -3,7 +3,8 @@ 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" @@ -120,6 +121,12 @@ class DAGUniverse : public Universe { void write_uwuw_materials_xml( const std::string& outfile = "uwuw_materials.xml") const; + //! Assign a material to a cell from uwuw material library + //! \param[in] vol_handle The DAGMC material assignment string + //! \param[in] c The OpenMC cell to which the material is assigned + void uwuw_assign_material( + moab::EntityHandle vol_handle, std::unique_ptr& c) const; + //! Assign a material to a cell based //! \param[in] mat_string The DAGMC material assignment string //! \param[in] c The OpenMC cell to which the material is assigned diff --git a/openmc/lib/__init__.py b/openmc/lib/__init__.py index 0e5ad92feb9..dc5bd7d9b45 100644 --- a/openmc/lib/__init__.py +++ b/openmc/lib/__init__.py @@ -54,6 +54,9 @@ def _libmesh_enabled(): def _mcpl_enabled(): return c_bool.in_dll(_dll, "MCPL_ENABLED").value +def _uwuw_enabled(): + return c_bool.in_dll(_dll, "UWUW_ENABLED").value + from .error import * from .core import * diff --git a/src/dagmc.cpp b/src/dagmc.cpp index 6a4865c391b..2f2502f6ea1 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -11,7 +11,7 @@ #include "openmc/settings.h" #include "openmc/string_utils.h" -#ifdef DAGMC +#ifdef UWUW #include "uwuw.hpp" #endif #include @@ -29,6 +29,12 @@ const bool DAGMC_ENABLED = true; const bool DAGMC_ENABLED = false; #endif +#ifdef UWUW +const bool UWUW_ENABLED = true; +#else +const bool UWUW_ENABLED = false; +#endif + } // namespace openmc #ifdef DAGMC @@ -85,7 +91,6 @@ DAGUniverse::DAGUniverse(std::shared_ptr dagmc_ptr, { set_id(); init_metadata(); - read_uwuw_materials(); init_geometry(); } @@ -111,8 +116,6 @@ void DAGUniverse::initialize() init_metadata(); - read_uwuw_materials(); - init_geometry(); } @@ -209,20 +212,7 @@ void DAGUniverse::init_geometry() c->material_.push_back(MATERIAL_VOID); } else { if (uses_uwuw()) { - // lookup material in uwuw if present - std::string uwuw_mat = - dmd_ptr->volume_material_property_data_eh[vol_handle]; - if (uwuw_->material_library.count(uwuw_mat) != 0) { - // Note: material numbers are set by UWUW - int mat_number = uwuw_->material_library.get_material(uwuw_mat) - .metadata["mat_number"] - .asInt(); - c->material_.push_back(mat_number); - } else { - fatal_error(fmt::format("Material with value '{}' not found in the " - "UWUW material library", - mat_str)); - } + uwuw_assign_material(vol_handle, c); } else { legacy_assign_material(mat_str, c); } @@ -439,11 +429,16 @@ void DAGUniverse::to_hdf5(hid_t universes_group) const bool DAGUniverse::uses_uwuw() const { +#ifdef UWUW return uwuw_ && !uwuw_->material_library.empty(); +#else + return false; +#endif // UWUW } std::string DAGUniverse::get_uwuw_materials_xml() const { +#ifdef UWUW if (!uses_uwuw()) { throw std::runtime_error("This DAGMC Universe does not use UWUW materials"); } @@ -461,10 +456,14 @@ std::string DAGUniverse::get_uwuw_materials_xml() const ss << ""; return ss.str(); +#else + fatal_error("DAGMC was not configured with UWUW."); +#endif // UWUW } void DAGUniverse::write_uwuw_materials_xml(const std::string& outfile) const { +#ifdef UWUW if (!uses_uwuw()) { throw std::runtime_error( "This DAGMC universe does not use UWUW materials."); @@ -475,6 +474,9 @@ void DAGUniverse::write_uwuw_materials_xml(const std::string& outfile) const std::ofstream mats_xml(outfile); mats_xml << xml_str; mats_xml.close(); +#else + fatal_error("DAGMC was not configured with UWUW."); +#endif } void DAGUniverse::legacy_assign_material( @@ -536,6 +538,7 @@ void DAGUniverse::legacy_assign_material( void DAGUniverse::read_uwuw_materials() { +#ifdef UWUW // If no filename was provided, don't read UWUW materials if (filename_ == "") return; @@ -573,8 +576,35 @@ void DAGUniverse::read_uwuw_materials() for (pugi::xml_node material_node : root.children("material")) { model::materials.push_back(std::make_unique(material_node)); } +#else + fatal_error("DAGMC was not configured with UWUW."); +#endif } +void DAGUniverse::uwuw_assign_material( + moab::EntityHandle vol_handle, std::unique_ptr& c) const +{ +#ifdef UWUW + // read materials from uwuw material file + read_uwuw_materials(); + + // lookup material in uwuw if present + std::string uwuw_mat = dmd_ptr->volume_material_property_data_eh[vol_handle]; + if (uwuw_->material_library.count(uwuw_mat) != 0) { + // Note: material numbers are set by UWUW + int mat_number = uwuw_->material_library.get_material(uwuw_mat) + .metadata["mat_number"] + .asInt(); + c->material_.push_back(mat_number); + } else { + fatal_error(fmt::format("Material with value '{}' not found in the " + "UWUW material library", + mat_str)); + } +#else + fatal_error("DAGMC was not configured with UWUW."); +#endif +} //============================================================================== // DAGMC Cell implementation //============================================================================== diff --git a/src/output.cpp b/src/output.cpp index b1b963f7d3c..5fdbea1304e 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -318,6 +318,7 @@ void print_build_info() std::string coverage(n); std::string mcpl(n); std::string ncrystal(n); + std::string uwuw(n); #ifdef PHDF5 phdf5 = y; @@ -346,6 +347,9 @@ void print_build_info() #ifdef COVERAGEBUILD coverage = y; #endif +#ifdef UWUW + uwuw = y; +#endif // Wraps macro variables in quotes #define STRINGIFY(x) STRINGIFY2(x) @@ -364,6 +368,7 @@ void print_build_info() fmt::print("NCrystal support: {}\n", ncrystal); fmt::print("Coverage testing: {}\n", coverage); fmt::print("Profiling flags: {}\n", profiling); + fmt::print("UWUW support: {}\n", uwuw); } } diff --git a/tests/regression_tests/dagmc/refl/test.py b/tests/regression_tests/dagmc/refl/test.py index 03c1c407bbb..a13acc0256a 100644 --- a/tests/regression_tests/dagmc/refl/test.py +++ b/tests/regression_tests/dagmc/refl/test.py @@ -6,8 +6,8 @@ from tests.testing_harness import PyAPITestHarness pytestmark = pytest.mark.skipif( - not openmc.lib._dagmc_enabled(), - reason="DAGMC CAD geometry is not enabled.") + not openmc.lib._uwuw_enabled(), + reason="UWUW is not enabled.") class UWUWTest(PyAPITestHarness): def __init__(self, *args, **kwargs): diff --git a/tests/regression_tests/dagmc/uwuw/test.py b/tests/regression_tests/dagmc/uwuw/test.py index 38c335a5ed4..bea464cfabc 100644 --- a/tests/regression_tests/dagmc/uwuw/test.py +++ b/tests/regression_tests/dagmc/uwuw/test.py @@ -6,8 +6,8 @@ from tests.testing_harness import PyAPITestHarness pytestmark = pytest.mark.skipif( - not openmc.lib._dagmc_enabled(), - reason="DAGMC CAD geometry is not enabled.") + not openmc.lib._uwuw_enabled(), + reason="UWUW is not enabled.") class UWUWTest(PyAPITestHarness): def __init__(self, *args, **kwargs):