source: trunk/LMDZ.COMMON/libf/evolution/deftank/launch_orb_1Dchained.sh @ 3161

Last change on this file since 3161 was 3149, checked in by jbclement, 2 years ago

PEM:

  • Simplification of the algorithm managing the stopping criteria;
  • Complete rework of the ice management in the PEM (H2O & CO2);

    Subroutines to evolve the H2O and CO2 ice are now in the same module "evol_ice_mod.F90".
    Tendencies are computed from the variation of "ice + frost" between the 2 PCM runs.
    Evolving ice in the PEM is now called 'h2o_ice' or 'co2_ice' (not anymore in 'qsurf' and free of 'water_reservoir').
    Default value 'ini_h2o_bigreservoir' (= 10 m) initializes the H2O ice of the first PEM run where there is 'watercap'. For the next PEM runs, initialization is done with the value kept in "startpem.nc". CO2 ice is taken from 'perennial_co2ice' of the PCM (paleoclimate flag must be true).
    Simplification of the condition to compute the surface ice cover needed for the stopping criteria.
    Frost ('qsurf') is not evolved by the PEM and given back to the PCM.
    New default threshold value 'inf_h2oice_threshold' (= 2 m) to decide at the end of the PEM run if the H2O ice should be 'watercap' or not for the next PCM runs. If H2O ice cannot be 'watercap', then the remaining H2O ice is transferred to the frost ('qsurf').

  • Renaming of variables/subroutines for clarity;
  • Some cleanings throughout the code;
  • Small updates in files of the deftank.

JBC

  • Property svn:executable set to *
