tcreatescript.py - 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
       ---
       tcreatescript.py (5986B)
       ---
            1 #!/usr/bin/env python3
            2 
            3 # Copyright (C) 2012-2015 Moritz Huetten and Torsten Albrecht (and Ed Bueler)
            4 
            5 import argparse
            6 
            7 # process command line arguments
            8 parser = argparse.ArgumentParser(description='Create run script for a MISMIP3d experiment.',
            9                                  formatter_class=argparse.ArgumentDefaultsHelpFormatter)
           10 parser.add_argument('-a', '--accumrate', metavar='A', type=float, default=0.5,
           11                     help='accumulation rate in meters/year')
           12 parser.add_argument('-d', '--duration', metavar='T', type=float, default=-1.0,
           13                     help='duration of run in years (if not set, use 3000 years for Stnd and 100 for others)')
           14 parser.add_argument('-e', default='Stnd',
           15                     choices=['Stnd', 'P10S', 'P10R', 'P75S', 'P75R'],
           16                     help='name of experiment; note P10D and P75D are not implemented yet')
           17 parser.add_argument('-m', choices=[1, 2], type=int, default=2,
           18                     help='model; 1 = SSA only, 2 = hybrid SIA+SSA')
           19 parser.add_argument('--mpiname', metavar='NAME', default='mpiexec',
           20                     help='name of mpi executable')
           21 parser.add_argument('-n', metavar='N', type=int, default=2,
           22                     help='number of MPI processes; if N=1 then MPI is not used')
           23 parser.add_argument('--pismpath', metavar='PATH', default='pismr',
           24                     help='full path to PISM executable pismr')
           25 parser.add_argument('--pythonpath', metavar='PATH', default='python',
           26                     help='full path to python executable')
           27 parser.add_argument('-r', type=int, choices=[1, 2, 3, 4, 5, 6, 7], default=5,
           28                     help='resolution mode; 1 = finest, 6 = coarsest')
           29 parser.add_argument('-s', '--subgl', action='store_true',  # thus defaults to False
           30                     help='use sub-grid grounding line method')
           31 
           32 args = parser.parse_args()
           33 # print args   # helpful for debugging
           34 
           35 print("""#!/bin/bash
           36 ###### MISMIP3D run script for experiment %s, model %d, and resolution mode %d ######
           37 
           38 accumrate=%s""" % (args.e, args.m, args.r, args.accumrate))
           39 
           40 # key: resolution mode; parameters: (resolution in km, Mx, My)
           41 grid_parameters = {1: (0.5,    3201, 201),
           42                    2: (1,      1601, 101),
           43                    3: (2,      801,  51),
           44                    4: (2.5,    641,  41),
           45                    5: (5,      321,  21),
           46                    6: (10,     161,  11),
           47                    7: (16.666, 97,   7)}
           48 
           49 # note My is ignored if args.e=='Stnd'
           50 print("""
           51 # grid
           52 resolution=%f # resolution in km
           53 Mx=%d
           54 My=%d""" % grid_parameters[args.r])
           55 
           56 print('')
           57 if args.subgl:
           58     print('# subgrid grounding line interpolation is used')
           59     print('s="-s"')
           60     print('subgl="-subgl"')
           61     print('gl_mask=",gl_mask"')
           62 else:
           63     print('# subgrid grounding line interpolation is not used')
           64     print('s=" "')
           65     print('subgl=" "')
           66     print('gl_mask=" "')
           67 
           68 print('')
           69 if args.e in {'Stnd', 'P10S', 'P75S'}:
           70     print('# create bootstrap file using python ...')
           71 else:
           72     print('# NOT creating bootstrap file since experiment %s starts from previously-saved state' % args.e)
           73 
           74 if args.e == 'Stnd':
           75     print('%s setup_Stnd.py -a $accumrate -r $resolution' % args.pythonpath)
           76 elif args.e == 'P10S':
           77     print('amplitude=0.1')
           78     print('%s setup_PXXS.py -a $amplitude -i ex_Stnd.nc $s' % args.pythonpath)
           79 elif args.e == 'P75S':
           80     print('amplitude=0.75')
           81     print('%s setup_PXXS.py -a $amplitude -i ex_Stnd.nc $s' % args.pythonpath)
           82 
           83 print('')
           84 print('# build the PISM command')
           85 if args.n > 1:
           86     print('pismr="%s"' % (args.mpiname + (' -n %d ' % args.n) + args.pismpath))
           87 else:
           88     print('pismr="%s"' % args.pismpath)
           89 
           90 print('')
           91 if args.duration < 0:
           92     if args.e == 'Stnd':
           93         print('duration=3000')
           94     else:
           95         print('duration=100')
           96 else:
           97     print('duration=%s' % args.duration)
           98 
           99 print('')
          100 print('listexvar="thk,topg,velbar_mag,flux_mag,mask,dHdt,usurf,hardav,velbase,velsurf,velbar,wvelbase,wvelsurf,tauc,deviatoric_stresses,climatic_mass_balance$gl_mask"')
          101 if args.e == 'Stnd':
          102     print('extrastuff="-extra_times 0:50:$duration -extra_vars $listexvar"')
          103 else:
          104     print('extrastuff="-extra_times 0:1:$duration -extra_vars $listexvar"')
          105 
          106 print('')
          107 print('stressbalance="-ssa_method fd -ssa_flow_law isothermal_glen -ssafd_ksp_rtol 1e-7"')
          108 print('basal="-yield_stress constant -pseudo_plastic -pseudo_plastic_q 0.333333333 -pseudo_plastic_uthreshold 3.155693e+07"')
          109 print('calvingfront="-cfbc -part_grid"')
          110 if args.m == 1:
          111     print('modelopt="-stress_balance ssa" ')
          112 elif args.m == 2:
          113     print('modelopt="-stress_balance ssa+sia -sia_flow_law isothermal_glen" ')
          114 
          115 print('STRONGKSP="-ssafd_ksp_type gmres -ssafd_ksp_norm_type unpreconditioned -ssafd_ksp_pc_side right -ssafd_pc_type asm -ssafd_sub_pc_type lu"')
          116 
          117 print('')
          118 print('opts="-config_override MISMIP3D_conf.nc $stressbalance $basal $calvingfront $subgl $modelopt -energy none -gradient eta -options_left -ts_file ts_%s.nc -ts_times 0:1:$duration -extra_file ex_%s.nc $extrastuff -ys 0 -ye $duration -o_order zyx -o_size big -o %s.nc $STRONGKSP"' % (args.e, args.e, args.e))
          119 
          120 print('')
          121 if args.e == 'Stnd':
          122     print('infile=MISMIP3D_Stnd_initialSetup.nc')
          123     print('cmd="$pismr -i $infile -bootstrap -Mx $Mx -My 3 -Mz 15 -Lz 6000 -tauc 1.0e7 -front_retreat_file $infile $opts"')
          124 elif args.e == 'P10S':
          125     print('infile=MISMIP3D_P10S_initialSetup.nc')
          126     print('cmp="$pismr -i $infile -bootstrap -Mx $Mx -My $My -Mz 15 -Lz 6000 -front_retreat_file $infile $opts"')
          127 elif args.e == 'P10R':
          128     print('infile=P10S.nc')
          129     print('cmd="$pismr -i $infile -tauc 1.0e7 -front_retreat_file $infile $opts"')
          130 elif args.e == 'P75S':
          131     print('infile=MISMIP3D_P75S_initialSetup.nc')
          132     print('cmd="$pismr -i $infile -bootstrap -Mx $Mx -My $My -Mz 15 -Lz 6000 -front_retreat_file $infile $opts"')
          133 elif args.e == 'P75R':
          134     print('infile=P75S.nc')
          135     print('cmd="$pismr -i $infile -tauc 1.0e7 -front_retreat_file $infile $opts"')
          136 
          137 print('')
          138 print('echo "running command:"')
          139 print('echo $cmd')
          140 print('echo')
          141 
          142 print('')
          143 print('$cmd')