source: trunk/LMDZ.COMMON/libf/evolution/deftank/launch_pem.sh @ 3170

Last change on this file since 3170 was 3145, checked in by jbclement, 2 years ago

PEM:

  • Addition of a script in LMDZ.MARS/deftank/pem/ to launch a chained simulation of 1D PCM runs which follow, year by year, the orbital parameters (obliquity, eccentricity, Ls perihelion) given in a specified file.
  • Small changes to other files of the deftank directory (check and cosmetic).

JBC

  • Property svn:executable set to *
File size: 6.8 KB
Line 
1#!/bin/bash
2#####################################################################
3### Launching script for a chained simulation of PEM and PCM runs ###
4#####################################################################
5
6echo "The launching script is starting!"
7echo "The output file is \"loglaunch.txt\"."
8if [ "$1" = "bg" ]; then
9    date
10else
11    nohup "$0" bg > loglaunch.txt 2>&1 &
12    exit 1
13fi
14
15# A few parameters that might need be changed depending on your setup:
16# Path to the arch.env to source:
17source ../trunk/LMDZ.COMMON/arch.env
18
19# Save the current value of LC_NUMERIC and set it to a locale that uses a dot as the decimal separator
20OLD_LC_NUMERIC=$LC_NUMERIC
21LC_NUMERIC=en_US.UTF-8
22
23#---------- Modify here the number of years to be simulated ------------
24## set the number of years, either Martian or Earth years:
25n_mars_years=1000000
26#n_earth_years=1000000
27
28#---------------- Modify here the number of PCM calls ------------------
29## set the number of PCM calls between each PEM call:
30nPCM=2
31
32#------------------ Modify here the name of PEM exe --------------------
33## fill in the name of executable for PEM:
34exePEM=pem_29_phymars_seq.e
35
36#-------------- Modify here the name of reshape XIOS exe ---------------
37## fill in the name of executable for reshape XIOS:
38exeReshape=reshape_XIOS_output_64x48x29_phymars_seq.e
39
40#------ Check if files/directories necessary for the script exist ------
41dir=`pwd`
42machine=`hostname`
43address=`whoami`
44if [ ! -f "$exePEM" ]; then
45    echo "Error: file \"$exePEM\" does not exist in $dir!"
46    exit 1
47fi
48if [ ! -f "$exeReshape" ]; then
49    echo "Error: file \"$exeReshape\" does not exist in $dir!"
50    exit 1
51fi
52if [ ! -f "exePCM.sh" ]; then
53    echo "Error: file \"exePCM.sh\" does not exist in $dir!"
54    exit 1
55fi
56if [ ! -f "run_PEM.def" ]; then
57    echo "Error: file \"run_PEM.def\" does not exist in $dir!"
58    exit 1
59fi
60if [ ! -f "run_PCM.def" ]; then
61    echo "Error: file \"run_PCM.def\" does not exist in $dir!"
62    exit 1
63fi
64if [ ! -f "context_lmdz_physics.xml" ]; then
65    echo "Error: file \"context_lmdz_physics.xml\" does not exist in $dir!"
66    exit 1
67fi
68if [ ! -f "field_def_physics_mars.xml" ]; then
69    echo "Error: file \"field_def_physics_mars.xml\" does not exist in $dir!"
70    exit 1
71fi
72if [ ! -f "file_def_physics_mars.xml" ]; then
73    echo "Error: file \"file_def_physics_mars.xml\" does not exist in $dir!"
74    exit 1
75fi
76if [ ! -f "iodef.xml" ]; then
77    echo "Error: file \"iodef.xml\" does not exist in $dir!"
78    exit 1
79fi
80if [ ! -d "out_PCM" ]; then
81    mkdir out_PCM
82fi
83if [ ! -d "out_PEM" ]; then
84    mkdir out_PEM
85fi
86if [ ! -d "starts" ]; then
87    mkdir starts
88fi
89if [ ! -d "diags" ]; then
90    mkdir diags
91fi
92
93#---------------------------- Initialization ---------------------------
94dir=`pwd`
95machine=`hostname`
96address=`whoami`
97echo "This is a chained simulation for PEM and PCM runs in $dir on $machine."
98myear=686.9725      # Number of Earth days in Martian year
99eyear=365.256363004 # Number of days in Earth year
100convert_years=$(echo "$myear/$eyear" | bc -l)
101convert_years=$(printf "%.4f" $convert_years) # Rounding to the 4th decimal to respect the precision of Martian year
102if [ -v n_mars_years ] && [ ! -z "$n_mars_years" ]; then
103    n_myear=$n_mars_years
104    echo "Number of years to be simulated: $n_myear Martian years."
105elif [ -v n_earth_years ] && [ ! -z "$n_earth_years" ]; then
106    n_myear=$(echo "($n_earth_years/$convert_years + 0.999999)/1" | bc) # Ceiling of n_earth_years/convert_years
107    echo "Number of years to be simulated: $n_earth_years Earth years = $n_myear Martian years."
108else
109    echo "No number of years to be simulated has been set!"
110    exit 1
111fi
112i_myear=0
113iPEM=1
114((iPCM = ($iPEM - 1)*$nPCM + 1))
115cp startfi.nc starts/
116if [ -f "start.nc" ]; then
117    cp start.nc starts/
118elif [ -f "star1D.nc" ]; then
119    cp star1D.txt starts/
120fi
121
122# Create a file to manage years of the chained simulation and store some info from the PEM runs
123if [ -f "info_PEM.txt" ]; then
124    rm info_PEM.txt
125fi
126echo $i_myear $n_myear $convert_years > info_PEM.txt
127
128#---------------------- Main loop to call PEM/PCM ----------------------
129while [ $i_myear -lt $n_myear ]; do
130    #--- Loop to run PCM year by year
131    cp run_PCM.def run.def
132    for ((i = 1; i <= $nPCM; i++)); do
133        echo "Run PCM $iPCM: call $i/$nPCM..."
134        sed -i "s/#SBATCH --job-name=runPCM.*/#SBATCH --job-name=runPCM${iPCM}/" exePCM.sh
135        sed -i "s/out_runPCM[0-9]\+/out_runPCM${iPCM}/" exePCM.sh
136        sbatch -W exePCM.sh
137        if [ ! -f "restartfi.nc" ]; then # Check if run ended abnormally
138            echo "Error: the run PCM $iPCM has crashed!"
139            exit 1
140        fi
141        # Copy data files and prepare the next run
142        mv out_runPCM${iPCM} out_PCM/run${iPCM}
143        mv diagfi.nc diags/diagfi${iPCM}.nc
144        if [ -f "diagsoil.nc" ]; then
145            mv diagsoil.nc diags/diagsoil${iPCM}.nc
146        fi
147        if [ -f "stats.nc" ]; then
148            mv stats.nc diags/stats${iPCM}.nc
149        fi
150        cp Xdiurnalave.nc diags/data2reshape${iPCM}.nc
151        mv Xdiurnalave.nc data2reshape${i}.nc
152        cp restartfi.nc starts/startfi${iPCM}.nc
153        mv restartfi.nc startfi.nc
154        if [ -f "restart.nc" ]; then
155            cp restart.nc starts/restart${iPCM}.nc
156            mv restart.nc start.nc
157        elif [ -f "restart1D.txt" ]; then
158            cp restart1D.txt starts/restart1D${iPCM}.txt
159            mv restart1D.txt start1D.txt
160        fi
161        ((iPCM++))
162        ((i_myear++))
163        echo "Done!"
164    done
165    sed -i "1s/.*/$i_myear $n_myear $convert_years/" info_PEM.txt
166
167    #--- Reshaping PCM data with XIOS
168    echo "Reshaping PCM data with XIOS..."
169    ./$exeReshape
170    echo "Done!"
171
172    #--- Running PEM
173    echo "Run PEM $iPEM..."
174    cp run_PEM.def run.def
175    mv startfi.nc startfi_evol.nc
176    if [ -f "start.nc" ]; then
177        mv start.nc start_evol.nc
178    elif [ -f "start1D.txt" ]; then
179        mv start1D.txt start1D_evol.txt
180    fi
181    ./$exePEM > out_runPEM${iPEM} 2>&1
182    if [ ! -f "restartfi_evol.nc" ]; then # Check if run ended abnormally
183        echo "Error: the run PEM $iPEM has crashed!"
184        exit 1
185    fi
186    # Copy data files and prepare the next run
187    mv out_runPEM${iPEM} out_PEM/run${iPEM}
188    mv diagpem.nc diags/diagpem${iPEM}.nc
189    cp restartpem.nc starts/startpem${iPEM}.nc
190    mv restartpem.nc startpem.nc
191    cp restartfi_evol.nc starts/startfi_postPEM${iPEM}.nc
192    mv restartfi_evol.nc startfi.nc
193    if [ -f "restart_evol.nc" ]; then
194        cp restart_evol.nc starts/restart_postPEM${iPEM}.nc
195        mv restart_evol.nc start.nc
196    elif [ -f "restart1D_evol.txt" ]; then
197        cp restart1D_evol.txt starts/restart1D_postPEM${iPEM}.txt
198        mv restart1D_evol.txt start1D.txt
199    fi
200    ((iPEM++))
201    read i_myear n_myear convert_years < info_PEM.txt
202    echo "Done!"
203done
204
205# Restore the previous value of LC_NUMERIC
206LC_NUMERIC=$OLD_LC_NUMERIC
207
208date
209echo "The launching script has terminated."
Note: See TracBrowser for help on using the repository browser.