source: trunk/LMDZ.COMMON/libf/evolution/deftank/launchPEM.sh @ 4068

Last change on this file since 4068 was 4065, checked in by jbclement, 2 weeks ago

PEM:
Major refactor following the previous ones (r3989 and r3991) completing the large structural reorganization and cleanup of the PEM codebase. This revision introduces newly designed modules, standardizes interfaces with explicit ini/end APIs and adds native NetCDF I/O together with explicit PCM/PEM adapters. In detail:

  • Some PEM models were corrected or improved:
    • Frost/perennial ice semantics are clarified via renaming;
    • Soil temperature remapping clarified, notably by removing the rescaling of temperature deviation;
    • Geothermal flux for the PCM is computed based on the PEM state;
  • New explicit PEM/PCM adapters ("set_*"/"build4PCM_*") to decouple PEM internal representation from PCM file layouts and reconstruct consistent fields returned to the PCM;
  • New explicit build/teardown routines that centralize allocation and initialization ordering, reducing accidental use of uninitialized data and making the model lifecycle explicit;
  • Add native read/write helpers for NetCDF that centralize all low-level NetCDF interactions with major improvements (and more simplicity) compared to legacy PEM/PCM I/O (see the modules "io_netcdf" and "output"). They support reading, creation and writing of "diagevol.nc" (renamed from "diagpem.nc") and start/restart files;
  • Provide well-focused modules ("numerics"/"maths"/"utility"/"display") to host commonly-used primitives:
    • "numerics" defines numerical types and constants for reproducibility, portability across compilers and future transitions (e.g. quadruple precision experiments);
    • "display" provides a single controlled interface for runtime messages, status output and diagnostics, avoiding direct 'print'/'write' to enable silent mode, log redirection, and MPI-safe output in the future.
    • "utility" (new module) hosts generic helpers used throughout the code (e.g. "int2str" or "real2str");
  • Add modules "clim_state_init"/"clim_state_rec" which provide robust read/write logic for "start/startfi/startpem", including 1D fallbacks, mesh conversions and dimension checks. NetCDF file creation is centralized and explicit. Restart files are now self-consistent and future-proof, requiring changes only to affected variables;
  • Add module "atmosphere" which computes pressure fields, reconstructs potential temperature and air mass. It also holds the whole logic to define sigma or hybrid coordinates for altitudes;
  • Add module "geometry" to centrilize dimensions logic and grid conversions routines (including 2 new ones "dyngrd2vect"/"vect2dyngrd");
  • Add module "slopes" to isolate slopes handling;
  • Add module "surface" to isolate surface management. Notably, albedo and emissivity are now fully reconstructed following the PCM settings;
  • Add module "allocation" to check the dimension initialization and centrilize allocation/deallocation;
  • Finalize module decomposition and renaming to consolidate domain-based modules, purpose-based routines and physics/process-based variables;
  • The main program now drives a clearer sequence of conceptual steps (initialization / reading / evolution / update / build / writing) and fails explicitly instead of silently defaulting;
  • Ice table logic is made restart-safe;
  • 'Open'/'read' intrinsic logic is made safe and automatic;
  • Improve discoverability and standardize the data handling (private vs protected vs public);
  • Apply consistent documentation/header style already introduced;
  • Update deftank scripts to reflect new names and launch wrappers;

This revision is a structural milestone aiming to be behavior-preserving where possible. It has been tested via compilation and short integration runs. However, due to extensive renames, moves, and API changes, full validation is still ongoing.
Note: the revision includes one (possibly two) easter egg hidden in the code for future archaeologists of the PEM. No physics were harmed.
JBC

  • Property svn:executable set to *
