tspinup.sh - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
 (HTM) git clone git://src.adamsgaard.dk/pism
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
       tspinup.sh (10466B)
       ---
            1 #!/bin/bash
            2 
            3 # Copyright (C) 2009-2015, 2017, 2018, 2019, 2020 The PISM Authors
            4 
            5 # PISM Greenland spinup using either constant present-day climate or modeled
            6 # paleoclimate.  See README.md.
            7 
            8 # Before using this script, run preprocess.sh to download and adjust metadata
            9 # in the SeaRISE "Present Day Greenland" master dataset.
           10 
           11 set -e  # exit on error
           12 
           13 GRIDLIST="{40, 20, 10, 5, 3, 2}"
           14 CLIMLIST="{const, paleo}"
           15 DYNALIST="{sia, hybrid}"
           16 
           17 # preprocess.sh generates pism_*.nc files; run it first
           18 PISM_DATAVERSION=1.1
           19 PISM_DATANAME=pism_Greenland_5km_v$PISM_DATAVERSION.nc
           20 PISM_TEMPSERIES=pism_dT.nc
           21 PISM_SLSERIES=pism_dSL.nc
           22 
           23 if [ $# -lt 5 ] ; then
           24   cat - <<EOF
           25 spinup.sh ERROR: needs 5 or 6 or 7 positional arguments ... ENDING NOW
           26 
           27 usage:
           28 
           29     spinup.sh PROCS CLIMATE DURATION GRID DYNAMICS [OUTFILE] [BOOTFILE]
           30 
           31   where:
           32     PROCS     = 1,2,3,... is number of MPI processes
           33     CLIMATE   in $CLIMLIST
           34     DURATION  = model run time in years; does '-ys -DURATION -ye 0'
           35     GRID      in $GRIDLIST (km)
           36     DYNAMICS  in $DYNALIST; sia is non-sliding; default = sia
           37     OUTFILE   optional name of output file; default = unnamed.nc
           38     BOOTFILE  optional name of input file; default = $PISM_DATANAME
           39 
           40 consider setting optional environment variables (see script for meaning):
           41     EXSTEP       spacing in years between -extra_files outputs; defaults to 100
           42     EXVARS       desired -extra_vars; defaults to 'diffusivity,temppabase,
           43                    tempicethk_basal,bmelt,tillwat,velsurf_mag,mask,thk,topg,usurf'
           44                    plus ',hardav,velbase_mag,tauc' if DYNAMICS=hybrid
           45     NODIAGS      if set, DON'T use -ts_file or -extra_file
           46     USEPIK       if set, add -pik -subgl
           47     PARAM_PPQ    sets (hybrid-only) option -pseudo_plastic_q \$PARAM_PPQ
           48                    [default=0.25]
           49     PARAM_SIAE   sets option -sia_e \$PARAM_SIAE   [default=3.0]
           50     PARAM_TEFO   sets (hybrid-only) option -till_effective_fraction_overburden
           51                    \$PARAM_TEFO   [default=0.02]
           52     PARAM_TTPHI  sets (hybrid-only) option -topg_to_phi \$PARAM_TTPHI
           53                    [default=15.0,40.0,-300.0,700.0]
           54     PARAM_NOSGL  if set, DON'T use -tauc_slippery_grounding_lines
           55     PISM_DO      set to 'echo' if no run desired; defaults to empty
           56     PISM_MPIDO   defaults to 'mpiexec -n'
           57     PISM_BIN  set to path to pismr executable if desired; defaults to empty
           58     PISM_EXEC    defaults to 'pismr'
           59     REGRIDFILE   set to file name to regrid from; defaults to empty (no regrid)
           60     REGRIDVARS   desired -regrid_vars; applies *if* REGRIDFILE set;
           61                    defaults to 'basal_melt_rate_grounded,enthalpy,litho_temp,thk,tillwat'
           62 
           63 example usage 1:
           64 
           65     $ ./spinup.sh 4 const 1000 20 sia
           66 
           67   Does spinup with 4 processors, constant-climate, 1000 year run, 20 km
           68   grid, and non-sliding SIA stress balance.  Bootstraps from and outputs to
           69   default files.
           70 
           71 example usage 2:
           72 
           73     $ PISM_DO=echo ./spinup.sh 128 paleo 100.0 5 hybrid out.nc boot.nc &> foo.sh
           74 
           75   Creates a script foo.sh for spinup with 128 processors, simulated paleo-climate,
           76   5 km grid, sliding with SIA+SSA hybrid, output to {out.nc,ts_out.nc,ex_out.nc},
           77   and bootstrapping from boot.nc.
           78 EOF
           79   exit
           80 fi
           81 
           82 if [ -n "${SCRIPTNAME:+1}" ] ; then
           83   echo "[SCRIPTNAME=$SCRIPTNAME (already set)]"
           84   echo ""
           85 else
           86   SCRIPTNAME="#(spinup.sh)"
           87 fi
           88 
           89 if [ $# -gt 7 ] ; then
           90   echo "$SCRIPTNAME WARNING: ignoring arguments after argument 7 ..."
           91 fi
           92 
           93 NN="$1" # first arg is number of processes
           94 DURATION=$3
           95 RUNSTARTEND="-ys -$DURATION -ye 0"
           96 
           97 # set coupler from argument 2
           98 if [ "$2" = "const" ]; then
           99   climname="constant-climate"
          100   INLIST=""
          101   COUPLER="-surface given -surface_given_file $PISM_DATANAME"
          102 elif [ "$2" = "paleo" ]; then
          103   climname="paleo-climate"
          104   INLIST="$PISM_TEMPSERIES $PISM_SLSERIES"
          105   COUPLER=" -bed_def lc -atmosphere searise_greenland,delta_T,precip_scaling -surface pdd -atmosphere_precip_scaling_file $PISM_TEMPSERIES -atmosphere_delta_T_file $PISM_TEMPSERIES -sea_level constant,delta_sl -ocean_delta_sl_file $PISM_SLSERIES"
          106 else
          107   echo "invalid second argument; must be in $CLIMLIST"
          108   exit
          109 fi
          110 
          111 # decide on grid and skip from argument 4
          112 COARSESKIP=10
          113 FINESKIP=20
          114 FINESTSKIP=50
          115 VDIMS="-Lz 4000 -Lbz 2000 -skip -skip_max "
          116 COARSEVGRID="-Mz 101 -Mbz 11 -z_spacing equal ${VDIMS} ${COARSESKIP}"
          117 FINEVGRID="-Mz 201 -Mbz 21 -z_spacing equal ${VDIMS} ${FINESKIP}"
          118 FINESTVGRID="-Mz 401 -Mbz 41 -z_spacing equal ${VDIMS} ${FINESTSKIP}"
          119 if [ "$4" -eq "40" ]; then
          120   dx=40
          121   myMx=38
          122   myMy=71
          123   vgrid=$COARSEVGRID
          124 elif [ "$4" -eq "20" ]; then
          125   dx=20
          126   myMx=76
          127   myMy=141
          128   vgrid=$COARSEVGRID
          129 elif [ "$4" -eq "10" ]; then
          130   dx=10
          131   myMx=151
          132   myMy=281
          133   vgrid=$FINEVGRID
          134 elif [ "$4" -eq "5" ]; then
          135   # "native" resolution in data file, with 561 x 301 grid
          136   dx=5
          137   myMx=301
          138   myMy=561
          139   vgrid=$FINEVGRID
          140 elif [ "$4" -eq "3" ]; then
          141   dx=3
          142   myMx=501
          143   myMy=934
          144   vgrid=$FINEVGRID
          145 elif [ "$4" -eq "2" ]; then
          146   dx=2
          147   myMx=750
          148   myMy=1400
          149   vgrid=$FINESTVGRID
          150 else
          151   echo "invalid fourth argument: must be in $GRIDLIST"
          152   exit
          153 fi
          154 
          155 grid="-Mx $myMx -My $myMy $vgrid -grid.recompute_longitude_and_latitude false -grid.registration corner"
          156 
          157 # set stress balance from argument 5
          158 if [ -n "${PARAM_SIAE:+1}" ] ; then  # check if env var is already set
          159   PHYS="-front_retreat_file ${PISM_DATANAME} -sia_e ${PARAM_SIAE}"
          160 else
          161   PHYS="-front_retreat_file ${PISM_DATANAME} -sia_e 3.0"
          162 fi
          163 if [ -n "${USEPIK:+1}" ] ; then  # check if env var is already set
          164   PHYS="${PHYS} -pik -subgl"
          165 fi
          166 
          167 # done forming $PHYS if "$5" = "sia"
          168 if [ "$5" = "hybrid" ]; then
          169   if [ -z "${PARAM_TTPHI}" ] ; then  # check if env var is NOT set
          170     PARAM_TTPHI="15.0,40.0,-300.0,700.0"
          171   fi
          172   if [ -z "${PARAM_PPQ}" ] ; then  # check if env var is NOT set
          173     PARAM_PPQ="0.25"
          174   fi
          175   if [ -z "${PARAM_TEFO}" ] ; then  # check if env var is NOT set
          176     PARAM_TEFO="0.02"
          177   fi
          178   if [ -z "${PARAM_NOSGL}" ] ; then  # check if env var is NOT set
          179     SGL="-tauc_slippery_grounding_lines"
          180   else
          181     SGL=""
          182   fi
          183   PHYS="${PHYS} -stress_balance ssa+sia -topg_to_phi ${PARAM_TTPHI} -pseudo_plastic -pseudo_plastic_q ${PARAM_PPQ} -till_effective_fraction_overburden ${PARAM_TEFO} ${SGL}"
          184 else
          185   if [ "$5" = "sia" ]; then
          186     echo "$SCRIPTNAME  sia-only case: ignoring PARAM_TTPHI, PARAM_PPQ, PARAM_TEFO ..."
          187   else
          188     echo "invalid fifth argument; must be in $DYNALIST"
          189     exit
          190   fi
          191 fi
          192 
          193 # set output filename from argument 6
          194 if [ -z "$6" ]; then
          195   OUTNAME=unnamed.nc
          196 else
          197   OUTNAME=$6
          198 fi
          199 
          200 # set bootstrapping input filename from argument 6
          201 if [ -z "$7" ]; then
          202   INNAME=$PISM_DATANAME
          203 else
          204   INNAME=$7
          205 fi
          206 INLIST="${INLIST} $INNAME $REGRIDFILE"
          207 
          208 # now we have read options ... we know enough to report to user ...
          209 echo
          210 echo "# ======================================================================="
          211 echo "# PISM std Greenland spinup:"
          212 echo "#    $NN processors, $DURATION a run, $dx km grid, $climname, $5 dynamics"
          213 echo "# ======================================================================="
          214 
          215 # actually check for input files
          216 for INPUT in $INLIST; do
          217   if [ -e "$INPUT" ] ; then  # check if file exist
          218     echo "$SCRIPTNAME           input   $INPUT (found)"
          219   else
          220     echo "$SCRIPTNAME           input   $INPUT (MISSING!!)"
          221     echo
          222     echo "$SCRIPTNAME  ***WARNING***  you may need to run ./preprocess.sh to generate standard input files!"
          223     echo
          224   fi
          225 done
          226 
          227 echo "$SCRIPTNAME              NN = $NN"
          228 
          229 # set MPIDO if using different MPI execution command, for example:
          230 #  $ export PISM_MPIDO="aprun -n "
          231 if [ -n "${PISM_MPIDO:+1}" ] ; then  # check if env var is already set
          232   echo "$SCRIPTNAME      PISM_MPIDO = $PISM_MPIDO  (already set)"
          233 else
          234   PISM_MPIDO="mpiexec -n "
          235   echo "$SCRIPTNAME      PISM_MPIDO = $PISM_MPIDO"
          236 fi
          237 
          238 # check if env var PISM_DO was set (i.e. PISM_DO=echo for a 'dry' run)
          239 if [ -n "${PISM_DO:+1}" ] ; then  # check if env var DO is already set
          240   echo "$SCRIPTNAME         PISM_DO = $PISM_DO  (already set)"
          241 else
          242   PISM_DO="" 
          243 fi
          244 
          245 # prefix to pism (not to executables)
          246 if [ -n "${PISM_BIN:+1}" ] ; then  # check if env var is already set
          247   echo "$SCRIPTNAME     PISM_BIN = $PISM_BIN  (already set)"
          248 else
          249   PISM_BIN=""    # just a guess
          250   echo "$SCRIPTNAME     PISM_BIN = $PISM_BIN"
          251 fi
          252 
          253 # set PISM_EXEC if using different executables, for example:
          254 #  $ export PISM_EXEC="pismr -energy cold"
          255 if [ -n "${PISM_EXEC:+1}" ] ; then  # check if env var is already set
          256   echo "$SCRIPTNAME       PISM_EXEC = $PISM_EXEC  (already set)"
          257 else
          258   PISM_EXEC="pismr"
          259   echo "$SCRIPTNAME       PISM_EXEC = $PISM_EXEC"
          260 fi
          261 
          262 # set EXSTEP to default if not set
          263 if [ -n "${EXSTEP:+1}" ] ; then  # check if env var is already set
          264   echo "$SCRIPTNAME          EXSTEP = $EXSTEP  (already set)"
          265 else
          266   EXSTEP="100"
          267   echo "$SCRIPTNAME          EXSTEP = $EXSTEP"
          268 fi
          269 
          270 # set EXVARS list to defaults if not set
          271 if [ -n "${EXVARS:+1}" ] ; then  # check if env var is already set
          272   echo "$SCRIPTNAME          EXVARS = $EXVARS  (already set)"
          273 else
          274   EXVARS="diffusivity,temppabase,tempicethk_basal,bmelt,tillwat,velsurf_mag,mask,thk,topg,usurf"
          275   if [ "$5" = "hybrid" ]; then
          276     EXVARS="${EXVARS},hardav,velbase_mag,tauc"
          277   fi
          278   echo "$SCRIPTNAME          EXVARS = $EXVARS"
          279 fi
          280 
          281 # if REGRIDFILE set then form regridcommand
          282 if [ -n "${REGRIDFILE:+1}" ] ; then  # check if env var is already set
          283   echo "$SCRIPTNAME      REGRIDFILE = $REGRIDFILE"
          284   if [ -n "${REGRIDVARS:+1}" ] ; then  # check if env var is already set
          285     echo "$SCRIPTNAME      REGRIDVARS = $REGRIDVARS  (already set)"
          286   else
          287     REGRIDVARS='litho_temp,thk,enthalpy,tillwat,basal_melt_rate_grounded'
          288     # note: other vars which are "state":  Href, dbdt, shelfbtemp, shelfbmassflux
          289     echo "$SCRIPTNAME      REGRIDVARS = $REGRIDVARS"
          290   fi
          291   regridcommand="-regrid_file $REGRIDFILE -regrid_vars $REGRIDVARS"
          292 else
          293   regridcommand=""
          294 fi
          295 
          296 # show remaining setup options:
          297 PISM="${PISM_BIN}/${PISM_EXEC}"
          298 echo "$SCRIPTNAME      executable = '$PISM'"
          299 echo "$SCRIPTNAME         coupler = '$COUPLER'"
          300 echo "$SCRIPTNAME        dynamics = '$PHYS'"
          301 
          302 # set up diagnostics
          303 if [ -z "${NODIAGS}" ] ; then  # check if env var is NOT set
          304   TSNAME=ts_$OUTNAME
          305   TSTIMES=-$DURATION:yearly:0
          306   EXNAME=ex_$OUTNAME
          307   EXTIMES=-$DURATION:$EXSTEP:0
          308   # check_stationarity.py can be applied to $EXNAME
          309   DIAGNOSTICS="-ts_file $TSNAME -ts_times $TSTIMES -extra_file $EXNAME -extra_times $EXTIMES -extra_vars $EXVARS"
          310 else
          311   DIAGNOSTICS=""
          312 fi
          313 
          314 # construct command
          315 cmd="$PISM_MPIDO $NN $PISM -i $INNAME -bootstrap ${grid} $RUNSTARTEND $regridcommand $COUPLER $PHYS $DIAGNOSTICS -o $OUTNAME"
          316 echo
          317 $PISM_DO $cmd
          318