File size: 6.5 KB
Line 
1#!/bin/bash
2################################################################
3### Launching script for a chained simulation of 1D 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 for initialization ----------
24## set the number of Earth years before present to start:
25eyears_bp_ini=-1000
26
27#---------- Modify here the number of years to be simulated ------------
28## set the number of Martian years:
29n_myears=500
30
31#------------------ Modify here the name of PCM exe --------------------
32## fill in the name of executable for PCM:
33exePCM=testphys1d_29_phymars_para.e
34
35#----------- Modify here the name of the orbital data file -------------
36## fill in the name of executable for PCM:
37orb_data=obl_ecc_lsp.asc
38
39#------ Check if files/directories necessary for the script exist ------
40dir=`pwd`
41machine=`hostname`
42address=`whoami`
43if [ ! -f "$exePCM" ]; then
44    echo "Error: file \"$exePCM\" does not exist in $dir!"
45    exit 1
46fi
47if [ ! -f "$orb_data" ]; then
48    echo "Error: file \"$orb_data\" does not exist in $dir!"
49    exit 1
50fi
51if [ ! -f "startfi.nc" ]; then
52    echo "Error: file \"startfi.nc\" does not exist in $dir!"
53    exit 1
54fi
55if [ ! -d "out_PCM" ]; then
56    mkdir out_PCM
57fi
58if [ ! -d "starts" ]; then
59    mkdir starts
60fi
61if [ ! -d "diags" ]; then
62    mkdir diags
63fi
64
65#---------------------------- Initialization ---------------------------
66dir=`pwd`
67machine=`hostname`
68address=`whoami`
69echo "This is a chained simulation for PCM runs in $dir on $machine."
70echo "Number of years to be simulated: $n_myears Martian years."
71myear=686.9725      # Number of Earth days in Martian year
72eyear=365.256363004 # Number of days in Earth year
73convert_years=$(echo "$myear/$eyear" | bc -l)
74convert_years=$(printf "%.4f" $convert_years) # Rounding to the 4th decimal to respect the precision of Martian year
75i_myear=0
76iPCM=1
77cp startfi.nc starts/
78if [ -f "star1D.nc" ]; then
79    cp star1D.txt starts/
80fi
81
82#---------------- Main loop to to run PCM year by year -----------------
83while [ $i_myear -lt $n_myears ]; do
84    # Get the new values for the orbital parameters
85    yearlask=$(echo "$eyears_bp_ini + $i_myear*$convert_years" | bc -l)
86    found=false
87    while read -r y1 obl1 ecc1 lsp1 && read -r y2 obl2 ecc2 lsp2; do
88        y1=$(echo "$y1*1000" | bc -l)
89        y2=$(echo "$y2*1000" | bc -l)
90        if [ "$(echo "$y1 >= $yearlask && $yearlask > $y2" | bc)" -eq 1 ]; then
91            found=true
92            # Calculate linear interpolations for each orbital parameter
93            new_obl=$(echo "($obl2 - $obl1)/($y2 - $y1)*($yearlask - $y1) + $obl1" | bc -l)
94            new_ecc=$(echo "($ecc2 - $ecc1)/($y2 - $y1)*($yearlask - $y1) + $ecc1" | bc -l)
95            if [ "$(echo "$lsp2 - $lsp1 > 300. || $lsp2 - $lsp1 < -300." | bc)" -eq 1 ]; then # If modulo is "crossed" through the interval
96                if [ "$(echo "$lsp1 < $lsp2" | bc -l)" -eq 1 ]; then # Lsp should be decreasing
97                    lsp1=$(echo "$lsp1 + 360" | bc -l)
98                else # Lsp should be increasing
99                    lsp2=$(echo "$lsp2 + 360" | bc -l)
100                fi
101            fi
102            new_Lsp=$(echo "($lsp2 - $lsp1)/($y2 - $y1)*($yearlask - $y1) + $lsp1" | bc -l)
103            echo "New obliquity    = $new_obl"
104            echo "New eccentricity = $new_ecc"
105            echo "New Lsp          = $new_Lsp"
106            echo "Done!"
107            break
108        fi
109    done < "$orb_data"
110    if [ "$found" = false ]; then
111        echo "Error: the current year could not be found in the file \"$orb_data\"!"
112        exit 1
113    fi
114    # Compute the modified values in the "starfi.nc"
115    year_day=669.
116    halfaxe=227.94
117    pi=$(echo "4.*a(1.)" | bc -l)
118    degrad=$(echo "180./$pi" | bc -l)
119    periheli=$(echo "$halfaxe*(1. - $new_ecc)" | bc -l)
120    aphelie=$(echo "$halfaxe*(1. + $new_ecc)" | bc -l)
121    tan=$(echo "s(0.5*$new_Lsp/$degrad)/c(0.5*$new_Lsp/$degrad)" | bc -l)
122    zx0=$(echo "-2.*a($tan*sqrt((1. - $new_ecc)/(1. + $new_ecc)))" | bc -l)
123    if [ $(echo "$zx0 <= 0." | bc -l) -eq 1 ]; then
124        zx0=$(echo "$zx0 + 2.*$pi" | bc -l)
125    fi
126    peri_day=$(echo "$year_day*(1. - ($zx0 - $new_ecc*s($zx0))/(2.*$pi))" | bc -l)
127    ztheta=$(echo "($new_iniLs - $new_Lsp)/$degrad" | bc -l)
128    tan=$(echo "s(0.5*$ztheta)/c(0.5*$ztheta)" | bc -l)
129    zx0=$(echo "2.*a($tan*sqrt((1. - $new_ecc)/(1. + $new_ecc)))" | bc -l)
130    xref=$(echo "$zx0 - $new_ecc*s($zx0)" | bc -l)
131    # Modify the orbital parameters
132      # controle(15) = periheli ! min. Sun-Mars distance (Mkm)  ̃206.66
133      # controle(16) = aphelie  ! max. SUn-Mars distance (Mkm)  ̃249.22
134      # controle(17) = peri_day ! date of perihelion (sols since N. spring)
135      # controle(18) = obliquit ! Obliquity of the planet (deg)  ̃23.98
136    ncap2 -O -s "controle(17)=$new_obl" \
137             -s "controle(14)=$periheli" \
138             -s "controle(15)=$aphelie" \
139             -s "controle(16)=$peri_day" \
140             "startfi.nc" "startfi.nc"
141    echo "New periheli = $periheli"
142    echo "New aphelie  = $aphelie"
143    echo "New peri_day = $peri_day"
144    echo "Done!"
145    # Run the PCM
146    echo "Run PCM $iPCM: year $iPCM/$n_myears..."
147    ./$exePCM > out_runPCM${iPCM} 2>&1
148    if [ ! -f "restartfi.nc" ]; then # Check if run ended abnormally
149        echo "Error: the run PCM $iPCM has crashed!"
150        exit 1
151    fi
152    # Copy data files and prepare the next run
153    mv out_runPCM${iPCM} out_PCM/run${iPCM}
154    mv diagfi.nc diags/diagfi${iPCM}.nc
155    if [ -f "diagsoil.nc" ]; then
156        mv diagsoil.nc diags/diagsoil${iPCM}.nc
157    fi
158    if [ -f "stats.nc" ]; then
159        mv stats.nc diags/stats${iPCM}.nc
160    fi
161    if [ -f "Xdiurnalave.nc" ]; then
162        mv Xdiurnalave.nc diags/Xdiurnalave${iPCM}.nc
163    fi
164    cp restartfi.nc starts/startfi${iPCM}.nc
165    mv restartfi.nc startfi.nc
166    if [ -f "restart1D.txt" ]; then
167        cp restart1D.txt starts/restart1D${iPCM}.txt
168        mv restart1D.txt start1D.txt
169    fi
170    ((iPCM++))
171    ((i_myear++))
172    echo "Done!"
173done
174
175# Restore the previous value of LC_NUMERIC
176LC_NUMERIC=$OLD_LC_NUMERIC
177
178date
179echo "The launching script has terminated."
Note: See TracBrowser for help on using the repository browser.