Skip to content

Commit 649ab9c

Browse files
authored
Merge pull request #47 from rthedin/f/bashscripts
Add bash scripts
2 parents 130260c + 28f3df7 commit 649ab9c

File tree

5 files changed

+129
-40
lines changed

5 files changed

+129
-40
lines changed

openfast_toolbox/fastfarm/FASTFarmCaseCreation.py

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,8 +1084,8 @@ def setTemplateFilename(self, templatePath=None, templateFiles=None):
10841084
self.EDtowerfilename = "unused"; self.EDtowerfilepath = "unused"
10851085
self.ADbladefilename = "unused"; self.ADbladefilepath = "unused"
10861086
self.turbfilename = "unused"; self.turbfilepath = "unused"
1087+
self.controllerInputfilename = "unused"; self.controllerInputfilepath = "unused"
10871088
self.libdisconfilepath = "unused"
1088-
self.controllerInputfilename = "unused"
10891089
self.coeffTablefilename = "unused"
10901090
self.hydroDatapath = "unused"
10911091
self.turbsimLowfilepath = "unused"
@@ -1663,7 +1663,24 @@ def TS_low_setup(self, writeFiles=True, runOnce=False):
16631663

16641664
self.TSlowBoxFilesCreatedBool = True
16651665

1666-
def TS_low_slurm_prepare(self, slurmfilepath):
1666+
1667+
def sed_inplace(self, sed_command, inplace):
1668+
'''
1669+
sed in place does not work on standard input. A workaround here
1670+
is to save to another file and then copy over
1671+
'''
1672+
1673+
if inplace:
1674+
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
1675+
else:
1676+
sed_split = sed_command.split(' ')
1677+
filename = sed_split[-1]
1678+
sed_split = f'sed ' + ' '.join(sed_split[2:]) + f"> {os.path.join(self.path, 'temp.txt')}"
1679+
_ = subprocess.call(sed_split, cwd=self.path, shell=True)
1680+
shutil.move(os.path.join(self.path,'temp.txt'), os.path.join(self.path,filename))
1681+
1682+
1683+
def TS_low_slurm_prepare(self, slurmfilepath, inplace=True):
16671684

16681685
# --------------------------------------------------
16691686
# ----- Prepare SLURM script for Low-res boxes -----
@@ -1680,35 +1697,35 @@ def TS_low_slurm_prepare(self, slurmfilepath):
16801697

16811698
# Change job name (for convenience only)
16821699
sed_command = f"sed -i 's|^#SBATCH --job-name=lowBox|#SBATCH --job-name=lowBox_{os.path.basename(self.path)}|g' {self.slurmfilename_low}"
1683-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
1700+
self.sed_inplace(sed_command, inplace)
16841701
# Change logfile name (for convenience only)
16851702
sed_command = f"sed -i 's|#SBATCH --output log.lowBox|#SBATCH --output log.turbsim_low|g' {self.slurmfilename_low}"
1686-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
1703+
self.sed_inplace(sed_command, inplace)
16871704
# Change memory per cpu
16881705
sed_command = f"sed -i 's|--mem-per-cpu=25000M|--mem-per-cpu={memory_per_cpu}M|g' {self.slurmfilename_low}"
1689-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
1706+
self.sed_inplace(sed_command, inplace)
16901707
# Change number of nodes values
16911708
sed_command = f"sed -i 's|^#SBATCH --nodes.*|#SBATCH --nodes={int(np.ceil(self.nConditions*self.nSeeds/6))}|g' {self.slurmfilename_low}"
1692-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
1709+
self.sed_inplace(sed_command, inplace)
16931710
# Change the fastfarm binary to be called
16941711
sed_command = f"""sed -i "s|^turbsimbin.*|turbsimbin='{self.tsbin}'|g" {self.slurmfilename_low}"""
1695-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
1712+
self.sed_inplace(sed_command, inplace)
16961713
# Change the path inside the script to the desired one
16971714
sed_command = f"""sed -i "s|^basepath.*|basepath='{self.path}'|g" {self.slurmfilename_low}"""
1698-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
1715+
self.sed_inplace(sed_command, inplace)
16991716
# Assemble list of conditions and write it
17001717
listtoprint = "' '".join(self.condDirList)
17011718
sed_command = f"""sed -i "s|^condList.*|condList=('{listtoprint}')|g" {self.slurmfilename_low}"""
1702-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
1719+
self.sed_inplace(sed_command, inplace)
17031720
# Change the number of seeds
17041721
sed_command = f"sed -i 's|^nSeeds.*|nSeeds={self.nSeeds}|g' {self.slurmfilename_low}"
1705-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
1722+
self.sed_inplace(sed_command, inplace)
17061723

17071724
if self.nSeeds > 6:
17081725
print(f'--- WARNING: The memory-per-cpu on the low-res boxes SLURM script might be too low given {self.nSeeds} seeds.')
17091726

17101727

1711-
def TS_low_slurm_submit(self, qos='normal', A=None, t=None, p=None):
1728+
def TS_low_slurm_submit(self, qos='normal', A=None, t=None, p=None, inplace=True):
17121729
# ---------------------------------
17131730
# ----- Run turbSim Low boxes -----
17141731
# ---------------------------------
@@ -1723,7 +1740,7 @@ def TS_low_slurm_submit(self, qos='normal', A=None, t=None, p=None):
17231740

17241741
sub_command = f"sbatch {options}{self.slurmfilename_low}"
17251742
print(f'Calling: {sub_command}')
1726-
_ = subprocess.call(sub_command, cwd=self.path, shell=True)
1743+
self.sed_inplace(sub_command, inplace)
17271744

17281745

17291746
def TS_low_createSymlinks(self):
@@ -1951,7 +1968,7 @@ def TS_high_setup(self, writeFiles=True):
19511968
self.TShighBoxFilesCreatedBool = True
19521969

19531970

1954-
def TS_high_slurm_prepare(self, slurmfilepath):
1971+
def TS_high_slurm_prepare(self, slurmfilepath, inplace=True):
19551972
# ---------------------------------------------------
19561973
# ----- Prepare SLURM script for High-res boxes -----
19571974
# ---------------------------------------------------
@@ -1965,38 +1982,38 @@ def TS_high_slurm_prepare(self, slurmfilepath):
19651982

19661983
# Change job name (for convenience only)
19671984
sed_command = f"sed -i 's|^#SBATCH --job-name.*|#SBATCH --job-name=highBox_{os.path.basename(self.path)}|g' {self.slurmfilename_high}"
1968-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
1985+
self.sed_inplace(sed_command, inplace)
19691986
# Change logfile name (for convenience only)
19701987
sed_command = f"sed -i 's|#SBATCH --output log.highBox|#SBATCH --output log.turbsim_high|g' {self.slurmfilename_high}"
1971-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
1988+
self.sed_inplace(sed_command, inplace)
19721989
# Change number of nodes values
19731990
sed_command = f"sed -i 's|^#SBATCH --nodes.*|#SBATCH --nodes={int(np.ceil(ntasks/36))}|g' {self.slurmfilename_high}"
1974-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
1991+
self.sed_inplace(sed_command, inplace)
19751992
# Change the fastfarm binary to be called
19761993
sed_command = f"""sed -i "s|^turbsimbin.*|turbsimbin='{self.tsbin}'|g" {self.slurmfilename_high}"""
1977-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
1994+
self.sed_inplace(sed_command, inplace)
19781995
# Change the path inside the script to the desired one
19791996
sed_command = f"""sed -i "s|^basepath.*|basepath='{self.path}'|g" {self.slurmfilename_high}"""
1980-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
1997+
self.sed_inplace(sed_command, inplace)
19811998
# Change number of turbines
19821999
sed_command = f"sed -i 's|^nTurbines.*|nTurbines={self.nTurbines}|g' {self.slurmfilename_high}"
1983-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
2000+
self.sed_inplace(sed_command, inplace)
19842001
# Change number of seeds
1985-
set_command = f"sed -i 's|^nSeeds.*|nSeeds={self.nSeeds}|g' {self.slurmfilename_high}"
1986-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
2002+
sed_command = f"sed -i 's|^nSeeds.*|nSeeds={self.nSeeds}|g' {self.slurmfilename_high}"
2003+
self.sed_inplace(sed_command, inplace)
19872004
# Assemble list of conditions and write it
19882005
listtoprint = "' '".join(self.condDirList)
19892006
sed_command = f"""sed -i "s|^condList.*|condList=('{listtoprint}')|g" {self.slurmfilename_high}"""
1990-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
2007+
self.sed_inplace(sed_command, inplace)
19912008
# Assemble list of cases and write it
19922009
highBoxesCaseDirList = [self.caseDirList[c] for c in self.allHighBoxCases.case.values]
19932010
listtoprint = "' '".join(highBoxesCaseDirList)
19942011
sed_command = f"""sed -i "s|^caseList.*|caseList=('{listtoprint}')|g" {self.slurmfilename_high}"""
1995-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
2012+
self.sed_inplace(sed_command, inplace)
19962013

19972014

19982015

1999-
def TS_high_slurm_submit(self, qos='normal', A=None, t=None, p=None):
2016+
def TS_high_slurm_submit(self, qos='normal', A=None, t=None, p=None, inplace=True):
20002017
# ----------------------------------
20012018
# ----- Run turbSim High boxes -----
20022019
# ----------------------------------
@@ -2011,7 +2028,7 @@ def TS_high_slurm_submit(self, qos='normal', A=None, t=None, p=None):
20112028

