From 27ce2ceee3e666d211cdd5d9db25300dada67fa1 Mon Sep 17 00:00:00 2001 From: Thomas Kittelmann Date: Tue, 11 Feb 2025 15:18:27 +0100 Subject: [PATCH] Updates for building with NCrystal support (and fix CI) (#3274) --- CMakeLists.txt | 10 +++- cmake/OpenMCConfig.cmake.in | 10 +++- docs/source/usersguide/install.rst | 5 +- include/openmc/ncrystal_interface.h | 16 ++----- .../ncrystal/results_true.dat | 14 +++--- tools/ci/gha-install-ncrystal.sh | 46 ------------------- tools/ci/gha-install.py | 2 - tools/ci/gha-install.sh | 4 +- tools/ci/gha-script.sh | 2 - 9 files changed, 33 insertions(+), 76 deletions(-) delete mode 100755 tools/ci/gha-install-ncrystal.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index e15de1b6f..f7079aebc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,7 +121,15 @@ endmacro() #=============================================================================== if(OPENMC_USE_NCRYSTAL) - find_package(NCrystal REQUIRED) + if(NOT DEFINED "NCrystal_DIR") + #Invocation of "ncrystal-config --show cmakedir" is needed to find NCrystal + #when it is installed from Python wheels: + execute_process( + COMMAND "ncrystal-config" "--show" "cmakedir" + OUTPUT_VARIABLE "NCrystal_DIR" OUTPUT_STRIP_TRAILING_WHITESPACE + ) + endif() + find_package(NCrystal 3.8.0 REQUIRED) message(STATUS "Found NCrystal: ${NCrystal_DIR} (version ${NCrystal_VERSION})") endif() diff --git a/cmake/OpenMCConfig.cmake.in b/cmake/OpenMCConfig.cmake.in index b3b901de4..b02bbffe5 100644 --- a/cmake/OpenMCConfig.cmake.in +++ b/cmake/OpenMCConfig.cmake.in @@ -10,6 +10,14 @@ if(@OPENMC_USE_DAGMC@) endif() if(@OPENMC_USE_NCRYSTAL@) + if(NOT DEFINED "NCrystal_DIR") + #Invocation of "ncrystal-config --show cmakedir" is needed to find NCrystal + #when it is installed from Python wheels: + execute_process( + COMMAND "ncrystal-config" "--show" "cmakedir" + OUTPUT_VARIABLE "NCrystal_DIR" OUTPUT_STRIP_TRAILING_WHITESPACE + ) + endif() find_package(NCrystal REQUIRED) message(STATUS "Found NCrystal: ${NCrystal_DIR} (version ${NCrystal_VERSION})") endif() @@ -41,4 +49,4 @@ endif() if(@OPENMC_USE_UWUW@ AND NOT ${DAGMC_BUILD_UWUW}) message(FATAL_ERROR "UWUW is enabled in OpenMC but the DAGMC installation discovered was not configured with UWUW.") -endif() \ No newline at end of file +endif() diff --git a/docs/source/usersguide/install.rst b/docs/source/usersguide/install.rst index 1c0b7fa5b..b86f5fee0 100644 --- a/docs/source/usersguide/install.rst +++ b/docs/source/usersguide/install.rst @@ -287,9 +287,8 @@ Prerequisites Adding this option allows the creation of materials from NCrystal, which replaces the scattering kernel treatment of ACE files with a modular, on-the-fly approach. To use it `install - `_ and `initialize - `_ - NCrystal and turn on the option in the CMake configuration step:: + `_ NCrystal and + turn on the option in the CMake configuration step:: cmake -DOPENMC_USE_NCRYSTAL=on .. diff --git a/include/openmc/ncrystal_interface.h b/include/openmc/ncrystal_interface.h index 5a3882df9..22422e378 100644 --- a/include/openmc/ncrystal_interface.h +++ b/include/openmc/ncrystal_interface.h @@ -2,7 +2,6 @@ #define OPENMC_NCRYSTAL_INTERFACE_H #ifdef NCRYSTAL -#include "NCrystal/NCRNG.hh" #include "NCrystal/NCrystal.hh" #endif @@ -58,19 +57,10 @@ public: //---------------------------------------------------------------------------- // Trivial methods when compiling without NCRYSTAL - std::string cfg() const - { - return ""; - } - double xs(const Particle& p) const - { - return -1.0; - } + std::string cfg() const { return ""; } + double xs(const Particle& p) const { return -1.0; } void scatter(Particle& p) const {} - operator bool() const - { - return false; - } + operator bool() const { return false; } #endif private: diff --git a/tests/regression_tests/ncrystal/results_true.dat b/tests/regression_tests/ncrystal/results_true.dat index 3ef0306fd..28c02c51c 100644 --- a/tests/regression_tests/ncrystal/results_true.dat +++ b/tests/regression_tests/ncrystal/results_true.dat @@ -106,8 +106,8 @@ 104 1 1.82e+00 1.83e+00 1 total current 1.10e-05 4.07e-06 105 1 1.83e+00 1.85e+00 1 total current 1.50e-05 4.01e-06 106 1 1.85e+00 1.87e+00 1 total current 1.90e-05 4.82e-06 -107 1 1.87e+00 1.88e+00 1 total current 2.20e-05 3.89e-06 -108 1 1.88e+00 1.90e+00 1 total current 2.10e-05 3.79e-06 +107 1 1.87e+00 1.88e+00 1 total current 2.30e-05 3.96e-06 +108 1 1.88e+00 1.90e+00 1 total current 2.00e-05 3.94e-06 109 1 1.90e+00 1.92e+00 1 total current 1.50e-05 3.42e-06 110 1 1.92e+00 1.94e+00 1 total current 2.20e-05 5.12e-06 111 1 1.94e+00 1.95e+00 1 total current 2.10e-05 5.86e-06 @@ -118,12 +118,12 @@ 116 1 2.02e+00 2.04e+00 1 total current 1.30e-05 3.35e-06 117 1 2.04e+00 2.06e+00 1 total current 1.90e-05 4.07e-06 118 1 2.06e+00 2.08e+00 1 total current 1.30e-05 3.00e-06 -119 1 2.08e+00 2.09e+00 1 total current 1.40e-05 4.00e-06 -120 1 2.09e+00 2.11e+00 1 total current 3.10e-05 5.47e-06 +119 1 2.08e+00 2.09e+00 1 total current 1.50e-05 4.28e-06 +120 1 2.09e+00 2.11e+00 1 total current 3.00e-05 4.94e-06 121 1 2.11e+00 2.13e+00 1 total current 2.30e-05 5.39e-06 122 1 2.13e+00 2.15e+00 1 total current 2.20e-05 4.67e-06 -123 1 2.15e+00 2.16e+00 1 total current 1.70e-05 4.48e-06 -124 1 2.16e+00 2.18e+00 1 total current 1.60e-05 4.00e-06 +123 1 2.15e+00 2.16e+00 1 total current 1.80e-05 4.67e-06 +124 1 2.16e+00 2.18e+00 1 total current 1.50e-05 4.01e-06 125 1 2.18e+00 2.20e+00 1 total current 1.80e-05 4.16e-06 126 1 2.20e+00 2.22e+00 1 total current 1.80e-05 4.42e-06 127 1 2.22e+00 2.23e+00 1 total current 1.80e-05 5.54e-06 @@ -135,7 +135,7 @@ 133 1 2.32e+00 2.34e+00 1 total current 2.30e-05 3.96e-06 134 1 2.34e+00 2.36e+00 1 total current 1.90e-05 3.48e-06 135 1 2.36e+00 2.37e+00 1 total current 1.60e-05 3.71e-06 -136 1 2.37e+00 2.39e+00 1 total current 1.60e-05 4.27e-06 +136 1 2.37e+00 2.39e+00 1 total current 1.70e-05 4.48e-06 137 1 2.39e+00 2.41e+00 1 total current 2.30e-05 4.48e-06 138 1 2.41e+00 2.43e+00 1 total current 2.10e-05 3.48e-06 139 1 2.43e+00 2.44e+00 1 total current 1.60e-05 2.21e-06 diff --git a/tools/ci/gha-install-ncrystal.sh b/tools/ci/gha-install-ncrystal.sh deleted file mode 100755 index 16f77e13e..000000000 --- a/tools/ci/gha-install-ncrystal.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash -set -ex -cd $HOME - -#Use the NCrystal develop branch (in the near future we can move this to master): -git clone https://github.com/mctools/ncrystal --branch develop --single-branch --depth 1 ncrystal_src - -SRC_DIR="$PWD/ncrystal_src" -BLD_DIR="$PWD/ncrystal_bld" -INST_DIR="$PWD/ncrystal_inst" -PYTHON=$(which python3) - -CPU_COUNT=1 - -mkdir "$BLD_DIR" -cd ncrystal_bld - -cmake \ - "${SRC_DIR}" \ - -DBUILD_SHARED_LIBS=ON \ - -DNCRYSTAL_NOTOUCH_CMAKE_BUILD_TYPE=ON \ - -DNCRYSTAL_MODIFY_RPATH=OFF \ - -DCMAKE_BUILD_TYPE=Release \ - -DNCRYSTAL_ENABLE_EXAMPLES=OFF \ - -DNCRYSTAL_ENABLE_SETUPSH=OFF \ - -DNCRYSTAL_ENABLE_DATA=EMBED \ - -DCMAKE_INSTALL_PREFIX="${INST_DIR}" \ - -DPython3_EXECUTABLE="$PYTHON" - -make -j${CPU_COUNT:-1} -make install - -#Note: There is no "make test" or "make ctest" functionality for NCrystal -# yet. If it appears in the future, we should add it here. - -# Output the configuration to the log - -"${INST_DIR}/bin/ncrystal-config" --setup - -# Change environmental variables - -eval $( "${INST_DIR}/bin/ncrystal-config" --setup ) - -# Check installation worked - -nctool --test diff --git a/tools/ci/gha-install.py b/tools/ci/gha-install.py index d52c4c825..1eb9a55b4 100644 --- a/tools/ci/gha-install.py +++ b/tools/ci/gha-install.py @@ -42,8 +42,6 @@ def install(omp=False, mpi=False, phdf5=False, dagmc=False, libmesh=False, ncrys if ncrystal: cmake_cmd.append('-DOPENMC_USE_NCRYSTAL=ON') - ncrystal_path = os.environ.get('HOME') + '/ncrystal_inst' - cmake_cmd.append(f'-DCMAKE_PREFIX_PATH={ncrystal_path}') # Build in coverage mode for coverage testing cmake_cmd.append('-DOPENMC_ENABLE_COVERAGE=on') diff --git a/tools/ci/gha-install.sh b/tools/ci/gha-install.sh index cff7dc834..50f110ed4 100755 --- a/tools/ci/gha-install.sh +++ b/tools/ci/gha-install.sh @@ -16,7 +16,9 @@ fi # Install NCrystal if needed if [[ $NCRYSTAL = 'y' ]]; then - ./tools/ci/gha-install-ncrystal.sh + pip install 'ncrystal>=4.0.0' + #Basic quick verification: + nctool --test fi # Install vectfit for WMP generation if needed diff --git a/tools/ci/gha-script.sh b/tools/ci/gha-script.sh index 9de84f3e5..4733907eb 100755 --- a/tools/ci/gha-script.sh +++ b/tools/ci/gha-script.sh @@ -16,8 +16,6 @@ fi # Check NCrystal installation if [[ $NCRYSTAL = 'y' ]]; then - # Change environmental variables - eval $( "${HOME}/ncrystal_inst/bin/ncrystal-config" --setup ) nctool --test fi