From fc5192c56cd918e9c01dee2b355c48a7552e5196 Mon Sep 17 00:00:00 2001 From: nscepi Date: Mon, 6 Nov 2023 15:00:23 +0100 Subject: [PATCH 001/370] Adding variables Er and F1,F2,F3 Added the variables Er and F1,F2,F3. I checked that I can initialize them correctly by outputting them using the ComputeUserVars function. --- src/dataBlock/dataBlockHost.cpp | 1 + src/dataBlock/dataBlockHost.hpp | 3 + src/fluid/fluid.hpp | 7 + src/idefix.hpp | 7 + src/physics.hpp | 25 ++ src/radiation/radiation.hpp | 22 ++ src/radiation/radiation_defs.hpp | 13 + test/Radiation/CMakeLists.txt | 0 .../cmake_packages/Kokkos/KokkosConfig.cmake | 88 +++++ .../Kokkos/KokkosConfigCommon.cmake | 302 ++++++++++++++++++ .../Kokkos/KokkosConfigVersion.cmake | 43 +++ .../cmake_packages/Kokkos/KokkosTargets.cmake | 127 ++++++++ test/Radiation/definitions.hpp | 6 + .../generated/Kokkos_Version_Info.cpp | 31 ++ .../generated/Kokkos_Version_Info.hpp | 34 ++ test/Radiation/git-state.txt | 1 + test/Radiation/idefix.ini | 28 ++ test/Radiation/setup.cpp | 64 ++++ 18 files changed, 802 insertions(+) create mode 100644 src/radiation/radiation.hpp create mode 100644 src/radiation/radiation_defs.hpp create mode 100644 test/Radiation/CMakeLists.txt create mode 100644 test/Radiation/cmake_packages/Kokkos/KokkosConfig.cmake create mode 100644 test/Radiation/cmake_packages/Kokkos/KokkosConfigCommon.cmake create mode 100644 test/Radiation/cmake_packages/Kokkos/KokkosConfigVersion.cmake create mode 100644 test/Radiation/cmake_packages/Kokkos/KokkosTargets.cmake create mode 100644 test/Radiation/definitions.hpp create mode 100644 test/Radiation/generated/Kokkos_Version_Info.cpp create mode 100644 test/Radiation/generated/Kokkos_Version_Info.hpp create mode 100644 test/Radiation/git-state.txt create mode 100644 test/Radiation/idefix.ini create mode 100644 test/Radiation/setup.cpp diff --git a/src/dataBlock/dataBlockHost.cpp b/src/dataBlock/dataBlockHost.cpp index ca26e5cb8..bcc40d26f 100644 --- a/src/dataBlock/dataBlockHost.cpp +++ b/src/dataBlock/dataBlockHost.cpp @@ -45,6 +45,7 @@ DataBlockHost::DataBlockHost(DataBlock& datain) { dV = Kokkos::create_mirror_view(data->dV); Vc = Kokkos::create_mirror_view(data->hydro->Vc); + Vrad = Kokkos::create_mirror_view(data->hydro->Vrad); Uc = Kokkos::create_mirror_view(data->hydro->Uc); InvDt = Kokkos::create_mirror_view(data->hydro->InvDt); diff --git a/src/dataBlock/dataBlockHost.hpp b/src/dataBlock/dataBlockHost.hpp index 86c8c570b..9b22c6a0a 100644 --- a/src/dataBlock/dataBlockHost.hpp +++ b/src/dataBlock/dataBlockHost.hpp @@ -48,6 +48,9 @@ class DataBlockHost { IdefixArray3D::HostMirror Ex3; ///< x3 electric field #endif + + IdefixArray4D::HostMirror Vrad; ///< Main face-centered primitive variables index for radiation + IdefixArray4D::HostMirror Uc; ///< Main cell-centered conservative variables IdefixArray3D::HostMirror InvDt; ///< Inverse of maximum timestep in each cell diff --git a/src/fluid/fluid.hpp b/src/fluid/fluid.hpp index ae809b489..01468f6d3 100644 --- a/src/fluid/fluid.hpp +++ b/src/fluid/fluid.hpp @@ -169,6 +169,8 @@ class Fluid { IdefixArray4D Ve; // Main edge-centered varariables (only when EVOLVE_VECTOR_POTENTIAL) IdefixArray4D Uc; // Main cell-centered conservative variables IdefixArray4D J; // Electrical current + IdefixArray4D Vrad; // Main cell-centered radiation variables + // (only defined when non-ideal MHD effects are enabled) // Name of the fields (used in outputs) @@ -559,6 +561,11 @@ Fluid::Fluid(Grid &grid, Input &input, DataBlock *datain, int n) { #endif // EVOLVE_VECTOR_POTENTIAL } + if constexpr(Phys::radiation) { + Vrad = IdefixArray4D(prefix+"_Vrad", 1+DIMENSIONS, + data->np_tot[KDIR]+KOFFSET, data->np_tot[JDIR]+JOFFSET, data->np_tot[IDIR]+IOFFSET); + } + if(this->haveCurrent) { // Allocate current (when hydro needs it) J = IdefixArray4D(prefix+"_J", 3, diff --git a/src/idefix.hpp b/src/idefix.hpp index a44bf4c26..953e11262 100644 --- a/src/idefix.hpp +++ b/src/idefix.hpp @@ -124,6 +124,13 @@ enum class LoopPattern { SIMDFOR, RANGE, MDRANGE, TPX, TPTTRTVR, UNDEFINED }; #endif #endif +#ifdef RADIATION + #define ER 0 + #define FR1 1 + #define FR2 (COMPONENTS >= 2 ? 2: 255) + #define FR3 (COMPONENTS >= 3 ? 3: 254) +#endif + // User-Friendly variables in non-cartesian geometry #if GEOMETRY == CYLINDRICAL #if COMPONENTS >= 1 diff --git a/src/physics.hpp b/src/physics.hpp index e9b29c455..6dfd39f1b 100644 --- a/src/physics.hpp +++ b/src/physics.hpp @@ -33,6 +33,12 @@ struct DefaultPhysics { static constexpr int nvar{1+COMPONENTS + (pressure?1:0)}; #endif + #ifdef RADIATION + static constexpr bool radiation{true}; + #else + static constexpr bool radiation{false}; + #endif + // prefix static constexpr std::string_view prefix = "Hydro"; }; @@ -47,8 +53,27 @@ struct DustPhysics { static constexpr bool mhd{false}; static constexpr int nvar{1+COMPONENTS}; + #ifdef RADIATION + static constexpr bool radiation{false}; // No radiation for dust for now + #endif + // prefix static constexpr std::string_view prefix = "Dust"; }; +// Radiation Physics +struct RadiationPhysics { + static constexpr bool dust{false}; + static constexpr bool pressure{false}; + static constexpr bool isothermal{false}; + static constexpr bool eos{false}; + + static constexpr bool mhd{false}; + static constexpr int radiation{true}; + static constexpr int nvar{1+COMPONENTS}; + + // prefix + static constexpr std::string_view prefix = "Radiation"; +}; + #endif // PHYSICS_HPP_ diff --git a/src/radiation/radiation.hpp b/src/radiation/radiation.hpp new file mode 100644 index 000000000..d777a96c6 --- /dev/null +++ b/src/radiation/radiation.hpp @@ -0,0 +1,22 @@ +// *********************************************************************************** +// Idefix MHD astrophysical code +// Copyright(C) Geoffroy R. J. Lesur +// and other code contributors +// Licensed under CeCILL 2.1 License, see COPYING for more information +// *********************************************************************************** + +#ifndef RAD_HPP_ +#define RAD_HPP_ + +#include "../idefix.hpp" + +// forward class declaration +class DataBlock; + +template +class Radiation { + public: + +} + +#endif //RAD_HPP_ \ No newline at end of file diff --git a/src/radiation/radiation_defs.hpp b/src/radiation/radiation_defs.hpp new file mode 100644 index 000000000..a3899bcc4 --- /dev/null +++ b/src/radiation/radiation_defs.hpp @@ -0,0 +1,13 @@ +#ifndef RADIATION_DEFS_HPP_ +#define RADIATION_DEFS_HPP_ + +#include "../idefix.hpp" + +// forward class declaration +class DataBlock; + +template +class Fluid; +class Radiation; + +#endif //RADIATION_DEFS_HPP_ \ No newline at end of file diff --git a/test/Radiation/CMakeLists.txt b/test/Radiation/CMakeLists.txt new file mode 100644 index 000000000..e69de29bb diff --git a/test/Radiation/cmake_packages/Kokkos/KokkosConfig.cmake b/test/Radiation/cmake_packages/Kokkos/KokkosConfig.cmake new file mode 100644 index 000000000..97ec40b9e --- /dev/null +++ b/test/Radiation/cmake_packages/Kokkos/KokkosConfig.cmake @@ -0,0 +1,88 @@ +# No need for policy push/pop. CMake also manages a new entry for scripts +# loaded by include() and find_package() commands except when invoked with +# the NO_POLICY_SCOPE option +# CMP0057 + NEW -> IN_LIST operator in IF(...) +CMAKE_POLICY(SET CMP0057 NEW) + +# Compute paths + +####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() ####### +####### Any changes to this file will be overwritten by the next CMake run #### +####### The input file was KokkosConfig.cmake.in ######## + +get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../" ABSOLUTE) + +macro(set_and_check _var _file) + set(${_var} "${_file}") + if(NOT EXISTS "${_file}") + message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !") + endif() +endmacro() + +macro(check_required_components _NAME) + foreach(comp ${${_NAME}_FIND_COMPONENTS}) + if(NOT ${_NAME}_${comp}_FOUND) + if(${_NAME}_FIND_REQUIRED_${comp}) + set(${_NAME}_FOUND FALSE) + endif() + endif() + endforeach() +endmacro() + +#################################################################################### + +#Find dependencies +INCLUDE(CMakeFindDependencyMacro) + +#This needs to go above the KokkosTargets in case +#the Kokkos targets depend in some way on the TPL imports + + +GET_FILENAME_COMPONENT(Kokkos_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +INCLUDE("${Kokkos_CMAKE_DIR}/KokkosTargets.cmake") +INCLUDE("${Kokkos_CMAKE_DIR}/KokkosConfigCommon.cmake") +UNSET(Kokkos_CMAKE_DIR) + +# check for conflicts +IF("launch_compiler" IN_LIST Kokkos_FIND_COMPONENTS AND + "separable_compilation" IN_LIST Kokkos_FIND_COMPONENTS) + MESSAGE(STATUS "'launch_compiler' implies global redirection of targets depending on Kokkos to appropriate compiler.") + MESSAGE(STATUS "'separable_compilation' implies explicitly defining where redirection occurs via 'kokkos_compilation(PROJECT|TARGET|SOURCE|DIRECTORY ...)'") + MESSAGE(FATAL_ERROR "Conflicting COMPONENTS: 'launch_compiler' and 'separable_compilation'") +ENDIF() + +IF("launch_compiler" IN_LIST Kokkos_FIND_COMPONENTS) + # + # if find_package(Kokkos COMPONENTS launch_compiler) then rely on the + # RULE_LAUNCH_COMPILE and RULE_LAUNCH_LINK to always redirect to the + # appropriate compiler for Kokkos + # + + MESSAGE(STATUS "kokkos_launch_compiler is enabled globally. C++ compiler commands with -DKOKKOS_DEPENDENCE will be redirected to the appropriate compiler for Kokkos") + kokkos_compilation( + GLOBAL + CHECK_CUDA_COMPILES) + +ELSEIF(OFF AND NOT "separable_compilation" IN_LIST Kokkos_FIND_COMPONENTS) + # + # if CUDA was enabled, separable compilation was not specified, and current compiler + # cannot compile CUDA, then set the RULE_LAUNCH_COMPILE and RULE_LAUNCH_LINK globally and + # kokkos_launch_compiler will re-direct to the compiler used to compile CUDA code during installation. + # kokkos_launch_compiler will re-direct if ${CMAKE_CXX_COMPILER} and -DKOKKOS_DEPENDENCE is present, + # otherwise, the original command will be executed + # + + # run test to see if CMAKE_CXX_COMPILER=nvcc_wrapper + kokkos_compiler_is_nvcc(IS_NVCC ${CMAKE_CXX_COMPILER}) + + # if not nvcc_wrapper and Kokkos_LAUNCH_COMPILER was not set to OFF + IF(NOT IS_NVCC AND (NOT DEFINED Kokkos_LAUNCH_COMPILER OR Kokkos_LAUNCH_COMPILER)) + MESSAGE(STATUS "kokkos_launch_compiler is enabled globally. C++ compiler commands with -DKOKKOS_DEPENDENCE will be redirected to the appropriate compiler for Kokkos") + kokkos_compilation(GLOBAL) + ENDIF() + + # be mindful of the environment, pollution is bad + UNSET(IS_NVCC) +ENDIF() + +set(Kokkos_COMPILE_LANGUAGE CXX) diff --git a/test/Radiation/cmake_packages/Kokkos/KokkosConfigCommon.cmake b/test/Radiation/cmake_packages/Kokkos/KokkosConfigCommon.cmake new file mode 100644 index 000000000..1791b569c --- /dev/null +++ b/test/Radiation/cmake_packages/Kokkos/KokkosConfigCommon.cmake @@ -0,0 +1,302 @@ +SET(Kokkos_DEVICES SERIAL) +SET(Kokkos_OPTIONS DEPRECATED_CODE_4;DEPRECATION_WARNINGS;COMPLEX_ALIGN) +SET(Kokkos_TPLS LIBDL) +SET(Kokkos_ARCH ) +SET(Kokkos_CXX_COMPILER "/Library/Developer/CommandLineTools/usr/bin/c++") +SET(Kokkos_CXX_COMPILER_ID "AppleClang") +SET(Kokkos_CXX_STANDARD 17) + +# Required to be a TriBITS-compliant external package +IF(NOT TARGET Kokkos::all_libs) + # CMake Error at /lib/cmake/Kokkos/KokkosConfigCommon.cmake:10 (ADD_LIBRARY): + # ADD_LIBRARY cannot create ALIAS target "Kokkos::all_libs" because target + # "Kokkos::kokkos" is imported but not globally visible. + IF(CMAKE_VERSION VERSION_LESS "3.18") + SET_TARGET_PROPERTIES(Kokkos::kokkos PROPERTIES IMPORTED_GLOBAL ON) + ENDIF() + ADD_LIBRARY(Kokkos::all_libs ALIAS Kokkos::kokkos) +ENDIF() + +# Export Kokkos_ENABLE_ for each backend that was enabled. +# NOTE: "Devices" is a little bit of a misnomer here. These are really +# backends, e.g. Kokkos_ENABLE_OPENMP, Kokkos_ENABLE_CUDA, Kokkos_ENABLE_HIP, +# or Kokkos_ENABLE_SYCL. +FOREACH(DEV ${Kokkos_DEVICES}) + SET(Kokkos_ENABLE_${DEV} ON) +ENDFOREACH() +# Export relevant Kokkos_ENABLE