Commit 7ad43352 authored by Jenni Rinker's avatar Jenni Rinker

add steady

parent d2c20f5c
"""Make htc files for running steady-state
import os
import shutil
def setup_dir(dirpath, clean_dir=False):
"""Setup a directory by either making it, cleaning it, or skipping"""
if os.path.exists(dirpath) and clean_dir:
shutil.rmtree(dirpath, ignore_errors=True)
if not os.path.exists(dirpath):
"""Make htc files for a series of steady winds
import os
import numpy as np
from wetb.hawc2 import HTCFile
from wetb.hawc2.hawc2_pbs_file import wine_cmd
from wetb.utils.cluster_tools.pbsfile import PBSMultiRunner
from _utils import setup_dir
if __name__ == '__main__':
# script inputs
wsps = np.arange(3, 26, 0.5) # wind speeds to simulate
htc_dir = '../htc_steady/' # directory to store htc files (end w/slash!)
master_dir = f'../htc_master/' # location of htc master file (normal turb. simulation)
tstart, tstop = 400, 500 # start and stop times for saving output
clean_htc_dir = True # delete existing files in htc_dir?
# intermediate values
model_key = os.path.basename(os.path.abspath('..')) # key for model directory, e.g. A0001
template_path = [os.path.join(master_dir, f) for f in
os.listdir(master_dir) if f.endswith('.htc')][0]
setup_dir(htc_dir, clean_dir=clean_htc_dir)
# make htc files for each wind speeds
for wsp in wsps:
basename = f'{model_key}_wsp{wsp}' # e.g., A0001_wsp6
htc_path = f'./{htc_dir}{basename}.htc'
# update values
htc = HTCFile(template_path)
# simulation
htc.simulation.time_stop = tstop
htc.simulation.logfile = f'./log/{basename}.log'
# wind
htc.wind.wsp = wsp
htc.wind.tint = 0
htc.wind.shear_format = [1, wsp]
htc.wind.turb_format = 0
del htc.wind.mann
# output
htc.output.time = [tstart, tstop]
htc.output.filename = f'./res/{basename}'
# save file
"""Create PBS files and a multirunner for htc files in a directory.
Can either be all htc files, or those that don't have a result file.
import os
from wetb.hawc2 import HTCFile
from wetb.hawc2.hawc2_pbs_file import wine_cmd
from wetb.utils.cluster_tools.pbsfile import PBSMultiRunner
from _utils import setup_dir
if __name__ == '__main__':
# script inputs
htc_dir = '../htc_steady/' # top folder w/htc files (end w/slash!)
regen = False # resimulate even if results exist?
h2_cwd = '../' # hawc2's working directory (end w/slash!)
# cluster settings
queue = 'xpresq' # queue to submit job to
ind_walltime = 30 # walltime of each individual job (minutes)
all_walltime = 30 # walltime of all simulations (minutes)
nnodes = 2 # number of nodes to use for job
# hawc2 configurations
version = "v12.8.0.0"
platform = "win32"
hawc2_path="/mnt/aiolos/groups/hawc2sim/HAWC2/%s/%s/" % (version, platform)
hawc2_cmd = wine_cmd(platform='win32', hawc2='hawc2mb.exe', cluster='jess')
# intermediate variables
workdir = os.path.abspath('..')
print('Generating pbs files...')
setup_dir('../pbs_in/') # check pbs directory exists
pbs_lst = []
for root, dirs, files in os.walk(htc_dir):
for file in files:
if '_master' in file:
if file.endswith('.htc'):
htc = HTCFile(os.path.join(root, file))
res_path = h2_cwd + str(htc.output.filename.values[0]) + '.dat'
if (os.path.exists(res_path) & (not regen)): # if res exists & we're not regenerating
if os.path.getsize(res_path): # also if res is nonzero size
continue # then don't simulate the file
pbs = htc.pbs_file(hawc2_path, hawc2_cmd,
queue=queue, # workq, windq, xpresq
walltime=ind_walltime*60, # individual wall time in seconds
input_files=None, # If none, required files are autodetected from htc file
output_files=None, # If none, output files are autodetected from htc file
copy_turb=(True, True) # copy turbulence files (to, from) simulation
pbs.workdir = workdir # update work directory (default is wrong)
os.chmod(pbs.workdir + '/' + pbs.filename, 0o774) # double-check permissions are ok
print(f'{len(pbs_lst)} files to simulate.')
# make multirunner
pbs_all = PBSMultiRunner(workdir=workdir,
queue=queue, # alternatives workq, windq, xpresq
walltime=all_walltime*60, # expected total simulation time in seconds
nodes=nnodes, # Number of nodes
ppn=20, # number of processors of each node (normally 20)
pbsfiles=pbs_lst # If None, the multirunner searches for *.in files
print('Multirunner file: ', os.path.join(workdir, pbs_all.filename))
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment