@@ -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# ----------------------------------------------
0 commit comments