Skip to content

Commit

Permalink
make uwuw optional (openmc-dev#2965)
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeLabrie authored and church89 committed Jul 18, 2024
1 parent ed13179 commit ca72b1e
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 26 deletions.
17 changes: 14 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()

#===============================================================================
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
#===============================================================================
Expand Down
4 changes: 4 additions & 0 deletions cmake/OpenMCConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ endif()
if(@OPENMC_USE_MCPL@)
find_package(MCPL REQUIRED)
endif()

if(@OPENMC_USE_UWUW@)
find_package(UWUW REQUIRED)
endif()
9 changes: 8 additions & 1 deletion include/openmc/dagmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<DAGCell>& 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
Expand Down
3 changes: 3 additions & 0 deletions openmc/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
66 changes: 48 additions & 18 deletions src/dagmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "openmc/settings.h"
#include "openmc/string_utils.h"

#ifdef DAGMC
#ifdef UWUW
#include "uwuw.hpp"
#endif
#include <fmt/core.h>
Expand All @@ -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
Expand Down Expand Up @@ -85,7 +91,6 @@ DAGUniverse::DAGUniverse(std::shared_ptr<moab::DagMC> dagmc_ptr,
{
set_id();
init_metadata();
read_uwuw_materials();
init_geometry();
}

Expand All @@ -111,8 +116,6 @@ void DAGUniverse::initialize()

init_metadata();

read_uwuw_materials();

init_geometry();
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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");
}
Expand All @@ -461,10 +456,14 @@ std::string DAGUniverse::get_uwuw_materials_xml() const
ss << "</materials>";

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.");
Expand All @@ -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(
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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>(material_node));
}
#else
fatal_error("DAGMC was not configured with UWUW.");
#endif
}

void DAGUniverse::uwuw_assign_material(
moab::EntityHandle vol_handle, std::unique_ptr<DAGCell>& 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
//==============================================================================
Expand Down
5 changes: 5 additions & 0 deletions src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/regression_tests/dagmc/refl/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions tests/regression_tests/dagmc/uwuw/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit ca72b1e

Please sign in to comment.