File size: 5.4 KB
Line 
1#!/bin/bash
2########################################################################
3#### Launching script for a chained simulation of PEM and PCM runs  ####
4########################################################################
5# This script can take an argument:
6#     1) None: to start a simulation from scratch;
7#     2) 're': to relaunch a simulation from a starting point (interactive prompt).
8########################################################################
9set -e
10trap 'echo -e "\033[31mError: an issue occurred in the script on line $LINENO! Please review the command and try again.\033[0m"' ERR
11
12
13########################################################################
14# Modify here the parameters for the simulation
15###############################################
16# Set the number of years to be simulated, either Planetary or Earth years (> 0):
17n_planetary_years=100.
18#n_earth_years=300.
19
20# Set the number of initial PCM years (>= 2):
21nPCM_ini=3
22
23# Set the number of PCM years between each PEM run (>= 2):
24nPCM=2
25
26# Set the launching mode (0 = "processing scripts"; any other values = "submitting jobs"). The former option is usually used to process the script on a local machine while the latter is used to submit jobs on a supercomputer with SLURM or PBS/TORQUE:
27mode=1
28########################################################################
29
30
31dir=`pwd`
32machine=`hostname`
33user=`whoami`
34if [ ! -f "lib_launchPEM.sh" ]; then
35    echo "Error: file \"lib_launchPEM.sh\" does not exist in $dir!"
36    echo "It can be found in the PEM deftank."
37    exit 1
38fi
39
40source lib_launchPEM.sh
41export mode
42
43if [ $# -eq 0 ]; then
44    # Starting from scratch
45    echo "The launching script is starting!"
46    echo "The output file is \"launchPEM.log\"."
47    exec > launchPEM.log 2>&1
48    echo "Beginning of the launching script for the PEM simulation."
49    date
50    checklaunch
51    initlaunch
52    cyclelaunch $mode $nPCM_ini
53
54else
55    # Starting a new cycle
56    if [ $1 = "new" ]; then
57        exec >> launchPEM.log 2>&1
58        echo
59        echo "This is a new cycle for the PEM simulation."
60        date
61        if [ $mode -ne 0 ]; then
62            job_scheduler
63            if command -v squeue &> /dev/null; then
64                unset SLURM_MEM_PER_CPU SLURM_MEM_PER_GPU SLURM_MEM_PER_NODE
65            fi
66        fi
67        read i_year n_year r_plnt2earth_yr iPCM iPEM nPCM nPCM_ini < launchPEM.info
68        cyclelaunch $mode $nPCM
69
70    # Starting a relaunch
71    elif [ $1 = "re" ]; then
72        if [ ! -f "launchPEM.info" ]; then
73            echo "Error: file \"launchPEM.info\" does not exist in $dir!"
74            echo "It is necessary to relaunch a PEM simulation."
75            errlaunch
76        fi
77        echo "The relaunch is initialized with a previous successful run to be specified."
78        while true; do
79            echo "Do you want to relaunch from a 'PCM' or 'PEM' run?"
80            read relaunch
81            if [ $relaunch = "PCM" ] || [ $relaunch = "PEM" ]; then
82                break
83            else
84                echo "Invalid input. Please enter 'PCM' or 'PEM'."
85            fi
86        done
87        read i_year n_year_old r_plnt2earth_yr iPCM iPEM nPCM_old nPCM_ini_old < launchPEM.info
88        while true; do
89            if [ $relaunch = "PCM" ]; then
90                echo "What is the number of the PCM run?"
91                echo "It should be between 1 and $(( $((iPCM - 1)) > 1 ? $((iPCM - 1)) : 1 ))."
92                read irelaunch
93                if [ 1 -le $irelaunch ] && [ $irelaunch -le $(( $((iPCM - 1)) > 1 ? $((iPCM - 1)) : 1 )) ]; then
94                    break
95                else
96                    echo "Invalid input. Please enter a valid PCM run number."
97                fi
98            else
99                echo "What is the number of the PEM run?"
100                echo "It should be between 1 and $(( $((iPEM - 1)) > 1 ? $((iPEM - 1)) : 1 ))."
101                read irelaunch
102                if [ 1 -le $irelaunch ] && [ $irelaunch -le $(( $((iPEM - 1)) > 1 ? $((iPEM - 1)) : 1 )) ]; then
103                    break
104                else
105                    echo "Invalid input. Please enter a valid PEM run number."
106                fi
107            fi
108        done
109        exec >> launchPEM.log 2>&1
110        echo
111        echo "This is a relaunch for the PEM simulation from the run \"$relaunch $irelaunch\"."
112        date
113        checklaunch
114        convertyears
115        if [ $nPCM_ini -ne $nPCM_ini_old ]; then
116            echo "The number of initial PCM years has been modified from $nPCM_ini_old to $nPCM_ini."
117        fi
118        if [ $nPCM -ne $nPCM_old ]; then
119            echo "The number of PCM years between each PEM run has been modified from $nPCM_old to $nPCM."
120        fi
121        if [ "$(echo "$n_year != $n_year_old" | bc)" -eq 1 ]; then
122            echo "The number of initial PCM years has been modified from $n_year_old to $n_year."
123        fi
124        sed -i "1s/.*/$i_year $n_year $r_plnt2earth_yr $iPCM $iPEM $nPCM $nPCM_ini/" launchPEM.info
125        if [ -f "kill_launchPEM.sh" ]; then
126            ./kill_launchPEM.sh
127        fi
128        if [ $relaunch = "PCM" ]; then
129            relaunchPCM $mode
130        else
131            relaunchPEM $mode
132        fi
133
134    # Continuing the PEM run
135    elif [ $1 = "cont" ]; then
136        exec >> launchPEM.log 2>&1
137        echo
138        echo "This is a continuation of the previous PEM run."
139        date
140        submitPEM $mode
141
142    # Default case: error
143    else
144        echo "Error: given argument '$1' for the launching script is unknown!"
145        errlaunch
146    fi
147fi
Note: See TracBrowser for help on using the repository browser.