From eb3b578b71a6bcc35fb22964485c5f361a1844c4 Mon Sep 17 00:00:00 2001 From: GuySten Date: Tue, 3 Mar 2026 00:12:11 +0200 Subject: [PATCH 1/7] refactor Ray class into its own file --- CMakeLists.txt | 1 + include/openmc/plot.h | 42 +---------- include/openmc/ray.h | 50 +++++++++++++ src/plot.cpp | 159 ---------------------------------------- src/ray.cpp | 164 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 216 insertions(+), 200 deletions(-) create mode 100644 include/openmc/ray.h create mode 100644 src/ray.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 10867384b14..20068d7e760 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -407,6 +407,7 @@ list(APPEND libopenmc_SOURCES src/random_ray/linear_source_domain.cpp src/random_ray/moment_matrix.cpp src/random_ray/source_region.cpp + src/ray.cpp src/reaction.cpp src/reaction_product.cpp src/scattdata.cpp diff --git a/include/openmc/plot.h b/include/openmc/plot.h index aa373945317..6c00fc2f6ba 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -17,6 +17,7 @@ #include "openmc/particle.h" #include "openmc/position.h" #include "openmc/random_lcg.h" +#include "openmc/ray.h" #include "openmc/xml_interface.h" namespace openmc { @@ -497,47 +498,6 @@ class SolidRayTracePlot : public RayTracePlot { Position light_location_; }; -// Base class that implements ray tracing logic, not necessarily through -// defined regions of the geometry but also outside of it. -class Ray : public GeometryState { - -public: - // Initialize from location and direction - Ray(Position r, Direction u) { init_from_r_u(r, u); } - - // Initialize from known geometry state - Ray(const GeometryState& p) : GeometryState(p) {} - - // Called at every surface intersection within the model - virtual void on_intersection() = 0; - - /* - * Traces the ray through the geometry, calling on_intersection - * at every surface boundary. - */ - void trace(); - - // Stops the ray and exits tracing when called from on_intersection - void stop() { stop_ = true; } - - // Sets the dist_ variable - void compute_distance(); - -protected: - // Records how far the ray has traveled - double traversal_distance_ {0.0}; - -private: - // Max intersections before we assume ray tracing is caught in an infinite - // loop: - static const int MAX_INTERSECTIONS = 1000000; - - bool hit_something_ {false}; - bool stop_ {false}; - - unsigned event_counter_ {0}; -}; - class ProjectionRay : public Ray { public: ProjectionRay(Position r, Direction u, const WireframeRayTracePlot& plot, diff --git a/include/openmc/ray.h b/include/openmc/ray.h new file mode 100644 index 00000000000..f9ccac7c5de --- /dev/null +++ b/include/openmc/ray.h @@ -0,0 +1,50 @@ +#ifndef OPENMC_RAY_H +#define OPENMC_RAY_H + +#include "openmc/tensor.h" + +namespace openmc { + +// Base class that implements ray tracing logic, not necessarily through +// defined regions of the geometry but also outside of it. +class Ray : public GeometryState { + + public: + // Initialize from location and direction + Ray(Position r, Direction u) { init_from_r_u(r, u); } + + // Initialize from known geometry state + Ray(const GeometryState& p) : GeometryState(p) {} + + // Called at every surface intersection within the model + virtual void on_intersection() = 0; + + /* + * Traces the ray through the geometry, calling on_intersection + * at every surface boundary. + */ + void trace(); + + // Stops the ray and exits tracing when called from on_intersection + void stop() { stop_ = true; } + + // Sets the dist_ variable + void compute_distance(); + + protected: + // Records how far the ray has traveled + double traversal_distance_ {0.0}; + + private: + // Max intersections before we assume ray tracing is caught in an infinite + // loop: + static const int MAX_INTERSECTIONS = 1000000; + + bool hit_something_ {false}; + bool stop_ {false}; + + unsigned event_counter_ {0}; +}; + +} // namespace openmc +#endif // OPENMC_RAY_H diff --git a/src/plot.cpp b/src/plot.cpp index 5e3342dd685..4d48beaf97c 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -1649,165 +1649,6 @@ void SolidRayTracePlot::set_diffuse_fraction(pugi::xml_node node) } } -void Ray::compute_distance() -{ - boundary() = distance_to_boundary(*this); -} - -void Ray::trace() -{ - // To trace the ray from its origin all the way through the model, we have - // to proceed in two phases. In the first, the ray may or may not be found - // inside the model. If the ray is already in the model, phase one can be - // skipped. Otherwise, the ray has to be advanced to the boundary of the - // model where all the cells are defined. Importantly, this is assuming that - // the model is convex, which is a very reasonable assumption for any - // radiation transport model. - // - // After phase one is done, we can starting tracing from cell to cell within - // the model. This step can use neighbor lists to accelerate the ray tracing. - - bool inside_cell; - // Check for location if the particle is already known - if (lowest_coord().cell() == C_NONE) { - // The geometry position of the particle is either unknown or outside of the - // edge of the model. - if (lowest_coord().universe() == C_NONE) { - // Attempt to initialize the particle. We may have to - // enter a loop to move it up to the edge of the model. - inside_cell = exhaustive_find_cell(*this, settings::verbosity >= 10); - } else { - // It has been already calculated that the current position is outside of - // the edge of the model. - inside_cell = false; - } - } else { - // Availability of the cell means that the particle is located inside the - // edge. - inside_cell = true; - } - - // Advance to the boundary of the model - while (!inside_cell) { - advance_to_boundary_from_void(); - inside_cell = exhaustive_find_cell(*this, settings::verbosity >= 10); - - // If true this means no surface was intersected. See cell.cpp and search - // for numeric_limits to see where we return it. - if (surface() == std::numeric_limits::max()) { - warning(fmt::format("Lost a ray, r = {}, u = {}", r(), u())); - return; - } - - // Exit this loop and enter into cell-to-cell ray tracing (which uses - // neighbor lists) - if (inside_cell) - break; - - // if there is no intersection with the model, we're done - if (boundary().surface() == SURFACE_NONE) - return; - - event_counter_++; - if (event_counter_ > MAX_INTERSECTIONS) { - warning("Likely infinite loop in ray traced plot"); - return; - } - } - - // Call the specialized logic for this type of ray. This is for the - // intersection for the first intersection if we had one. - if (boundary().surface() != SURFACE_NONE) { - // set the geometry state's surface attribute to be used for - // surface normal computation - surface() = boundary().surface(); - on_intersection(); - if (stop_) - return; - } - - // reset surface attribute to zero after the first intersection so that it - // doesn't perturb surface crossing logic from here on out - surface() = 0; - - // This is the ray tracing loop within the model. It exits after exiting - // the model, which is equivalent to assuming that the model is convex. - // It would be nice to factor out the on_intersection at the end of this - // loop and then do "while (inside_cell)", but we can't guarantee it's - // on a surface in that case. There might be some other way to set it - // up that is perhaps a little more elegant, but this is what works just - // fine. - while (true) { - - compute_distance(); - - // There are no more intersections to process - // if we hit the edge of the model, so stop - // the particle in that case. Also, just exit - // if a negative distance was somehow computed. - if (boundary().distance() == INFTY || boundary().distance() == INFINITY || - boundary().distance() < 0) { - return; - } - - // See below comment where call_on_intersection is checked in an - // if statement for an explanation of this. - bool call_on_intersection {true}; - if (boundary().distance() < 10 * TINY_BIT) { - call_on_intersection = false; - } - - // DAGMC surfaces expect us to go a little bit further than the advance - // distance to properly check cell inclusion. - boundary().distance() += TINY_BIT; - - // Advance particle, prepare for next intersection - for (int lev = 0; lev < n_coord(); ++lev) { - coord(lev).r() += boundary().distance() * coord(lev).u(); - } - surface() = boundary().surface(); - // Initialize last cells from the current cell, because the cell() variable - // does not contain the data for the case of a single-segment ray - for (int j = 0; j < n_coord(); ++j) { - cell_last(j) = coord(j).cell(); - } - n_coord_last() = n_coord(); - n_coord() = boundary().coord_level(); - if (boundary().lattice_translation()[0] != 0 || - boundary().lattice_translation()[1] != 0 || - boundary().lattice_translation()[2] != 0) { - cross_lattice(*this, boundary(), settings::verbosity >= 10); - } - - // Record how far the ray has traveled - traversal_distance_ += boundary().distance(); - inside_cell = neighbor_list_find_cell(*this, settings::verbosity >= 10); - - // Call the specialized logic for this type of ray. Note that we do not - // call this if the advance distance is very small. Unfortunately, it seems - // darn near impossible to get the particle advanced to the model boundary - // and through it without sometimes accidentally calling on_intersection - // twice. This incorrectly shades the region as occluded when it might not - // actually be. By screening out intersection distances smaller than a - // threshold 10x larger than the scoot distance used to advance up to the - // model boundary, we can avoid that situation. - if (call_on_intersection) { - on_intersection(); - if (stop_) - return; - } - - if (!inside_cell) - return; - - event_counter_++; - if (event_counter_ > MAX_INTERSECTIONS) { - warning("Likely infinite loop in ray traced plot"); - return; - } - } -} - void ProjectionRay::on_intersection() { // This records a tuple with the following info diff --git a/src/ray.cpp b/src/ray.cpp new file mode 100644 index 00000000000..d7a975bb64e --- /dev/null +++ b/src/ray.cpp @@ -0,0 +1,164 @@ +#include "openmc/plot.h" + +namespace openmc { + +void Ray::compute_distance() +{ + boundary() = distance_to_boundary(*this); +} + +void Ray::trace() +{ + // To trace the ray from its origin all the way through the model, we have + // to proceed in two phases. In the first, the ray may or may not be found + // inside the model. If the ray is already in the model, phase one can be + // skipped. Otherwise, the ray has to be advanced to the boundary of the + // model where all the cells are defined. Importantly, this is assuming that + // the model is convex, which is a very reasonable assumption for any + // radiation transport model. + // + // After phase one is done, we can starting tracing from cell to cell within + // the model. This step can use neighbor lists to accelerate the ray tracing. + + bool inside_cell; + // Check for location if the particle is already known + if (lowest_coord().cell() == C_NONE) { + // The geometry position of the particle is either unknown or outside of the + // edge of the model. + if (lowest_coord().universe() == C_NONE) { + // Attempt to initialize the particle. We may have to + // enter a loop to move it up to the edge of the model. + inside_cell = exhaustive_find_cell(*this, settings::verbosity >= 10); + } else { + // It has been already calculated that the current position is outside of + // the edge of the model. + inside_cell = false; + } + } else { + // Availability of the cell means that the particle is located inside the + // edge. + inside_cell = true; + } + + // Advance to the boundary of the model + while (!inside_cell) { + advance_to_boundary_from_void(); + inside_cell = exhaustive_find_cell(*this, settings::verbosity >= 10); + + // If true this means no surface was intersected. See cell.cpp and search + // for numeric_limits to see where we return it. + if (surface() == std::numeric_limits::max()) { + warning(fmt::format("Lost a ray, r = {}, u = {}", r(), u())); + return; + } + + // Exit this loop and enter into cell-to-cell ray tracing (which uses + // neighbor lists) + if (inside_cell) + break; + + // if there is no intersection with the model, we're done + if (boundary().surface() == SURFACE_NONE) + return; + + event_counter_++; + if (event_counter_ > MAX_INTERSECTIONS) { + warning("Likely infinite loop in ray traced plot"); + return; + } + } + + // Call the specialized logic for this type of ray. This is for the + // intersection for the first intersection if we had one. + if (boundary().surface() != SURFACE_NONE) { + // set the geometry state's surface attribute to be used for + // surface normal computation + surface() = boundary().surface(); + on_intersection(); + if (stop_) + return; + } + + // reset surface attribute to zero after the first intersection so that it + // doesn't perturb surface crossing logic from here on out + surface() = 0; + + // This is the ray tracing loop within the model. It exits after exiting + // the model, which is equivalent to assuming that the model is convex. + // It would be nice to factor out the on_intersection at the end of this + // loop and then do "while (inside_cell)", but we can't guarantee it's + // on a surface in that case. There might be some other way to set it + // up that is perhaps a little more elegant, but this is what works just + // fine. + while (true) { + + compute_distance(); + + // There are no more intersections to process + // if we hit the edge of the model, so stop + // the particle in that case. Also, just exit + // if a negative distance was somehow computed. + if (boundary().distance() == INFTY || boundary().distance() == INFINITY || + boundary().distance() < 0) { + return; + } + + // See below comment where call_on_intersection is checked in an + // if statement for an explanation of this. + bool call_on_intersection {true}; + if (boundary().distance() < 10 * TINY_BIT) { + call_on_intersection = false; + } + + // DAGMC surfaces expect us to go a little bit further than the advance + // distance to properly check cell inclusion. + boundary().distance() += TINY_BIT; + + // Advance particle, prepare for next intersection + for (int lev = 0; lev < n_coord(); ++lev) { + coord(lev).r() += boundary().distance() * coord(lev).u(); + } + surface() = boundary().surface(); + // Initialize last cells from the current cell, because the cell() variable + // does not contain the data for the case of a single-segment ray + for (int j = 0; j < n_coord(); ++j) { + cell_last(j) = coord(j).cell(); + } + n_coord_last() = n_coord(); + n_coord() = boundary().coord_level(); + if (boundary().lattice_translation()[0] != 0 || + boundary().lattice_translation()[1] != 0 || + boundary().lattice_translation()[2] != 0) { + cross_lattice(*this, boundary(), settings::verbosity >= 10); + } + + // Record how far the ray has traveled + traversal_distance_ += boundary().distance(); + inside_cell = neighbor_list_find_cell(*this, settings::verbosity >= 10); + + // Call the specialized logic for this type of ray. Note that we do not + // call this if the advance distance is very small. Unfortunately, it seems + // darn near impossible to get the particle advanced to the model boundary + // and through it without sometimes accidentally calling on_intersection + // twice. This incorrectly shades the region as occluded when it might not + // actually be. By screening out intersection distances smaller than a + // threshold 10x larger than the scoot distance used to advance up to the + // model boundary, we can avoid that situation. + if (call_on_intersection) { + on_intersection(); + if (stop_) + return; + } + + if (!inside_cell) + return; + + event_counter_++; + if (event_counter_ > MAX_INTERSECTIONS) { + warning("Likely infinite loop in ray traced plot"); + return; + } + } +} + +} // namespace openmc From 63fa03b1b76476e3752616182664a8f4460bff0b Mon Sep 17 00:00:00 2001 From: GuySten Date: Tue, 3 Mar 2026 00:18:28 +0200 Subject: [PATCH 2/7] ran clang format --- CMakeLists.txt | 1746 +++++++++++++++++++++++++++--------------- include/openmc/ray.h | 8 +- src/plot.cpp | 4 +- src/ray.cpp | 8 +- 4 files changed, 1125 insertions(+), 641 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 20068d7e760..a68d47c0215 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,632 +1,1116 @@ -cmake_minimum_required(VERSION 3.16 FATAL_ERROR) -project(openmc C CXX) - -# Set module path -set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules) - -include(GetVersionFromGit) - -# Output version information -message(STATUS "OpenMC version: ${OPENMC_VERSION}") -message(STATUS "OpenMC dev state: ${OPENMC_DEV_STATE}") -message(STATUS "OpenMC commit hash: ${OPENMC_COMMIT_HASH}") -message(STATUS "OpenMC commit count: ${OPENMC_COMMIT_COUNT}") - -# Generate version.h -configure_file(include/openmc/version.h.in "${CMAKE_BINARY_DIR}/include/openmc/version.h" @ONLY) - -# Setup output directories -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) - -# Enable correct usage of CXX_EXTENSIONS -if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.22) - cmake_policy(SET CMP0128 NEW) -endif() - -#=============================================================================== -# Command line options -#=============================================================================== - -option(OPENMC_USE_OPENMP "Enable shared-memory parallelism with OpenMP" ON) -option(OPENMC_BUILD_TESTS "Build tests" ON) -option(OPENMC_ENABLE_PROFILE "Compile with profiling flags" OFF) -option(OPENMC_ENABLE_COVERAGE "Compile with coverage analysis flags" OFF) -option(OPENMC_USE_DAGMC "Enable support for DAGMC (CAD) geometry" OFF) -option(OPENMC_USE_LIBMESH "Enable support for libMesh unstructured mesh tallies" OFF) -option(OPENMC_USE_MPI "Enable MPI" OFF) -option(OPENMC_USE_UWUW "Enable UWUW" OFF) -option(OPENMC_FORCE_VENDORED_LIBS "Explicitly use submodules defined in 'vendor'" OFF) -option(OPENMC_ENABLE_STRICT_FP "Enable strict FP flags to improve test portability" OFF) - -message(STATUS "OPENMC_USE_OPENMP ${OPENMC_USE_OPENMP}") -message(STATUS "OPENMC_BUILD_TESTS ${OPENMC_BUILD_TESTS}") -message(STATUS "OPENMC_ENABLE_PROFILE ${OPENMC_ENABLE_PROFILE}") -message(STATUS "OPENMC_ENABLE_COVERAGE ${OPENMC_ENABLE_COVERAGE}") -message(STATUS "OPENMC_USE_DAGMC ${OPENMC_USE_DAGMC}") -message(STATUS "OPENMC_USE_LIBMESH ${OPENMC_USE_LIBMESH}") -message(STATUS "OPENMC_USE_MPI ${OPENMC_USE_MPI}") -message(STATUS "OPENMC_USE_UWUW ${OPENMC_USE_UWUW}") -message(STATUS "OPENMC_FORCE_VENDORED_LIBS ${OPENMC_FORCE_VENDORED_LIBS}") -message(STATUS "OPENMC_ENABLE_STRICT_FP ${OPENMC_ENABLE_STRICT_FP}") - -# Warnings for deprecated options -foreach(OLD_OPT IN ITEMS "openmp" "profile" "coverage" "dagmc" "libmesh") - if(DEFINED ${OLD_OPT}) - string(TOUPPER ${OLD_OPT} OPT_UPPER) - if ("${OLD_OPT}" STREQUAL "profile" OR "${OLD_OPT}" STREQUAL "coverage") - set(NEW_OPT_PREFIX "OPENMC_ENABLE") - else() - set(NEW_OPT_PREFIX "OPENMC_USE") - endif() - message(WARNING "The OpenMC CMake option '${OLD_OPT}' has been deprecated. " - "Its value will be ignored. " - "Please use '-D${NEW_OPT_PREFIX}_${OPT_UPPER}=${${OLD_OPT}}' instead.") - unset(${OLD_OPT} CACHE) - endif() -endforeach() - -foreach(OLD_BLD in ITEMS "debug" "optimize") - if(DEFINED ${OLD_BLD}) - if("${OLD_BLD}" STREQUAL "debug") - set(BLD_VAR "Debug") - else() - set(BLD_VAR "Release") - endif() - message(WARNING "The OpenMC CMake option '${OLD_BLD}' has been deprecated. " - "Its value will be ignored. " - "OpenMC now uses the CMAKE_BUILD_TYPE variable to set the build mode. " - "Please use '-DCMAKE_BUILD_TYPE=${BLD_VAR}' instead.") - unset(${OLD_BLD} CACHE) - endif() -endforeach() - -#=============================================================================== -# Set a default build configuration if not explicitly specified -#=============================================================================== - -if(NOT CMAKE_BUILD_TYPE) - message(STATUS "No build type selected, defaulting to RelWithDebInfo") - set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build" FORCE) -endif() - -#=============================================================================== -# When STRICT_FP is enabled, remove NDEBUG from RelWithDebInfo flags so that -# assert() remains active. CMake normally adds -DNDEBUG for both Release and -# RelWithDebInfo, which disables C/C++ assert() statements. -#=============================================================================== - -if(OPENMC_ENABLE_STRICT_FP) - foreach(FLAG_VAR CMAKE_CXX_FLAGS_RELWITHDEBINFO CMAKE_C_FLAGS_RELWITHDEBINFO) - string(REPLACE "-DNDEBUG" "" ${FLAG_VAR} "${${FLAG_VAR}}") - string(REPLACE "/DNDEBUG" "" ${FLAG_VAR} "${${FLAG_VAR}}") - endforeach() -endif() - -#=============================================================================== -# OpenMP for shared-memory parallelism (and GPU support some day!) -#=============================================================================== - -if(OPENMC_USE_OPENMP) - find_package(OpenMP REQUIRED) -endif() - -#=============================================================================== -# MPI for distributed-memory parallelism -#=============================================================================== - -if(OPENMC_USE_MPI) - find_package(MPI REQUIRED) -endif() - -#=============================================================================== -# Helper macro for finding a dependency -#=============================================================================== - -macro(find_package_write_status pkg) - find_package(${pkg} QUIET NO_SYSTEM_ENVIRONMENT_PATH) - if(${pkg}_FOUND) - message(STATUS "Found ${pkg}: ${${pkg}_DIR} (version ${${pkg}_VERSION})") - else() - message(STATUS "Did not find ${pkg}, will use submodule instead") - endif() -endmacro() - -#=============================================================================== -# DAGMC Geometry Support - need DAGMC/MOAB -#=============================================================================== - -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.") - 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() - -#=============================================================================== -# libMesh Unstructured Mesh Support -#=============================================================================== - -if(OPENMC_USE_LIBMESH) - find_package(LIBMESH REQUIRED) -endif() - -#=============================================================================== -# libpng -#=============================================================================== - -find_package(PNG) - -#=============================================================================== -# HDF5 for binary output -#=============================================================================== - -# Unfortunately FindHDF5.cmake will always prefer a serial HDF5 installation -# over a parallel installation if both appear on the user's PATH. To get around -# this, we check for the environment variable HDF5_ROOT and if it exists, use it -# to check whether its a parallel version. - -if(NOT DEFINED HDF5_PREFER_PARALLEL) - if(DEFINED ENV{HDF5_ROOT} AND EXISTS $ENV{HDF5_ROOT}/bin/h5pcc) - set(HDF5_PREFER_PARALLEL TRUE) - else() - set(HDF5_PREFER_PARALLEL FALSE) - endif() -endif() - -find_package(HDF5 REQUIRED COMPONENTS C HL) - -# Remove HDF5 transitive dependencies that are system libraries -list(FILTER HDF5_LIBRARIES EXCLUDE REGEX ".*lib(pthread|dl|m).*") -message(STATUS "HDF5 Libraries: ${HDF5_LIBRARIES}") - -if(HDF5_IS_PARALLEL) - if(NOT OPENMC_USE_MPI) - message(FATAL_ERROR "Parallel HDF5 was detected, but MPI was not enabled.\ +cmake_minimum_required(VERSION 3.16 FATAL_ERROR) project(openmc C CXX) + +#Set module path + set(CMAKE_MODULE_PATH $ {CMAKE_CURRENT_SOURCE_DIR} / cmake / Modules) + + include(GetVersionFromGit) + +#Output version information + message(STATUS "OpenMC version: ${OPENMC_VERSION}") message( + STATUS "OpenMC dev state: ${OPENMC_DEV_STATE}") message(STATUS + "OpenMC commit hash: ${OPENMC_COMMIT_HASH}") message(STATUS + "OpenMC commit count: ${OPENMC_COMMIT_COUNT}") + +#Generate version.h + configure_file( + include / openmc / + version.h.in "${CMAKE_BINARY_DIR}/include/openmc/version.h" @ONLY) + +#Setup output directories + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY $ {CMAKE_BINARY_DIR} / lib) set( + CMAKE_LIBRARY_OUTPUT_DIRECTORY $ {CMAKE_BINARY_DIR} / + lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY $ {CMAKE_BINARY_DIR} / bin) + +#Enable correct usage of CXX_EXTENSIONS + if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.22) cmake_policy( + SET CMP0128 NEW) endif() + +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = +#Command line options +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = + + option(OPENMC_USE_OPENMP "Enable shared-memory parallelism with " + "OpenMP" ON) option(OPENMC_BUILD_TESTS + "Build tests" ON) option(OPENMC_ENABLE_PROFILE + "Compile with profiling flags" OFF) option(OPENMC_ENABLE_COVERAGE + "Compile with coverage analysis flags" OFF) + option(OPENMC_USE_DAGMC "Enable support for DAGMC (CAD) " + "geometry" OFF) option( + OPENMC_USE_LIBMESH "Enable support for libMesh unstructured " + "mesh tallies" OFF) option(OPENMC_USE_MPI + "Enable MPI" OFF) option(OPENMC_USE_UWUW + "Enable UWUW" OFF) option(OPENMC_FORCE_VENDORED_LIBS + "Explicitly use submodules defined in 'vendor'" OFF) + option(OPENMC_ENABLE_STRICT_FP + "Enable strict FP flags to improve test portability" OFF) + + message(STATUS + "OPENMC_USE_OPENMP ${OPENMC_USE_OPENMP}") message(STATUS + "OPENMC_BUILD_TESTS ${OPENMC_BUILD_TESTS}") message(STATUS + "OPENMC_ENABLE_PROFILE ${OPENMC_ENABLE_PROFILE}") message(STATUS + "OPENMC_ENABLE_COVERAGE ${OPENMC_ENABLE_COVERAGE}") message(STATUS + "OPENMC_USE_DAGMC ${OPENMC_USE_DAGMC}") message(STATUS + "OPENMC_USE_LIBMESH ${OPENMC_USE_LIBMESH}") message(STATUS + "OPENMC_USE_MPI ${OPENMC_USE_MPI}") message(STATUS + "OPENMC_USE_UWUW ${OPENMC_USE_UWUW}") message(STATUS + "OPENMC_FORCE_VENDORED_LIBS " + "${OPENMC_FORCE_VENDORED_LIBS}") message(STATUS + "OPENMC_ENABLE_STRICT_FP ${OPENMC_ENABLE_STRICT_FP}") + +#Warnings for deprecated options + foreach (OLD_OPT IN ITEMS + "openmp" + "profile" + "coverage" + "dagmc" + "libmesh") if (DEFINED $ {OLD_OPT}) string(TOUPPER $ { + OLD_OPT} OPT_UPPER) if ("${OLD_OPT}" STREQUAL + "profile" OR + "${OLD_OPT}" STREQUAL + "coverage") set(NEW_OPT_PREFIX + "OPENMC_ENABLE") else() set(NEW_OPT_PREFIX + "OPENMC_USE") endif() message(WARNING + "The OpenMC CMake option '${OLD_OPT}' has been " + "deprecated. " + "Its value will be ignored. " + "Please use " + "'-D${NEW_OPT_PREFIX}_${OPT_UPPER}=${${OLD_OPT}}' " + "instead.") unset($ { + OLD_OPT} CACHE) endif() endforeach() + + foreach (OLD_BLD in ITEMS + "debug" + "optimize") if (DEFINED $ { + OLD_BLD}) if ("${OLD_BLD}" STREQUAL + "debug") set(BLD_VAR + "Debug") else() set(BLD_VAR + "Release") endif() message(WARNING "The OpenMC CMake " + "option " + "'${OLD_BLD}' has " + "been deprecated. " + "Its value will " + "be ignored. " + "OpenMC now uses " + "the " + "CMAKE_BUILD_TYPE " + "variable to set " + "the build mode. " + "Please use " + "'-DCMAKE_BUILD_" + "TYPE=${BLD_VAR}' " + "instead.") unset($ { + OLD_BLD} CACHE) endif() endforeach() + +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = +#Set a default build configuration if not explicitly specified +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = + + if (NOT CMAKE_BUILD_TYPE) message( + STATUS "No build type selected, defaulting to " + "RelWithDebInfo") set(CMAKE_BUILD_TYPE + RelWithDebInfo CACHE STRING + "Choose the type of build" FORCE) endif() + +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = +#When STRICT_FP is enabled, remove NDEBUG from RelWithDebInfo flags so that +#assert() remains active.CMake normally adds - DNDEBUG for both Release and +#RelWithDebInfo, which disables C / C++ assert() statements. +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = + + if (OPENMC_ENABLE_STRICT_FP) foreach ( + FLAG_VAR CMAKE_CXX_FLAGS_RELWITHDEBINFO + CMAKE_C_FLAGS_RELWITHDEBINFO) string(REPLACE + "-DNDEBUG" + "" $ { FLAG_VAR } "${${FLAG_VAR}}") string(REPLACE + "/DNDEBUG" + "" $ { + FLAG_VAR + } "${${FLAG_VAR}}") endforeach() endif() + +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = +#OpenMP for shared - memory parallelism(and GPU support some day !) +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = + + if (OPENMC_USE_OPENMP) find_package( + OpenMP REQUIRED) endif() + +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = +#MPI for distributed - memory parallelism +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = + + if (OPENMC_USE_MPI) find_package( + MPI REQUIRED) endif() + +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = +#Helper macro for finding a dependency +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = + + macro(find_package_write_status + pkg) find_package($ {pkg} QUIET + NO_SYSTEM_ENVIRONMENT_PATH) if ($ { + pkg} _FOUND) + message(STATUS + "Found ${pkg}: ${${pkg}_DIR} (version " + "${${pkg}_VERSION})") else() message(STATUS + "Did not find ${pkg}, will use submodule " + "instead") endif() endmacro() + +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = +#DAGMC Geometry Support - need DAGMC / MOAB +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = + + 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.") 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() + +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = +#libMesh Unstructured Mesh Support +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = + + if (OPENMC_USE_LIBMESH) find_package( + LIBMESH REQUIRED) endif() + +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = +#libpng +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = + + find_package(PNG) + +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = +#HDF5 for binary output +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = + +#Unfortunately FindHDF5.cmake will always prefer a serial HDF5 installation +#over a parallel installation if both appear on the user's PATH. To get around +#this, we check for the environment variable HDF5_ROOT and if it exists, use it +#to check whether its a parallel version. + + if (NOT DEFINED HDF5_PREFER_PARALLEL) if ( + DEFINED ENV { + HDF5_ROOT} AND EXISTS $ENV { + HDF5_ROOT} / + bin / h5pcc) + set(HDF5_PREFER_PARALLEL + TRUE) else() + set(HDF5_PREFER_PARALLEL + FALSE) endif() endif() + + find_package(HDF5 REQUIRED + COMPONENTS C HL) + +#Remove HDF5 transitive dependencies that are system libraries + list( + FILTER HDF5_LIBRARIES + EXCLUDE REGEX + ".*lib(pthread|dl|m)." + "*") message(STATUS + "HDF5 Libraries: " + "${HDF5_LIBRARIES}") + + if (HDF5_IS_PARALLEL) if ( + NOT OPENMC_USE_MPI) + message(FATAL_ERROR + "Parallel HDF5 was detected, but MPI was not enabled.\ To use parallel HDF5, OpenMC needs to be built with MPI support by passing\ - -DOPENMC_USE_MPI=ON when calling cmake.") - endif() - message(STATUS "Using parallel HDF5") -endif() - -# Version 1.12 of HDF5 deprecates the H5Oget_info_by_idx() interface. -# Thus, we give these flags to allow usage of the old interface in newer -# versions of HDF5. -if(${HDF5_VERSION} VERSION_GREATER_EQUAL 1.12.0) - list(APPEND cxxflags -DH5Oget_info_by_idx_vers=1 -DH5O_info_t_vers=1) -endif() - -#=============================================================================== -# Set compile/link flags based on which compiler is being used -#=============================================================================== - -# When OPENMC_ENABLE_STRICT_FP is enabled, disable compiler optimizations that change -# floating-point results relative to -O0, improving cross-platform and -# cross-optimization-level reproducibility for regression testing: -# -ffp-contract=off Prevents FMA contraction (fused multiply-add changes rounding) -# -fno-builtin Prevents replacing math function calls (pow, exp, log, etc.) -# with builtin versions that may differ from libm -# By default (OFF), the compiler is free to use all optimizations for best -# performance. -if(OPENMC_ENABLE_STRICT_FP) - include(CheckCXXCompilerFlag) - check_cxx_compiler_flag(-ffp-contract=off SUPPORTS_FP_CONTRACT_OFF) - if(SUPPORTS_FP_CONTRACT_OFF) - list(APPEND cxxflags -ffp-contract=off) - endif() - check_cxx_compiler_flag(-fno-builtin SUPPORTS_NO_BUILTIN) - if(SUPPORTS_NO_BUILTIN) - list(APPEND cxxflags -fno-builtin) - endif() -endif() - -# Skip for Visual Studio which has its own configurations through GUI -if(NOT MSVC) - -set(CMAKE_POSITION_INDEPENDENT_CODE ON) - -if(OPENMC_ENABLE_PROFILE) - list(APPEND cxxflags -g -fno-omit-frame-pointer) -endif() - -if(OPENMC_ENABLE_COVERAGE) - list(APPEND cxxflags --coverage) - list(APPEND ldflags --coverage) -endif() - -# Show flags being used -message(STATUS "OpenMC C++ flags: ${cxxflags}") -message(STATUS "OpenMC Linker flags: ${ldflags}") - -endif() - -#=============================================================================== -# Update git submodules as needed -#=============================================================================== -if(GIT_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") - option(GIT_SUBMODULE "Check submodules during build" ON) - if(GIT_SUBMODULE) - message(STATUS "Submodule update") - execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - RESULT_VARIABLE GIT_SUBMOD_RESULT) - if(NOT GIT_SUBMOD_RESULT EQUAL 0) - message(FATAL_ERROR "git submodule update --init failed with \ - ${GIT_SUBMOD_RESULT}, please checkout submodules") - endif() - endif() -endif() - -# Check to see if submodules exist (by checking one) -if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/vendor/pugixml/CMakeLists.txt") - message(FATAL_ERROR "The git submodules were not downloaded! GIT_SUBMODULE was \ - turned off or failed. Please update submodules and try again.") -endif() - -#=============================================================================== -# pugixml library -#=============================================================================== - -if(OPENMC_FORCE_VENDORED_LIBS) - add_subdirectory(vendor/pugixml) - set_target_properties(pugixml PROPERTIES CXX_STANDARD 14 CXX_EXTENSIONS OFF) -else() - find_package_write_status(pugixml) - if (NOT pugixml_FOUND) - add_subdirectory(vendor/pugixml) - set_target_properties(pugixml PROPERTIES CXX_STANDARD 14 CXX_EXTENSIONS OFF) - endif() -endif() - -#=============================================================================== -# {fmt} library -#=============================================================================== - -if(OPENMC_FORCE_VENDORED_LIBS) - set(FMT_INSTALL ON CACHE BOOL "Generate the install target.") - add_subdirectory(vendor/fmt) -else() - find_package_write_status(fmt) - if (NOT fmt_FOUND) - set(FMT_INSTALL ON CACHE BOOL "Generate the install target.") - add_subdirectory(vendor/fmt) - endif() -endif() - -#=============================================================================== -# Catch2 library -#=============================================================================== - -if(OPENMC_BUILD_TESTS) - if (OPENMC_FORCE_VENDORED_LIBS) - add_subdirectory(vendor/Catch2) - else() - find_package_write_status(Catch2) - if (NOT Catch2_FOUND) - add_subdirectory(vendor/Catch2) - endif() - endif() -endif() - -#=============================================================================== -# RPATH information -#=============================================================================== - -# Provide install directory variables as defined by GNU coding standards -include(GNUInstallDirs) - -# This block of code ensures that dynamic libraries can be found via the RPATH -# whether the executable is the original one from the build directory or the -# installed one in CMAKE_INSTALL_PREFIX. Ref: -# https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling - -# use, i.e. don't skip the full RPATH for the build tree -set(CMAKE_SKIP_BUILD_RPATH FALSE) - -# when building, don't use the install RPATH already -# (but later on when installing) -set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) - -# add the automatically determined parts of the RPATH -# which point to directories outside the build tree to the install RPATH -set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) - -# the RPATH to be used when installing, but only if it's not a system directory -list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_FULL_LIBDIR}" isSystemDir) -if("${isSystemDir}" STREQUAL "-1") - set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}") -endif() - -#=============================================================================== -# libopenmc -#=============================================================================== - -list(APPEND libopenmc_SOURCES - src/atomic_mass.cpp - src/bank.cpp - src/boundary_condition.cpp - src/bremsstrahlung.cpp - src/cell.cpp - src/chain.cpp - src/cmfd_solver.cpp - src/collision_track.cpp - src/cross_sections.cpp - src/dagmc.cpp - src/distribution.cpp - src/distribution_angle.cpp - src/distribution_energy.cpp - src/distribution_multi.cpp - src/distribution_spatial.cpp - src/eigenvalue.cpp - src/endf.cpp - src/error.cpp - src/event.cpp - src/file_utils.cpp - src/finalize.cpp - src/geometry.cpp - src/geometry_aux.cpp - src/hdf5_interface.cpp - src/ifp.cpp - src/initialize.cpp - src/lattice.cpp - src/material.cpp - src/math_functions.cpp - src/mcpl_interface.cpp - src/mesh.cpp - src/message_passing.cpp - src/mgxs.cpp - src/mgxs_interface.cpp - src/ncrystal_interface.cpp - src/ncrystal_load.cpp - src/nuclide.cpp - src/output.cpp - src/particle.cpp - src/particle_data.cpp - src/particle_restart.cpp - src/particle_type.cpp - src/photon.cpp - src/physics.cpp - src/physics_common.cpp - src/physics_mg.cpp - src/plot.cpp - src/position.cpp - src/progress_bar.cpp - src/random_dist.cpp - src/random_lcg.cpp - src/random_ray/random_ray_simulation.cpp - src/random_ray/random_ray.cpp - src/random_ray/flat_source_domain.cpp - src/random_ray/linear_source_domain.cpp - src/random_ray/moment_matrix.cpp - src/random_ray/source_region.cpp - src/ray.cpp - src/reaction.cpp - src/reaction_product.cpp - src/scattdata.cpp - src/secondary_correlated.cpp - src/secondary_kalbach.cpp - src/secondary_nbody.cpp - src/secondary_thermal.cpp - src/secondary_uncorrelated.cpp - src/settings.cpp - src/simulation.cpp - src/source.cpp - src/state_point.cpp - src/string_utils.cpp - src/summary.cpp - src/surface.cpp - src/tallies/derivative.cpp - src/tallies/filter.cpp - src/tallies/filter_azimuthal.cpp - src/tallies/filter_cell.cpp - src/tallies/filter_cell_instance.cpp - src/tallies/filter_cellborn.cpp - src/tallies/filter_cellfrom.cpp - src/tallies/filter_collision.cpp - src/tallies/filter_delayedgroup.cpp - src/tallies/filter_distribcell.cpp - src/tallies/filter_energy.cpp - src/tallies/filter_energyfunc.cpp - src/tallies/filter_legendre.cpp - src/tallies/filter_material.cpp - src/tallies/filter_materialfrom.cpp - src/tallies/filter_mesh.cpp - src/tallies/filter_meshborn.cpp - src/tallies/filter_meshmaterial.cpp - src/tallies/filter_meshsurface.cpp - src/tallies/filter_mu.cpp - src/tallies/filter_musurface.cpp - src/tallies/filter_parent_nuclide.cpp - src/tallies/filter_particle.cpp - src/tallies/filter_particle_production.cpp - src/tallies/filter_polar.cpp - src/tallies/filter_reaction.cpp - src/tallies/filter_sph_harm.cpp - src/tallies/filter_sptl_legendre.cpp - src/tallies/filter_surface.cpp - src/tallies/filter_time.cpp - src/tallies/filter_universe.cpp - src/tallies/filter_weight.cpp - src/tallies/filter_zernike.cpp - src/tallies/tally.cpp - src/tallies/tally_scoring.cpp - src/tallies/trigger.cpp - src/thermal.cpp - src/timer.cpp - src/track_output.cpp - src/universe.cpp - src/urr.cpp - src/volume_calc.cpp - src/weight_windows.cpp - src/wmp.cpp - src/xml_interface.cpp - src/xsdata.cpp) - -# Add bundled external dependencies -list(APPEND libopenmc_SOURCES - src/external/quartic_solver.cpp - src/external/Faddeeva.cc) - -# For Visual Studio compilers -if(MSVC) - # Use static library (otherwise explicit symbol portings are needed) - add_library(libopenmc STATIC ${libopenmc_SOURCES}) - - # To use the shared HDF5 libraries on Windows, the H5_BUILT_AS_DYNAMIC_LIB - # compile definition must be specified. - target_compile_definitions(libopenmc PRIVATE -DH5_BUILT_AS_DYNAMIC_LIB) -else() - add_library(libopenmc SHARED ${libopenmc_SOURCES}) -endif() - -add_library(OpenMC::libopenmc ALIAS libopenmc) - -# Avoid vs error lnk1149 :output filename matches input filename -if(NOT MSVC) - set_target_properties(libopenmc PROPERTIES OUTPUT_NAME openmc) -endif() - -target_include_directories(libopenmc - PUBLIC - $ - $ - ${HDF5_INCLUDE_DIRS} -) - -# Set compile flags -target_compile_options(libopenmc PRIVATE ${cxxflags}) - -# Add include directory for configured version file -target_include_directories(libopenmc - PUBLIC $) - -if (HDF5_IS_PARALLEL) - target_compile_definitions(libopenmc PRIVATE -DPHDF5) -endif() -if (OPENMC_USE_MPI) - target_compile_definitions(libopenmc PUBLIC -DOPENMC_MPI) -endif() - -# target_link_libraries treats any arguments starting with - but not -l as -# linker flags. Thus, we can pass both linker flags and libraries together. -target_link_libraries(libopenmc ${ldflags} ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES} - fmt::fmt ${CMAKE_DL_LIBS}) - -if(TARGET pugixml::pugixml) - target_link_libraries(libopenmc pugixml::pugixml) -else() - target_link_libraries(libopenmc pugixml) -endif() - -if(OPENMC_USE_DAGMC) - target_compile_definitions(libopenmc PRIVATE OPENMC_DAGMC_ENABLED) - target_link_libraries(libopenmc dagmc-shared) - - if(OPENMC_USE_UWUW) - target_compile_definitions(libopenmc PRIVATE OPENMC_UWUW_ENABLED) - target_link_libraries(libopenmc uwuw-shared) - endif() -elseif(OPENMC_USE_UWUW) - set(OPENMC_USE_UWUW OFF) - message(FATAL_ERROR "DAGMC must be enabled when UWUW is enabled.") -endif() - -if(OPENMC_USE_LIBMESH) - target_compile_definitions(libopenmc PRIVATE OPENMC_LIBMESH_ENABLED) - target_link_libraries(libopenmc PkgConfig::LIBMESH) -endif() - -if (PNG_FOUND) - target_compile_definitions(libopenmc PRIVATE USE_LIBPNG) - target_link_libraries(libopenmc PNG::PNG) -endif() - -if (OPENMC_USE_OPENMP) - target_link_libraries(libopenmc OpenMP::OpenMP_CXX) -endif() - -if (OPENMC_USE_MPI) - target_link_libraries(libopenmc MPI::MPI_CXX) -endif() - -if (OPENMC_BUILD_TESTS) - # Add cpp tests directory - include(CTest) - add_subdirectory(tests/cpp_unit_tests) -endif() - -#=============================================================================== -# Log build info that this executable can report later -#=============================================================================== -target_compile_definitions(libopenmc PRIVATE BUILD_TYPE=${CMAKE_BUILD_TYPE}) -target_compile_definitions(libopenmc PRIVATE COMPILER_ID=${CMAKE_CXX_COMPILER_ID}) -target_compile_definitions(libopenmc PRIVATE COMPILER_VERSION=${CMAKE_CXX_COMPILER_VERSION}) -if (OPENMC_ENABLE_PROFILE) - target_compile_definitions(libopenmc PRIVATE PROFILINGBUILD) -endif() -if (OPENMC_ENABLE_COVERAGE) - target_compile_definitions(libopenmc PRIVATE COVERAGEBUILD) -endif() -if (OPENMC_ENABLE_STRICT_FP) - target_compile_definitions(libopenmc PRIVATE OPENMC_ENABLE_STRICT_FP) -endif() - -#=============================================================================== -# openmc executable -#=============================================================================== -add_executable(openmc src/main.cpp) -add_executable(OpenMC::openmc ALIAS openmc) -target_compile_options(openmc PRIVATE ${cxxflags}) -target_include_directories(openmc PRIVATE ${CMAKE_BINARY_DIR}/include) -target_link_libraries(openmc libopenmc) - -# Ensure C++17 standard is used and turn off GNU extensions -target_compile_features(openmc PUBLIC cxx_std_17) -target_compile_features(libopenmc PUBLIC cxx_std_17) -set_target_properties(openmc libopenmc PROPERTIES CXX_EXTENSIONS OFF) - -#=============================================================================== -# Python package -#=============================================================================== - -add_custom_command(TARGET libopenmc POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - $ - ${CMAKE_CURRENT_SOURCE_DIR}/openmc/lib/$ - COMMENT "Copying libopenmc to Python module directory") - -#=============================================================================== -# Install executable, scripts, manpage, license -#=============================================================================== - -configure_file(cmake/OpenMCConfig.cmake.in "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMCConfig.cmake" @ONLY) -configure_file(cmake/OpenMCConfigVersion.cmake.in "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMCConfigVersion.cmake" @ONLY) - -set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/OpenMC) -install(TARGETS openmc libopenmc - EXPORT openmc-targets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} -) -install(EXPORT openmc-targets - FILE OpenMCTargets.cmake - NAMESPACE OpenMC:: - DESTINATION ${INSTALL_CONFIGDIR}) - -install(FILES - "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMCConfig.cmake" - "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMCConfigVersion.cmake" - DESTINATION ${INSTALL_CONFIGDIR}) -install(FILES man/man1/openmc.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) -install(FILES LICENSE DESTINATION "${CMAKE_INSTALL_DOCDIR}" RENAME copyright) -install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) -install(FILES "${CMAKE_BINARY_DIR}/include/openmc/version.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/openmc) + -DOPENMC_USE_MPI=ON when calling cmake.") endif() message(STATUS + "Using parallel " + "HDF5") endif() + +#Version 1.12 of HDF5 deprecates the H5Oget_info_by_idx() interface. +#Thus, we give these flags to allow usage of the old interface in newer +#versions of HDF5. + if ($ {HDF5_VERSION} VERSION_GREATER_EQUAL 1.12.0) list( + APPEND + cxxflags - + DH5Oget_info_by_idx_vers = + 1 - + DH5O_info_t_vers = + 1) endif() + +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = +#Set compile / link flags based on which compiler is being used +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = + +#When OPENMC_ENABLE_STRICT_FP is enabled, \ + disable compiler optimizations that change +#floating - point results relative to - O0, improving cross - platform and +#cross - optimization - level reproducibility for regression testing: +#- ffp - contract = off Prevents FMA contraction( \ + fused multiply - add changes rounding) +#- fno - builtin Prevents replacing math function calls(pow, exp, log, etc.) +#with builtin versions that may differ from libm +#By default(OFF), the compiler is free to use all optimizations for best +#performance. + if (OPENMC_ENABLE_STRICT_FP) include(CheckCXXCompilerFlag) check_cxx_compiler_flag( + -ffp - + contract = off + SUPPORTS_FP_CONTRACT_OFF) if (SUPPORTS_FP_CONTRACT_OFF) + list( + APPEND + cxxflags - + ffp - + contract = + off) endif() + check_cxx_compiler_flag( + -fno - + builtin + SUPPORTS_NO_BUILTIN) if (SUPPORTS_NO_BUILTIN) + list( + APPEND + cxxflags - + fno - + builtin) endif() endif() + +#Skip for Visual Studio which has its own configurations through GUI + if ( + NOT + MSVC) + + set( + CMAKE_POSITION_INDEPENDENT_CODE + ON) + + if (OPENMC_ENABLE_PROFILE) list( + APPEND + cxxflags - + g - + fno - + omit - + frame - + pointer) endif() + + if (OPENMC_ENABLE_COVERAGE) list( + APPEND + cxxflags-- coverage) list(APPEND + ldflags-- coverage) endif() + +#Show flags being used + message( + STATUS + "OpenMC C++ flags: ${cxxflags}") + message( + STATUS + "OpenMC Linker flags: ${ldflags}") + + endif() + +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = +#Update git submodules as needed +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = + if ( + GIT_FOUND + AND EXISTS + "${CMAKE_CURRENT_SOURCE_DIR}/.git") + option( + GIT_SUBMODULE + "Check submodules during build" ON) if (GIT_SUBMODULE) + message( + STATUS + "Submodule update") + execute_process( + COMMAND $ { + GIT_EXECUTABLE} submodule + update-- init-- recursive WORKING_DIRECTORY + $ { + CMAKE_CURRENT_SOURCE_DIR} RESULT_VARIABLE + GIT_SUBMOD_RESULT) if (NOT GIT_SUBMOD_RESULT + EQUAL 0) + message( + FATAL_ERROR + "git submodule update --init failed with \ + ${GIT_SUBMOD_RESULT}, please checkout submodules") endif() endif() endif() + +#Check to see if submodules exist(by checking one) + if ( + NOT EXISTS + "${CMAKE_CURRENT_SOURCE_DIR}/vendor/pugixml/CMakeLists.txt") + message( + FATAL_ERROR + "The git submodules were not downloaded! GIT_SUBMODULE was \ + turned off or failed. Please update submodules and try again.") endif() + +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = +#pugixml library +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = + + if ( + OPENMC_FORCE_VENDORED_LIBS) add_subdirectory(vendor / + pugixml) + set_target_properties( + pugixml PROPERTIES + CXX_STANDARD 14 CXX_EXTENSIONS + OFF) else() + find_package_write_status( + pugixml) if (NOT + pugixml_FOUND) + add_subdirectory( + vendor / + pugixml) + set_target_properties( + pugixml PROPERTIES + CXX_STANDARD 14 CXX_EXTENSIONS + OFF) + endif() + endif() + +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = +#{fmt } library +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = + + if ( + OPENMC_FORCE_VENDORED_LIBS) + set( + FMT_INSTALL + ON + CACHE BOOL + "Generate the install target.") + add_subdirectory( + vendor / + fmt) else() + find_package_write_status( + fmt) if (NOT + fmt_FOUND) + set(FMT_INSTALL ON CACHE BOOL "Generate the install target.") add_subdirectory( + vendor / + fmt) + endif() endif() + +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = +#Catch2 library +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = + + if (OPENMC_BUILD_TESTS) if ( + OPENMC_FORCE_VENDORED_LIBS) + add_subdirectory( + vendor / + Catch2) else() + find_package_write_status( + Catch2) if (NOT + Catch2_FOUND) + add_subdirectory( + vendor / + Catch2) + endif() + endif() endif() + +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = +#RPATH information +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = + +#Provide install directory variables as defined by GNU coding standards + include( + GNUInstallDirs) + +#This block of code ensures that dynamic libraries can be found via the RPATH +#whether the executable is the original one from the build directory or the +#installed one in CMAKE_INSTALL_PREFIX.Ref: +#https: // gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling + +#use, i.e.don't skip the full RPATH for the build tree + set( + CMAKE_SKIP_BUILD_RPATH + FALSE) + +#when building, don't use the install RPATH already +#(but later on when installing) + set( + CMAKE_BUILD_WITH_INSTALL_RPATH + FALSE) + +#add the automatically determined parts of the RPATH +#which point to directories outside the build tree to the install RPATH + set( + CMAKE_INSTALL_RPATH_USE_LINK_PATH + TRUE) + +#the RPATH to be used when installing, but only if it's not a system directory + list( + FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES + "${CMAKE_INSTALL_FULL_LIBDIR}" isSystemDir) if ("${isSystemDir}" STREQUAL + "-1") + set( + CMAKE_INSTALL_RPATH + "${CMAKE_INSTALL_FULL_LIBDIR}") endif() + +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = +#libopenmc +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = + + list(APPEND libopenmc_SOURCES + src / + atomic_mass + .cpp + src / + bank + .cpp + src / + boundary_condition + .cpp + src / + bremsstrahlung + .cpp + src / + cell + .cpp + src / + chain + .cpp + src / + cmfd_solver + .cpp + src / + collision_track + .cpp + src / + cross_sections + .cpp + src / + dagmc + .cpp + src / + distribution + .cpp + src / + distribution_angle + .cpp + src / + distribution_energy + .cpp + src / + distribution_multi + .cpp + src / + distribution_spatial + .cpp + src / + eigenvalue + .cpp + src / + endf + .cpp + src / + error + .cpp + src / + event + .cpp + src / + file_utils + .cpp + src / + finalize + .cpp + src / + geometry + .cpp + src / + geometry_aux + .cpp + src / + hdf5_interface + .cpp + src / + ifp + .cpp + src / + initialize + .cpp + src / + lattice + .cpp + src / + material + .cpp + src / + math_functions + .cpp + src / + mcpl_interface + .cpp + src / + mesh + .cpp + src / + message_passing + .cpp + src / + mgxs + .cpp + src / + mgxs_interface + .cpp + src / + ncrystal_interface + .cpp + src / + ncrystal_load + .cpp + src / + nuclide + .cpp + src / + output + .cpp + src / + particle + .cpp + src / + particle_data + .cpp + src / + particle_restart + .cpp + src / + particle_type + .cpp + src / + photon + .cpp + src / + physics + .cpp + src / + physics_common + .cpp + src / + physics_mg + .cpp + src / + plot + .cpp + src / + position + .cpp + src / + progress_bar + .cpp + src / + random_dist + .cpp + src / + random_lcg + .cpp + src / + random_ray / + random_ray_simulation + .cpp + src / + random_ray / + random_ray + .cpp + src / + random_ray / + flat_source_domain + .cpp + src / + random_ray / + linear_source_domain + .cpp + src / + random_ray / + moment_matrix + .cpp + src / + random_ray / + source_region + .cpp + src / + ray + .cpp + src / + reaction + .cpp + src / + reaction_product + .cpp + src / + scattdata + .cpp + src / + secondary_correlated + .cpp + src / + secondary_kalbach + .cpp + src / + secondary_nbody + .cpp + src / + secondary_thermal + .cpp + src / + secondary_uncorrelated + .cpp + src / + settings + .cpp + src / + simulation + .cpp + src / + source + .cpp + src / + state_point + .cpp + src / + string_utils + .cpp + src / + summary + .cpp + src / + surface + .cpp + src / + tallies / + derivative + .cpp + src / + tallies / + filter + .cpp + src / + tallies / + filter_azimuthal + .cpp + src / + tallies / + filter_cell + .cpp + src / + tallies / + filter_cell_instance + .cpp + src / + tallies / + filter_cellborn + .cpp + src / + tallies / + filter_cellfrom + .cpp + src / + tallies / + filter_collision + .cpp + src / + tallies / + filter_delayedgroup + .cpp + src / + tallies / + filter_distribcell + .cpp + src / + tallies / + filter_energy + .cpp + src / + tallies / + filter_energyfunc + .cpp + src / + tallies / + filter_legendre + .cpp + src / + tallies / + filter_material + .cpp + src / + tallies / + filter_materialfrom + .cpp + src / + tallies / + filter_mesh + .cpp + src / + tallies / + filter_meshborn + .cpp + src / + tallies / + filter_meshmaterial + .cpp + src / + tallies / + filter_meshsurface + .cpp + src / + tallies / + filter_mu + .cpp + src / + tallies / + filter_musurface + .cpp + src / + tallies / + filter_parent_nuclide + .cpp + src / + tallies / + filter_particle + .cpp + src / + tallies / + filter_particle_production + .cpp + src / + tallies / + filter_polar + .cpp + src / + tallies / + filter_reaction + .cpp + src / + tallies / + filter_sph_harm + .cpp + src / + tallies / + filter_sptl_legendre + .cpp + src / + tallies / + filter_surface + .cpp + src / + tallies / + filter_time + .cpp + src / + tallies / + filter_universe + .cpp + src / + tallies / + filter_weight + .cpp + src / + tallies / + filter_zernike + .cpp + src / + tallies / + tally + .cpp + src / + tallies / + tally_scoring + .cpp + src / + tallies / + trigger + .cpp + src / + thermal + .cpp + src / + timer + .cpp + src / + track_output + .cpp + src / + universe + .cpp + src / + urr + .cpp + src / + volume_calc + .cpp + src / + weight_windows + .cpp + src / + wmp + .cpp + src / + xml_interface + .cpp + src / + xsdata + .cpp) + +#Add bundled external dependencies + list(APPEND + libopenmc_SOURCES + src / + external / + quartic_solver + .cpp src / + external / + Faddeeva + .cc) + +#For Visual Studio compilers + if ( + MSVC) +#Use static library(otherwise explicit symbol portings are needed) + add_library( + libopenmc STATIC + $ { + libopenmc_SOURCES}) + +#To use the shared HDF5 libraries on Windows, the H5_BUILT_AS_DYNAMIC_LIB +#compile definition must be specified. + target_compile_definitions( + libopenmc + PRIVATE - + DH5_BUILT_AS_DYNAMIC_LIB) else() + add_library( + libopenmc SHARED + $ { + libopenmc_SOURCES}) + endif() + + add_library( + OpenMC:: + libopenmc ALIAS + libopenmc) + +#Avoid vs error lnk1149 : output filename matches input filename + if ( + NOT MSVC) + set_target_properties( + libopenmc + PROPERTIES + OUTPUT_NAME + openmc) + endif() + + target_include_directories(libopenmc PUBLIC $ $ + $ { + HDF5_INCLUDE_DIRS}) + +#Set compile flags + target_compile_options( + libopenmc PRIVATE + $ { + cxxflags}) + +#Add include directory for configured version file + target_include_directories( + libopenmc + PUBLIC + $) + + if (HDF5_IS_PARALLEL) target_compile_definitions( + libopenmc PRIVATE - DPHDF5) endif() if (OPENMC_USE_MPI) target_compile_definitions(libopenmc PUBLIC - DOPENMC_MPI) endif() + +#target_link_libraries treats any arguments starting with - but not -l as +#linker flags.Thus, we can pass both linker flags and libraries together. + target_link_libraries( + libopenmc + $ { + ldflags} $ { + HDF5_LIBRARIES} $ { + HDF5_HL_LIBRARIES} fmt:: + fmt $ { + CMAKE_DL_LIBS}) + + if ( + TARGET pugixml:: + pugixml) target_link_libraries(libopenmc pugixml:: + pugixml) else() target_link_libraries(libopenmc + pugixml) endif() + + if ( + OPENMC_USE_DAGMC) target_compile_definitions(libopenmc PRIVATE OPENMC_DAGMC_ENABLED) target_link_libraries(libopenmc + dagmc - + shared) + + if (OPENMC_USE_UWUW) target_compile_definitions(libopenmc PRIVATE OPENMC_UWUW_ENABLED) target_link_libraries(libopenmc uwuw - shared) endif() elseif( + OPENMC_USE_UWUW) set(OPENMC_USE_UWUW + OFF) message(FATAL_ERROR + "DAGMC must be enabled when UWUW is enabled.") endif() + + if ( + OPENMC_USE_LIBMESH) target_compile_definitions(libopenmc PRIVATE OPENMC_LIBMESH_ENABLED) target_link_libraries(libopenmc + PkgConfig:: + LIBMESH) endif() + + if (PNG_FOUND) target_compile_definitions( + libopenmc PRIVATE + USE_LIBPNG) target_link_libraries(libopenmc + PNG::PNG) endif() + + if (OPENMC_USE_OPENMP) target_link_libraries( + libopenmc + OpenMP:: + OpenMP_CXX) + endif() + + if ( + OPENMC_USE_MPI) + target_link_libraries( + libopenmc + MPI:: + MPI_CXX) + endif() + + if ( + OPENMC_BUILD_TESTS) +#Add cpp tests directory + include( + CTest) + add_subdirectory( + tests / + cpp_unit_tests) + endif() + +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = +#Log build info that this executable can report later +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = + target_compile_definitions( + libopenmc PRIVATE + BUILD_TYPE = + $ { + CMAKE_BUILD_TYPE}) + target_compile_definitions(libopenmc PRIVATE COMPILER_ID = $ {CMAKE_CXX_COMPILER_ID}) + target_compile_definitions(libopenmc PRIVATE COMPILER_VERSION = $ {CMAKE_CXX_COMPILER_VERSION}) if (OPENMC_ENABLE_PROFILE) target_compile_definitions(libopenmc + PRIVATE PROFILINGBUILD) + endif() if ( + OPENMC_ENABLE_COVERAGE) + target_compile_definitions( + libopenmc PRIVATE COVERAGEBUILD) + endif() if (OPENMC_ENABLE_STRICT_FP) target_compile_definitions( + libopenmc PRIVATE OPENMC_ENABLE_STRICT_FP) + endif() + +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = +#openmc executable +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = + add_executable(openmc src / main + .cpp) add_executable(OpenMC::openmc ALIAS openmc) target_compile_options(openmc + PRIVATE $ { + cxxflags}) target_include_directories(openmc PRIVATE $ {CMAKE_BINARY_DIR} / include) target_link_libraries(openmc + libopenmc) + +#Ensure C++ 17 standard is used and turn off GNU extensions + target_compile_features( + openmc + PUBLIC cxx_std_17) target_compile_features(libopenmc PUBLIC cxx_std_17) set_target_properties(openmc libopenmc PROPERTIES + CXX_EXTENSIONS + OFF) + +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = +#Python package +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = + + add_custom_command(TARGET libopenmc POST_BUILD COMMAND $ {CMAKE_COMMAND} - E copy $ < TARGET_FILE : libopenmc > + $ { + CMAKE_CURRENT_SOURCE_DIR} / + openmc / + lib / + $ < + TARGET_FILE_NAME : libopenmc > + COMMENT + "Copying libopenmc to Python module directory") + +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = +#Install executable, scripts, manpage, license +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == = + + configure_file(cmake / OpenMCConfig + .cmake + .in "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMCConfig.cmake" @ONLY) configure_file(cmake / OpenMCConfigVersion + .cmake + .in + "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMCConfigVersion.cmake" + @ONLY) + + set( + INSTALL_CONFIGDIR + $ { + CMAKE_INSTALL_LIBDIR} / + cmake / + OpenMC) install(TARGETS openmc libopenmc EXPORT + openmc - + targets RUNTIME DESTINATION + $ { + CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION $ {CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION $ {CMAKE_INSTALL_LIBDIR}) install(EXPORT openmc - targets FILE + OpenMCTargets + .cmake + NAMESPACE + OpenMC::DESTINATION + $ {INSTALL_CONFIGDIR}) + + install( + FILES + "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMCConfig.cmake" + "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMCConfigVersion.cmake" DESTINATION $ {INSTALL_CONFIGDIR}) install(FILES man / man1 / openmc.1 DESTINATION $ {CMAKE_INSTALL_MANDIR} / + man1) + install(FILES LICENSE DESTINATION "${CMAKE_INSTALL_DOCDIR}" RENAME copyright) install(DIRECTORY include / + DESTINATION + $ { + CMAKE_INSTALL_INCLUDEDIR}) + install( + FILES + "${CMAKE_BINARY_DIR}/include/openmc/version.h" DESTINATION + $ { + CMAKE_INSTALL_INCLUDEDIR} / + openmc) diff --git a/include/openmc/ray.h b/include/openmc/ray.h index f9ccac7c5de..b407d8f4414 100644 --- a/include/openmc/ray.h +++ b/include/openmc/ray.h @@ -9,12 +9,12 @@ namespace openmc { // defined regions of the geometry but also outside of it. class Ray : public GeometryState { - public: +public: // Initialize from location and direction Ray(Position r, Direction u) { init_from_r_u(r, u); } // Initialize from known geometry state - Ray(const GeometryState& p) : GeometryState(p) {} + Ray(const GeometryState& p) : GeometryState(p) {} // Called at every surface intersection within the model virtual void on_intersection() = 0; @@ -31,11 +31,11 @@ class Ray : public GeometryState { // Sets the dist_ variable void compute_distance(); - protected: +protected: // Records how far the ray has traveled double traversal_distance_ {0.0}; - private: +private: // Max intersections before we assume ray tracing is caught in an infinite // loop: static const int MAX_INTERSECTIONS = 1000000; diff --git a/src/plot.cpp b/src/plot.cpp index 4d48beaf97c..da093fbbfb3 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -1413,9 +1413,9 @@ ImageData WireframeRayTracePlot::create_image() const if (wireframe_thickness_ == 1) data(horiz, vert) = wireframe_color_; for (int i = -wireframe_thickness_ / 2; i < wireframe_thickness_ / 2; - ++i) + ++i) for (int j = -wireframe_thickness_ / 2; j < wireframe_thickness_ / 2; - ++j) + ++j) if (i * i + j * j < wireframe_thickness_ * wireframe_thickness_) { // Check if wireframe pixel is out of bounds diff --git a/src/ray.cpp b/src/ray.cpp index d7a975bb64e..ce13aca2e37 100644 --- a/src/ray.cpp +++ b/src/ray.cpp @@ -99,7 +99,7 @@ void Ray::trace() // the particle in that case. Also, just exit // if a negative distance was somehow computed. if (boundary().distance() == INFTY || boundary().distance() == INFINITY || - boundary().distance() < 0) { + boundary().distance() < 0) { return; } @@ -127,8 +127,8 @@ void Ray::trace() n_coord_last() = n_coord(); n_coord() = boundary().coord_level(); if (boundary().lattice_translation()[0] != 0 || - boundary().lattice_translation()[1] != 0 || - boundary().lattice_translation()[2] != 0) { + boundary().lattice_translation()[1] != 0 || + boundary().lattice_translation()[2] != 0) { cross_lattice(*this, boundary(), settings::verbosity >= 10); } @@ -147,7 +147,7 @@ void Ray::trace() if (call_on_intersection) { on_intersection(); if (stop_) - return; + return; } if (!inside_cell) From c73e5709c7b66f81ace09be18962fcae9bba5dc1 Mon Sep 17 00:00:00 2001 From: GuySten Date: Tue, 3 Mar 2026 00:19:47 +0200 Subject: [PATCH 3/7] fixed a bug --- CMakeLists.txt | 1746 +++++++++++++++++------------------------------- 1 file changed, 631 insertions(+), 1115 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a68d47c0215..20068d7e760 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,1116 +1,632 @@ -cmake_minimum_required(VERSION 3.16 FATAL_ERROR) project(openmc C CXX) - -#Set module path - set(CMAKE_MODULE_PATH $ {CMAKE_CURRENT_SOURCE_DIR} / cmake / Modules) - - include(GetVersionFromGit) - -#Output version information - message(STATUS "OpenMC version: ${OPENMC_VERSION}") message( - STATUS "OpenMC dev state: ${OPENMC_DEV_STATE}") message(STATUS - "OpenMC commit hash: ${OPENMC_COMMIT_HASH}") message(STATUS - "OpenMC commit count: ${OPENMC_COMMIT_COUNT}") - -#Generate version.h - configure_file( - include / openmc / - version.h.in "${CMAKE_BINARY_DIR}/include/openmc/version.h" @ONLY) - -#Setup output directories - set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY $ {CMAKE_BINARY_DIR} / lib) set( - CMAKE_LIBRARY_OUTPUT_DIRECTORY $ {CMAKE_BINARY_DIR} / - lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY $ {CMAKE_BINARY_DIR} / bin) - -#Enable correct usage of CXX_EXTENSIONS - if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.22) cmake_policy( - SET CMP0128 NEW) endif() - -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = -#Command line options -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = - - option(OPENMC_USE_OPENMP "Enable shared-memory parallelism with " - "OpenMP" ON) option(OPENMC_BUILD_TESTS - "Build tests" ON) option(OPENMC_ENABLE_PROFILE - "Compile with profiling flags" OFF) option(OPENMC_ENABLE_COVERAGE - "Compile with coverage analysis flags" OFF) - option(OPENMC_USE_DAGMC "Enable support for DAGMC (CAD) " - "geometry" OFF) option( - OPENMC_USE_LIBMESH "Enable support for libMesh unstructured " - "mesh tallies" OFF) option(OPENMC_USE_MPI - "Enable MPI" OFF) option(OPENMC_USE_UWUW - "Enable UWUW" OFF) option(OPENMC_FORCE_VENDORED_LIBS - "Explicitly use submodules defined in 'vendor'" OFF) - option(OPENMC_ENABLE_STRICT_FP - "Enable strict FP flags to improve test portability" OFF) - - message(STATUS - "OPENMC_USE_OPENMP ${OPENMC_USE_OPENMP}") message(STATUS - "OPENMC_BUILD_TESTS ${OPENMC_BUILD_TESTS}") message(STATUS - "OPENMC_ENABLE_PROFILE ${OPENMC_ENABLE_PROFILE}") message(STATUS - "OPENMC_ENABLE_COVERAGE ${OPENMC_ENABLE_COVERAGE}") message(STATUS - "OPENMC_USE_DAGMC ${OPENMC_USE_DAGMC}") message(STATUS - "OPENMC_USE_LIBMESH ${OPENMC_USE_LIBMESH}") message(STATUS - "OPENMC_USE_MPI ${OPENMC_USE_MPI}") message(STATUS - "OPENMC_USE_UWUW ${OPENMC_USE_UWUW}") message(STATUS - "OPENMC_FORCE_VENDORED_LIBS " - "${OPENMC_FORCE_VENDORED_LIBS}") message(STATUS - "OPENMC_ENABLE_STRICT_FP ${OPENMC_ENABLE_STRICT_FP}") - -#Warnings for deprecated options - foreach (OLD_OPT IN ITEMS - "openmp" - "profile" - "coverage" - "dagmc" - "libmesh") if (DEFINED $ {OLD_OPT}) string(TOUPPER $ { - OLD_OPT} OPT_UPPER) if ("${OLD_OPT}" STREQUAL - "profile" OR - "${OLD_OPT}" STREQUAL - "coverage") set(NEW_OPT_PREFIX - "OPENMC_ENABLE") else() set(NEW_OPT_PREFIX - "OPENMC_USE") endif() message(WARNING - "The OpenMC CMake option '${OLD_OPT}' has been " - "deprecated. " - "Its value will be ignored. " - "Please use " - "'-D${NEW_OPT_PREFIX}_${OPT_UPPER}=${${OLD_OPT}}' " - "instead.") unset($ { - OLD_OPT} CACHE) endif() endforeach() - - foreach (OLD_BLD in ITEMS - "debug" - "optimize") if (DEFINED $ { - OLD_BLD}) if ("${OLD_BLD}" STREQUAL - "debug") set(BLD_VAR - "Debug") else() set(BLD_VAR - "Release") endif() message(WARNING "The OpenMC CMake " - "option " - "'${OLD_BLD}' has " - "been deprecated. " - "Its value will " - "be ignored. " - "OpenMC now uses " - "the " - "CMAKE_BUILD_TYPE " - "variable to set " - "the build mode. " - "Please use " - "'-DCMAKE_BUILD_" - "TYPE=${BLD_VAR}' " - "instead.") unset($ { - OLD_BLD} CACHE) endif() endforeach() - -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = -#Set a default build configuration if not explicitly specified -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = - - if (NOT CMAKE_BUILD_TYPE) message( - STATUS "No build type selected, defaulting to " - "RelWithDebInfo") set(CMAKE_BUILD_TYPE - RelWithDebInfo CACHE STRING - "Choose the type of build" FORCE) endif() - -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = -#When STRICT_FP is enabled, remove NDEBUG from RelWithDebInfo flags so that -#assert() remains active.CMake normally adds - DNDEBUG for both Release and -#RelWithDebInfo, which disables C / C++ assert() statements. -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = - - if (OPENMC_ENABLE_STRICT_FP) foreach ( - FLAG_VAR CMAKE_CXX_FLAGS_RELWITHDEBINFO - CMAKE_C_FLAGS_RELWITHDEBINFO) string(REPLACE - "-DNDEBUG" - "" $ { FLAG_VAR } "${${FLAG_VAR}}") string(REPLACE - "/DNDEBUG" - "" $ { - FLAG_VAR - } "${${FLAG_VAR}}") endforeach() endif() - -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = -#OpenMP for shared - memory parallelism(and GPU support some day !) -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = - - if (OPENMC_USE_OPENMP) find_package( - OpenMP REQUIRED) endif() - -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = -#MPI for distributed - memory parallelism -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = - - if (OPENMC_USE_MPI) find_package( - MPI REQUIRED) endif() - -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = -#Helper macro for finding a dependency -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = - - macro(find_package_write_status - pkg) find_package($ {pkg} QUIET - NO_SYSTEM_ENVIRONMENT_PATH) if ($ { - pkg} _FOUND) - message(STATUS - "Found ${pkg}: ${${pkg}_DIR} (version " - "${${pkg}_VERSION})") else() message(STATUS - "Did not find ${pkg}, will use submodule " - "instead") endif() endmacro() - -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = -#DAGMC Geometry Support - need DAGMC / MOAB -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = - - 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.") 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() - -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = -#libMesh Unstructured Mesh Support -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = - - if (OPENMC_USE_LIBMESH) find_package( - LIBMESH REQUIRED) endif() - -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = -#libpng -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = - - find_package(PNG) - -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = -#HDF5 for binary output -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = - -#Unfortunately FindHDF5.cmake will always prefer a serial HDF5 installation -#over a parallel installation if both appear on the user's PATH. To get around -#this, we check for the environment variable HDF5_ROOT and if it exists, use it -#to check whether its a parallel version. - - if (NOT DEFINED HDF5_PREFER_PARALLEL) if ( - DEFINED ENV { - HDF5_ROOT} AND EXISTS $ENV { - HDF5_ROOT} / - bin / h5pcc) - set(HDF5_PREFER_PARALLEL - TRUE) else() - set(HDF5_PREFER_PARALLEL - FALSE) endif() endif() - - find_package(HDF5 REQUIRED - COMPONENTS C HL) - -#Remove HDF5 transitive dependencies that are system libraries - list( - FILTER HDF5_LIBRARIES - EXCLUDE REGEX - ".*lib(pthread|dl|m)." - "*") message(STATUS - "HDF5 Libraries: " - "${HDF5_LIBRARIES}") - - if (HDF5_IS_PARALLEL) if ( - NOT OPENMC_USE_MPI) - message(FATAL_ERROR - "Parallel HDF5 was detected, but MPI was not enabled.\ +cmake_minimum_required(VERSION 3.16 FATAL_ERROR) +project(openmc C CXX) + +# Set module path +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules) + +include(GetVersionFromGit) + +# Output version information +message(STATUS "OpenMC version: ${OPENMC_VERSION}") +message(STATUS "OpenMC dev state: ${OPENMC_DEV_STATE}") +message(STATUS "OpenMC commit hash: ${OPENMC_COMMIT_HASH}") +message(STATUS "OpenMC commit count: ${OPENMC_COMMIT_COUNT}") + +# Generate version.h +configure_file(include/openmc/version.h.in "${CMAKE_BINARY_DIR}/include/openmc/version.h" @ONLY) + +# Setup output directories +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +# Enable correct usage of CXX_EXTENSIONS +if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.22) + cmake_policy(SET CMP0128 NEW) +endif() + +#=============================================================================== +# Command line options +#=============================================================================== + +option(OPENMC_USE_OPENMP "Enable shared-memory parallelism with OpenMP" ON) +option(OPENMC_BUILD_TESTS "Build tests" ON) +option(OPENMC_ENABLE_PROFILE "Compile with profiling flags" OFF) +option(OPENMC_ENABLE_COVERAGE "Compile with coverage analysis flags" OFF) +option(OPENMC_USE_DAGMC "Enable support for DAGMC (CAD) geometry" OFF) +option(OPENMC_USE_LIBMESH "Enable support for libMesh unstructured mesh tallies" OFF) +option(OPENMC_USE_MPI "Enable MPI" OFF) +option(OPENMC_USE_UWUW "Enable UWUW" OFF) +option(OPENMC_FORCE_VENDORED_LIBS "Explicitly use submodules defined in 'vendor'" OFF) +option(OPENMC_ENABLE_STRICT_FP "Enable strict FP flags to improve test portability" OFF) + +message(STATUS "OPENMC_USE_OPENMP ${OPENMC_USE_OPENMP}") +message(STATUS "OPENMC_BUILD_TESTS ${OPENMC_BUILD_TESTS}") +message(STATUS "OPENMC_ENABLE_PROFILE ${OPENMC_ENABLE_PROFILE}") +message(STATUS "OPENMC_ENABLE_COVERAGE ${OPENMC_ENABLE_COVERAGE}") +message(STATUS "OPENMC_USE_DAGMC ${OPENMC_USE_DAGMC}") +message(STATUS "OPENMC_USE_LIBMESH ${OPENMC_USE_LIBMESH}") +message(STATUS "OPENMC_USE_MPI ${OPENMC_USE_MPI}") +message(STATUS "OPENMC_USE_UWUW ${OPENMC_USE_UWUW}") +message(STATUS "OPENMC_FORCE_VENDORED_LIBS ${OPENMC_FORCE_VENDORED_LIBS}") +message(STATUS "OPENMC_ENABLE_STRICT_FP ${OPENMC_ENABLE_STRICT_FP}") + +# Warnings for deprecated options +foreach(OLD_OPT IN ITEMS "openmp" "profile" "coverage" "dagmc" "libmesh") + if(DEFINED ${OLD_OPT}) + string(TOUPPER ${OLD_OPT} OPT_UPPER) + if ("${OLD_OPT}" STREQUAL "profile" OR "${OLD_OPT}" STREQUAL "coverage") + set(NEW_OPT_PREFIX "OPENMC_ENABLE") + else() + set(NEW_OPT_PREFIX "OPENMC_USE") + endif() + message(WARNING "The OpenMC CMake option '${OLD_OPT}' has been deprecated. " + "Its value will be ignored. " + "Please use '-D${NEW_OPT_PREFIX}_${OPT_UPPER}=${${OLD_OPT}}' instead.") + unset(${OLD_OPT} CACHE) + endif() +endforeach() + +foreach(OLD_BLD in ITEMS "debug" "optimize") + if(DEFINED ${OLD_BLD}) + if("${OLD_BLD}" STREQUAL "debug") + set(BLD_VAR "Debug") + else() + set(BLD_VAR "Release") + endif() + message(WARNING "The OpenMC CMake option '${OLD_BLD}' has been deprecated. " + "Its value will be ignored. " + "OpenMC now uses the CMAKE_BUILD_TYPE variable to set the build mode. " + "Please use '-DCMAKE_BUILD_TYPE=${BLD_VAR}' instead.") + unset(${OLD_BLD} CACHE) + endif() +endforeach() + +#=============================================================================== +# Set a default build configuration if not explicitly specified +#=============================================================================== + +if(NOT CMAKE_BUILD_TYPE) + message(STATUS "No build type selected, defaulting to RelWithDebInfo") + set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build" FORCE) +endif() + +#=============================================================================== +# When STRICT_FP is enabled, remove NDEBUG from RelWithDebInfo flags so that +# assert() remains active. CMake normally adds -DNDEBUG for both Release and +# RelWithDebInfo, which disables C/C++ assert() statements. +#=============================================================================== + +if(OPENMC_ENABLE_STRICT_FP) + foreach(FLAG_VAR CMAKE_CXX_FLAGS_RELWITHDEBINFO CMAKE_C_FLAGS_RELWITHDEBINFO) + string(REPLACE "-DNDEBUG" "" ${FLAG_VAR} "${${FLAG_VAR}}") + string(REPLACE "/DNDEBUG" "" ${FLAG_VAR} "${${FLAG_VAR}}") + endforeach() +endif() + +#=============================================================================== +# OpenMP for shared-memory parallelism (and GPU support some day!) +#=============================================================================== + +if(OPENMC_USE_OPENMP) + find_package(OpenMP REQUIRED) +endif() + +#=============================================================================== +# MPI for distributed-memory parallelism +#=============================================================================== + +if(OPENMC_USE_MPI) + find_package(MPI REQUIRED) +endif() + +#=============================================================================== +# Helper macro for finding a dependency +#=============================================================================== + +macro(find_package_write_status pkg) + find_package(${pkg} QUIET NO_SYSTEM_ENVIRONMENT_PATH) + if(${pkg}_FOUND) + message(STATUS "Found ${pkg}: ${${pkg}_DIR} (version ${${pkg}_VERSION})") + else() + message(STATUS "Did not find ${pkg}, will use submodule instead") + endif() +endmacro() + +#=============================================================================== +# DAGMC Geometry Support - need DAGMC/MOAB +#=============================================================================== + +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.") + 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() + +#=============================================================================== +# libMesh Unstructured Mesh Support +#=============================================================================== + +if(OPENMC_USE_LIBMESH) + find_package(LIBMESH REQUIRED) +endif() + +#=============================================================================== +# libpng +#=============================================================================== + +find_package(PNG) + +#=============================================================================== +# HDF5 for binary output +#=============================================================================== + +# Unfortunately FindHDF5.cmake will always prefer a serial HDF5 installation +# over a parallel installation if both appear on the user's PATH. To get around +# this, we check for the environment variable HDF5_ROOT and if it exists, use it +# to check whether its a parallel version. + +if(NOT DEFINED HDF5_PREFER_PARALLEL) + if(DEFINED ENV{HDF5_ROOT} AND EXISTS $ENV{HDF5_ROOT}/bin/h5pcc) + set(HDF5_PREFER_PARALLEL TRUE) + else() + set(HDF5_PREFER_PARALLEL FALSE) + endif() +endif() + +find_package(HDF5 REQUIRED COMPONENTS C HL) + +# Remove HDF5 transitive dependencies that are system libraries +list(FILTER HDF5_LIBRARIES EXCLUDE REGEX ".*lib(pthread|dl|m).*") +message(STATUS "HDF5 Libraries: ${HDF5_LIBRARIES}") + +if(HDF5_IS_PARALLEL) + if(NOT OPENMC_USE_MPI) + message(FATAL_ERROR "Parallel HDF5 was detected, but MPI was not enabled.\ To use parallel HDF5, OpenMC needs to be built with MPI support by passing\ - -DOPENMC_USE_MPI=ON when calling cmake.") endif() message(STATUS - "Using parallel " - "HDF5") endif() - -#Version 1.12 of HDF5 deprecates the H5Oget_info_by_idx() interface. -#Thus, we give these flags to allow usage of the old interface in newer -#versions of HDF5. - if ($ {HDF5_VERSION} VERSION_GREATER_EQUAL 1.12.0) list( - APPEND - cxxflags - - DH5Oget_info_by_idx_vers = - 1 - - DH5O_info_t_vers = - 1) endif() - -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = -#Set compile / link flags based on which compiler is being used -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = - -#When OPENMC_ENABLE_STRICT_FP is enabled, \ - disable compiler optimizations that change -#floating - point results relative to - O0, improving cross - platform and -#cross - optimization - level reproducibility for regression testing: -#- ffp - contract = off Prevents FMA contraction( \ - fused multiply - add changes rounding) -#- fno - builtin Prevents replacing math function calls(pow, exp, log, etc.) -#with builtin versions that may differ from libm -#By default(OFF), the compiler is free to use all optimizations for best -#performance. - if (OPENMC_ENABLE_STRICT_FP) include(CheckCXXCompilerFlag) check_cxx_compiler_flag( - -ffp - - contract = off - SUPPORTS_FP_CONTRACT_OFF) if (SUPPORTS_FP_CONTRACT_OFF) - list( - APPEND - cxxflags - - ffp - - contract = - off) endif() - check_cxx_compiler_flag( - -fno - - builtin - SUPPORTS_NO_BUILTIN) if (SUPPORTS_NO_BUILTIN) - list( - APPEND - cxxflags - - fno - - builtin) endif() endif() - -#Skip for Visual Studio which has its own configurations through GUI - if ( - NOT - MSVC) - - set( - CMAKE_POSITION_INDEPENDENT_CODE - ON) - - if (OPENMC_ENABLE_PROFILE) list( - APPEND - cxxflags - - g - - fno - - omit - - frame - - pointer) endif() - - if (OPENMC_ENABLE_COVERAGE) list( - APPEND - cxxflags-- coverage) list(APPEND - ldflags-- coverage) endif() - -#Show flags being used - message( - STATUS - "OpenMC C++ flags: ${cxxflags}") - message( - STATUS - "OpenMC Linker flags: ${ldflags}") - - endif() - -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = -#Update git submodules as needed -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = - if ( - GIT_FOUND - AND EXISTS - "${CMAKE_CURRENT_SOURCE_DIR}/.git") - option( - GIT_SUBMODULE - "Check submodules during build" ON) if (GIT_SUBMODULE) - message( - STATUS - "Submodule update") - execute_process( - COMMAND $ { - GIT_EXECUTABLE} submodule - update-- init-- recursive WORKING_DIRECTORY - $ { - CMAKE_CURRENT_SOURCE_DIR} RESULT_VARIABLE - GIT_SUBMOD_RESULT) if (NOT GIT_SUBMOD_RESULT - EQUAL 0) - message( - FATAL_ERROR - "git submodule update --init failed with \ - ${GIT_SUBMOD_RESULT}, please checkout submodules") endif() endif() endif() - -#Check to see if submodules exist(by checking one) - if ( - NOT EXISTS - "${CMAKE_CURRENT_SOURCE_DIR}/vendor/pugixml/CMakeLists.txt") - message( - FATAL_ERROR - "The git submodules were not downloaded! GIT_SUBMODULE was \ - turned off or failed. Please update submodules and try again.") endif() - -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = -#pugixml library -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = - - if ( - OPENMC_FORCE_VENDORED_LIBS) add_subdirectory(vendor / - pugixml) - set_target_properties( - pugixml PROPERTIES - CXX_STANDARD 14 CXX_EXTENSIONS - OFF) else() - find_package_write_status( - pugixml) if (NOT - pugixml_FOUND) - add_subdirectory( - vendor / - pugixml) - set_target_properties( - pugixml PROPERTIES - CXX_STANDARD 14 CXX_EXTENSIONS - OFF) - endif() - endif() - -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = -#{fmt } library -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = - - if ( - OPENMC_FORCE_VENDORED_LIBS) - set( - FMT_INSTALL - ON - CACHE BOOL - "Generate the install target.") - add_subdirectory( - vendor / - fmt) else() - find_package_write_status( - fmt) if (NOT - fmt_FOUND) - set(FMT_INSTALL ON CACHE BOOL "Generate the install target.") add_subdirectory( - vendor / - fmt) - endif() endif() - -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = -#Catch2 library -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = - - if (OPENMC_BUILD_TESTS) if ( - OPENMC_FORCE_VENDORED_LIBS) - add_subdirectory( - vendor / - Catch2) else() - find_package_write_status( - Catch2) if (NOT - Catch2_FOUND) - add_subdirectory( - vendor / - Catch2) - endif() - endif() endif() - -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = -#RPATH information -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = - -#Provide install directory variables as defined by GNU coding standards - include( - GNUInstallDirs) - -#This block of code ensures that dynamic libraries can be found via the RPATH -#whether the executable is the original one from the build directory or the -#installed one in CMAKE_INSTALL_PREFIX.Ref: -#https: // gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling - -#use, i.e.don't skip the full RPATH for the build tree - set( - CMAKE_SKIP_BUILD_RPATH - FALSE) - -#when building, don't use the install RPATH already -#(but later on when installing) - set( - CMAKE_BUILD_WITH_INSTALL_RPATH - FALSE) - -#add the automatically determined parts of the RPATH -#which point to directories outside the build tree to the install RPATH - set( - CMAKE_INSTALL_RPATH_USE_LINK_PATH - TRUE) - -#the RPATH to be used when installing, but only if it's not a system directory - list( - FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES - "${CMAKE_INSTALL_FULL_LIBDIR}" isSystemDir) if ("${isSystemDir}" STREQUAL - "-1") - set( - CMAKE_INSTALL_RPATH - "${CMAKE_INSTALL_FULL_LIBDIR}") endif() - -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = -#libopenmc -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = - - list(APPEND libopenmc_SOURCES - src / - atomic_mass - .cpp - src / - bank - .cpp - src / - boundary_condition - .cpp - src / - bremsstrahlung - .cpp - src / - cell - .cpp - src / - chain - .cpp - src / - cmfd_solver - .cpp - src / - collision_track - .cpp - src / - cross_sections - .cpp - src / - dagmc - .cpp - src / - distribution - .cpp - src / - distribution_angle - .cpp - src / - distribution_energy - .cpp - src / - distribution_multi - .cpp - src / - distribution_spatial - .cpp - src / - eigenvalue - .cpp - src / - endf - .cpp - src / - error - .cpp - src / - event - .cpp - src / - file_utils - .cpp - src / - finalize - .cpp - src / - geometry - .cpp - src / - geometry_aux - .cpp - src / - hdf5_interface - .cpp - src / - ifp - .cpp - src / - initialize - .cpp - src / - lattice - .cpp - src / - material - .cpp - src / - math_functions - .cpp - src / - mcpl_interface - .cpp - src / - mesh - .cpp - src / - message_passing - .cpp - src / - mgxs - .cpp - src / - mgxs_interface - .cpp - src / - ncrystal_interface - .cpp - src / - ncrystal_load - .cpp - src / - nuclide - .cpp - src / - output - .cpp - src / - particle - .cpp - src / - particle_data - .cpp - src / - particle_restart - .cpp - src / - particle_type - .cpp - src / - photon - .cpp - src / - physics - .cpp - src / - physics_common - .cpp - src / - physics_mg - .cpp - src / - plot - .cpp - src / - position - .cpp - src / - progress_bar - .cpp - src / - random_dist - .cpp - src / - random_lcg - .cpp - src / - random_ray / - random_ray_simulation - .cpp - src / - random_ray / - random_ray - .cpp - src / - random_ray / - flat_source_domain - .cpp - src / - random_ray / - linear_source_domain - .cpp - src / - random_ray / - moment_matrix - .cpp - src / - random_ray / - source_region - .cpp - src / - ray - .cpp - src / - reaction - .cpp - src / - reaction_product - .cpp - src / - scattdata - .cpp - src / - secondary_correlated - .cpp - src / - secondary_kalbach - .cpp - src / - secondary_nbody - .cpp - src / - secondary_thermal - .cpp - src / - secondary_uncorrelated - .cpp - src / - settings - .cpp - src / - simulation - .cpp - src / - source - .cpp - src / - state_point - .cpp - src / - string_utils - .cpp - src / - summary - .cpp - src / - surface - .cpp - src / - tallies / - derivative - .cpp - src / - tallies / - filter - .cpp - src / - tallies / - filter_azimuthal - .cpp - src / - tallies / - filter_cell - .cpp - src / - tallies / - filter_cell_instance - .cpp - src / - tallies / - filter_cellborn - .cpp - src / - tallies / - filter_cellfrom - .cpp - src / - tallies / - filter_collision - .cpp - src / - tallies / - filter_delayedgroup - .cpp - src / - tallies / - filter_distribcell - .cpp - src / - tallies / - filter_energy - .cpp - src / - tallies / - filter_energyfunc - .cpp - src / - tallies / - filter_legendre - .cpp - src / - tallies / - filter_material - .cpp - src / - tallies / - filter_materialfrom - .cpp - src / - tallies / - filter_mesh - .cpp - src / - tallies / - filter_meshborn - .cpp - src / - tallies / - filter_meshmaterial - .cpp - src / - tallies / - filter_meshsurface - .cpp - src / - tallies / - filter_mu - .cpp - src / - tallies / - filter_musurface - .cpp - src / - tallies / - filter_parent_nuclide - .cpp - src / - tallies / - filter_particle - .cpp - src / - tallies / - filter_particle_production - .cpp - src / - tallies / - filter_polar - .cpp - src / - tallies / - filter_reaction - .cpp - src / - tallies / - filter_sph_harm - .cpp - src / - tallies / - filter_sptl_legendre - .cpp - src / - tallies / - filter_surface - .cpp - src / - tallies / - filter_time - .cpp - src / - tallies / - filter_universe - .cpp - src / - tallies / - filter_weight - .cpp - src / - tallies / - filter_zernike - .cpp - src / - tallies / - tally - .cpp - src / - tallies / - tally_scoring - .cpp - src / - tallies / - trigger - .cpp - src / - thermal - .cpp - src / - timer - .cpp - src / - track_output - .cpp - src / - universe - .cpp - src / - urr - .cpp - src / - volume_calc - .cpp - src / - weight_windows - .cpp - src / - wmp - .cpp - src / - xml_interface - .cpp - src / - xsdata - .cpp) - -#Add bundled external dependencies - list(APPEND - libopenmc_SOURCES - src / - external / - quartic_solver - .cpp src / - external / - Faddeeva - .cc) - -#For Visual Studio compilers - if ( - MSVC) -#Use static library(otherwise explicit symbol portings are needed) - add_library( - libopenmc STATIC - $ { - libopenmc_SOURCES}) - -#To use the shared HDF5 libraries on Windows, the H5_BUILT_AS_DYNAMIC_LIB -#compile definition must be specified. - target_compile_definitions( - libopenmc - PRIVATE - - DH5_BUILT_AS_DYNAMIC_LIB) else() - add_library( - libopenmc SHARED - $ { - libopenmc_SOURCES}) - endif() - - add_library( - OpenMC:: - libopenmc ALIAS - libopenmc) - -#Avoid vs error lnk1149 : output filename matches input filename - if ( - NOT MSVC) - set_target_properties( - libopenmc - PROPERTIES - OUTPUT_NAME - openmc) - endif() - - target_include_directories(libopenmc PUBLIC $ $ - $ { - HDF5_INCLUDE_DIRS}) - -#Set compile flags - target_compile_options( - libopenmc PRIVATE - $ { - cxxflags}) - -#Add include directory for configured version file - target_include_directories( - libopenmc - PUBLIC - $) - - if (HDF5_IS_PARALLEL) target_compile_definitions( - libopenmc PRIVATE - DPHDF5) endif() if (OPENMC_USE_MPI) target_compile_definitions(libopenmc PUBLIC - DOPENMC_MPI) endif() - -#target_link_libraries treats any arguments starting with - but not -l as -#linker flags.Thus, we can pass both linker flags and libraries together. - target_link_libraries( - libopenmc - $ { - ldflags} $ { - HDF5_LIBRARIES} $ { - HDF5_HL_LIBRARIES} fmt:: - fmt $ { - CMAKE_DL_LIBS}) - - if ( - TARGET pugixml:: - pugixml) target_link_libraries(libopenmc pugixml:: - pugixml) else() target_link_libraries(libopenmc - pugixml) endif() - - if ( - OPENMC_USE_DAGMC) target_compile_definitions(libopenmc PRIVATE OPENMC_DAGMC_ENABLED) target_link_libraries(libopenmc - dagmc - - shared) - - if (OPENMC_USE_UWUW) target_compile_definitions(libopenmc PRIVATE OPENMC_UWUW_ENABLED) target_link_libraries(libopenmc uwuw - shared) endif() elseif( - OPENMC_USE_UWUW) set(OPENMC_USE_UWUW - OFF) message(FATAL_ERROR - "DAGMC must be enabled when UWUW is enabled.") endif() - - if ( - OPENMC_USE_LIBMESH) target_compile_definitions(libopenmc PRIVATE OPENMC_LIBMESH_ENABLED) target_link_libraries(libopenmc - PkgConfig:: - LIBMESH) endif() - - if (PNG_FOUND) target_compile_definitions( - libopenmc PRIVATE - USE_LIBPNG) target_link_libraries(libopenmc - PNG::PNG) endif() - - if (OPENMC_USE_OPENMP) target_link_libraries( - libopenmc - OpenMP:: - OpenMP_CXX) - endif() - - if ( - OPENMC_USE_MPI) - target_link_libraries( - libopenmc - MPI:: - MPI_CXX) - endif() - - if ( - OPENMC_BUILD_TESTS) -#Add cpp tests directory - include( - CTest) - add_subdirectory( - tests / - cpp_unit_tests) - endif() - -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = -#Log build info that this executable can report later -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = - target_compile_definitions( - libopenmc PRIVATE - BUILD_TYPE = - $ { - CMAKE_BUILD_TYPE}) - target_compile_definitions(libopenmc PRIVATE COMPILER_ID = $ {CMAKE_CXX_COMPILER_ID}) - target_compile_definitions(libopenmc PRIVATE COMPILER_VERSION = $ {CMAKE_CXX_COMPILER_VERSION}) if (OPENMC_ENABLE_PROFILE) target_compile_definitions(libopenmc - PRIVATE PROFILINGBUILD) - endif() if ( - OPENMC_ENABLE_COVERAGE) - target_compile_definitions( - libopenmc PRIVATE COVERAGEBUILD) - endif() if (OPENMC_ENABLE_STRICT_FP) target_compile_definitions( - libopenmc PRIVATE OPENMC_ENABLE_STRICT_FP) - endif() - -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = -#openmc executable -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = - add_executable(openmc src / main - .cpp) add_executable(OpenMC::openmc ALIAS openmc) target_compile_options(openmc - PRIVATE $ { - cxxflags}) target_include_directories(openmc PRIVATE $ {CMAKE_BINARY_DIR} / include) target_link_libraries(openmc - libopenmc) - -#Ensure C++ 17 standard is used and turn off GNU extensions - target_compile_features( - openmc - PUBLIC cxx_std_17) target_compile_features(libopenmc PUBLIC cxx_std_17) set_target_properties(openmc libopenmc PROPERTIES - CXX_EXTENSIONS - OFF) - -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = -#Python package -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = - - add_custom_command(TARGET libopenmc POST_BUILD COMMAND $ {CMAKE_COMMAND} - E copy $ < TARGET_FILE : libopenmc > - $ { - CMAKE_CURRENT_SOURCE_DIR} / - openmc / - lib / - $ < - TARGET_FILE_NAME : libopenmc > - COMMENT - "Copying libopenmc to Python module directory") - -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = -#Install executable, scripts, manpage, license -#== == == == == == == == == == == == == == == == == == == == == == == == == == \ - == == == == == == == == == == == == == = - - configure_file(cmake / OpenMCConfig - .cmake - .in "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMCConfig.cmake" @ONLY) configure_file(cmake / OpenMCConfigVersion - .cmake - .in - "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMCConfigVersion.cmake" - @ONLY) - - set( - INSTALL_CONFIGDIR - $ { - CMAKE_INSTALL_LIBDIR} / - cmake / - OpenMC) install(TARGETS openmc libopenmc EXPORT - openmc - - targets RUNTIME DESTINATION - $ { - CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION $ {CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION $ {CMAKE_INSTALL_LIBDIR}) install(EXPORT openmc - targets FILE - OpenMCTargets - .cmake - NAMESPACE - OpenMC::DESTINATION - $ {INSTALL_CONFIGDIR}) - - install( - FILES - "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMCConfig.cmake" - "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMCConfigVersion.cmake" DESTINATION $ {INSTALL_CONFIGDIR}) install(FILES man / man1 / openmc.1 DESTINATION $ {CMAKE_INSTALL_MANDIR} / - man1) - install(FILES LICENSE DESTINATION "${CMAKE_INSTALL_DOCDIR}" RENAME copyright) install(DIRECTORY include / - DESTINATION - $ { - CMAKE_INSTALL_INCLUDEDIR}) - install( - FILES - "${CMAKE_BINARY_DIR}/include/openmc/version.h" DESTINATION - $ { - CMAKE_INSTALL_INCLUDEDIR} / - openmc) + -DOPENMC_USE_MPI=ON when calling cmake.") + endif() + message(STATUS "Using parallel HDF5") +endif() + +# Version 1.12 of HDF5 deprecates the H5Oget_info_by_idx() interface. +# Thus, we give these flags to allow usage of the old interface in newer +# versions of HDF5. +if(${HDF5_VERSION} VERSION_GREATER_EQUAL 1.12.0) + list(APPEND cxxflags -DH5Oget_info_by_idx_vers=1 -DH5O_info_t_vers=1) +endif() + +#=============================================================================== +# Set compile/link flags based on which compiler is being used +#=============================================================================== + +# When OPENMC_ENABLE_STRICT_FP is enabled, disable compiler optimizations that change +# floating-point results relative to -O0, improving cross-platform and +# cross-optimization-level reproducibility for regression testing: +# -ffp-contract=off Prevents FMA contraction (fused multiply-add changes rounding) +# -fno-builtin Prevents replacing math function calls (pow, exp, log, etc.) +# with builtin versions that may differ from libm +# By default (OFF), the compiler is free to use all optimizations for best +# performance. +if(OPENMC_ENABLE_STRICT_FP) + include(CheckCXXCompilerFlag) + check_cxx_compiler_flag(-ffp-contract=off SUPPORTS_FP_CONTRACT_OFF) + if(SUPPORTS_FP_CONTRACT_OFF) + list(APPEND cxxflags -ffp-contract=off) + endif() + check_cxx_compiler_flag(-fno-builtin SUPPORTS_NO_BUILTIN) + if(SUPPORTS_NO_BUILTIN) + list(APPEND cxxflags -fno-builtin) + endif() +endif() + +# Skip for Visual Studio which has its own configurations through GUI +if(NOT MSVC) + +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + +if(OPENMC_ENABLE_PROFILE) + list(APPEND cxxflags -g -fno-omit-frame-pointer) +endif() + +if(OPENMC_ENABLE_COVERAGE) + list(APPEND cxxflags --coverage) + list(APPEND ldflags --coverage) +endif() + +# Show flags being used +message(STATUS "OpenMC C++ flags: ${cxxflags}") +message(STATUS "OpenMC Linker flags: ${ldflags}") + +endif() + +#=============================================================================== +# Update git submodules as needed +#=============================================================================== +if(GIT_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") + option(GIT_SUBMODULE "Check submodules during build" ON) + if(GIT_SUBMODULE) + message(STATUS "Submodule update") + execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE GIT_SUBMOD_RESULT) + if(NOT GIT_SUBMOD_RESULT EQUAL 0) + message(FATAL_ERROR "git submodule update --init failed with \ + ${GIT_SUBMOD_RESULT}, please checkout submodules") + endif() + endif() +endif() + +# Check to see if submodules exist (by checking one) +if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/vendor/pugixml/CMakeLists.txt") + message(FATAL_ERROR "The git submodules were not downloaded! GIT_SUBMODULE was \ + turned off or failed. Please update submodules and try again.") +endif() + +#=============================================================================== +# pugixml library +#=============================================================================== + +if(OPENMC_FORCE_VENDORED_LIBS) + add_subdirectory(vendor/pugixml) + set_target_properties(pugixml PROPERTIES CXX_STANDARD 14 CXX_EXTENSIONS OFF) +else() + find_package_write_status(pugixml) + if (NOT pugixml_FOUND) + add_subdirectory(vendor/pugixml) + set_target_properties(pugixml PROPERTIES CXX_STANDARD 14 CXX_EXTENSIONS OFF) + endif() +endif() + +#=============================================================================== +# {fmt} library +#=============================================================================== + +if(OPENMC_FORCE_VENDORED_LIBS) + set(FMT_INSTALL ON CACHE BOOL "Generate the install target.") + add_subdirectory(vendor/fmt) +else() + find_package_write_status(fmt) + if (NOT fmt_FOUND) + set(FMT_INSTALL ON CACHE BOOL "Generate the install target.") + add_subdirectory(vendor/fmt) + endif() +endif() + +#=============================================================================== +# Catch2 library +#=============================================================================== + +if(OPENMC_BUILD_TESTS) + if (OPENMC_FORCE_VENDORED_LIBS) + add_subdirectory(vendor/Catch2) + else() + find_package_write_status(Catch2) + if (NOT Catch2_FOUND) + add_subdirectory(vendor/Catch2) + endif() + endif() +endif() + +#=============================================================================== +# RPATH information +#=============================================================================== + +# Provide install directory variables as defined by GNU coding standards +include(GNUInstallDirs) + +# This block of code ensures that dynamic libraries can be found via the RPATH +# whether the executable is the original one from the build directory or the +# installed one in CMAKE_INSTALL_PREFIX. Ref: +# https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling + +# use, i.e. don't skip the full RPATH for the build tree +set(CMAKE_SKIP_BUILD_RPATH FALSE) + +# when building, don't use the install RPATH already +# (but later on when installing) +set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) + +# add the automatically determined parts of the RPATH +# which point to directories outside the build tree to the install RPATH +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) + +# the RPATH to be used when installing, but only if it's not a system directory +list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_FULL_LIBDIR}" isSystemDir) +if("${isSystemDir}" STREQUAL "-1") + set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}") +endif() + +#=============================================================================== +# libopenmc +#=============================================================================== + +list(APPEND libopenmc_SOURCES + src/atomic_mass.cpp + src/bank.cpp + src/boundary_condition.cpp + src/bremsstrahlung.cpp + src/cell.cpp + src/chain.cpp + src/cmfd_solver.cpp + src/collision_track.cpp + src/cross_sections.cpp + src/dagmc.cpp + src/distribution.cpp + src/distribution_angle.cpp + src/distribution_energy.cpp + src/distribution_multi.cpp + src/distribution_spatial.cpp + src/eigenvalue.cpp + src/endf.cpp + src/error.cpp + src/event.cpp + src/file_utils.cpp + src/finalize.cpp + src/geometry.cpp + src/geometry_aux.cpp + src/hdf5_interface.cpp + src/ifp.cpp + src/initialize.cpp + src/lattice.cpp + src/material.cpp + src/math_functions.cpp + src/mcpl_interface.cpp + src/mesh.cpp + src/message_passing.cpp + src/mgxs.cpp + src/mgxs_interface.cpp + src/ncrystal_interface.cpp + src/ncrystal_load.cpp + src/nuclide.cpp + src/output.cpp + src/particle.cpp + src/particle_data.cpp + src/particle_restart.cpp + src/particle_type.cpp + src/photon.cpp + src/physics.cpp + src/physics_common.cpp + src/physics_mg.cpp + src/plot.cpp + src/position.cpp + src/progress_bar.cpp + src/random_dist.cpp + src/random_lcg.cpp + src/random_ray/random_ray_simulation.cpp + src/random_ray/random_ray.cpp + src/random_ray/flat_source_domain.cpp + src/random_ray/linear_source_domain.cpp + src/random_ray/moment_matrix.cpp + src/random_ray/source_region.cpp + src/ray.cpp + src/reaction.cpp + src/reaction_product.cpp + src/scattdata.cpp + src/secondary_correlated.cpp + src/secondary_kalbach.cpp + src/secondary_nbody.cpp + src/secondary_thermal.cpp + src/secondary_uncorrelated.cpp + src/settings.cpp + src/simulation.cpp + src/source.cpp + src/state_point.cpp + src/string_utils.cpp + src/summary.cpp + src/surface.cpp + src/tallies/derivative.cpp + src/tallies/filter.cpp + src/tallies/filter_azimuthal.cpp + src/tallies/filter_cell.cpp + src/tallies/filter_cell_instance.cpp + src/tallies/filter_cellborn.cpp + src/tallies/filter_cellfrom.cpp + src/tallies/filter_collision.cpp + src/tallies/filter_delayedgroup.cpp + src/tallies/filter_distribcell.cpp + src/tallies/filter_energy.cpp + src/tallies/filter_energyfunc.cpp + src/tallies/filter_legendre.cpp + src/tallies/filter_material.cpp + src/tallies/filter_materialfrom.cpp + src/tallies/filter_mesh.cpp + src/tallies/filter_meshborn.cpp + src/tallies/filter_meshmaterial.cpp + src/tallies/filter_meshsurface.cpp + src/tallies/filter_mu.cpp + src/tallies/filter_musurface.cpp + src/tallies/filter_parent_nuclide.cpp + src/tallies/filter_particle.cpp + src/tallies/filter_particle_production.cpp + src/tallies/filter_polar.cpp + src/tallies/filter_reaction.cpp + src/tallies/filter_sph_harm.cpp + src/tallies/filter_sptl_legendre.cpp + src/tallies/filter_surface.cpp + src/tallies/filter_time.cpp + src/tallies/filter_universe.cpp + src/tallies/filter_weight.cpp + src/tallies/filter_zernike.cpp + src/tallies/tally.cpp + src/tallies/tally_scoring.cpp + src/tallies/trigger.cpp + src/thermal.cpp + src/timer.cpp + src/track_output.cpp + src/universe.cpp + src/urr.cpp + src/volume_calc.cpp + src/weight_windows.cpp + src/wmp.cpp + src/xml_interface.cpp + src/xsdata.cpp) + +# Add bundled external dependencies +list(APPEND libopenmc_SOURCES + src/external/quartic_solver.cpp + src/external/Faddeeva.cc) + +# For Visual Studio compilers +if(MSVC) + # Use static library (otherwise explicit symbol portings are needed) + add_library(libopenmc STATIC ${libopenmc_SOURCES}) + + # To use the shared HDF5 libraries on Windows, the H5_BUILT_AS_DYNAMIC_LIB + # compile definition must be specified. + target_compile_definitions(libopenmc PRIVATE -DH5_BUILT_AS_DYNAMIC_LIB) +else() + add_library(libopenmc SHARED ${libopenmc_SOURCES}) +endif() + +add_library(OpenMC::libopenmc ALIAS libopenmc) + +# Avoid vs error lnk1149 :output filename matches input filename +if(NOT MSVC) + set_target_properties(libopenmc PROPERTIES OUTPUT_NAME openmc) +endif() + +target_include_directories(libopenmc + PUBLIC + $ + $ + ${HDF5_INCLUDE_DIRS} +) + +# Set compile flags +target_compile_options(libopenmc PRIVATE ${cxxflags}) + +# Add include directory for configured version file +target_include_directories(libopenmc + PUBLIC $) + +if (HDF5_IS_PARALLEL) + target_compile_definitions(libopenmc PRIVATE -DPHDF5) +endif() +if (OPENMC_USE_MPI) + target_compile_definitions(libopenmc PUBLIC -DOPENMC_MPI) +endif() + +# target_link_libraries treats any arguments starting with - but not -l as +# linker flags. Thus, we can pass both linker flags and libraries together. +target_link_libraries(libopenmc ${ldflags} ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES} + fmt::fmt ${CMAKE_DL_LIBS}) + +if(TARGET pugixml::pugixml) + target_link_libraries(libopenmc pugixml::pugixml) +else() + target_link_libraries(libopenmc pugixml) +endif() + +if(OPENMC_USE_DAGMC) + target_compile_definitions(libopenmc PRIVATE OPENMC_DAGMC_ENABLED) + target_link_libraries(libopenmc dagmc-shared) + + if(OPENMC_USE_UWUW) + target_compile_definitions(libopenmc PRIVATE OPENMC_UWUW_ENABLED) + target_link_libraries(libopenmc uwuw-shared) + endif() +elseif(OPENMC_USE_UWUW) + set(OPENMC_USE_UWUW OFF) + message(FATAL_ERROR "DAGMC must be enabled when UWUW is enabled.") +endif() + +if(OPENMC_USE_LIBMESH) + target_compile_definitions(libopenmc PRIVATE OPENMC_LIBMESH_ENABLED) + target_link_libraries(libopenmc PkgConfig::LIBMESH) +endif() + +if (PNG_FOUND) + target_compile_definitions(libopenmc PRIVATE USE_LIBPNG) + target_link_libraries(libopenmc PNG::PNG) +endif() + +if (OPENMC_USE_OPENMP) + target_link_libraries(libopenmc OpenMP::OpenMP_CXX) +endif() + +if (OPENMC_USE_MPI) + target_link_libraries(libopenmc MPI::MPI_CXX) +endif() + +if (OPENMC_BUILD_TESTS) + # Add cpp tests directory + include(CTest) + add_subdirectory(tests/cpp_unit_tests) +endif() + +#=============================================================================== +# Log build info that this executable can report later +#=============================================================================== +target_compile_definitions(libopenmc PRIVATE BUILD_TYPE=${CMAKE_BUILD_TYPE}) +target_compile_definitions(libopenmc PRIVATE COMPILER_ID=${CMAKE_CXX_COMPILER_ID}) +target_compile_definitions(libopenmc PRIVATE COMPILER_VERSION=${CMAKE_CXX_COMPILER_VERSION}) +if (OPENMC_ENABLE_PROFILE) + target_compile_definitions(libopenmc PRIVATE PROFILINGBUILD) +endif() +if (OPENMC_ENABLE_COVERAGE) + target_compile_definitions(libopenmc PRIVATE COVERAGEBUILD) +endif() +if (OPENMC_ENABLE_STRICT_FP) + target_compile_definitions(libopenmc PRIVATE OPENMC_ENABLE_STRICT_FP) +endif() + +#=============================================================================== +# openmc executable +#=============================================================================== +add_executable(openmc src/main.cpp) +add_executable(OpenMC::openmc ALIAS openmc) +target_compile_options(openmc PRIVATE ${cxxflags}) +target_include_directories(openmc PRIVATE ${CMAKE_BINARY_DIR}/include) +target_link_libraries(openmc libopenmc) + +# Ensure C++17 standard is used and turn off GNU extensions +target_compile_features(openmc PUBLIC cxx_std_17) +target_compile_features(libopenmc PUBLIC cxx_std_17) +set_target_properties(openmc libopenmc PROPERTIES CXX_EXTENSIONS OFF) + +#=============================================================================== +# Python package +#=============================================================================== + +add_custom_command(TARGET libopenmc POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + $ + ${CMAKE_CURRENT_SOURCE_DIR}/openmc/lib/$ + COMMENT "Copying libopenmc to Python module directory") + +#=============================================================================== +# Install executable, scripts, manpage, license +#=============================================================================== + +configure_file(cmake/OpenMCConfig.cmake.in "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMCConfig.cmake" @ONLY) +configure_file(cmake/OpenMCConfigVersion.cmake.in "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMCConfigVersion.cmake" @ONLY) + +set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/OpenMC) +install(TARGETS openmc libopenmc + EXPORT openmc-targets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} +) +install(EXPORT openmc-targets + FILE OpenMCTargets.cmake + NAMESPACE OpenMC:: + DESTINATION ${INSTALL_CONFIGDIR}) + +install(FILES + "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMCConfig.cmake" + "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMCConfigVersion.cmake" + DESTINATION ${INSTALL_CONFIGDIR}) +install(FILES man/man1/openmc.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) +install(FILES LICENSE DESTINATION "${CMAKE_INSTALL_DOCDIR}" RENAME copyright) +install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +install(FILES "${CMAKE_BINARY_DIR}/include/openmc/version.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/openmc) From bf3194aa85ab5af62368ce22da6d5c0b47b5fff8 Mon Sep 17 00:00:00 2001 From: GuySten <62616591+GuySten@users.noreply.github.com> Date: Tue, 3 Mar 2026 00:24:09 +0200 Subject: [PATCH 4/7] Fix increment operator syntax in plot.cpp --- src/plot.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index da093fbbfb3..4d48beaf97c 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -1413,9 +1413,9 @@ ImageData WireframeRayTracePlot::create_image() const if (wireframe_thickness_ == 1) data(horiz, vert) = wireframe_color_; for (int i = -wireframe_thickness_ / 2; i < wireframe_thickness_ / 2; - ++i) + ++i) for (int j = -wireframe_thickness_ / 2; j < wireframe_thickness_ / 2; - ++j) + ++j) if (i * i + j * j < wireframe_thickness_ * wireframe_thickness_) { // Check if wireframe pixel is out of bounds From 2e67fabea753ad7025478d05a9c8223e07508e53 Mon Sep 17 00:00:00 2001 From: GuySten Date: Tue, 3 Mar 2026 00:58:53 +0200 Subject: [PATCH 5/7] fixed imports --- include/openmc/ray.h | 2 -- src/ray.cpp | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/include/openmc/ray.h b/include/openmc/ray.h index b407d8f4414..fcca1c43071 100644 --- a/include/openmc/ray.h +++ b/include/openmc/ray.h @@ -1,8 +1,6 @@ #ifndef OPENMC_RAY_H #define OPENMC_RAY_H -#include "openmc/tensor.h" - namespace openmc { // Base class that implements ray tracing logic, not necessarily through diff --git a/src/ray.cpp b/src/ray.cpp index ce13aca2e37..4b06c3eae7f 100644 --- a/src/ray.cpp +++ b/src/ray.cpp @@ -1,4 +1,4 @@ -#include "openmc/plot.h" +#include "openmc/ray.h" namespace openmc { From b9dc1eb976831c420dbbeb3ffe3b0e8a96b5f243 Mon Sep 17 00:00:00 2001 From: GuySten Date: Tue, 3 Mar 2026 01:04:56 +0200 Subject: [PATCH 6/7] fixed imports --- include/openmc/ray.h | 2 ++ src/ray.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/include/openmc/ray.h b/include/openmc/ray.h index fcca1c43071..3335794cde2 100644 --- a/include/openmc/ray.h +++ b/include/openmc/ray.h @@ -1,6 +1,8 @@ #ifndef OPENMC_RAY_H #define OPENMC_RAY_H +#include "openmc/particle_data.h" + namespace openmc { // Base class that implements ray tracing logic, not necessarily through diff --git a/src/ray.cpp b/src/ray.cpp index 4b06c3eae7f..0b76cd6bf63 100644 --- a/src/ray.cpp +++ b/src/ray.cpp @@ -1,5 +1,7 @@ #include "openmc/ray.h" +#include "openmc/geometry.h" + namespace openmc { void Ray::compute_distance() From 803bea6597d05040b45204b37e900d4ce888ae53 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 5 Mar 2026 18:15:36 -0600 Subject: [PATCH 7/7] Update includes, remove unused hit_something_ member --- include/openmc/ray.h | 2 +- src/ray.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/openmc/ray.h b/include/openmc/ray.h index 3335794cde2..62e86b0d90f 100644 --- a/include/openmc/ray.h +++ b/include/openmc/ray.h @@ -2,6 +2,7 @@ #define OPENMC_RAY_H #include "openmc/particle_data.h" +#include "openmc/position.h" namespace openmc { @@ -40,7 +41,6 @@ class Ray : public GeometryState { // loop: static const int MAX_INTERSECTIONS = 1000000; - bool hit_something_ {false}; bool stop_ {false}; unsigned event_counter_ {0}; diff --git a/src/ray.cpp b/src/ray.cpp index 0b76cd6bf63..3d848e3a3a7 100644 --- a/src/ray.cpp +++ b/src/ray.cpp @@ -1,6 +1,8 @@ #include "openmc/ray.h" +#include "openmc/error.h" #include "openmc/geometry.h" +#include "openmc/settings.h" namespace openmc {