From e2ae7e7c861d4d0e816ea5c3b175e6d737f97d4c Mon Sep 17 00:00:00 2001 From: Cheng Li <69489965+chengcli@users.noreply.github.com> Date: Tue, 31 Oct 2023 00:47:25 -0400 Subject: [PATCH] Add Jupiter CRM (#103) add jupiter_crm to test case --- CMakeLists.txt | 8 + ...{sedimentation.cmake => jupiter_crm.cmake} | 6 +- cmake/macros/macro_setup_problem.cmake | 23 ++ cmake/macros/macro_setup_test.cmake | 31 +++ examples/2019-Li-snap/CMakeLists.txt | 60 +---- .../{bryan_pgen.cpp => bryan.cpp} | 3 + ...yan_mods.cpp => bryan_vapor_functions.hpp} | 10 +- examples/2019-Li-snap/jupiter2d.inp | 99 +++++++++ examples/2019-Li-snap/jupiter_crm.cpp | 209 ++++++++++++++++++ examples/2019-Li-snap/sedimentation.cpp | 3 + examples/2019-Li-snap/water_ammonia.yaml | 5 +- examples/2023-jupiter-mwr-eq/CMakeLists.txt | 39 +--- .../{juno_mwr_pgen.cpp => juno_mwr.cpp} | 3 + .../{juno_mwr_mods.cpp => juno_mwr_specs.hpp} | 89 ++++---- examples/2024-Li-plume/plume_mods.cpp | 10 +- src/CMakeLists.txt | 2 + src/microphysics/kessler94.cpp | 7 +- src/microphysics/microphysical_schemes.hpp | 62 ++++-- src/microphysics/microphysics.cpp | 19 +- src/microphysics/microphysics.hpp | 43 +++- src/snap/eos/ideal_moist_hydro.cpp | 2 +- src/snap/riemann/lmars.cpp | 14 +- .../thermodynamics/enroll_vapor_functions.cpp | 24 +- src/snap/thermodynamics/thermodynamics.cpp | 2 +- src/snap/thermodynamics/thermodynamics.hpp | 47 ++-- src/special/CMakeLists.txt | 1 + .../special/giants_add_absorber_v1.hpp | 0 .../giants_enroll_vapor_functions_v1.hpp | 86 +++---- .../special}/jupiter_opacity.yaml | 0 {examples => src/special}/mars_absorber.cpp | 0 src/tasklist/implicit_hydro_tasks.cpp | 2 +- tests/CMakeLists.txt | 106 ++------- tests/test_air_parcel.cpp | 4 + tests/test_ammonium_hydrosulfide.cpp | 4 + tests/test_impl.cpp | 4 + tests/test_microphysics.cpp | 4 + tests/test_microwave_opacity.cpp | 4 + tests/test_moist_adiabat.cpp | 10 +- tests/test_radiation.cpp | 4 + tests/test_thermodynamics.cpp | 4 + 40 files changed, 685 insertions(+), 368 deletions(-) rename cmake/{sedimentation.cmake => jupiter_crm.cmake} (81%) create mode 100644 cmake/macros/macro_setup_problem.cmake create mode 100644 cmake/macros/macro_setup_test.cmake rename examples/2019-Li-snap/{bryan_pgen.cpp => bryan.cpp} (98%) rename examples/2019-Li-snap/{bryan_mods.cpp => bryan_vapor_functions.hpp} (69%) create mode 100644 examples/2019-Li-snap/jupiter2d.inp create mode 100644 examples/2019-Li-snap/jupiter_crm.cpp rename examples/2023-jupiter-mwr-eq/{juno_mwr_pgen.cpp => juno_mwr.cpp} (99%) rename examples/2023-jupiter-mwr-eq/{juno_mwr_mods.cpp => juno_mwr_specs.hpp} (77%) create mode 100644 src/special/CMakeLists.txt rename examples/giants_add_absorber.cpp => src/special/giants_add_absorber_v1.hpp (100%) rename examples/giants_enroll_vapor_functions.cpp => src/special/giants_enroll_vapor_functions_v1.hpp (52%) rename {examples => src/special}/jupiter_opacity.yaml (100%) rename {examples => src/special}/mars_absorber.cpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index ceb6b502..8a47281b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,6 +77,14 @@ endif() ## 6. set up unit tests and examples message(STATUS "6. Set up unit tests") + +# load all macros +FILE(GLOB _macro_files "${CMAKE_SOURCE_DIR}/cmake/macros/*.cmake") +FOREACH(_file ${_macro_files}) + MESSAGE(STATUS "Include ${_file}") + INCLUDE(${_file}) +ENDFOREACH() + add_subdirectory(examples) add_subdirectory(tests) diff --git a/cmake/sedimentation.cmake b/cmake/jupiter_crm.cmake similarity index 81% rename from cmake/sedimentation.cmake rename to cmake/jupiter_crm.cmake index 5413a859..10848f4c 100644 --- a/cmake/sedimentation.cmake +++ b/cmake/jupiter_crm.cmake @@ -1,4 +1,4 @@ -# configure file for test sedimentation +# configure file for test jupiter crm macro(SET_IF_EMPTY _variable) if("${${_variable}}" STREQUAL "") @@ -10,8 +10,8 @@ endmacro() set_if_empty(NUMBER_GHOST_CELLS 3) # canoe configure -set(NVAPOR 2) -set(NCLOUD 4) +set(NVAPOR 1) +set(NCLOUD 2) set(NPHASE_LEGACY 3) set(NETCDF ON) set(PNETCDF ON) diff --git a/cmake/macros/macro_setup_problem.cmake b/cmake/macros/macro_setup_problem.cmake new file mode 100644 index 00000000..571a0b75 --- /dev/null +++ b/cmake/macros/macro_setup_problem.cmake @@ -0,0 +1,23 @@ +# A small macro used for setting up the build of a problem. +# +# Usage: setup_problem(name) + +string(TOLOWER ${CMAKE_BUILD_TYPE} buildl) +string(TOUPPER ${CMAKE_BUILD_TYPE} buildu) + +macro(setup_problem namel) + add_executable(${namel}.${buildl} ${namel}.cpp + ${CMAKE_BINARY_DIR}/main_${TASK}.cpp) + + set_target_properties( + ${namel}.${buildl} + PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" + COMPILE_FLAGS ${CMAKE_CXX_FLAGS_${buildu}}) + + target_link_libraries(${namel}.${buildl} ${CANOE_LIBRARY_${buildu}}) + + target_include_directories( + ${namel}.${buildl} + PRIVATE ${CMAKE_BINARY_DIR} ${CANOE_INCLUDE_DIR} ${EIGEN3_INCLUDE_DIR} + ${MPI_CXX_INCLUDE_PATH} ${NETCDF_INCLUDES} ${PNETCDF_INCLUDE_DIR}) +endmacro() diff --git a/cmake/macros/macro_setup_test.cmake b/cmake/macros/macro_setup_test.cmake new file mode 100644 index 00000000..768d4c23 --- /dev/null +++ b/cmake/macros/macro_setup_test.cmake @@ -0,0 +1,31 @@ +# A small macro used for setting up the build of a test. +# +# Usage: setup_test(name) + +macro(setup_test namel) + string(TOLOWER ${CMAKE_BUILD_TYPE} buildl) + string(TOUPPER ${CMAKE_BUILD_TYPE} buildu) + + add_executable(${namel}.${buildl} ${namel}.cpp globals.cpp) + + set_target_properties(${namel}.${buildl} + PROPERTIES COMPILE_FLAGS ${CMAKE_CXX_FLAGS_${buildu}}) + + target_include_directories( + ${namel}.${buildl} + PRIVATE $<$:${PVFMM_SOURCE_DIR}/SCTL/include> + ${CMAKE_BINARY_DIR} + ${CANOE_INCLUDE_DIR} + ${EIGEN3_INCLUDE_DIR} + ${MPI_CXX_INCLUDE_PATH} + ${NETCDF_INCLUDES} + ${PNETCDF_INCLUDE_DIR} + ${OpenMP_CXX_INCLUDE_DIR} + ${FFTW_INCLUDE_DIRS}) + + target_link_libraries( + ${namel}.${buildl} gtest_main $<$:pvfmmStatic> + ${CANOE_LIBRARY_${buildu}}) + + add_test(NAME ${namel}.${buildl} COMMAND ${namel}.${buildl}) +endmacro() diff --git a/examples/2019-Li-snap/CMakeLists.txt b/examples/2019-Li-snap/CMakeLists.txt index 101cb26c..de44b373 100644 --- a/examples/2019-Li-snap/CMakeLists.txt +++ b/examples/2019-Li-snap/CMakeLists.txt @@ -1,56 +1,20 @@ -string(TOLOWER ${CMAKE_BUILD_TYPE} buildl) -string(TOUPPER ${CMAKE_BUILD_TYPE} buildu) +# ============================================ +# Examples published in Li et al. (2019), ApJS +# ============================================ -macro(setup_problem namel) - set_target_properties( - ${namel}.${buildl} - PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" - COMPILE_FLAGS ${CMAKE_CXX_FLAGS_${buildu}} - ) +# 1. Compile straka, robert and bryan +setup_problem(straka) +setup_problem(robert) +setup_problem(bryan) - target_link_libraries(${namel}.${buildl} - ${CANOE_LIBRARY_${buildu}} - ) - - target_include_directories(${namel}.${buildl} - PRIVATE - ${CMAKE_BINARY_DIR} - ${CANOE_INCLUDE_DIR} - ${EIGEN3_INCLUDE_DIR} - ${MPI_CXX_INCLUDE_PATH} - ${NETCDF_INCLUDES} - ${PNETCDF_INCLUDE_DIR} - ) -endmacro() - -# 1. Compile straka and robert -foreach(namel straka robert) - add_executable(${namel}.${buildl} ${namel}.cpp - ${CMAKE_BINARY_DIR}/main_${TASK}.cpp) - setup_problem(${namel}) -endforeach() - -# 2. Compile bryan -if (${NVAPOR} EQUAL 1 AND ${NCLOUD} EQUAL 1 AND ${NPHASE_LEGACY} EQUAL 2) - set(namel bryan) - - add_executable(${namel}.${buildl} ${namel}_pgen.cpp ${namel}_mods.cpp - ${CMAKE_BINARY_DIR}/main_${TASK}.cpp) - - setup_problem(${namel}) -endif() - -# 3. Compile sedimentation +# 2. Compile sedimentation if (${NVAPOR} EQUAL 2 AND ${NCLOUD} EQUAL 4 AND ${NPHASE_LEGACY} EQUAL 3) - set(namel sedimentation) - - add_executable(${namel}.${buildl} ${namel}.cpp ../giants_enroll_vapor_functions.cpp - ${CMAKE_BINARY_DIR}/main_${TASK}.cpp) - - setup_problem(${namel}) + setup_problem(sedimentation) endif() +# 3. Compile jupiter crm +setup_problem(jupiter_crm) + # 4. Copy input files to run directory file(GLOB inputs *.inp *.yaml) foreach(input ${inputs}) diff --git a/examples/2019-Li-snap/bryan_pgen.cpp b/examples/2019-Li-snap/bryan.cpp similarity index 98% rename from examples/2019-Li-snap/bryan_pgen.cpp rename to examples/2019-Li-snap/bryan.cpp index c4fb54ab..5943220d 100644 --- a/examples/2019-Li-snap/bryan_pgen.cpp +++ b/examples/2019-Li-snap/bryan.cpp @@ -38,6 +38,9 @@ // snap #include +// special includes +#include "bryan_vapor_functions.hpp" + int iH2O, iH2Oc; Real p0, grav; diff --git a/examples/2019-Li-snap/bryan_mods.cpp b/examples/2019-Li-snap/bryan_vapor_functions.hpp similarity index 69% rename from examples/2019-Li-snap/bryan_mods.cpp rename to examples/2019-Li-snap/bryan_vapor_functions.hpp index 250eb3a8..cec6c70c 100644 --- a/examples/2019-Li-snap/bryan_mods.cpp +++ b/examples/2019-Li-snap/bryan_vapor_functions.hpp @@ -12,17 +12,19 @@ double sat_vapor_p_H2O(double T) { return SatVaporPresIdeal(T / tr, pr, betal, gammal); } -void Thermodynamics::enrollVaporFunctions() { enrollVaporFunctionH2O(); } - // water svp -void Thermodynamics::enrollVaporFunctionH2O() { +void enroll_vapor_Function_H2O(Thermodynamics::SVPFunc1Container &svp_func1) { Application::Logger app("snap"); app->Log("Enrolling H2O vapor pressures"); auto pindex = IndexMap::GetInstance(); int iH2O = pindex->GetVaporId("H2O"); - svp_func1_[iH2O][0] = [](AirParcel const &qfrac, int, int) { + svp_func1[iH2O][0] = [](AirParcel const &qfrac, int, int) { return sat_vapor_p_H2O(qfrac.w[IDN]); }; } + +void Thermodynamics::enrollVaporFunctions() { + enroll_vapor_Function_H2O(svp_func1_); +} diff --git a/examples/2019-Li-snap/jupiter2d.inp b/examples/2019-Li-snap/jupiter2d.inp new file mode 100644 index 00000000..409bf08f --- /dev/null +++ b/examples/2019-Li-snap/jupiter2d.inp @@ -0,0 +1,99 @@ + +problem = test jupiter + + +problem_id = jupiter2d # problem ID: basename of output filenames + + +file_type = rst +dt = 10.E5 + + +file_type = hst # History data dump +dt = 2.E4 # time increment between outputs + + +file_type = netcdf # Netcdf format output +variable = prim # variables to be output +dt = 1.E4 # time increment between outputs + + +file_type = netcdf # Netcdf format output +variable = uov # diagnostic variables +dt = 1.E4 # time increment + +