Ignore:
Timestamp:
Mar 9, 2026, 10:29:53 AM (5 days ago)
Author:
jbclement
Message:

PEM:

  • Introduction of a configurable display/logging system with options 'out2term', 'out2log', 'verbosity_lvl'. All messages now use verbosity levels ('LVL_NFO', 'LVL_WRN', 'LVL_ERR' and 'LVL_DBG').
  • Code encapsulation improvements with systematic privacy/protection of module variables.
  • Addition of workflow safety checks for required executables, dependencies (e.g. 'ncdump'), input files and callphys keys.
  • Renaming of PEM starting and diagnostic files ("startevol.nc" into "startevo.nc", "diagevol.nc" into "diagevo.nc").

JBC

Location:
trunk/LMDZ.COMMON/libf/evolution/deftank
Files:
9 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/LMDZ.COMMON/libf/evolution/deftank/README

    r4090 r4110  
    4747    > the starting files you want to run the PCM: "startfi.nc" and "start.nc"/"start1D.txt";
    4848    > the necessary PEM files: "pem_workflow.sh", "pem_workflow_lib.sh", "pcm_run.job", "pem_run.job", "run_pem.def" and "obl_ecc_lsp.asc";
    49     > the optional PEM files: "diagevol.def" to define the PEM variables to be ouputted and "startevol.nc" to set the initial state of the PEM.
     49    > the optional PEM files: "diagevo.def" to define the PEM variables to be ouputted and "startevo.nc" to set the initial state of the PEM.
    5050
    5151The PEM files can be found in the deftank folder.
     
    5555    > "pcm_run.job" (see below for details);
    5656    > "pem_run.job" (see below for details);
    57     > def files, especially for "run_pem.def", "run_pcm.def" and "callphys.def" which must be consistent. In particular, "run_pem.def" needs to include some definitions for the physics in file "run_pcm.def" with "INCLUDEDEF=run_pcm.def".
     57    > def files, especially for "run_pem.def", "run_pcm.def" and "callphys.def" which must be consistent. In particular, "run_pem.def" needs to include some definitions in file "run_pcm.def" and "callphys.def" with "INCLUDEDEF=run_pcm.def".
    5858In addition, the user has to provide a "startfi.nc" whose orbital parameters are consistent with the initial date set in "run_pem.def". The script "ini_pem_orbit.sh" can do it automatically reading "obl_ecc_lsp.asc".
    5959
     
    6464    > the XIOS outputs of the PCM: "Xoutdaily4pem*.nc"/"Xoutyearly4pem*.nc";
    6565    > the outputs of the chained simulation: "pem_workflow.log", "pem_workflow.sts" and possibly "kill_pem_workflow.sh";
    66     > the usual outputs of the PEM: "restartevol.nc", "restartfi.nc", "restart.nc"/"restart1D.txt" and "diagevol.nc".
     66    > the usual outputs of the PEM: "restartevo.nc", "restartfi.nc", "restart.nc"/"restart1D.txt" and "diagevo.nc".
    6767During the simulation, the PCM/PEM run files are renamed conveniently and stored in the sub-directories "logs" (log files), "starts" (starting files) and "diags" (diagnostic files).
    6868If you run a simulation by submitting jobs, the script "kill_pem_workflow.sh" is automatically generated. It can be used to kill the jobs related to your chained simulation in the queue of the job scheduler.
     
    102102# run_pem.def
    103103  All the possible parameters to define a PEM run (read in "config.F90").
    104   It needs to include some definitions for the physics in file "run_pcm.def" with "INCLUDEDEF=run_pcm.def".
     104  It needs to include some definitions in file "run_pcm.def" and "callphys.def" with "INCLUDEDEF=run_pcm.def".
    105105
    106106# obl_ecc_lsp.asc [default], obl_ecc_lsp_pos.asc [future years]
     
    126126
    127127# visu_layering.py:
    128   Python script file to output the stratification data from the "startevol.nc" files.
     128  Python script file to output the stratification data from the "startevo.nc" files.
    129129
    130 # visu_layering_evol.py:
    131   Python script file to output the stratification data over time from the "startevol.nc" files.
     130# visu_layering_evo.py:
     131  Python script file to output the stratification data over time from the "startevo.nc" files.
  • trunk/LMDZ.COMMON/libf/evolution/deftank/clean.sh

    r4091 r4110  
    3535    cp starts/start1D.txt .
    3636fi
    37 if [ -f "starts/startevol.nc" ]; then
    38     cp starts/startevol.nc .
     37if [ -f "starts/startevo.nc" ]; then
     38    cp starts/startevo.nc .
    3939fi
    4040# Cleaning of files in the sub-folders
  • trunk/LMDZ.COMMON/libf/evolution/deftank/concat_pem.py

    r4065 r4110  
    3535    parser.add_argument(
    3636        "--basename", type=str,
    37         help="Base name of the files, e.g., 'diagevol' for files like diagevol1.nc"
     37        help="Base name of the files, e.g., 'diagevo' for files like diagevo1.nc"
    3838    )
    3939    parser.add_argument(
     
    8888    # Defaults
    8989    default_folder = args.folder or "diags"
    90     default_basename = args.basename or "diagevol"
     90    default_basename = args.basename or "diagevo"
    9191
    9292    # Prompt for folder and basename with defaults
  • trunk/LMDZ.COMMON/libf/evolution/deftank/pcm_run.job

    r4091 r4110  
    3232
    3333ulimit -s unlimited
     34
     35# Checking the executable
     36if [ ! -f $pcm_exe ]; then
     37    echo "Error: required file \"$pcm_exe\" not found!"
     38    exit 1
     39fi
    3440
    3541# Running the PCM
  • trunk/LMDZ.COMMON/libf/evolution/deftank/pem_run.job

    r4091 r4110  
    3030ulimit -s unlimited
    3131
     32# Checking the executable
     33if [ ! -f $pem_exe ]; then
     34    echo "Error: required file \"$pem_exe\" not found!"
     35    exit 1
     36fi
     37
    3238# Running the PEM
    3339read n_yr_sim ntot_yr_sim r_plnt2earth_yr i_pcm_run i_pem_run n_pcm_runs n_pcm_runs_ini < pem_workflow.sts
     
    4248# Copy data files and prepare the next run
    4349mv run.log logs/run_pem${i_pem_run}.log
    44 if [ -f "diagevol.nc" ]; then
    45     mv diagevol.nc diags/diagevol${i_pem_run}.nc
     50if [ -f "diagevo.nc" ]; then
     51    mv diagevo.nc diags/diagevo${i_pem_run}.nc
    4652fi
    47 if [ -f "diagevol_soil.nc" ]; then
    48     mv diagevol_soil.nc diags/diagevol_soil${i_pem_run}.nc
     53if [ -f "diagevo_soil.nc" ]; then
     54    mv diagevo_soil.nc diags/diagevo_soil${i_pem_run}.nc
    4955fi
    50 cp restartevol.nc starts/restartevol${i_pem_run}.nc
    51 mv restartevol.nc startevol.nc
     56cp restartevo.nc starts/restartevo${i_pem_run}.nc
     57mv restartevo.nc startevo.nc
    5258cp restartfi.nc starts/restartfi_postpem${i_pem_run}.nc
    5359mv restartfi.nc startfi.nc
  • trunk/LMDZ.COMMON/libf/evolution/deftank/pem_workflow.sh

    r4074 r4110  
    3333user=`whoami`
    3434if [ ! -f "pem_workflow_lib.sh" ]; then
    35     echo "Error: file \"pem_workflow_lib.sh\" does not exist in $dir!"
     35    echo "Error: required file \"pem_workflow_lib.sh\" does not exist in $dir!"
    3636    echo "It can be found in the PEM deftank."
    3737    exit 1
  • trunk/LMDZ.COMMON/libf/evolution/deftank/pem_workflow_lib.sh

    • Property svn:executable deleted
    r4091 r4110  
    2121    echo "Error: an issue occured in the PEM workflow script!"
    2222    exit 1
     23}
     24
     25# To check if the command exists
     26# arg1: required command
     27require_cmd() {
     28    if ! command -v "$1" >/dev/null 2>&1; then
     29        echo "Error: required command '$1' not found."
     30        echo "Please install or load the corresonding library."
     31        abort_workflow
     32    fi
    2333}
    2434
     
    3747    else
    3848        echo "Error: neither SLURM nor TORQUE/PBS is installed on $machine!"
    39         echo "You need to adapt the script to your job job_scheduler or set 'mode' to 0."
     49        echo "Please adapt the script to your job scheduler or set 'mode' to 0."
    4050        abort_workflow
    4151    fi
     
    176186}
    177187
     188# To check the "callphys.def" compatibility to run with the PEM
     189# arg1: callphys key
     190check_callphys_key() {
     191    key="$1"
     192    line=$(grep -E "^[[:space:]]*${key}[[:space:]]*=" callphys.def \
     193           | grep -v '^[[:space:]]*#' \
     194           | tail -n 1)
     195    if [[ -z "$line" ]]; then
     196        echo "Error: the key '$key' is missing in \"callphys.def\"!"
     197        abort_workflow
     198    fi
     199    # Remove inline comments, extract value, normalize
     200    value=$(echo "$line" \
     201            | cut -d'#' -f1 \
     202            | cut -d'=' -f2 \
     203            | tr -d '[:space:]' \
     204            | tr '[:upper:]' '[:lower:]')
     205    if [[ "$value" == "true" || "$value" == ".true." ]]; then
     206        return 0
     207    else
     208        echo "Error: the key '$key' must be true in \"callphys.def\"!"
     209        abort_workflow
     210    fi
     211}
     212
    178213# To check if everything necessary for the workflow script is ok
    179214check_workflow() {
     
    220255        abort_workflow
    221256    fi
     257    if [ ! -f "callphys.def" ]; then
     258        echo "Error: file \"callphys.def\" does not exist in $dir!"
     259        abort_workflow
     260    fi
     261    if [ ! -f "z2sig.def" ]; then
     262        echo "Error: file \"z2sig.def\" does not exist in $dir!"
     263        abort_workflow
     264    fi
     265    if [ ! -f "traceur.def" ]; then
     266        echo "Error: file \"traceur.def\" does not exist in $dir!"
     267        abort_workflow
     268    fi
    222269    if [ ! -f "context_lmdz_physics.xml" ]; then
    223270        echo "Error: file \"context_lmdz_physics.xml\" does not exist in $dir!"
     
    236283        abort_workflow
    237284    fi
     285    if [ ! -f "obl_ecc_lsp.asc" ]; then
     286        echo "Warning: file \"obl_ecc_lsp.asc\" has not been found in $dir!"
     287    fi
    238288    if [ ! -d "logs" ]; then
    239289        mkdir logs
     
    248298        detect_scheduler
    249299    fi
     300    require_cmd ncdump
     301    # Check if the "callphys.def" is compatible with the PEM
     302    check_callphys_key paleoclimate
    250303    # Set automatically the XIOS output file for the PEM according to the number of slopes
    251304    get_nslope
     
    285338        cp start1D.txt starts/
    286339    fi
    287     if [ -f "startevol.nc" ]; then
    288         cp startevol.nc starts/
     340    if [ -f "startevo.nc" ]; then
     341        cp startevo.nc starts/
    289342    fi
    290343
     
    462515        n_yr_sim=0
    463516        sed -i "1s/.*/$n_yr_sim $ntot_yr_sim $r_plnt2earth_yr $i_pcm_run $i_pem_run $n_pcm_runs $n_pcm_runs_ini/" pem_workflow.sts
    464         cleanup diags/diagevol .nc $(($i_pem_run - 1))
    465         cleanup diags/diagevol_soil .nc $(($i_pem_run - 1))
     517        cleanup diags/diagevo .nc $(($i_pem_run - 1))
     518        cleanup diags/diagevo_soil .nc $(($i_pem_run - 1))
    466519        cleanup logs/run_pem .log $(($i_pem_run - 1))
    467520        cleanup starts/restart1D_postpem .txt $(($i_pem_run - 1))
    468521        cleanup starts/restart_postpem .nc $(($i_pem_run - 1))
    469522        cleanup starts/restartfi_postpem .nc $(($i_pem_run - 1))
    470         cleanup starts/restartevol .nc $(($i_pem_run - 1))
    471         rm -f startevol.nc
    472         if [ -f "starts/startevol.nc" ]; then
    473             cp starts/startevol.nc .
     523        cleanup starts/restartevo .nc $(($i_pem_run - 1))
     524        rm -f startevo.nc
     525        if [ -f "starts/startevo.nc" ]; then
     526            cp starts/startevo.nc .
    474527        fi
    475528        if [ $i_resume -eq $(($n_pcm_runs_ini - 1)) ]; then
     
    492545        n_yr_sim=$(awk "NR==$i_pem_run {printf \"%s\n\", \$3}" "pem_workflow.sts")
    493546        sed -i "1s/.*/$n_yr_sim $ntot_yr_sim $r_plnt2earth_yr $i_pcm_run $i_pem_run $n_pcm_runs $n_pcm_runs_ini/" pem_workflow.sts
    494         cleanup diags/diagevol .nc $(($i_pem_run - 1))
    495         cleanup diags/diagevol_soil .nc $(($i_pem_run - 1))
     547        cleanup diags/diagevo .nc $(($i_pem_run - 1))
     548        cleanup diags/diagevo_soil .nc $(($i_pem_run - 1))
    496549        cleanup logs/run_pem .log $(($i_pem_run - 1))
    497550        cleanup starts/restart1D_postpem .txt $(($i_pem_run - 1))
    498551        cleanup starts/restart_postpem .nc $(($i_pem_run - 1))
    499552        cleanup starts/restartfi_postpem .nc $(($i_pem_run - 1))
    500         cleanup starts/restartevol .nc $(($i_pem_run - 1))
    501         cp starts/restartevol$(($i_pem_run - 1)).nc startevol.nc
     553        cleanup starts/restartevo .nc $(($i_pem_run - 1))
     554        cp starts/restartevo$(($i_pem_run - 1)).nc startevo.nc
    502555        if [ $il -eq $(($n_pcm_runs - 1)) ]; then # Second to last PCM run
    503556            cp diags/Xoutdaily4pem${i_resume}.nc Xoutdaily4pem_Y1.nc
     
    531584    cleanup diags/Xoutdaily4pem .nc $(($i_pcm_run - 1))
    532585    cleanup diags/Xoutyearly4pem .nc $(($i_pcm_run - 1))
    533     cleanup diags/diagevol .nc $i_resume
    534     cleanup diags/diagevol_soil .nc $i_resume
     586    cleanup diags/diagevo .nc $i_resume
     587    cleanup diags/diagevo_soil .nc $i_resume
    535588    cleanup logs/run_pem .log $i_resume
    536589    cleanup starts/restart1D_postpem .txt $i_resume
    537590    cleanup starts/restart_postpem .nc $i_resume
    538591    cleanup starts/restartfi_postpem .nc $i_resume
    539     cleanup starts/restartevol .nc $i_resume
    540     cp starts/restartevol${i_resume}.nc startevol.nc
     592    cleanup starts/restartevo .nc $i_resume
     593    cp starts/restartevo${i_resume}.nc startevo.nc
    541594    cp starts/restartfi_postpem${i_resume}.nc startfi.nc
    542595    if [ -f "starts/restart_postpem${i_resume}.nc" ]; then
  • trunk/LMDZ.COMMON/libf/evolution/deftank/run_pem.def

    r4090 r4110  
    44
    55#---------- Output parameters ----------#
    6 # Output rate? Default = 1
    7 output_rate=1
     6# Do you want to output onto the terminal? Default = .true.
     7# out2term=.true.
     8
     9# Do you want to output into a log file? Default = .false.
     10# out2log=.false.
     11
     12# Which level of verbosity do you want to? Default = 2
     13# verbosity_lvl=2
     14
     15# Value of output rate for diagnostic files? Default = 1
     16# output_rate=1
    817
    918#---------- Orbital parameters ----------#
    1019# Do you want to follow an orbital forcing read in "obl_ecc_lsp.asc"? Default = .false.
    11 # evol_orbit=.false.
     20# evo_orbit=.false.
    1221
    13 # If evol_orbit=.true., number of Earth years before present to start the PEM run. Default = 0
     22# If evo_orbit=.true., number of Earth years before present to start the PEM run. Default = 0
    1423# pem_ini_earth_date=0
    1524
    1625# Do you want the obliquity to evolve when following "obl_ecc_lsp.asc"? Default = .true.
    17 # evol_obl=.true.
     26# evo_obl=.true.
    1827
    1928# Do you want the eccentricity to evolve when following "obl_ecc_lsp.asc"? Default = .true.
    20 # evol_ecc=.true.
     29# evo_ecc=.true.
    2130
    2231# Do you want the ls perihelie to evolve when following "obl_ecc_lsp.asc"? Default = .true.
    23 # evol_lsp=.true.
     32# evo_lsp=.true.
    2433
    2534# Time step length of the PEM in Martian years? Default = 1.
     
    2736
    2837#---------- Stopping criteria parameters ----------#
    29 # If evol_orbit=.false., maximal number of iterations if no stopping criterion is reached. Default=100000000.
     38# If evo_orbit=.false., maximal number of iterations if no stopping criterion is reached. Default=100000000.
    3039# nmax_yr_run=100000000
    3140
     
    7483
    7584#---------- Ice management parameters ----------#
    76 # Amount of H2O ice to initialize the huge reservoir if the variable is not present in "startevol.nc". Default = 9200. kg.m-2 (= 10 m)
     85# Amount of H2O ice to initialize the huge reservoir if the variable is not present in "startevo.nc". Default = 9200. kg.m-2 (= 10 m)
    7786# h2oice_huge_ini=9200.
    7887
     
    99108# dust2ice_ratio=0.1
    100109
    101 # Some definitions for the physics in file "run_pcm.def"
     110# Some definitions in file "run_pcm.def" and "callphys.def"
    102111INCLUDEDEF=run_pcm.def
  • trunk/LMDZ.COMMON/libf/evolution/deftank/visu_layering.py

    r4090 r4110  
    11#!/usr/bin/env python3
    22#######################################################################################
    3 ### Python script to output the stratification data from the "restartevol#.nc" files ###
     3### Python script to output the stratification data from the "restartevo#.nc" files ###
    44#######################################################################################
    55
  • trunk/LMDZ.COMMON/libf/evolution/deftank/visu_layering_evo.py

    r4109 r4110  
    11#!/usr/bin/env python3
    22#######################################################################################################
    3 ### Python script to output stratification data over time from "restartevol#.nc" files               ###
     3### Python script to output stratification data over time from "restartevo#.nc" files               ###
    44### and to plot orbital parameters from "obl_ecc_lsp.asc"                                           ###
    55#######################################################################################################
     
    2121    Prompt the user for:
    2222      - folder_path: directory containing NetCDF files (default: "starts")
    23       - base_name:   base filename (default: "restartevol")
     23      - base_name:   base filename (default: "restartevo")
    2424      - infofile:    name of the PEM info file (default: "pem_workflow.sts")
    2525    Validates existence of folder and infofile before returning.
     
    3737    base_name = input(
    3838        "Enter the base name of the NetCDF files "
    39         "(press Enter for default [restartevol]): "
    40     ).strip() or "restartevol"
     39        "(press Enter for default [restartevo]): "
     40    ).strip() or "restartevo"
    4141
    4242    infofile = input(
Note: See TracChangeset for help on using the changeset viewer.