tgenerate-rate-state-scripts-comet-rs0.py - sphere - GPU-based 3D discrete element method algorithm with optional fluid coupling
 (HTM) git clone git://src.adamsgaard.dk/sphere
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
       tgenerate-rate-state-scripts-comet-rs0.py (4399B)
       ---
            1 #!/usr/bin/env python
            2 
            3 # Account and cluster information
            4 # https://portal.xsede.org/sdsc-comet
            5 # https://www.sdsc.edu/support/user_guides/comet.html
            6 account = 'csd492'  # from `show_accounts`
            7 jobname_prefix = 'rs0-'
            8 walltime = '2-0'   # hours:minutes:seconds or days-hours
            9 partition = 'gpu-shared'
           10 no_gpus = 1
           11 no_nodes = 1
           12 ntasks_per_node = 1
           13 folder = '~/code/sphere/python'
           14 
           15 
           16 # Simulation parameter values
           17 effective_stresses = [10e3, 20e3, 100e3, 200e3, 1000e3, 2000e3]
           18 velfacs = [0.1, 1.0, 10.0]
           19 mu_s_vals = [0.5]
           20 mu_d_vals = [0.5]
           21 
           22 
           23 # Script generating functions
           24 
           25 def generate_slurm_script(jobname):
           26 
           27     script = '''#!/bin/bash
           28 #SBATCH -A {account}
           29 #SBATCH --job-name="{jobname}"
           30 #SBATCH --output="{jobname}.%j.%N.out"
           31 #SBATCH --time={walltime}
           32 #SBATCH --partition={partition}
           33 #SBATCH --gres=gpu:{no_gpus}
           34 #SBATCH --nodes={no_nodes}
           35 #SBATCH --ntasks-per-node={ntasks_per_node}
           36 #SBATCH --export=ALL
           37 
           38 echo Job start `whoami`@`hostname`, `date`
           39 module load cmake
           40 module load cuda/7.0
           41 module load python
           42 module load scipy
           43 
           44 cd {folder}
           45 python ./{jobname}.py
           46 
           47 echo Job end `whoami`@`hostname`, `date`
           48 '''.format(account=account,
           49            jobname=jobname,
           50            walltime=walltime,
           51            partition=partition,
           52            no_gpus=no_gpus,
           53            no_nodes=no_nodes,
           54            ntasks_per_node=ntasks_per_node,
           55            folder=folder)
           56     with open(jobname + '.sh', 'w') as file:
           57         file.write(script)
           58 
           59 
           60 def generate_slurm_continue_script(jobname):
           61 
           62     script = '''#!/bin/bash
           63 #SBATCH -A {account}
           64 #SBATCH --job-name="{jobname}"
           65 #SBATCH --output="{jobname}.%j.%N.out"
           66 #SBATCH --time={walltime}
           67 #SBATCH --partition={partition}
           68 #SBATCH --gres=gpu:{no_gpus}
           69 #SBATCH --nodes={no_nodes}
           70 #SBATCH --ntasks-per-node={ntasks_per_node}
           71 #SBATCH --export=ALL
           72 
           73 echo Job start `whoami`@`hostname`, `date`
           74 module load cmake
           75 module load cuda/7.0
           76 module load python
           77 module load scipy
           78 
           79 cd {folder}
           80 python ./continue_sim.py {jobname} 0
           81 
           82 echo Job end `whoami`@`hostname`, `date`
           83 '''.format(account=account,
           84            jobname=jobname,
           85            walltime=walltime,
           86            partition=partition,
           87            no_gpus=no_gpus,
           88            no_nodes=no_nodes,
           89            ntasks_per_node=ntasks_per_node,
           90            folder=folder)
           91     with open(jobname + '-cont.sh', 'w') as file:
           92         file.write(script)
           93 
           94 
           95 # Generate scripts for sphere
           96 def generate_simulation_script(jobname, effective_stress, velfac, mu_s, mu_d):
           97 
           98     script = '''#!/usr/bin/env python
           99 import sphere
          100 import numpy
          101 
          102 # load consolidated granular assemblage
          103 sim = sphere.sim(fluid=False)
          104 cons_jobname = 'cons-1e4-' + '{{}}Pa'.format({effective_stress})
          105 sim = sphere.sim(cons_jobname, fluid=False)
          106 sim.readlast()
          107 sim.id('{jobname}')
          108 
          109 sim.checkerboardColors(nx=6, ny=6, nz=6)
          110 sim.cleanup()
          111 sim.adjustUpperWall()
          112 sim.zeroKinematics()
          113 
          114 sim.shear(1.0/20.0 * {velfac})
          115 
          116 sim.setStiffnessNormal(1.16e7)
          117 sim.setStiffnessTangential(1.16e7)
          118 sim.setStaticFriction({mu_s})
          119 sim.setDynamicFriction({mu_d})
          120 sim.setDampingNormal(0.0)
          121 sim.setDampingTangential(0.0)
          122 
          123 sim.w_sigma0[0] = {effective_stress}
          124 sim.w_m[0] = numpy.abs({effective_stress}*sim.L[0]*sim.L[1]/sim.g[2])
          125 
          126 sim.initTemporal(total = 20.0, file_dt = 0.01, epsilon=0.07)
          127 
          128 I = numpy.nonzero(sim.fixvel > 0)
          129 sim.fixvel[I] = 8.0 # step-wise velocity change when fixvel in ]5.0; 10.0[
          130 
          131 sim.run(dry=True)
          132 sim.run(device=0)
          133 sim.writeVTKall()
          134 sim.visualize('shear')
          135 '''.format(jobname=jobname,
          136            effective_stress=effective_stress,
          137            velfac=velfac,
          138            mu_s=mu_s,
          139            mu_d=mu_d)
          140 
          141     with open(jobname + '.py', 'w') as file:
          142         file.write(script)
          143 
          144 
          145 # Generate scripts
          146 for effective_stress in effective_stresses:
          147     for velfac in velfacs:
          148         for mu_s in mu_s_vals:
          149             for mu_d in mu_s_vals:
          150 
          151                 jobname = 'rs0-{}Pa-v={}-mu_s={}-mu_d={}'.format(
          152                     effective_stress,
          153                     velfac,
          154                     mu_s,
          155                     mu_d)
          156 
          157                 print(jobname)
          158 
          159                 # Generate scripts for slurm, submit with `sbatch <script>`
          160                 generate_slurm_script(jobname)
          161 
          162                 generate_slurm_continue_script(jobname)
          163 
          164                 generate_simulation_script(jobname,
          165                                            effective_stress,
          166                                            velfac,
          167                                            mu_s,
          168                                            mu_d)