From b50858b278904a66b449c11724f7931042871df7 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Wed, 10 Jan 2024 17:15:56 -0700 Subject: [PATCH 01/16] first pass at plugins --- CMakeLists.txt | 21 +- cmake/plugins.cmake | 49 +++++ .../CMakeDirectoryInformation.cmake | 16 ++ example/plugin/CMakeFiles/progress.marks | 1 + example/plugin/CMakeLists.txt | 22 ++ example/plugin/Makefile | 202 ++++++++++++++++++ example/plugin/cmake_install.cmake | 44 ++++ example/plugin/dust.hpp | 144 +++++++++++++ example/plugin/test_dust.cpp | 48 +++++ singularity-eos/CMakeLists.txt | 23 +- test/CMakeLists.txt | 16 ++ 11 files changed, 564 insertions(+), 22 deletions(-) create mode 100644 cmake/plugins.cmake create mode 100644 example/plugin/CMakeFiles/CMakeDirectoryInformation.cmake create mode 100644 example/plugin/CMakeFiles/progress.marks create mode 100644 example/plugin/CMakeLists.txt create mode 100644 example/plugin/Makefile create mode 100644 example/plugin/cmake_install.cmake create mode 100644 example/plugin/dust.hpp create mode 100644 example/plugin/test_dust.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7353b4aea1..7452b4d4ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,6 +118,9 @@ option(SINGULARITY_FORCE_SUBMODULE_MODE "Submodule mode" OFF) option(SINGULARITY_PATCH_MPARK_VARIANT "Apply GPU patch to mpark-variant submodule" ON) +# Plugins +set(SINGULARITY_PLUGINS "" CACHE STRING "List of paths to plugin directories") + # ------------------------------------------------------------------------------# # singularity-eos Library # ------------------------------------------------------------------------------# @@ -359,27 +362,27 @@ if(SINGULARITY_BUILD_TESTS) endif() endif() -# ##########################OLD # ------------------------------------------------------------------------------# # singularity-eos library # ------------------------------------------------------------------------------# -# this subdirectory populates `EOS_HEADERS/EOS_SRCS` NOTE: these include path +# Here we populate `EOS_HEADERS/EOS_SRCS` NOTE: these include path # prefixes of subdirectories on files (e.g. eos/eos.hpp) see # singularity-eos/CMakeLists.txt +include(cmake/plugins.cmake) add_subdirectory(singularity-eos) -foreach(_header ${EOS_HEADERS}) - list(APPEND _install_headers ${_header}) - list(APPEND _headers singularity-eos/${_header}) +foreach(_plugin ${SINGULARITY_PLUGINS}) + message(STATUS "Adding plugin ${_plugin}...") + add_subdirectory(${_plugin} ${_plugin}) endforeach() -foreach(_src ${EOS_SRCS}) - list(APPEND _srcs singularity-eos/${_src}) -endforeach() +# TODO(JMM): Kind of nice to have? +message(STATUS "EOS Headers:\n\t${EOS_HEADERS}") +message(STATUS "EOS Sources:\n\t${EOS_SRCS}") -target_sources(singularity-eos PRIVATE ${_srcs} ${_headers}) +target_sources(singularity-eos PRIVATE ${EOS_SRCS} ${EOS_HEADERS}) if(SINGULARITY_USE_FORTRAN) # Turn on preprocessor for fortran files diff --git a/cmake/plugins.cmake b/cmake/plugins.cmake new file mode 100644 index 0000000000..11ad8a6ce9 --- /dev/null +++ b/cmake/plugins.cmake @@ -0,0 +1,49 @@ +#------------------------------------------------------------------------------# +# © 2024. Triad National Security, LLC. All rights reserved. This +# program was produced under U.S. Government contract 89233218CNA000001 +# for Los Alamos National Laboratory (LANL), which is operated by Triad +# National Security, LLC for the U.S. Department of Energy/National +# Nuclear Security Administration. All rights in the program are +# reserved by Triad National Security, LLC, and the U.S. Department of +# Energy/National Nuclear Security Administration. The Government is +# granted for itself and others acting on its behalf a nonexclusive, +# paid-up, irrevocable worldwide license in this material to reproduce, +# prepare derivative works, distribute copies to the public, perform +# publicly and display publicly, and to permit others to do so. +#------------------------------------------------------------------------------# + +set(EOS_HEADERS "") +set(_install_headers "") +function(register_headers) + foreach(arg IN LISTS ARGN) + file(RELATIVE_PATH relative_path ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) + list(APPEND EOS_HEADERS ${relative_path}/${arg}) + list(APPEND _install_headers ${arg}) + endforeach() + set(EOS_HEADERS ${EOS_HEADERS} PARENT_SCOPE) + set(_install_headers ${_install_headers} PARENT_SCOPE) +endfunction() + +set(EOS_SRCS "") +function(register_srcs) + foreach(arg IN LISTS ARGN) + file(RELATIVE_PATH relative_path ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) + list(APPEND EOS_SRCS ${relative_path}/${arg}) + endforeach() + set(EOS_SRCS ${EOS_SRCS} PARENT_SCOPE) +endfunction() + +set(PLUGIN_TESTS "") +function(register_tests) + foreach(arg IN LISTS ARGN) + list(APPEND PLUGIN_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/${arg}) + endforeach() + set(PLUGIN_TESTS ${PLUGIN_TESTS} PARENT_SCOPE) +endfunction() + +macro(export_plugin) + set(EOS_HEADERS ${EOS_HEADERS} PARENT_SCOPE) + set(_install_headers ${_install_headers} PARENT_SCOPE) + set(EOS_SRCS ${EOS_SRCS} PARENT_SCOPE) + set(PLUGIN_TESTS ${PLUGIN_TESTS} PARENT_SCOPE) +endmacro() diff --git a/example/plugin/CMakeFiles/CMakeDirectoryInformation.cmake b/example/plugin/CMakeFiles/CMakeDirectoryInformation.cmake new file mode 100644 index 0000000000..d5f4c60f97 --- /dev/null +++ b/example/plugin/CMakeFiles/CMakeDirectoryInformation.cmake @@ -0,0 +1,16 @@ +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 3.25 + +# Relative path conversion top directories. +set(CMAKE_RELATIVE_PATH_TOP_SOURCE "/home/jonahm/programming/singularity-eos") +set(CMAKE_RELATIVE_PATH_TOP_BINARY "/home/jonahm/programming/singularity-eos/example/plugin") + +# Force unix paths in dependencies. +set(CMAKE_FORCE_UNIX_PATHS 1) + + +# The C and CXX include file regular expressions for this directory. +set(CMAKE_C_INCLUDE_REGEX_SCAN "^.*$") +set(CMAKE_C_INCLUDE_REGEX_COMPLAIN "^$") +set(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN}) +set(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN ${CMAKE_C_INCLUDE_REGEX_COMPLAIN}) diff --git a/example/plugin/CMakeFiles/progress.marks b/example/plugin/CMakeFiles/progress.marks new file mode 100644 index 0000000000..573541ac97 --- /dev/null +++ b/example/plugin/CMakeFiles/progress.marks @@ -0,0 +1 @@ +0 diff --git a/example/plugin/CMakeLists.txt b/example/plugin/CMakeLists.txt new file mode 100644 index 0000000000..16f4616c6b --- /dev/null +++ b/example/plugin/CMakeLists.txt @@ -0,0 +1,22 @@ +#------------------------------------------------------------------------------# +# © 2024. Triad National Security, LLC. All rights reserved. This +# program was produced under U.S. Government contract 89233218CNA000001 +# for Los Alamos National Laboratory (LANL), which is operated by Triad +# National Security, LLC for the U.S. Department of Energy/National +# Nuclear Security Administration. All rights in the program are +# reserved by Triad National Security, LLC, and the U.S. Department of +# Energy/National Nuclear Security Administration. The Government is +# granted for itself and others acting on its behalf a nonexclusive, +# paid-up, irrevocable worldwide license in this material to reproduce, +# prepare derivative works, distribute copies to the public, perform +# publicly and display publicly, and to permit others to do so. +#------------------------------------------------------------------------------# + +# Add the header file to the list of headers +register_headers(dust.hpp) + +# Register this test to be built in the test suite +register_tests(test_dust.cpp) + +# Export lists to parent scope +export_plugin() diff --git a/example/plugin/Makefile b/example/plugin/Makefile new file mode 100644 index 0000000000..b4c8c93e1e --- /dev/null +++ b/example/plugin/Makefile @@ -0,0 +1,202 @@ +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 3.25 + +# Default target executed when no arguments are given to make. +default_target: all +.PHONY : default_target + +# Allow only one "make -f Makefile2" at a time, but pass parallelism. +.NOTPARALLEL: + +#============================================================================= +# Special targets provided by cmake. + +# Disable implicit rules so canonical targets will work. +.SUFFIXES: + +# Disable VCS-based implicit rules. +% : %,v + +# Disable VCS-based implicit rules. +% : RCS/% + +# Disable VCS-based implicit rules. +% : RCS/%,v + +# Disable VCS-based implicit rules. +% : SCCS/s.% + +# Disable VCS-based implicit rules. +% : s.% + +.SUFFIXES: .hpux_make_needs_suffix_list + +# Command-line flag to silence nested $(MAKE). +$(VERBOSE)MAKESILENT = -s + +#Suppress display of executed commands. +$(VERBOSE).SILENT: + +# A target that is always out of date. +cmake_force: +.PHONY : cmake_force + +#============================================================================= +# Set environment variables for the build. + +# The shell in which to execute make rules. +SHELL = /bin/sh + +# The CMake executable. +CMAKE_COMMAND = /usr/bin/cmake + +# The command to remove a file. +RM = /usr/bin/cmake -E rm -f + +# Escaping for special characters. +EQUALS = = + +# The top-level source directory on which CMake was run. +CMAKE_SOURCE_DIR = /home/jonahm/programming/singularity-eos + +# The top-level build directory on which CMake was run. +CMAKE_BINARY_DIR = /home/jonahm/programming/singularity-eos/build + +#============================================================================= +# Targets provided globally by CMake. + +# Special rule for the target test +test: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running tests..." + /usr/bin/ctest --force-new-ctest-process $(ARGS) +.PHONY : test + +# Special rule for the target test +test/fast: test +.PHONY : test/fast + +# Special rule for the target edit_cache +edit_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..." + /usr/bin/ccmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) +.PHONY : edit_cache + +# Special rule for the target edit_cache +edit_cache/fast: edit_cache +.PHONY : edit_cache/fast + +# Special rule for the target rebuild_cache +rebuild_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." + /usr/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) +.PHONY : rebuild_cache + +# Special rule for the target rebuild_cache +rebuild_cache/fast: rebuild_cache +.PHONY : rebuild_cache/fast + +# Special rule for the target list_install_components +list_install_components: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Available install components are: \"Unspecified\"" +.PHONY : list_install_components + +# Special rule for the target list_install_components +list_install_components/fast: list_install_components +.PHONY : list_install_components/fast + +# Special rule for the target install +install: preinstall + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..." + /usr/bin/cmake -P cmake_install.cmake +.PHONY : install + +# Special rule for the target install +install/fast: preinstall/fast + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..." + /usr/bin/cmake -P cmake_install.cmake +.PHONY : install/fast + +# Special rule for the target install/local +install/local: preinstall + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..." + /usr/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake +.PHONY : install/local + +# Special rule for the target install/local +install/local/fast: preinstall/fast + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..." + /usr/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake +.PHONY : install/local/fast + +# Special rule for the target install/strip +install/strip: preinstall + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..." + /usr/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake +.PHONY : install/strip + +# Special rule for the target install/strip +install/strip/fast: preinstall/fast + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..." + /usr/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake +.PHONY : install/strip/fast + +# The main all target +all: cmake_check_build_system + cd /home/jonahm/programming/singularity-eos/build && $(CMAKE_COMMAND) -E cmake_progress_start /home/jonahm/programming/singularity-eos/build/CMakeFiles /home/jonahm/programming/singularity-eos/example/plugin//CMakeFiles/progress.marks + cd /home/jonahm/programming/singularity-eos/build && $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 /home/jonahm/programming/singularity-eos/example/plugin/all + $(CMAKE_COMMAND) -E cmake_progress_start /home/jonahm/programming/singularity-eos/build/CMakeFiles 0 +.PHONY : all + +# The main clean target +clean: + cd /home/jonahm/programming/singularity-eos/build && $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 /home/jonahm/programming/singularity-eos/example/plugin/clean +.PHONY : clean + +# The main clean target +clean/fast: clean +.PHONY : clean/fast + +# Prepare targets for installation. +preinstall: all + cd /home/jonahm/programming/singularity-eos/build && $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 /home/jonahm/programming/singularity-eos/example/plugin/preinstall +.PHONY : preinstall + +# Prepare targets for installation. +preinstall/fast: + cd /home/jonahm/programming/singularity-eos/build && $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 /home/jonahm/programming/singularity-eos/example/plugin/preinstall +.PHONY : preinstall/fast + +# clear depends +depend: + cd /home/jonahm/programming/singularity-eos/build && $(CMAKE_COMMAND) -P /home/jonahm/programming/singularity-eos/build/CMakeFiles/VerifyGlobs.cmake + cd /home/jonahm/programming/singularity-eos/build && $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 +.PHONY : depend + +# Help Target +help: + @echo "The following are some of the valid targets for this Makefile:" + @echo "... all (the default if no target is provided)" + @echo "... clean" + @echo "... depend" + @echo "... edit_cache" + @echo "... install" + @echo "... install/local" + @echo "... install/strip" + @echo "... list_install_components" + @echo "... rebuild_cache" + @echo "... test" +.PHONY : help + + + +#============================================================================= +# Special targets to cleanup operation of make. + +# Special rule to run CMake to check the build system integrity. +# No rule that depends on this can have commands that come from listfiles +# because they might be regenerated. +cmake_check_build_system: + cd /home/jonahm/programming/singularity-eos/build && $(CMAKE_COMMAND) -P /home/jonahm/programming/singularity-eos/build/CMakeFiles/VerifyGlobs.cmake + cd /home/jonahm/programming/singularity-eos/build && $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 +.PHONY : cmake_check_build_system + diff --git a/example/plugin/cmake_install.cmake b/example/plugin/cmake_install.cmake new file mode 100644 index 0000000000..88c1fd1691 --- /dev/null +++ b/example/plugin/cmake_install.cmake @@ -0,0 +1,44 @@ +# Install script for directory: /home/jonahm/programming/singularity-eos/example/plugin + +# Set the install prefix +if(NOT DEFINED CMAKE_INSTALL_PREFIX) + set(CMAKE_INSTALL_PREFIX "/home/jonahm/test") +endif() +string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") + +# Set the install configuration name. +if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME) + if(BUILD_TYPE) + string(REGEX REPLACE "^[^A-Za-z0-9_]+" "" + CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}") + else() + set(CMAKE_INSTALL_CONFIG_NAME "") + endif() + message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"") +endif() + +# Set the component getting installed. +if(NOT CMAKE_INSTALL_COMPONENT) + if(COMPONENT) + message(STATUS "Install component: \"${COMPONENT}\"") + set(CMAKE_INSTALL_COMPONENT "${COMPONENT}") + else() + set(CMAKE_INSTALL_COMPONENT) + endif() +endif() + +# Install shared libraries without execute permission? +if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE) + set(CMAKE_INSTALL_SO_NO_EXE "1") +endif() + +# Is this installation the result of a crosscompile? +if(NOT DEFINED CMAKE_CROSSCOMPILING) + set(CMAKE_CROSSCOMPILING "FALSE") +endif() + +# Set default install directory permissions. +if(NOT DEFINED CMAKE_OBJDUMP) + set(CMAKE_OBJDUMP "/usr/bin/objdump") +endif() + diff --git a/example/plugin/dust.hpp b/example/plugin/dust.hpp new file mode 100644 index 0000000000..e99828661f --- /dev/null +++ b/example/plugin/dust.hpp @@ -0,0 +1,144 @@ +//------------------------------------------------------------------------------ +// © 2024. Triad National Security, LLC. All rights reserved. This +// program was produced under U.S. Government contract 89233218CNA000001 +// for Los Alamos National Laboratory (LANL), which is operated by Triad +// National Security, LLC for the U.S. Department of Energy/National +// Nuclear Security Administration. All rights in the program are +// reserved by Triad National Security, LLC, and the U.S. Department of +// Energy/National Nuclear Security Administration. The Government is +// granted for itself and others acting on its behalf a nonexclusive, +// paid-up, irrevocable worldwide license in this material to reproduce, +// prepare derivative works, distribute copies to the public, perform +// publicly and display publicly, and to permit others to do so. +//------------------------------------------------------------------------------ + +#ifndef _EXAMPLE_PLUGIN_DUST_ +#define _EXAMPLE_PLUGIN_DUST_ + +// Ports-of-call +#include + +// Base stuff +#include +#include +#include +#include + +namespace singularity { + +using namespace eos_base; + +class Dust : public EosBase { + public: + PORTABLE_INLINE_FUNCTION Dust() : _Cv(1) {} + PORTABLE_INLINE_FUNCTION Dust(Real Cv) : _Cv(Cv) {} + + Dust GetOnDevice() { return *this; } + inline void Finalize() {} + + PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( + const Real rho, const Real sie, Real *lambda = nullptr) const { + return sie / _Cv; + } + PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( + const Real rho, const Real temperature, Real *lambda = nullptr) { + return _Cv * temperature; + } + PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( + const Real rho, const Real temperature, Real *lambda = nullptr) const { + return 0; + } + PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( + const Real rho, const Real sie, Real *lambda = nullptr) const { + return 0; + } + PORTABLE_INLINE_FUNCTION Real + MinInternalEnergyFromDensity(const Real rho, Real *lambda = nullptr) const { + return 0.0; + }; + + PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( + const Real rho, const Real temperature, Real *lambda = nullptr) const { + return 0; + } + PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( + const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real temp = TemperatureFromDensityInternalEnergy(rho, sie, lambda); + return 0; + } + PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( + const Real rho, const Real temperature, Real *lambda = nullptr) const { + return _Cv; + } + PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( + const Real rho, const Real sie, Real *lambda = nullptr) const { + return _Cv; + } + PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( + const Real rho, const Real temperature, Real *lambda = nullptr) const { + return 0; + } + PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( + const Real rho, const Real sie, Real *lambda = nullptr) const { + return 0; + } + PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( + const Real rho, const Real temperature, Real *lambda = nullptr) const { + return 0; + } + PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( + const Real rho, const Real sie, Real *lambda = nullptr) const { + return 0; + } + PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, + Real &cv, Real &bmod, const unsigned long output, + Real *lambda = nullptr) const { + press = 0; + bmod = 0; + cv = _Cv; + if (output & thermalqs::density) { + UNDEFINED_ERROR; + } + if (output & thermalqs::specific_internal_energy) { + if (!(output & thermalqs::temperature)) { + UNDEFINED_ERROR; + } + energy = _Cv*temp; + } + if (output & thermalqs::temperature) { + if (!(output & thermalqs::specific_internal_energy)) { + temp = energy / _Cv; + } + } + }; + PORTABLE_INLINE_FUNCTION + void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, Real &dpde, Real &dvdt, + Real *lambda = nullptr) const { + rho = temp = sie = 1; + press = bmod = dpde = 0; + dvdt = 0; + } + SG_ADD_BASE_CLASS_USINGS(Dust) + + PORTABLE_INLINE_FUNCTION int nlambda() const noexcept { return 0; } + static constexpr unsigned long PreferredInput() { return _preferred_input; } + static inline unsigned long scratch_size(std::string method, unsigned int nelements) { + return 0; + } + static inline unsigned long max_scratch_size(unsigned int nelements) { return 0; } + PORTABLE_INLINE_FUNCTION void PrintParams() const { + printf("Dust Parameters:\nCv = %g\n", _Cv); + } + static std::string EosType() { return std::string("Dust"); } + static std::string EosPyType() { return EosType(); } + +private: + Real _Cv = 1; + static constexpr const unsigned long _preferred_input = + thermalqs::density | thermalqs::specific_internal_energy | thermalqs::temperature; +}; + +} // namespace singularity + +#endif // _EXAMPLE_PLUGIN_DUST_ diff --git a/example/plugin/test_dust.cpp b/example/plugin/test_dust.cpp new file mode 100644 index 0000000000..bef73438a6 --- /dev/null +++ b/example/plugin/test_dust.cpp @@ -0,0 +1,48 @@ +//------------------------------------------------------------------------------ +// © 2024. Triad National Security, LLC. All rights reserved. This +// program was produced under U.S. Government contract 89233218CNA000001 +// for Los Alamos National Laboratory (LANL), which is operated by Triad +// National Security, LLC for the U.S. Department of Energy/National +// Nuclear Security Administration. All rights in the program are +// reserved by Triad National Security, LLC, and the U.S. Department of +// Energy/National Nuclear Security Administration. The Government is +// granted for itself and others acting on its behalf a nonexclusive, +// paid-up, irrevocable worldwide license in this material to reproduce, +// prepare derivative works, distribute copies to the public, perform +// publicly and display publicly, and to permit others to do so. +//------------------------------------------------------------------------------ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#ifdef SINGULARITY_BUILD_CLOSURE +#include +#endif + +#ifndef CATCH_CONFIG_FAST_COMPILE +#define CATCH_CONFIG_FAST_COMPILE +#include +#endif + +#include +#include "dust.hpp" + +using singularity::Dust; +using EOS = singularity::Variant; + +SCENARIO("Dust EOS", "[Dust]") { + GIVEN("A dust EOS") { + constexpr Real Cv = 1; + EOS dust = Dust(Cv); + THEN("The pressure is zero") { + REQUIRE(dust.PressureFromDensityInternalEnergy(1, 1) == 0); + } + } +} diff --git a/singularity-eos/CMakeLists.txt b/singularity-eos/CMakeLists.txt index 46c86316a7..82deec6e2c 100644 --- a/singularity-eos/CMakeLists.txt +++ b/singularity-eos/CMakeLists.txt @@ -12,7 +12,7 @@ # publicly and display publicly, and to permit others to do so. #------------------------------------------------------------------------------# -set(EOS_HEADERS +register_headers( base/fast-math/logs.hpp base/robust_utils.hpp base/root-finding-1d/root_finding.hpp @@ -45,33 +45,30 @@ set(EOS_HEADERS eos/eos_stiff.hpp ) -set(EOS_SRCS eos/eos.cpp) +register_srcs(eos/eos.cpp) if (SINGULARITY_BUILD_CLOSURE) - list(APPEND EOS_HEADERS - closure/mixed_cell_models.hpp) + register_headers(closure/mixed_cell_models.hpp) if (SINGULARITY_USE_FORTRAN) - list(APPEND EOS_SRCS - eos/get_sg_eos.cpp) + register_srcs(eos/get_sg_eos.cpp) if (SINGULARITY_USE_KOKKOS) - list(APPEND EOS_SRCS + register_srcs( eos/get_sg_eos_p_t.cpp eos/get_sg_eos_rho_t.cpp eos/get_sg_eos_rho_p.cpp eos/get_sg_eos_rho_e.cpp) endif() - list(APPEND EOS_HEADERS + register_headers( eos/get_sg_eos.hpp eos/get_sg_eos_functors.hpp) endif() endif() if (SINGULARITY_USE_FORTRAN) - list(APPEND EOS_SRCS eos/singularity_eos.f90) - list(APPEND EOS_SRCS eos/singularity_eos.cpp) - list(APPEND EOS_HEADERS eos/singularity_eos.hpp) + register_srcs(eos/singularity_eos.f90) + register_srcs(eos/singularity_eos.cpp) + register_headers(eos/singularity_eos.hpp) endif() # export to parent scope -set(EOS_HEADERS ${EOS_HEADERS} PARENT_SCOPE) -set(EOS_SRCS ${EOS_SRCS} PARENT_SCOPE) +export_plugin() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6add5dbd39..5830f0b0cd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -43,6 +43,15 @@ add_executable( test_eos_stellar_collapse.cpp ) +if (PLUGIN_TESTS) + add_executable( + eos_plugin_tests + catch2_define.cpp + eos_unit_test_helpers.hpp + ${PLUGIN_TESTS} + ) +endif() + if(SINGULARITY_TEST_HELMHOLTZ) configure_file(${PROJECT_SOURCE_DIR}/data/helmholtz/helm_table.dat ${CMAKE_BINARY_DIR}/data/helmholtz/helm_table.dat COPYONLY) target_compile_definitions(eos_tabulated_unit_tests PRIVATE SINGULARITY_TEST_HELMHOLTZ SINGULARITY_USE_HELMHOLTZ) @@ -62,10 +71,17 @@ target_link_libraries(eos_infrastructure_tests PRIVATE Catch2::Catch2 singularity-eos::singularity-eos) target_link_libraries(eos_tabulated_unit_tests PRIVATE Catch2::Catch2 singularity-eos::singularity-eos) +if (PLUGIN_TESTS) + target_link_libraries(eos_plugin_tests PRIVATE Catch2::Catch2 + singularity-eos::singularity-eos) +endif() include(Catch) catch_discover_tests(eos_analytic_unit_tests PROPERTIES TIMEOUT 60) catch_discover_tests(eos_infrastructure_tests PROPERTIES TIMEOUT 60) catch_discover_tests(eos_tabulated_unit_tests PROPERTIES TIMEOUT 60) +if (PLUGIN_TESTS) + catch_discover_tests(eos_plugin_tests PROPERTIES TIMEOUT 60) +endif() if(SINGULARITY_USE_EOSPAC AND SINGULARITY_TEST_SESAME) add_executable(compare_to_eospac compare_to_eospac.cpp) From 900c4ffc7252a5ed1977a26e57da91051a8a2b8d Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Wed, 10 Jan 2024 17:20:14 -0700 Subject: [PATCH 02/16] remove extraneous cmake files that got added --- .../CMakeDirectoryInformation.cmake | 16 -- example/plugin/CMakeFiles/progress.marks | 1 - example/plugin/Makefile | 202 ------------------ example/plugin/cmake_install.cmake | 44 ---- 4 files changed, 263 deletions(-) delete mode 100644 example/plugin/CMakeFiles/CMakeDirectoryInformation.cmake delete mode 100644 example/plugin/CMakeFiles/progress.marks delete mode 100644 example/plugin/Makefile delete mode 100644 example/plugin/cmake_install.cmake diff --git a/example/plugin/CMakeFiles/CMakeDirectoryInformation.cmake b/example/plugin/CMakeFiles/CMakeDirectoryInformation.cmake deleted file mode 100644 index d5f4c60f97..0000000000 --- a/example/plugin/CMakeFiles/CMakeDirectoryInformation.cmake +++ /dev/null @@ -1,16 +0,0 @@ -# CMAKE generated file: DO NOT EDIT! -# Generated by "Unix Makefiles" Generator, CMake Version 3.25 - -# Relative path conversion top directories. -set(CMAKE_RELATIVE_PATH_TOP_SOURCE "/home/jonahm/programming/singularity-eos") -set(CMAKE_RELATIVE_PATH_TOP_BINARY "/home/jonahm/programming/singularity-eos/example/plugin") - -# Force unix paths in dependencies. -set(CMAKE_FORCE_UNIX_PATHS 1) - - -# The C and CXX include file regular expressions for this directory. -set(CMAKE_C_INCLUDE_REGEX_SCAN "^.*$") -set(CMAKE_C_INCLUDE_REGEX_COMPLAIN "^$") -set(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN}) -set(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN ${CMAKE_C_INCLUDE_REGEX_COMPLAIN}) diff --git a/example/plugin/CMakeFiles/progress.marks b/example/plugin/CMakeFiles/progress.marks deleted file mode 100644 index 573541ac97..0000000000 --- a/example/plugin/CMakeFiles/progress.marks +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/example/plugin/Makefile b/example/plugin/Makefile deleted file mode 100644 index b4c8c93e1e..0000000000 --- a/example/plugin/Makefile +++ /dev/null @@ -1,202 +0,0 @@ -# CMAKE generated file: DO NOT EDIT! -# Generated by "Unix Makefiles" Generator, CMake Version 3.25 - -# Default target executed when no arguments are given to make. -default_target: all -.PHONY : default_target - -# Allow only one "make -f Makefile2" at a time, but pass parallelism. -.NOTPARALLEL: - -#============================================================================= -# Special targets provided by cmake. - -# Disable implicit rules so canonical targets will work. -.SUFFIXES: - -# Disable VCS-based implicit rules. -% : %,v - -# Disable VCS-based implicit rules. -% : RCS/% - -# Disable VCS-based implicit rules. -% : RCS/%,v - -# Disable VCS-based implicit rules. -% : SCCS/s.% - -# Disable VCS-based implicit rules. -% : s.% - -.SUFFIXES: .hpux_make_needs_suffix_list - -# Command-line flag to silence nested $(MAKE). -$(VERBOSE)MAKESILENT = -s - -#Suppress display of executed commands. -$(VERBOSE).SILENT: - -# A target that is always out of date. -cmake_force: -.PHONY : cmake_force - -#============================================================================= -# Set environment variables for the build. - -# The shell in which to execute make rules. -SHELL = /bin/sh - -# The CMake executable. -CMAKE_COMMAND = /usr/bin/cmake - -# The command to remove a file. -RM = /usr/bin/cmake -E rm -f - -# Escaping for special characters. -EQUALS = = - -# The top-level source directory on which CMake was run. -CMAKE_SOURCE_DIR = /home/jonahm/programming/singularity-eos - -# The top-level build directory on which CMake was run. -CMAKE_BINARY_DIR = /home/jonahm/programming/singularity-eos/build - -#============================================================================= -# Targets provided globally by CMake. - -# Special rule for the target test -test: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running tests..." - /usr/bin/ctest --force-new-ctest-process $(ARGS) -.PHONY : test - -# Special rule for the target test -test/fast: test -.PHONY : test/fast - -# Special rule for the target edit_cache -edit_cache: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..." - /usr/bin/ccmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) -.PHONY : edit_cache - -# Special rule for the target edit_cache -edit_cache/fast: edit_cache -.PHONY : edit_cache/fast - -# Special rule for the target rebuild_cache -rebuild_cache: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." - /usr/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) -.PHONY : rebuild_cache - -# Special rule for the target rebuild_cache -rebuild_cache/fast: rebuild_cache -.PHONY : rebuild_cache/fast - -# Special rule for the target list_install_components -list_install_components: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Available install components are: \"Unspecified\"" -.PHONY : list_install_components - -# Special rule for the target list_install_components -list_install_components/fast: list_install_components -.PHONY : list_install_components/fast - -# Special rule for the target install -install: preinstall - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..." - /usr/bin/cmake -P cmake_install.cmake -.PHONY : install - -# Special rule for the target install -install/fast: preinstall/fast - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..." - /usr/bin/cmake -P cmake_install.cmake -.PHONY : install/fast - -# Special rule for the target install/local -install/local: preinstall - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..." - /usr/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake -.PHONY : install/local - -# Special rule for the target install/local -install/local/fast: preinstall/fast - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..." - /usr/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake -.PHONY : install/local/fast - -# Special rule for the target install/strip -install/strip: preinstall - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..." - /usr/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake -.PHONY : install/strip - -# Special rule for the target install/strip -install/strip/fast: preinstall/fast - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..." - /usr/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake -.PHONY : install/strip/fast - -# The main all target -all: cmake_check_build_system - cd /home/jonahm/programming/singularity-eos/build && $(CMAKE_COMMAND) -E cmake_progress_start /home/jonahm/programming/singularity-eos/build/CMakeFiles /home/jonahm/programming/singularity-eos/example/plugin//CMakeFiles/progress.marks - cd /home/jonahm/programming/singularity-eos/build && $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 /home/jonahm/programming/singularity-eos/example/plugin/all - $(CMAKE_COMMAND) -E cmake_progress_start /home/jonahm/programming/singularity-eos/build/CMakeFiles 0 -.PHONY : all - -# The main clean target -clean: - cd /home/jonahm/programming/singularity-eos/build && $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 /home/jonahm/programming/singularity-eos/example/plugin/clean -.PHONY : clean - -# The main clean target -clean/fast: clean -.PHONY : clean/fast - -# Prepare targets for installation. -preinstall: all - cd /home/jonahm/programming/singularity-eos/build && $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 /home/jonahm/programming/singularity-eos/example/plugin/preinstall -.PHONY : preinstall - -# Prepare targets for installation. -preinstall/fast: - cd /home/jonahm/programming/singularity-eos/build && $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 /home/jonahm/programming/singularity-eos/example/plugin/preinstall -.PHONY : preinstall/fast - -# clear depends -depend: - cd /home/jonahm/programming/singularity-eos/build && $(CMAKE_COMMAND) -P /home/jonahm/programming/singularity-eos/build/CMakeFiles/VerifyGlobs.cmake - cd /home/jonahm/programming/singularity-eos/build && $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 -.PHONY : depend - -# Help Target -help: - @echo "The following are some of the valid targets for this Makefile:" - @echo "... all (the default if no target is provided)" - @echo "... clean" - @echo "... depend" - @echo "... edit_cache" - @echo "... install" - @echo "... install/local" - @echo "... install/strip" - @echo "... list_install_components" - @echo "... rebuild_cache" - @echo "... test" -.PHONY : help - - - -#============================================================================= -# Special targets to cleanup operation of make. - -# Special rule to run CMake to check the build system integrity. -# No rule that depends on this can have commands that come from listfiles -# because they might be regenerated. -cmake_check_build_system: - cd /home/jonahm/programming/singularity-eos/build && $(CMAKE_COMMAND) -P /home/jonahm/programming/singularity-eos/build/CMakeFiles/VerifyGlobs.cmake - cd /home/jonahm/programming/singularity-eos/build && $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 -.PHONY : cmake_check_build_system - diff --git a/example/plugin/cmake_install.cmake b/example/plugin/cmake_install.cmake deleted file mode 100644 index 88c1fd1691..0000000000 --- a/example/plugin/cmake_install.cmake +++ /dev/null @@ -1,44 +0,0 @@ -# Install script for directory: /home/jonahm/programming/singularity-eos/example/plugin - -# Set the install prefix -if(NOT DEFINED CMAKE_INSTALL_PREFIX) - set(CMAKE_INSTALL_PREFIX "/home/jonahm/test") -endif() -string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") - -# Set the install configuration name. -if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME) - if(BUILD_TYPE) - string(REGEX REPLACE "^[^A-Za-z0-9_]+" "" - CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}") - else() - set(CMAKE_INSTALL_CONFIG_NAME "") - endif() - message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"") -endif() - -# Set the component getting installed. -if(NOT CMAKE_INSTALL_COMPONENT) - if(COMPONENT) - message(STATUS "Install component: \"${COMPONENT}\"") - set(CMAKE_INSTALL_COMPONENT "${COMPONENT}") - else() - set(CMAKE_INSTALL_COMPONENT) - endif() -endif() - -# Install shared libraries without execute permission? -if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE) - set(CMAKE_INSTALL_SO_NO_EXE "1") -endif() - -# Is this installation the result of a crosscompile? -if(NOT DEFINED CMAKE_CROSSCOMPILING) - set(CMAKE_CROSSCOMPILING "FALSE") -endif() - -# Set default install directory permissions. -if(NOT DEFINED CMAKE_OBJDUMP) - set(CMAKE_OBJDUMP "/usr/bin/objdump") -endif() - From 6c43d6971f2b236e1143430d52561b13ac6b961c Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Wed, 10 Jan 2024 17:25:25 -0700 Subject: [PATCH 03/16] bin dir should be in build directory --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7452b4d4ff..86f6dd96d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -375,7 +375,8 @@ add_subdirectory(singularity-eos) foreach(_plugin ${SINGULARITY_PLUGINS}) message(STATUS "Adding plugin ${_plugin}...") - add_subdirectory(${_plugin} ${_plugin}) + get_filename_component(BINDIR_LOC ${_plugin} NAME) + add_subdirectory(${_plugin} ${CMAKE_CURRENT_BINARY_DIR}/${BINDIR_LOC}) endforeach() # TODO(JMM): Kind of nice to have? From d508698e66ead3e8ce30680944a0a962e5b3bd8a Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Thu, 11 Jan 2024 12:07:22 -0700 Subject: [PATCH 04/16] make include directories and install directories work... I think --- CMakeLists.txt | 22 +++++++++++++++++----- cmake/install.cmake | 4 ++-- cmake/plugins.cmake | 12 +++++++++++- example/plugin/CMakeLists.txt | 4 ++-- example/plugin/{ => dust}/dust.hpp | 14 +++++++------- example/plugin/{ => tst}/test_dust.cpp | 2 +- singularity-eos/CMakeLists.txt | 2 +- 7 files changed, 41 insertions(+), 19 deletions(-) rename example/plugin/{ => dust}/dust.hpp (95%) rename example/plugin/{ => tst}/test_dust.cpp (98%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 86f6dd96d6..bafe34bec6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,6 +121,9 @@ option(SINGULARITY_PATCH_MPARK_VARIANT # Plugins set(SINGULARITY_PLUGINS "" CACHE STRING "List of paths to plugin directories") +# CMake specific options +option(SINGULARITY_VERBOSE_CONFIG "Have cmake output additional information" OFF) + # ------------------------------------------------------------------------------# # singularity-eos Library # ------------------------------------------------------------------------------# @@ -362,6 +365,12 @@ if(SINGULARITY_BUILD_TESTS) endif() endif() +# ------------------------------------------------------------------------------# +# Plugin infrastructure +# ------------------------------------------------------------------------------# +include(cmake/plugins.cmake) +set(PLUGIN_BUILD_ROOT "${CMAKE_CURRENT_BINARY_DIR}/plugins") + # ------------------------------------------------------------------------------# # singularity-eos library # ------------------------------------------------------------------------------# @@ -369,19 +378,19 @@ endif() # Here we populate `EOS_HEADERS/EOS_SRCS` NOTE: these include path # prefixes of subdirectories on files (e.g. eos/eos.hpp) see # singularity-eos/CMakeLists.txt -include(cmake/plugins.cmake) - add_subdirectory(singularity-eos) foreach(_plugin ${SINGULARITY_PLUGINS}) message(STATUS "Adding plugin ${_plugin}...") get_filename_component(BINDIR_LOC ${_plugin} NAME) - add_subdirectory(${_plugin} ${CMAKE_CURRENT_BINARY_DIR}/${BINDIR_LOC}) + add_subdirectory(${_plugin} ${PLUGIN_BUILD_ROOT}/${BINDIR_LOC}) endforeach() # TODO(JMM): Kind of nice to have? -message(STATUS "EOS Headers:\n\t${EOS_HEADERS}") -message(STATUS "EOS Sources:\n\t${EOS_SRCS}") +if (SINGULARITY_VERBOSE_CONFIG) + message(STATUS "EOS Headers:\n\t${EOS_HEADERS}") + message(STATUS "EOS Sources:\n\t${EOS_SRCS}") +endif() target_sources(singularity-eos PRIVATE ${EOS_SRCS} ${EOS_HEADERS}) @@ -400,6 +409,9 @@ endif() # SINGULARITY_USE_FORTRAN target_include_directories( singularity-eos PUBLIC $ $) +foreach(path ${PLUGIN_INCLUDE_PATHS}) + target_include_directories(singularity-eos PUBLIC $) +endforeach() # plug in collected includes/libs/definitions diff --git a/cmake/install.cmake b/cmake/install.cmake index 3067aa5ed1..679c2f2671 100644 --- a/cmake/install.cmake +++ b/cmake/install.cmake @@ -72,8 +72,8 @@ install( # install singularity-eos headers foreach(file ${_install_headers}) get_filename_component(DIR ${file} DIRECTORY) - install(FILES singularity-eos/${file} - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/singularity-eos/${DIR}) + install(FILES ${file} + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${DIR}) endforeach() # file # install the fortran modules NB: cmake doesn't provide a clean way to handle diff --git a/cmake/plugins.cmake b/cmake/plugins.cmake index 11ad8a6ce9..4a26384fdf 100644 --- a/cmake/plugins.cmake +++ b/cmake/plugins.cmake @@ -18,7 +18,7 @@ function(register_headers) foreach(arg IN LISTS ARGN) file(RELATIVE_PATH relative_path ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) list(APPEND EOS_HEADERS ${relative_path}/${arg}) - list(APPEND _install_headers ${arg}) + list(APPEND _install_headers ${relative_path}/${arg}) endforeach() set(EOS_HEADERS ${EOS_HEADERS} PARENT_SCOPE) set(_install_headers ${_install_headers} PARENT_SCOPE) @@ -41,9 +41,19 @@ function(register_tests) set(PLUGIN_TESTS ${PLUGIN_TESTS} PARENT_SCOPE) endfunction() +set(PLUGIN_INCLUDE_PATHS "") +macro(export_source) + set(EOS_HEADERS ${EOS_HEADERS} PARENT_SCOPE) + set(_install_headers ${_install_headers} PARENT_SCOPE) + set(EOS_SRCS ${EOS_SRCS} PARENT_SCOPE) + set(PLUGIN_TESTS ${PLUGIN_TESTS} PARENT_SCOPE) + set(PLUGIN_INCLUDE_PATHS ${PLUGIN_INCLUDE_PATHS} PARENT_SCOPE) +endmacro() macro(export_plugin) + list(APPEND PLUGIN_INCLUDE_PATHS ${CMAKE_CURRENT_SOURCE_DIR}) set(EOS_HEADERS ${EOS_HEADERS} PARENT_SCOPE) set(_install_headers ${_install_headers} PARENT_SCOPE) set(EOS_SRCS ${EOS_SRCS} PARENT_SCOPE) set(PLUGIN_TESTS ${PLUGIN_TESTS} PARENT_SCOPE) + set(PLUGIN_INCLUDE_PATHS ${PLUGIN_INCLUDE_PATHS} PARENT_SCOPE) endmacro() diff --git a/example/plugin/CMakeLists.txt b/example/plugin/CMakeLists.txt index 16f4616c6b..03984c8f63 100644 --- a/example/plugin/CMakeLists.txt +++ b/example/plugin/CMakeLists.txt @@ -13,10 +13,10 @@ #------------------------------------------------------------------------------# # Add the header file to the list of headers -register_headers(dust.hpp) +register_headers(dust/dust.hpp) # Register this test to be built in the test suite -register_tests(test_dust.cpp) +register_tests(tst/test_dust.cpp) # Export lists to parent scope export_plugin() diff --git a/example/plugin/dust.hpp b/example/plugin/dust/dust.hpp similarity index 95% rename from example/plugin/dust.hpp rename to example/plugin/dust/dust.hpp index e99828661f..03c737d4ec 100644 --- a/example/plugin/dust.hpp +++ b/example/plugin/dust/dust.hpp @@ -26,7 +26,7 @@ namespace singularity { -using namespace eos_base; +using namespace eos_base; class Dust : public EosBase { public: @@ -44,9 +44,9 @@ class Dust : public EosBase { const Real rho, const Real temperature, Real *lambda = nullptr) { return _Cv * temperature; } - PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( + PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( const Real rho, const Real temperature, Real *lambda = nullptr) const { - return 0; + return 0; } PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( const Real rho, const Real sie, Real *lambda = nullptr) const { @@ -103,7 +103,7 @@ class Dust : public EosBase { if (!(output & thermalqs::temperature)) { UNDEFINED_ERROR; } - energy = _Cv*temp; + energy = _Cv * temp; } if (output & thermalqs::temperature) { if (!(output & thermalqs::specific_internal_energy)) { @@ -120,7 +120,7 @@ class Dust : public EosBase { dvdt = 0; } SG_ADD_BASE_CLASS_USINGS(Dust) - + PORTABLE_INLINE_FUNCTION int nlambda() const noexcept { return 0; } static constexpr unsigned long PreferredInput() { return _preferred_input; } static inline unsigned long scratch_size(std::string method, unsigned int nelements) { @@ -133,10 +133,10 @@ class Dust : public EosBase { static std::string EosType() { return std::string("Dust"); } static std::string EosPyType() { return EosType(); } -private: + private: Real _Cv = 1; static constexpr const unsigned long _preferred_input = - thermalqs::density | thermalqs::specific_internal_energy | thermalqs::temperature; + thermalqs::density | thermalqs::specific_internal_energy | thermalqs::temperature; }; } // namespace singularity diff --git a/example/plugin/test_dust.cpp b/example/plugin/tst/test_dust.cpp similarity index 98% rename from example/plugin/test_dust.cpp rename to example/plugin/tst/test_dust.cpp index bef73438a6..19bdd8ddc0 100644 --- a/example/plugin/test_dust.cpp +++ b/example/plugin/tst/test_dust.cpp @@ -31,8 +31,8 @@ #include #endif +#include #include -#include "dust.hpp" using singularity::Dust; using EOS = singularity::Variant; diff --git a/singularity-eos/CMakeLists.txt b/singularity-eos/CMakeLists.txt index 82deec6e2c..87f73c708d 100644 --- a/singularity-eos/CMakeLists.txt +++ b/singularity-eos/CMakeLists.txt @@ -71,4 +71,4 @@ if (SINGULARITY_USE_FORTRAN) endif() # export to parent scope -export_plugin() +export_source() From 57ada428a9085f112174d86c77bb25d008402bcb Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Thu, 11 Jan 2024 12:56:05 -0700 Subject: [PATCH 05/16] fix installs by adding PLUGIN named argument --- cmake/install.cmake | 10 +++++++--- cmake/plugins.cmake | 15 ++++++++++++--- example/plugin/CMakeLists.txt | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/cmake/install.cmake b/cmake/install.cmake index 679c2f2671..77fabcd491 100644 --- a/cmake/install.cmake +++ b/cmake/install.cmake @@ -70,9 +70,13 @@ install( # ----------------------------------------------------------------------------# # install singularity-eos headers -foreach(file ${_install_headers}) - get_filename_component(DIR ${file} DIRECTORY) - install(FILES ${file} +list(LENGTH _install_headers length) +math(EXPR max_index "${length} - 1") +foreach(index RANGE ${max_index}) + list(GET EOS_HEADERS ${index} src) + list(GET _install_headers ${index} dst) + get_filename_component(DIR ${dst} DIRECTORY) + install(FILES ${src} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${DIR}) endforeach() # file diff --git a/cmake/plugins.cmake b/cmake/plugins.cmake index 4a26384fdf..5cb836224b 100644 --- a/cmake/plugins.cmake +++ b/cmake/plugins.cmake @@ -15,10 +15,19 @@ set(EOS_HEADERS "") set(_install_headers "") function(register_headers) - foreach(arg IN LISTS ARGN) + set(keyword_args PLUGIN) + cmake_parse_arguments(ARG "" "${keyword_args}" "" ${ARGN}) + set(variadic_args ${ARG_UNPARSED_ARGUMENTS}) + + foreach(arg IN LISTS variadic_args) file(RELATIVE_PATH relative_path ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) - list(APPEND EOS_HEADERS ${relative_path}/${arg}) - list(APPEND _install_headers ${relative_path}/${arg}) + if (ARG_PLUGIN) + list(APPEND EOS_HEADERS ${relative_path}/${ARG_PLUGIN}/${arg}) + list(APPEND _install_headers ${ARG_PLUGIN}/${arg}) + else() + list(APPEND EOS_HEADERS ${relative_path}/${arg}) + list(APPEND _install_headers ${relative_path}/${arg}) + endif() endforeach() set(EOS_HEADERS ${EOS_HEADERS} PARENT_SCOPE) set(_install_headers ${_install_headers} PARENT_SCOPE) diff --git a/example/plugin/CMakeLists.txt b/example/plugin/CMakeLists.txt index 03984c8f63..8b9efa1f7f 100644 --- a/example/plugin/CMakeLists.txt +++ b/example/plugin/CMakeLists.txt @@ -13,7 +13,7 @@ #------------------------------------------------------------------------------# # Add the header file to the list of headers -register_headers(dust/dust.hpp) +register_headers(PLUGIN dust dust.hpp) # Register this test to be built in the test suite register_tests(tst/test_dust.cpp) From 29a18d7ec83c3442dcba25091d35c5c8f7381f16 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Thu, 11 Jan 2024 17:31:18 -0700 Subject: [PATCH 06/16] add ability to specify variant with cmake filegen --- CMakeLists.txt | 6 + cmake/install.cmake | 7 + example/plugin/CMakeLists.txt | 2 +- example/plugin/dust/dust_variant.hpp | 144 ++++++++++++++++++ example/plugin/tst/test_dust.cpp | 1 + singularity-eos/CMakeLists.txt | 14 +- .../eos/{eos.hpp => default_variant.hpp} | 28 +--- singularity-eos/eos/eos.hpp.in | 20 +++ singularity-eos/eos/eos_models.hpp | 39 +++++ 9 files changed, 236 insertions(+), 25 deletions(-) create mode 100644 example/plugin/dust/dust_variant.hpp rename singularity-eos/eos/{eos.hpp => default_variant.hpp} (83%) create mode 100644 singularity-eos/eos/eos.hpp.in create mode 100644 singularity-eos/eos/eos_models.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index bafe34bec6..6e262e8c95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,6 +120,8 @@ option(SINGULARITY_PATCH_MPARK_VARIANT # Plugins set(SINGULARITY_PLUGINS "" CACHE STRING "List of paths to plugin directories") +set(SINGULARITY_VARIANT "singularity-eos/eos/default_variant.hpp" CACHE STRING + "The include path for the file containing the definition of singularity::EOS.") # CMake specific options option(SINGULARITY_VERBOSE_CONFIG "Have cmake output additional information" OFF) @@ -409,6 +411,10 @@ endif() # SINGULARITY_USE_FORTRAN target_include_directories( singularity-eos PUBLIC $ $) +target_include_directories( + singularity-eos PUBLIC $) + + foreach(path ${PLUGIN_INCLUDE_PATHS}) target_include_directories(singularity-eos PUBLIC $) endforeach() diff --git a/cmake/install.cmake b/cmake/install.cmake index 77fabcd491..cac21733b3 100644 --- a/cmake/install.cmake +++ b/cmake/install.cmake @@ -80,6 +80,13 @@ foreach(index RANGE ${max_index}) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${DIR}) endforeach() # file +# Special sauce so generated file has proper include path +install(FILES + ${CMAKE_BINARY_DIR}/generated/singularity-eos/eos/eos.hpp + DESTINATION + ${CMAKE_INSTALL_INCLUDEDIR}/singularity-eos/eos + ) + # install the fortran modules NB: cmake doesn't provide a clean way to handle if(SINGULARITY_USE_FORTRAN) install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fortran/ diff --git a/example/plugin/CMakeLists.txt b/example/plugin/CMakeLists.txt index 8b9efa1f7f..c7f4340673 100644 --- a/example/plugin/CMakeLists.txt +++ b/example/plugin/CMakeLists.txt @@ -13,7 +13,7 @@ #------------------------------------------------------------------------------# # Add the header file to the list of headers -register_headers(PLUGIN dust dust.hpp) +register_headers(PLUGIN dust dust.hpp dust_variant.hpp) # Register this test to be built in the test suite register_tests(tst/test_dust.cpp) diff --git a/example/plugin/dust/dust_variant.hpp b/example/plugin/dust/dust_variant.hpp new file mode 100644 index 0000000000..cba779a537 --- /dev/null +++ b/example/plugin/dust/dust_variant.hpp @@ -0,0 +1,144 @@ +//------------------------------------------------------------------------------ +// © 2024. Triad National Security, LLC. All rights reserved. This +// program was produced under U.S. Government contract 89233218CNA000001 +// for Los Alamos National Laboratory (LANL), which is operated by Triad +// National Security, LLC for the U.S. Department of Energy/National +// Nuclear Security Administration. All rights in the program are +// reserved by Triad National Security, LLC, and the U.S. Department of +// Energy/National Nuclear Security Administration. The Government is +// granted for itself and others acting on its behalf a nonexclusive, +// paid-up, irrevocable worldwide license in this material to reproduce, +// prepare derivative works, distribute copies to the public, perform +// publicly and display publicly, and to permit others to do so. +//------------------------------------------------------------------------------ + +#ifndef _EXAMPLE_PLUGIN_DUST_DUST_VARIANT_HPP_ +#define _EXAMPLE_PLUGIN_DUST_DUST_VARIANT_HPP_ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +// Base stuff +#include +#include +#include + +// EOS models +#include + +#include + +namespace singularity { + +// recreate variadic list +template +using tl = singularity::variadic_utils::type_list; + +template