From 6afa5c7e4257600c438ecb6ddbd72511bb46d522 Mon Sep 17 00:00:00 2001 From: s-poll Date: Thu, 26 Sep 2024 14:26:55 +0200 Subject: [PATCH] Frontend for TSMP2 (#24) * add model components as git submodules * add component feature to CmakeLists * add modelcounter in CMakeLists * implementation of first version of front end - add shell script build_tsmp2.sh - CMakeLists.txt adaptations - Revise README and add quickstart with front-end - update gitignore * Update ReadMe * tip-o fix, clean-up and change to stg2022 * bugfixes for setting `PDAF_SRC` * use `${PDAF}` instead of `PDAF_SRC` for checking PDAF * clean-up and ICON build -clean up confusing messages in CMakeLists.txt -add message to indicate cmake call -change ICON build according to model component not comp_srcs * update readme quickstart and cmake/BuildICON.cmake * update ReadMe and build_tsmp2.sh (review) -add version in build_tsmp2.sh -fix spelling quiet in build_tsmp2.sh -change bash shebang for more portability in build_tsmp2.sh -add pipefail in build_tsmp2.sh -rephrase tip in README -change header to Building TSMP2 with CMake in README * take the directory of build_tsmp2.sh for cmake_tsmp2_dir and remove option tsmp2_dir * rename eTSMP to TSMP2 in xxxx_MODEL_VERSIONS * add check_build_oasis function -use function for OASIS3 build check -shift MODELCOUNT to function -add TSMP2_ENV output in build_tsmp2.sh log * fix/unify if-clause in build_tsmp2.sh * Cloning of component submodules in build_tsmp2.sh * add branches to submodules * add --init to submodule overwrite and fix ParFlow component name * add CLM3.5 and COSMO5.01 as submodules * update eCLM submodule * remove source_dir option in build_tsmp2.sh, README typ-o - take cmake_tsmp2_dir as cmake source directory * change submodule remote url of COSMO * fix submodule overwrite prompting * update models/pdaf submodule * include --force option when overwriting submodule --------- Co-authored-by: Johannes Keller --- .gitignore | 7 - .gitmodules | 32 +++++ CMakeLists.txt | 108 ++++++++++++--- README.md | 146 +++++++++++++-------- build_tsmp2.sh | 260 +++++++++++++++++++++++++++++++++++++ cmake/BuildCLM3.5.cmake | 4 +- cmake/BuildCOSMO.cmake | 2 +- cmake/BuildICON.cmake | 4 +- cmake/BuildOASIS3MCT.cmake | 4 +- cmake/BuildPDAF.cmake | 2 +- cmake/BuildParFlow.cmake | 2 +- cmake/BuildeCLM.cmake | 12 +- cmake/Utils.cmake | 23 +++- models/.gitkeep | 0 models/CLM3.5 | 1 + models/cosmo5.01_fresh | 1 + models/eCLM | 1 + models/icon | 1 + models/oasis3-mct | 1 + models/parflow | 1 + models/parflow_pdaf | 1 + models/pdaf | 1 + 22 files changed, 517 insertions(+), 97 deletions(-) create mode 100644 .gitmodules create mode 100755 build_tsmp2.sh create mode 100644 models/.gitkeep create mode 160000 models/CLM3.5 create mode 160000 models/cosmo5.01_fresh create mode 160000 models/eCLM create mode 160000 models/icon create mode 160000 models/oasis3-mct create mode 160000 models/parflow create mode 160000 models/parflow_pdaf create mode 160000 models/pdaf diff --git a/.gitignore b/.gitignore index ac6f091..abf2c80 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,3 @@ bin/* bld/* run/ -eCLM/ -icon2.6.4_oascoup/ -oasis3-mct/ -parflow/ -CLM3.5/ -cosmo5.01_fresh/ -pdaf/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..d31661e --- /dev/null +++ b/.gitmodules @@ -0,0 +1,32 @@ +[submodule "models/icon"] + path = models/icon + url = https://gitlab.jsc.fz-juelich.de/sdlts/tsmp_components_mirrors/icon2.6.4_oascoup + branch = master +[submodule "models/parflow"] + path = models/parflow + url = https://github.com/parflow/parflow.git + branch = master +[submodule "models/parflow_pdaf"] + path = models/parflow_pdaf + url = https://github.com/HPSCTerrSys/parflow + branch = tsmp-pdaf +[submodule "models/pdaf"] + path = models/pdaf + url = https://github.com/HPSCTerrSys/pdaf.git + branch = tsmp-pdaf-patched +[submodule "models/eCLM"] + path = models/eCLM + url = https://github.com/HPSCTerrSys/eCLM.git + branch = master +[submodule "models/oasis3-mct"] + path = models/oasis3-mct + url = https://icg4geo.icg.kfa-juelich.de/ExternalReposPublic/oasis3-mct + branch = v5.0_patched +[submodule "models/CLM3.5"] + path = models/CLM3.5 + url = https://github.com/HPSCTerrSys/CLM3.5.git + branch = tsmp-patches-v0.1 +[submodule "models/cosmo5.01_fresh"] + path = models/cosmo5.01_fresh + url = https://gitlab.jsc.fz-juelich.de/sdlts/tsmp_components_mirrors/cosmo5.01_fresh.git + branch = tsmp-oasis diff --git a/CMakeLists.txt b/CMakeLists.txt index e193981..fc1b878 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,56 +1,128 @@ cmake_minimum_required (VERSION 3.21.1) -project(eTSMP LANGUAGES C CXX Fortran) +project(TSMP2 LANGUAGES C CXX Fortran) include(ExternalProject) list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") include(Utils) +# Prevent in-source builds +set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) + +# set default of components to off +option(ICON "Compile ICON within TSMP2 framework" OFF) +option(COSMO "Compile COSMO within TSMP2 framework" OFF) +option(eCLM "Compile eCLM within TSMP2 framework" OFF) +option(CLM3.5 "Compile CLM3.5 within TSMP2 framework" OFF) +option(ParFlow "Compile ParFlow within TSMP2 framework" OFF) +option(PDAF "Compile PDAF within TSMP2 framework" OFF) + + if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "RELEASE" CACHE STRING "Choose the type of build." FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "DEBUG" "RELEASE") endif() -find_package(MPIFortran REQUIRED) -if(DEFINED OASIS_SRC) - include(BuildOASIS3MCT) - list(APPEND MODEL_DEPENDENCIES OASIS3_MCT) -endif() +# init CMAKE internal variables +string(TOUPPER $ENV{SYSTEMNAME} SYSTEMNAME) +set(MODEL_ID "") # TODO (for all Build*.cmake scripts): # - Check validity of compile flags # - Implement set of compile flags depending on compiler (e.g. GNU, Intel) and # build configuration (e.g. Debug, Release, Profiling) -if(DEFINED eCLM_SRC) - include(BuildeCLM) - list(APPEND COMPONENT_MODELS "eCLM") -endif() +# model settings +set(MODEL_ID "") -if(DEFINED CLM35_SRC) - include(BuildCLM3.5) - list(APPEND COMPONENT_MODELS "CLM3.5") +find_package(MPIFortran REQUIRED) +check_build_oasis(BUILD_OASIS) # check if >=2 components (ICON, COSMO, eCLM, CLM3.5, ParFlow) are build +if (BUILD_OASIS) + if(NOT DEFINED OASIS_SRC) + set(OASIS_SRC "${CMAKE_SOURCE_DIR}/models/oasis3-mct") + endif() + include(BuildOASIS3MCT) + list(APPEND MODEL_DEPENDENCIES OASIS3_MCT) endif() -if(DEFINED ICON_SRC) +if (${ICON}) + if(NOT DEFINED ICON_SRC) + set(ICON_SRC "${CMAKE_SOURCE_DIR}/models/icon") + endif() include(BuildICON) list(APPEND COMPONENT_MODELS "ICON") + if ("${MODEL_ID}" STREQUAL "") + set(MODEL_ID "ICON") + else() + set(MODEL_ID "${MODEL_ID}-ICON") + endif() endif() -if(DEFINED COSMO_SRC) +if (${COSMO}) + if(DEFINED COSMO_SRC) + set(COSMO_SRC "${CMAKE_SOURCE_DIR}/models/cosmo5.01_fresh") + endif() include(BuildCOSMO) list(APPEND COMPONENT_MODELS "COSMO5.1") + set(MODEL_ID "${MODEL_ID}COSMO") endif() -if(DEFINED PARFLOW_SRC) +if (${eCLM}) + if(NOT DEFINED eCLM_SRC) + set(eCLM_SRC "${CMAKE_SOURCE_DIR}/models/eCLM") + endif() + include(BuildeCLM) + list(APPEND COMPONENT_MODELS "eCLM") + if ("${MODEL_ID}" STREQUAL "") + set(MODEL_ID "eCLM") + else() + set(MODEL_ID "${MODEL_ID}-eCLM") + endif() +endif() + +if (${CLM3.5}) + if(DEFINED CLM35_SRC) + set(CLM35_SRC "${CMAKE_SOURCE_DIR}/models/CLM3.5") + endif() + include(BuildCLM3.5) + list(APPEND COMPONENT_MODELS "CLM3.5") + set(MODEL_ID "${MODEL_ID}CLM3.5") +endif() + +if (${ParFlow}) + if(NOT DEFINED PARFLOW_SRC AND NOT ${PDAF}) + set(PARFLOW_SRC "${CMAKE_SOURCE_DIR}/models/parflow") + elseif (NOT DEFINED PARFLOW_SRC AND ${PDAF}) + set(PARFLOW_SRC "${CMAKE_SOURCE_DIR}/models/parflow_pdaf") + endif() include(BuildParFlow) list(APPEND COMPONENT_MODELS "ParFlow") + if ("${MODEL_ID}" STREQUAL "") + set(MODEL_ID "ParFlow") + else() + set(MODEL_ID "${MODEL_ID}-ParFlow") + endif() endif() -if(DEFINED PDAF_SRC) +if (${PDAF}) + if(NOT DEFINED PDAF_SRC) + set(PDAF_SRC "${CMAKE_SOURCE_DIR}/models/pdaf") + endif() include(BuildPDAF) include(BuildPDAFMODEL) include(BuildPDAFFRAMEWORK) list(APPEND COMPONENT_MODELS "PDAF") + if ("${MODEL_ID}" STREQUAL "") + set(MODEL_ID "PDAF") + else() + set(MODEL_ID "${MODEL_ID}-PDAF") + endif() endif() -print_model_versions("${COMPONENT_MODELS}" "${eTSMP_MODEL_VERSIONS}") +# set paths +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set (CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/bin/${SYSTEMNAME}_${MODEL_ID}" CACHE PATH "default install path" FORCE) +endif() + +print_model_versions("${COMPONENT_MODELS}" "${TSMP2_MODEL_VERSIONS}") + +#message(FATAL_ERROR "at the end of script") diff --git a/README.md b/README.md index 58d26ff..09fb098 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,49 @@ ## Quickstart +> [!TIP] +> `build_tsmp2.sh` is a lightweight shell-script calling the CMake-based build-system. During execution of `build_tsmp2.sh`, the executed CMake-command is printed out. For advanced build use-cases, users can modify the outputed CMake command or directly head over to [Building TSMP2 with CMake](#Building-TSMP2-with-CMake). + +1. Clone this repository. + +```bash +git clone https://github.com/HPSCTerrSys/TSMP2.git +cd $TSMP2_DIR +``` + +2. Build model components with TSMP2 framework + +To build a model component one need to activate the component model `--`. The options are not case-sensitive and do not need to be in an specific order. + +> [!NOTE] +> The component models (git submodules) are cloned during the execution of `build_tsmp2.sh`. If the component model (`models/`) are already exists, the user is asked if the folder should be overwritten or not. If you do want to use the default model component source codes, one can use the option `--`. + + +```bash +# to see options +./build_tsmp2.sh --help + +# ICON-eCLM-ParFlow +./build_tsmp2.sh --ICON --eCLM --PARFLOW + +# eCLM-ParFlow +./build_tsmp2.sh --eCLM --PARFLOW + +# ICON-eCLM +./build_tsmp2.sh --ICON --eCLM + +# eCLM-PDAF +./build_tsmp2.sh --eCLM --PDAF + +# ICON (with source code) +./build_tsmp2.sh --ICON --ICON_SRC ${ICON_SRC} +``` + + +## Building TSMP2 with CMake + +> [!NOTE] +> For experienced users. + 1. Clone this repository. ```bash @@ -37,36 +81,36 @@ mkdir -p ${BUILD_DIR} ${INSTALL_DIR} ## NOTE: Download only the component models that you need! ## # eCLM -git clone https://github.com/HPSCTerrSys/eCLM.git -eCLM_SRC=`realpath eCLM` +git clone https://github.com/HPSCTerrSys/eCLM.git models/eCLM +eCLM_SRC=`realpath models/eCLM` # ICON -git clone https://icg4geo.icg.kfa-juelich.de/spoll/icon2.6.4_oascoup.git -ICON_SRC=`realpath icon2.6.4_oascoup` +git clone https://icg4geo.icg.kfa-juelich.de/spoll/icon2.6.4_oascoup.git models/icon +ICON_SRC=`realpath models/icon` # ParFlow -git clone -b v3.12.0 https://github.com/parflow/parflow.git -PARFLOW_SRC=`realpath parflow` +git clone -b v3.12.0 https://github.com/parflow/parflow.git models/parflow +PARFLOW_SRC=`realpath models/parflow` # ParFlow (PDAF-patched) -git clone -b v3.12.0-tsmp https://github.com/HPSCTerrSys/parflow -PARFLOW_SRC=`realpath parflow` +git clone -b v3.12.0-tsmp https://github.com/HPSCTerrSys/parflow models/parflow_pdaf +PARFLOW_SRC=`realpath models/parflow_pdaf` # CLM3.5 -git clone -b tsmp-patches-v0.1 https://github.com/HPSCTerrSys/CLM3.5.git -CLM35_SRC=`realpath CLM3.5` +git clone -b tsmp-patches-v0.1 https://github.com/HPSCTerrSys/CLM3.5.git models/CLM3.5 +CLM35_SRC=`realpath models/CLM3.5` # COSMO5.01 -git clone -b tsmp-oasis https://icg4geo.icg.kfa-juelich.de/ModelSystems/tsmp_src/cosmo5.01_fresh.git -COSMO_SRC=`realpath cosmo5.01_fresh` +git clone -b tsmp-oasis https://icg4geo.icg.kfa-juelich.de/ModelSystems/tsmp_src/cosmo5.01_fresh.git models/cosmo5.01_fresh +COSMO_SRC=`realpath models/cosmo5.01_fresh` # OASIS3-MCT (required for coupled models) -git clone -b tsmp-patches-v0.1 https://icg4geo.icg.kfa-juelich.de/ExternalReposPublic/oasis3-mct -OASIS_SRC=`realpath oasis3-mct` +git clone -b tsmp-patches-v0.1 https://icg4geo.icg.kfa-juelich.de/ExternalReposPublic/oasis3-mct models/oasis3-mct +OASIS_SRC=`realpath models/oasis3-mct` # PDAF -git clone -b PDAF_V2.2.1-tsmp https://github.com/HPSCTerrSys/pdaf.git -PDAF_SRC=`realpath pdaf` +git clone -b PDAF_V2.2.1-tsmp https://github.com/HPSCTerrSys/pdaf.git models/pdaf +PDAF_SRC=`realpath models/pdaf` ``` 5. Run CMake configure step for the model combination that you wish to build. The @@ -74,104 +118,96 @@ PDAF_SRC=`realpath pdaf` ```bash # -# Coupled models requires the option -DOASIS_SRC=${OASIS_SRC}. +# The component source is searched in models/component by default but there is also the possibility to choose the path to the source code of components with -D_SRC=${_SRC}. OASIS is taken by default when coupled models are chosen. # # ICON-eCLM cmake -S . -B ${BUILD_DIR} \ -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \ - -DOASIS_SRC=${OASIS_SRC} \ - -DeCLM_SRC=${eCLM_SRC} \ - -DICON_SRC=${ICON_SRC} + -DeCLM=ON \ + -DICON=ON # eCLM-ParFlow cmake -S . -B ${BUILD_DIR} \ -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \ - -DOASIS_SRC=${OASIS_SRC} \ - -DeCLM_SRC=${eCLM_SRC} \ - -DPARFLOW_SRC=${PARFLOW_SRC} + -DeCLM=ON \ + -DPARFLOW_SRC=ON # ICON-eCLM-ParFlow cmake -S . -B ${BUILD_DIR} \ -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \ - -DOASIS_SRC=${OASIS_SRC} \ - -DeCLM_SRC=${eCLM_SRC} \ - -DICON_SRC=${ICON_SRC} \ - -DPARFLOW_SRC=${PARFLOW_SRC} + -DeCLM=ON \ + -DICON=ON \ + -DPARFLOW=ON # CLM3.5-COSMO5.01-ParFlow cmake -S . -B ${BUILD_DIR} \ -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \ - -DOASIS_SRC=${OASIS_SRC} \ - -DCLM35_SRC=${CLM35_SRC} \ - -DCOSMO_SRC=${COSMO_SRC} \ - -DPARFLOW_SRC=${PARFLOW_SRC} + -DCLM35=ON \ + -DCOSMO=ON \ + -DPARFLOW=ON # CLM3.5-ParFlow cmake -S . -B ${BUILD_DIR} \ -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \ - -DOASIS_SRC=${OASIS_SRC} \ - -DCLM35_SRC=${CLM35_SRC} \ - -DPARFLOW_SRC=${PARFLOW_SRC} + -DCLM35=ON \ + -DPARFLOW=ON # CLM3.5-COSMO5.01 cmake -S . -B ${BUILD_DIR} \ -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \ - -DOASIS_SRC=${OASIS_SRC} \ - -DCLM35_SRC=${CLM35_SRC} \ - -DCOSMO_SRC=${COSMO_SRC} + -DCLM35=ON \ + -DCOSMO=ON # -# For standalone models, remove -DOASIS_SRC=${OASIS_SRC} -# and pass the path to the component model (i.e. -D_SRC=${_SRC}). +# For standalone models +# pass the component model name (i.e. -D=ON). # # CLM3.5 standalone cmake -S . -B ${BUILD_DIR} \ -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \ - -DCLM35_SRC=${CLM35_SRC} + -DCLM35=ON # eCLM standalone cmake -S . -B ${BUILD_DIR} \ -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \ - -DeCLM_SRC=${eCLM_SRC} + -DeCLM=ON # ParFlow standalone cmake -S . -B ${BUILD_DIR} \ -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \ - -DPARFLOW_SRC=${PARFLOW_SRC} + -DPARFLOW=ON # -# For TSMP-PDAF builds, add -PDAF_SRC=${PDAF_SRC} +# For TSMP-PDAF builds, add -PDAF=ON # # CLM3.5-PDAF cmake -S . -B ${BUILD_DIR} \ -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \ - -DCLM35_SRC=${CLM35_SRC} \ - -DPDAF_SRC=${PDAF_SRC} + -DCLM35=ON \ + -DPDAF=ON # CLM3.5-ParFlow-PDAF cmake -S . -B ${BUILD_DIR} \ -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \ - -DOASIS_SRC=${OASIS_SRC} \ - -DCLM35_SRC=${CLM35_SRC} \ - -DPARFLOW_SRC=${PARFLOW_SRC} \ - -DPDAF_SRC=${PDAF_SRC} + -DCLM35=ON \ + -DPARFLOW=ON \ + -DPDAF=ON # eCLM-PDAF cmake -S . -B ${BUILD_DIR} \ -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \ - -DeCLM_SRC=${eCLM_SRC} \ - -DPDAF_SRC=${PDAF_SRC} + -DeCLM=ON \ + -DPDAF=ON # eCLM-ParFlow-PDAF cmake -S . -B ${BUILD_DIR} \ -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \ - -DOASIS_SRC=${OASIS_SRC} \ - -DeCLM_SRC=${eCLM_SRC} \ - -DPARFLOW_SRC=${PARFLOW_SRC} \ - -DPDAF_SRC=${PDAF_SRC} + -DeCLM=ON \ + -DPARFLOW=ON \ + -DPDAF=ON ``` diff --git a/build_tsmp2.sh b/build_tsmp2.sh new file mode 100755 index 0000000..7ee6eed --- /dev/null +++ b/build_tsmp2.sh @@ -0,0 +1,260 @@ +#!/usr/bin/env bash +### TSMP2 frontend +### Shell-based script to compile model components within the TSMP2 framework. +### +### For more information: +### ./build_tsmp2.sh --help + +# Force script to exit when error occurs +set -eo pipefail + +## functions + +function help_tsmp2() { + echo "Usage: $0 [-v ] [--component_name] [--optionals]" + echo " -q, --quiet Write less output during shell execution" + echo " --version Print $0 scipt version" + echo " --ICON Compile with ICON" + echo " --eCLM Compile with eCLM" + echo " --ParFlow Compile with ParFlow" + echo " --PDAF Compile with PDAF" + echo " --COSMO Compile with COSMO" + echo " --CLM35 Compile with CLM3.5" + echo " --ICON_SRC Set ICON_SRC directory" + echo " --eCLM_SRC Set eCLM_SRC directory" + echo " --ParFlow_SRC Set ParFlow_SRC directory" + echo " --OASIS_SRC Set OASIS3-MCT directory" + echo " --PDAF_SRC Set PDAF_SRC directory" + echo " --build_config Set build configuration: 'Debug' 'Release'" + echo " --compiler Set compiler for building" + echo " --build_dir Set build dir cmake, if not set bld/_ is used. Build artifacts will be generated in this folder." + echo " --install_dir Set install dir cmake, if not set bin/_ is used. Model executables and libraries will be installed here" + echo " --tsmp2_env Set model environment." + echo "" + echo "Example: $0 --ICON --eCLM --ParFlow" + exit 1 +} + +function set_component(){ +local -n component=$1 +cmake_name=$2 +if [ "${component}" = "y" ];then + if [ ! "${model_id}" ];then + model_id="${cmake_name}" + else + model_id+="-${cmake_name}" + fi # model_id + cmake_comp_str+=" -D${cmake_name}=ON" + if [[ $cmake_name = @(ICON|eCLM|ParFlow|COSMO|CLM3.5) ]]; then + model_count=$(( $model_count + 1 )) + fi # cmake_name +fi # component +} + +function set_compsrc(){ +local -n compsrc_name=$1 +cmake_srcname=$2 +if [ -n "${compsrc_name}" ];then + cmake_compsrc_str+=" -D${cmake_srcname}=${compsrc_name}" +fi # compsrc +} + +function dwn_compsrc(){ +comp_name=$1 +local -n comp_namey=$1 +local -n comp_srcname=$2 +sub_srcname=$3 +if [ -n "${comp_namey}" ] && [ -z "${comp_srcname}" ];then + if [ "${comp_name}" = "parflow" ] && [ -n "${pdaf}" ];then + submodule_name=$(echo "models/${sub_srcname}_pdaf") + else + submodule_name=$(echo "models/"${sub_srcname}) + fi + if [ "$( ls -A ${cmake_tsmp2_dir}/${submodule_name} | wc -l)" -ne 0 ];then + echo "submodule ${submodule_name} aleady exist. Do you want overwrite it? (y/n)" + read yn + if [ "${yn,}" = "y" ];then + message "Overwrite submodule ${submodule_name}" + git submodule update --init --force -- ${submodule_name} + else + message "Do not overwrite submodule ${submodule_name}" + fi + else + git submodule update --init -- ${submodule_name} + fi +fi # compsrc +} + +function message(){ +if [ -z "${quiet}" ];then + echo "$1" +fi # quiet +} + +### +## PROGRAM START +### + +## get params +while [[ "$#" -gt 0 ]]; do + case "${1,,}" in + -h|--help) help_tsmp2;; + -q|--quiet) quiet=y;; + --version) echo "$0 version 0.1.0"; exit 1;; + --icon) icon=y;; + --eclm) eclm=y;; + --parflow) parflow=y;; + --pdaf) pdaf=y;; + --cosmo) cosmo=y;; + --clm35) clm35=y;; + --icon_src) icon_src="$2"; shift ;; + --eclm_src) eclm_src="$2"; shift ;; + --parflow_src) parflow_src="$2"; shift ;; + --cosmo_src) cosmo_src="$2"; shift ;; + --clm35_src) clm35_src="$2"; shift ;; + --pdaf_src) pdaf_src="$2"; shift ;; + --oasis_src) oasis_src="$2"; shift ;; + --build_config) build_config="$2"; shift ;; + --compiler) compiler="$2"; shift ;; + --build_dir) build_dir="$2"; shift ;; + --install_dir) install_dir="$2"; shift ;; + --tsmp2_env) tsmp2_env="$2"; shift ;; + *) echo "Unknown parameter passed: $1"; exit 1 ;; + esac + shift +done + +# Get tsmp2_dir (full path) from location of $0 +cmake_tsmp2_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +## Create MODEL_ID + COMPONENT STRING +model_id="" +model_count=0 +cmake_comp_str="" + +message "set model-id and component string" +# fun set_component shell_name cmake_name +set_component icon "ICON" +set_component eclm "eCLM" +set_component parflow "ParFlow" +set_component pdaf "PDAF" +set_component cosmo "COSMO" +set_component clm35 "CLM3.5" + +if [ $model_count = 0 ];then + echo "No model component is chosen" + exit 1 +elif [ $model_count -ge 2 ];then + oasis=y +fi + +## CONCADINATE SOURCE CODE STRING +message "set component source dir" +cmake_compsrc_str="" +set_compsrc icon_src "ICON_SRC" +set_compsrc eclm_src "eCLM_SRC" +set_compsrc parflow_src "PARFLOW_SRC" +set_compsrc oasis_src "OASIS_SRC" +set_compsrc pdaf_src "PDAF_SRC" +set_compsrc cosmo_src "COSMO_SRC" +set_compsrc clm35_src "CLM35_SRC" + +## download model components +dwn_compsrc icon icon_src "icon" +dwn_compsrc eclm eclm_src "eCLM" +dwn_compsrc parflow parflow_src "parflow" +dwn_compsrc oasis oasis_src "oasis3-mct" +dwn_compsrc pdaf pdaf_src "pdaf" +dwn_compsrc cosmo cosmo_src "cosmo" +dwn_compsrc clm35 clm35_src "clm35" + +## CMAKE options + +message "set CMAKE options" +# build_config +if [ -z "$build_config" ];then + cmake_build_config="" +else + cmake_build_config=" -DCMAKE_BUILD_TYPE=${build_config}" +fi + +# set compiler +if [ -z "$compiler" ];then + cmake_compiler="" +else + cmake_comiler=" -DCMAKE_CXX_COMPILER_ID=${compiler}" +fi + +# set INSTALL and BUILD DIR (neccesary for building) +if [ -z "${SYSTEMNAME}" ]; then SYSTEMNAME="UNKN"; fi + +if [ -z "${build_dir}" ]; then + cmake_build_dir="${cmake_tsmp2_dir}/bld/${SYSTEMNAME^^}_${model_id}" +else + cmake_build_dir="${build_dir}" +fi # build_dir + +if [ -z "${install_dir}" ]; then + cmake_install_dir="-DCMAKE_INSTALL_PREFIX=${cmake_tsmp2_dir}/bin/${SYSTEMNAME^^}_${model_id}" +else + cmake_install_dir="-DCMAKE_INSTALL_PREFIX=${install_dir}" +fi # install_dir + +build_log="$(dirname ${cmake_build_dir})/${model_id}_$(date +%Y-%m-%d_%H-%M).log" + +## source environment +message "source environment" +if [ -z "${tsmp2_env}" ]; then + tsmp2_env="${cmake_tsmp2_dir}/env/jsc.2023_Intel.sh" +else + tsmp2_env="${tsmp2_env}" +fi # tsmp2_env +source $tsmp2_env + +## CMAKE config +# rm -rf ${cmake_build_dir} +mkdir -pv ${cmake_build_dir} $( echo "${cmake_install_dir}" |cut -d\= -f2) +message "====================" +message "== TSMP2 settings ==" +message "====================" +message "MODEL_ID: $model_id" +message "TSMP2_DIR: $cmake_tsmp2_dir" +message "TSMP2_ENV: $tsmp2_env" +message "BUILD_DIR: $cmake_build_dir" +message "INSTALL_DIR: $( echo "${cmake_install_dir}" |cut -d\= -f2)" +message "CMAKE command:" +message "cmake -S ${cmake_tsmp2_dir} -B ${cmake_build_dir} ${cmake_build_config} ${cmake_comp_str} ${cmake_compsrc_str} ${cmake_compiler} ${cmake_install_dir} |& tee ${build_log} " +message "== CMAKE GENERATE PROJECT start" + +cmake -S ${cmake_tsmp2_dir} -B ${cmake_build_dir} \ + ${cmake_build_config} \ + ${cmake_comp_str} \ + ${cmake_compsrc_str} \ + ${cmake_compiler} ${cmake_install_dir} \ + |& tee ${build_log} + +message "== CMAKE GENERATE PROJECT finished" + +## Build and install + +message "CMAKE build:" +message "cmake --build ${cmake_build_dir} |& tee -a $build_log" +message "== CMAKE BUILD start" +cmake --build ${cmake_build_dir} |& tee -a $build_log +message "== CMAKE BUILD finished" + +message "CMAKE install:" +message "cmake --install ${cmake_build_dir} |& tee -a $build_log" +message "== CMAKE INSTALL start" +cmake --install ${cmake_build_dir} |& tee -a $build_log +message "== CMAKE INSTALL finished" + +## Copy log and environment +message "Copy log and environment to install_dir" +cp ${tsmp2_env} $( echo "${cmake_install_dir}" |cut -d\= -f2) +cp ${build_log} $( echo "${cmake_install_dir}" |cut -d\= -f2) + +## message +message "Log can be found in: ${build_log}" +message "Model environment used: ${tsmp2_env}" +message "Model binaries can be found in: $( echo "${cmake_install_dir}" |cut -d\= -f2)" diff --git a/cmake/BuildCLM3.5.cmake b/cmake/BuildCLM3.5.cmake index f4f90ca..cbdf80e 100644 --- a/cmake/BuildCLM3.5.cmake +++ b/cmake/BuildCLM3.5.cmake @@ -5,7 +5,7 @@ list(APPEND CLM35_CONFIG_OPTS -cc ${CMAKE_C_COMPILER}) list(APPEND CLM35_CONFIG_OPTS -fc ${CMAKE_Fortran_COMPILER}) list(APPEND CLM35_CONFIG_OPTS -clm_bld ${CMAKE_BINARY_DIR}/CLM3_5/bld) list(APPEND CLM35_CONFIG_OPTS -clm_exedir ${CMAKE_INSTALL_PREFIX}/bin) -if(DEFINED PDAF_SRC) +if(${PDAF}) list(APPEND CLM35_CONFIG_OPTS -clm_libdir ${CMAKE_INSTALL_PREFIX}/lib) list(APPEND CLM35_CONFIG_OPTS -clm_incdir ${CMAKE_INSTALL_PREFIX}/include/clm3.5) set(CLM35_MAKE_TARGET "all") @@ -48,4 +48,4 @@ ExternalProject_Add(CLM3_5 ) get_model_version(${CLM35_SRC} CLM35_VERSION) -list(APPEND eTSMP_MODEL_VERSIONS "CLM3.5: ${CLM35_VERSION}") +list(APPEND TSMP2_MODEL_VERSIONS "CLM3.5: ${CLM35_VERSION}") diff --git a/cmake/BuildCOSMO.cmake b/cmake/BuildCOSMO.cmake index c58090e..fc923df 100644 --- a/cmake/BuildCOSMO.cmake +++ b/cmake/BuildCOSMO.cmake @@ -36,4 +36,4 @@ install (FILES ${COSMO_BLD_DIR}/lmparbin_pur GROUP_EXECUTE GROUP_READ) get_model_version(${COSMO_SRC} COSMO_VERSION) -list(APPEND eTSMP_MODEL_VERSIONS "COSMO5.1: ${COSMO_VERSION}") \ No newline at end of file +list(APPEND TSMP2_MODEL_VERSIONS "COSMO5.1: ${COSMO_VERSION}") \ No newline at end of file diff --git a/cmake/BuildICON.cmake b/cmake/BuildICON.cmake index 0796a72..aa85e85 100644 --- a/cmake/BuildICON.cmake +++ b/cmake/BuildICON.cmake @@ -39,7 +39,7 @@ list(APPEND ICON_LIBS "${NetCDF_LIBRARIES}") list(JOIN ICON_LIBS " " ICON_LIBS) list(APPEND EXTRA_CONFIG_ARGS --disable-coupling --disable-ocean --disable-jsbach --enable-ecrad --enable-parallel-netcdf) -if(DEFINED eCLM_SRC OR DEFINED CLM35_SRC) +if( ${eCLM} OR ${CLM3.5} ) list(APPEND EXTRA_CONFIG_ARGS --enable-oascoupling) endif() @@ -65,4 +65,4 @@ ExternalProject_Add(ICON ) get_model_version(${ICON_SRC} ICON_VERSION) -list(APPEND eTSMP_MODEL_VERSIONS "ICON: ${ICON_VERSION}") +list(APPEND TSMP2_MODEL_VERSIONS "ICON: ${ICON_VERSION}") diff --git a/cmake/BuildOASIS3MCT.cmake b/cmake/BuildOASIS3MCT.cmake index 878d35c..d3cc924 100644 --- a/cmake/BuildOASIS3MCT.cmake +++ b/cmake/BuildOASIS3MCT.cmake @@ -34,7 +34,7 @@ file(APPEND ${OASIS_MAKE_INC} "AR = ar\n") file(APPEND ${OASIS_MAKE_INC} "ARFLAGS = -ruv\n") file(APPEND ${OASIS_MAKE_INC} "DYNOPT = -fPIC\n") file(APPEND ${OASIS_MAKE_INC} "LDDYNOPT = -shared\n") -if(DEFINED PDAF_SRC) +if(${PDAF}) file(APPEND ${OASIS_MAKE_INC} "CPPDEF = -Duse_netCDF -Duse_comm_$(CHAN) -D__VERBOSE -DTREAT_OVERLAY -DUSE_PDAF\n") else() file(APPEND ${OASIS_MAKE_INC} "CPPDEF = -Duse_netCDF -Duse_comm_$(CHAN) -D__VERBOSE -DTREAT_OVERLAY\n") @@ -68,4 +68,4 @@ ExternalProject_Add(OASIS3_MCT set(OASIS_ROOT ${OASIS_INSTALL_PREFIX} CACHE PATH "Full path to the root directory containing OASIS3-MCT include files and libraries.") set(OASIS_LIBRARIES "-L${OASIS_ROOT}/lib -lpsmile.MPI1 -lmct -lmpeu -lscrip" CACHE STRING "OASIS3-MCT linker options") get_model_version(${OASIS_SRC} OASIS_VERSION) -list(APPEND eTSMP_MODEL_VERSIONS "OASIS3-MCT: ${OASIS_VERSION}") +list(APPEND TSMP2_MODEL_VERSIONS "OASIS3-MCT: ${OASIS_VERSION}") diff --git a/cmake/BuildPDAF.cmake b/cmake/BuildPDAF.cmake index 5b250ed..4e785ae 100644 --- a/cmake/BuildPDAF.cmake +++ b/cmake/BuildPDAF.cmake @@ -165,5 +165,5 @@ ExternalProject_Add(PDAF ) get_model_version(${PDAF_SRC} PDAF_VERSION) -list(APPEND eTSMP_MODEL_VERSIONS "PDAF: ${PDAF_VERSION}") +list(APPEND TSMP2_MODEL_VERSIONS "PDAF: ${PDAF_VERSION}") diff --git a/cmake/BuildParFlow.cmake b/cmake/BuildParFlow.cmake index d1b5e97..834b58a 100644 --- a/cmake/BuildParFlow.cmake +++ b/cmake/BuildParFlow.cmake @@ -42,4 +42,4 @@ ExternalProject_Add(ParFlow ) get_model_version(${PARFLOW_SRC} PARFLOW_VERSION) -list(APPEND eTSMP_MODEL_VERSIONS "ParFlow: ${PARFLOW_VERSION}") \ No newline at end of file +list(APPEND TSMP2_MODEL_VERSIONS "ParFlow: ${PARFLOW_VERSION}") \ No newline at end of file diff --git a/cmake/BuildeCLM.cmake b/cmake/BuildeCLM.cmake index c753a61..ca7bd83 100644 --- a/cmake/BuildeCLM.cmake +++ b/cmake/BuildeCLM.cmake @@ -1,16 +1,16 @@ -if(DEFINED ICON_SRC OR DEFINED PARFLOW_SRC) +if(${ICON} OR ${ParFlow}) list(APPEND COUP_OAS_FLAGS -DUSE_OASIS=True) - if(DEFINED PARFLOW_SRC) + if(${ParFlow}) list(APPEND COUP_OAS_FLAGS -DCOUP_OAS_PFL=True) endif() - if(DEFINED ICON_SRC) + if(${ICON}) list(APPEND COUP_OAS_FLAGS -DCOUP_OAS_ICON=True) endif() else() list(APPEND COUP_OAS_FLAGS -DUSE_OASIS=False) endif() -if(DEFINED PDAF_SRC) +if(${PDAF}) list(APPEND PDAF_FLAGS -DUSE_PDAF=True) endif() @@ -40,7 +40,7 @@ ExternalProject_Add_Step(eCLM install-scripts USES_TERMINAL TRUE ) -if(DEFINED PDAF_SRC) +if(${PDAF}) ExternalProject_Add_Step(eCLM pdaf-workaround COMMAND mv ${CMAKE_INSTALL_PREFIX}/lib/libmct.a ${CMAKE_INSTALL_PREFIX}/lib/libmct2.a COMMENT "Workaround for PDAF: Renaming libmct.a to libmct2.a ..." @@ -51,4 +51,4 @@ if(DEFINED PDAF_SRC) endif() get_model_version(${eCLM_SRC} eCLM_VERSION) -list(APPEND eTSMP_MODEL_VERSIONS "eCLM: ${eCLM_VERSION}") \ No newline at end of file +list(APPEND TSMP2_MODEL_VERSIONS "eCLM: ${eCLM_VERSION}") diff --git a/cmake/Utils.cmake b/cmake/Utils.cmake index 03740ef..8a3c610 100644 --- a/cmake/Utils.cmake +++ b/cmake/Utils.cmake @@ -1,8 +1,27 @@ find_package(Git) if(NOT Git_FOUND) - message(WARNING "eTSMP: git executable not found. Model versions would not be detected.") + message(WARNING "TSMP2: git executable not found. Model versions would not be detected.") endif() +# Count how many component models shoul be build, and if >=2 compile with OASIS +function(check_build_oasis BUILD_OASIS) + # Combine all options into a list + list(APPEND COMPONENT_MODELS ICON COSMO eCLM CLM3.5 ParFlow) + # Count enabled models + set(MODELCOUNT 0) + foreach(comp_model IN LISTS COMPONENT_MODELS) + if (${comp_model}) + MATH(EXPR MODELCOUNT "${MODELCOUNT}+1") + endif() + endforeach() + # + if (${MODELCOUNT} GREATER_EQUAL 2) + set(${BUILD_OASIS} TRUE PARENT_SCOPE) + else() + set(${BUILD_OASIS} FALSE PARENT_SCOPE) + endif() +endfunction() + function(get_model_version MODEL_DIR MODEL_VERSION) if(Git_FOUND) EXECUTE_PROCESS( @@ -33,4 +52,4 @@ function(print_model_versions COMPONENT_MODELS MODEL_VERSIONS) endforeach() endif() message(STATUS ${H_SEPARATOR}) -endfunction() \ No newline at end of file +endfunction() diff --git a/models/.gitkeep b/models/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/models/CLM3.5 b/models/CLM3.5 new file mode 160000 index 0000000..9f1cfcc --- /dev/null +++ b/models/CLM3.5 @@ -0,0 +1 @@ +Subproject commit 9f1cfccef269556c4ee992fffb8a9afe1e4e32d8 diff --git a/models/cosmo5.01_fresh b/models/cosmo5.01_fresh new file mode 160000 index 0000000..91e02eb --- /dev/null +++ b/models/cosmo5.01_fresh @@ -0,0 +1 @@ +Subproject commit 91e02eb88ffd8eb251fcdc25cb575d14869dcdfd diff --git a/models/eCLM b/models/eCLM new file mode 160000 index 0000000..4582f14 --- /dev/null +++ b/models/eCLM @@ -0,0 +1 @@ +Subproject commit 4582f148490edf621cbc1a6f11692017bc344469 diff --git a/models/icon b/models/icon new file mode 160000 index 0000000..21be042 --- /dev/null +++ b/models/icon @@ -0,0 +1 @@ +Subproject commit 21be04212a5481980db6d8ba9b15d5dad94f8802 diff --git a/models/oasis3-mct b/models/oasis3-mct new file mode 160000 index 0000000..5253349 --- /dev/null +++ b/models/oasis3-mct @@ -0,0 +1 @@ +Subproject commit 5253349d4ce15259fcd76e0443495c1ddb7788bb diff --git a/models/parflow b/models/parflow new file mode 160000 index 0000000..6ea2098 --- /dev/null +++ b/models/parflow @@ -0,0 +1 @@ +Subproject commit 6ea209875f6478450ec0dbbff313ca7a97291b92 diff --git a/models/parflow_pdaf b/models/parflow_pdaf new file mode 160000 index 0000000..d67aa13 --- /dev/null +++ b/models/parflow_pdaf @@ -0,0 +1 @@ +Subproject commit d67aa13c831087d6f74ea07a1c5b6504d59b3d82 diff --git a/models/pdaf b/models/pdaf new file mode 160000 index 0000000..a2c3a4b --- /dev/null +++ b/models/pdaf @@ -0,0 +1 @@ +Subproject commit a2c3a4b69003dbfebe13bf8909f81288bbf19a20