20122029
sub_command = f"sbatch {options}{self.slurmfilename_high}"
20132030
print(f'Calling: {sub_command}')
2014-
_ = subprocess.call(sub_command, cwd=self.path, shell=True)
2031+
self.sed_inplace(sub_command, inplace)
20152032

20162033

20172034
def TS_high_create_symlink(self):
@@ -2518,7 +2535,7 @@ def _getBoxesParamsForFF(self, lowbts, highbts, dt_low_desired, D, HubHt, xWT, y
25182535

25192536

25202537

2521-
def FF_slurm_prepare(self, slurmfilepath):
2538+
def FF_slurm_prepare(self, slurmfilepath, inplace=True):
25222539
# ----------------------------------------------
25232540
# ----- Prepare SLURM script for FAST.Farm -----
25242541
# ------------- ONE SCRIPT PER CASE ------------
@@ -2538,32 +2555,32 @@ def FF_slurm_prepare(self, slurmfilepath):
25382555

25392556
# Change job name (for convenience only)
25402557
sed_command = f"sed -i 's|#SBATCH --job-name=runFF|#SBATCH --job-name=c{cond}_c{case}_s{seed}_runFF_{os.path.basename(self.path)}|g' {fname}"
2541-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
2558+
self.sed_inplace(sed_command, inplace)
25422559
# Change logfile name (for convenience only)
25432560
sed_command = f"sed -i 's|#SBATCH --output log.fastfarm_c0_c0_seed0|#SBATCH --output log.fastfarm_c{cond}_c{case}_s{seed}|g' {fname}"
2544-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
2561+
self.sed_inplace(sed_command, inplace)
25452562
# Change the fastfarm binary to be called
25462563
sed_command = f"""sed -i "s|^fastfarmbin.*|fastfarmbin='{self.ffbin}'|g" {fname}"""
2547-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
2564+
self.sed_inplace(sed_command, inplace)
25482565
# Change the path inside the script to the desired one
25492566
sed_command = f"""sed -i "s|^basepath.*|basepath='{self.path}'|g" {fname}"""
2550-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
2567+
self.sed_inplace(sed_command, inplace)
25512568
# Write condition
25522569
sed_command = f"""sed -i "s|^cond.*|cond='{self.condDirList[cond]}'|g" {fname}"""
2553-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
2570+
self.sed_inplace(sed_command, inplace)
25542571
# Write case
25552572
sed_command = f"""sed -i "s|^case.*|case='{self.caseDirList[case]}'|g" {fname}"""
2556-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
2573+
self.sed_inplace(sed_command, inplace)
25572574
# Write seed
25582575
sed_command = f"""sed -i "s|^seed.*|seed={seed}|g" {fname}"""
2559-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
2576+
self.sed_inplace(sed_command, inplace)
25602577
# Wirte FAST.Farm filename
25612578
sed_command = f"""sed -i "s/FFarm_mod.fstf/FF.fstf/g" {fname}"""
2562-
_ = subprocess.call(sed_command, cwd=self.path, shell=True)
2579+
self.sed_inplace(sed_command, inplace)
25632580

25642581

25652582

2566-
def FF_slurm_submit(self, qos='normal', A=None, t=None, p=None, delay=4):
2583+
def FF_slurm_submit(self, qos='normal', A=None, t=None, p=None, delay=4, inplace=True):
25672584

25682585
# ----------------------------------
25692586
# ---------- Run FAST.Farm ---------
@@ -2588,7 +2605,7 @@ def FF_slurm_submit(self, qos='normal', A=None, t=None, p=None, delay=4):
25882605

25892606
sub_command = f"sbatch {options}{fname}"
25902607
print(f'Calling: {sub_command}')
2591-
_ = subprocess.call(sub_command, cwd=self.path, shell=True)
2608+
self.sed_inplace(sub_command, inplace)
25922609
time.sleep(delay) # Sometimes the same job gets submitted twice. This gets around it.
25932610

25942611
# ----------------------------------------------
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
source $HOME/.bash_profile
3+
4+
# ********************************** USER INPUT ********************************** #
5+
turbsimbin='/full/path/to/your/binary/.../bin/turbsim'
6+
basepath='/full/path/to/your/case/dir'
7+
8+
condList=('Cond00_v08.6_PL0.2_TI10' 'Cond01_v10.6_PL0.2_TI10' 'Cond02_v12.6_PL0.2_TI10')
9+
10+
caseList=('Case00_wdirp00_WSfalse_YMfalse' 'Case01_wdirp00_WStrue_YMfalse')
11+
12+
nSeeds=6
13+
nTurbines=12
14+
# ******************************************************************************** #
15+
16+
for cond in ${condList[@]}; do
17+
for case in ${caseList[@]}; do
18+
for ((seed=0; seed<$nSeeds; seed++)); do
19+
for ((t=1; t<=$nTurbines; t++)); do
20+
dir=$(printf "%s/%s/%s/Seed_%01d/TurbSim" $basepath $cond $case $seed)
21+
echo "Submitting $dir/HighT$t.inp"
22+
$turbsimbin $dir/HighT$t.inp > $dir/log.hight$t.seed$seed.txt 2>&1 &
23+
sleep 0.1
24+
done
25+
done
26+
done
27+
done
28+
29+
wait
30+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
source $HOME/.bash_profile
4+
5+
# ********************************** USER INPUT ********************************** #
6+
turbsimbin='/full/path/to/your/binary/.../bin/turbsim'
7+
basepath='/full/path/to/your/case/dir'
8+
9+
condList=('Cond00_v08.6_PL0.2_TI10' 'Cond01_v10.6_PL0.2_TI10' 'Cond02_v12.6_PL0.2_TI10')
10+
11+
nSeeds=6
12+
# ******************************************************************************** #
13+
14+
for cond in ${condList[@]}; do
15+
for((seed=0; seed<$nSeeds; seed++)); do
16+
dir=$(printf "%s/%s/Seed_%01d" $basepath $cond $seed)
17+
echo "Running $dir/Low.inp"
18+
$turbsimbin $dir/Low.inp > $dir/log.low.seed$seed.txt 2>&1 &
19+
done
20+
done
21+
22+
wait
23+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
source $HOME/.bash_profile
4+
5+
# ********************************** USER INPUT ********************************** #
6+
fastfarmbin='/full/path/to/your/binary/.../bin/FAST.Farm'
7+
basepath='/full/path/to/your/case/dir'
8+
9+
cond='Cond00_v08.6_TI10'
10+
case='Case00_wdirp00'
11+
seed=0
12+
# ******************************************************************************** #
13+
14+
dir=$(printf "%s/%s/%s/Seed_%01d" $basepath $cond $case $seed)
15+
cd $dir
16+
export OMP_STACKSIZE="32 M"
17+
echo "Running $dir/FFarm_mod.fstf with OMP_STACKSIZE=32M"
18+
$fastfarmbin $dir/FFarm_mod.fstf > $dir/log.fastfarm.seed$seed.txt 2>&1
19+

openfast_toolbox/fastfarm/postpro/ff_postpro.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ def readTurbineOutputPar(caseobj, dt_openfast, dt_processing, saveOutput=True, o
7171
outputnc = os.path.join(caseobj.path, ncfile)
7272

7373
if output=='zarr' and os.path.isdir(outputzarr) and saveOutput:
74-
print(f'Output file {zarrstore} exists. Loading it..')
74+
print(f'Output file {zarrstore} exists. Loading it.')
7575
comb_ds = xr.open_zarr(outputzarr)
7676
return comb_ds
7777
if output=='nc' and os.path.isfile(outputnc) and saveOutput:
78-
print(f'Output file {ncfile} exists. Loading it..')
78+
print(f'Output file {ncfile} exists. Loading it.')
7979
comb_ds = xr.open_dataset(outputnc)
8080
return comb_ds
8181

@@ -440,7 +440,7 @@ def readFFPlanes(caseobj, slicesToRead=['x','y','z'], verbose=False, saveOutput=
440440
if len(slicesToRead) > 1:
441441
print(f"!! WARNING: Asked for multiple slices. Returning only the first one, {slices}\n",
442442
f" To load other slices, request `slicesToRead='y'`")
443-
print(f'Processed output for slice {slices} found. Loading it.')
443+
print(f'Processed output file {outputfile} for slice {slices} exists. Loading it.')
444444
# Data already processed. Reading output
445445
Slices = xr.open_zarr(outputfile)
446446
return Slices
@@ -449,7 +449,7 @@ def readFFPlanes(caseobj, slicesToRead=['x','y','z'], verbose=False, saveOutput=
449449
if len(slicesToRead) > 1:
450450
print(f"!! WARNING: Asked for multiple slices. Returning only the first one, {slices}\n",
451451
f" To load other slices, request `slicesToRead='y'`")
452-
print(f'Processed output for slice {slices} found. Loading it.')
452+
print(f'Processed output file {outputfile} for slice {slices} exists. Loading it.')
453453
# Data already processed. Reading output
454454
Slices = xr.open_dataset(outputfile)
455455
return Slices

0 commit comments

Comments
 (0)