Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 5b4c6be

Browse files
committed
Update of case_generation, support for multiple batches
1 parent 12252b3 commit 5b4c6be

9 files changed

+58
-31
lines changed
File renamed without changes.

pyFAST/case_generation/case_gen.py

+25-17
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ def handleRemoveReadonlyWin(func, path, exc_info):
3232
raise
3333

3434

35+
def forceCopyFile (sfile, dfile):
36+
# ---- Handling error due to wrong mod
37+
if os.path.isfile(dfile):
38+
if not os.access(dfile, os.W_OK):
39+
os.chmod(dfile, stat.S_IWUSR)
40+
#print(sfile, ' > ', dfile)
41+
shutil.copy2(sfile, dfile)
42+
3543
def copyTree(src, dst):
3644
"""
3745
Copy a directory to another one, overwritting files if necessary.
@@ -45,14 +53,6 @@ def forceMergeFlatDir(srcDir, dstDir):
4553
dstFile = os.path.join(dstDir, item)
4654
forceCopyFile(srcFile, dstFile)
4755

48-
def forceCopyFile (sfile, dfile):
49-
# ---- Handling error due to wrong mod
50-
if os.path.isfile(dfile):
51-
if not os.access(dfile, os.W_OK):
52-
os.chmod(dfile, stat.S_IWUSR)
53-
#print(sfile, ' > ', dfile)
54-
shutil.copy2(sfile, dfile)
55-
5656
def isAFlatDir(sDir):
5757
for item in os.listdir(sDir):
5858
sItem = os.path.join(sDir, item)
@@ -292,35 +292,41 @@ def removeFASTOuputs(workDir):
292292
# --------------------------------------------------------------------------------}
293293
# --- Tools for template replacement
294294
# --------------------------------------------------------------------------------{
295-
def paramsSteadyAero(p=dict()):
295+
def paramsSteadyAero(p=None):
296+
p = dict() if p is None else p
296297
p['AeroFile|AFAeroMod']=1 # remove dynamic effects dynamic
297298
p['AeroFile|WakeMod']=1 # remove dynamic inflow dynamic
298299
p['AeroFile|TwrPotent']=0 # remove tower shadow
299300
return p
300301

301-
def paramsNoGen(p=dict()):
302+
def paramsNoGen(p=None):
303+
p = dict() if p is None else p
302304
p['EDFile|GenDOF' ] = 'False'
303305
return p
304306

305-
def paramsGen(p=dict()):
307+
def paramsGen(p=None):
308+
p = dict() if p is None else p
306309
p['EDFile|GenDOF' ] = 'True'
307310
return p
308311

309-
def paramsNoController(p=dict()):
312+
def paramsNoController(p=None):
313+
p = dict() if p is None else p
310314
p['ServoFile|PCMode'] = 0;
311315
p['ServoFile|VSContrl'] = 0;
312316
p['ServoFile|YCMode'] = 0;
313317
return p
314318

315-
def paramsControllerDLL(p=dict()):
319+
def paramsControllerDLL(p=None):
320+
p = dict() if p is None else p
316321
p['ServoFile|PCMode'] = 5;
317322
p['ServoFile|VSContrl'] = 5;
318323
p['ServoFile|YCMode'] = 5;
319324
p['EDFile|GenDOF'] = 'True';
320325
return p
321326

322327

323-
def paramsStiff(p=dict()):
328+
def paramsStiff(p=None):
329+
p = dict() if p is None else p
324330
p['EDFile|FlapDOF1'] = 'False'
325331
p['EDFile|FlapDOF2'] = 'False'
326332
p['EDFile|EdgeDOF' ] = 'False'
@@ -352,7 +358,7 @@ def iterify(x):
352358
RPM = iterify(RPM)
353359
Pitch = iterify(Pitch)
354360
# --- If inputs are not flat but different vectors to length through, we flatten them (TODO: meshgrid and ravel?)
355-
if not FlatInputs :
361+
if not flatInputs :
356362
WS_flat = []
357363
Pitch_flat = []
358364
RPM_flat = []
@@ -386,7 +392,8 @@ def iterify(x):
386392
PARAMS.append(p)
387393
return PARAMS
388394

389-
def paramsLinearTrim(p=dict()):
395+
def paramsLinearTrim(p=None):
396+
p = dict() if p is None else p
390397

391398
# Set a few DOFs, move this to main file
392399
p['Linearize'] = True
@@ -435,7 +442,8 @@ def paramsLinearTrim(p=dict()):
435442
# ---
436443
# --------------------------------------------------------------------------------{
437444
def createStepWind(filename,WSstep=1,WSmin=3,WSmax=25,tstep=100,dt=0.5,tmin=0,tmax=999):
438-
f = weio.FASTWndFile()
445+
from pyFAST.input_output.fast_wind_file import FASTWndFile
446+
f = FASTWndFile()
439447
Steps= np.arange(WSmin,WSmax+WSstep,WSstep)
440448
print(Steps)
441449
nCol = len(f.colNames)

pyFAST/case_generation/examples/Example_CPLambdaPitch.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def CPLambdaExample():
1414
"""
1515
FAST_EXE = os.path.join(MyDir, '../../../data/openfast.exe') # Location of a FAST exe (and dll)
1616
ref_dir = os.path.join(MyDir, '../../../data/NREL5MW/') # Folder where the fast input files are located (will be copied)
17-
main_file = 'Main_Onshore_OF2.fst' # Main file in ref_dir, used as a template
17+
main_file = 'Main_Onshore.fst' # Main file in ref_dir, used as a template
1818

1919
# --- Computing CP and CT matrices for range of lambda and pitches
2020
Lambda = np.linspace(0.1,10,3)

pyFAST/case_generation/examples/Example_ExcelFile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def main():
1717
# --- Main Parameters
1818
ref_dir = os.path.join(MyDir, '../../../data/NREL5MW/') # Folder where the fast input files are located (will be copied)
1919
FAST_EXE = os.path.join(MyDir, '../../../data/openfast.exe') # Location of a FAST exe (and dll)
20-
main_file = 'Main_Onshore_OF2.fst' # Main file in ref_dir, used as a template
20+
main_file = 'Main_Onshore.fst' # Main file in ref_dir, used as a template
2121
work_dir = '_NREL5MW_ParametricExcel/' # Output folder (will be created)
2222
parametricFile = 'ParametricExcel.xlsx' # Excel file containing set of parameters
2323

pyFAST/case_generation/examples/Example_Parametric.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def ParametricExample():
3030
# --- Parameters for this script
3131
FAST_EXE = os.path.join(MyDir, '../../../data/openfast.exe') # Location of a FAST exe (and dll)
3232
ref_dir = os.path.join(MyDir, '../../../data/NREL5MW/') # Folder where the fast input files are located (will be copied)
33-
main_file = 'Main_Onshore_OF2.fst' # Main file in ref_dir, used as a template
33+
main_file = 'Main_Onshore.fst' # Main file in ref_dir, used as a template
3434
work_dir = '_NREL5MW_Parametric/' # Output folder (will be created)
3535

3636
# --- Defining the parametric study (list of dictionnaries with keys as FAST parameters)
@@ -50,6 +50,12 @@ def ParametricExample():
5050
p['EDFile|BldFile(1)|AdjBlMs'] =1.1
5151
p['EDFile|BldFile(2)|AdjBlMs'] =1.1
5252
p['EDFile|BldFile(3)|AdjBlMs'] =1.1
53+
# # Changing BeamDyn properties
54+
# BP_ref = fBD['BeamProperties']
55+
# BP = BP_ref.copy()
56+
# BP['K']= BP['K']*i
57+
# p['BDBldFile(1)|BldFile|BeamProperties'] =BP
58+
5359

5460
p['EDFile|RotSpeed'] = rpm
5561
p['InflowFile|HWindSpeed'] = wsp

pyFAST/case_generation/examples/Example_PowerCurve_Parametric.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def PowerCurveParametricExample1():
2525
# --- Parameters for this script
2626
FAST_EXE = os.path.join(MyDir, '../../../data/openfast.exe') # Location of a FAST exe (and dll)
2727
ref_dir = os.path.join(MyDir, '../../../data/NREL5MW/') # Folder where the fast input files are located (will be copied)
28-
main_file = 'Main_Onshore_OF2.fst' # Main file in ref_dir, used as a template
28+
main_file = 'Main_Onshore.fst' # Main file in ref_dir, used as a template
2929
work_dir = '_NREL5MW_PowerCurveParametric/' # Output folder (will be created)
3030

3131
# --- Defining the parametric study (list of dictionnaries with keys as FAST parameters)
@@ -84,7 +84,7 @@ def PowerCurveParametricExample2():
8484
# --- Parameters for this script
8585
FAST_EXE = os.path.join(MyDir, '../../../data/openfast.exe') # Location of a FAST exe (and dll)
8686
ref_dir = os.path.join(MyDir, '../../../data/NREL5MW/') # Folder where the fast input files are located (will be copied)
87-
main_file = 'Main_Onshore_OF2.fst' # Main file in ref_dir, used as a template
87+
main_file = 'Main_Onshore_OF.fst' # Main file in ref_dir, used as a template
8888
work_dir = '_NREL5MW_PowerCurveParametric2/' # Output folder (will be created)
8989
out_Ext = '.outb' # Output extension
9090

pyFAST/case_generation/runner.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,33 @@ def run_fast(input_file, fastExe=None, wait=True, showOutputs=False, showCommand
139139
return run_cmd(input_file, fastExe, wait=wait, showOutputs=showOutputs, showCommand=showCommand)
140140

141141

142-
def writeBatch(batchfile, fastfiles, fastExe=None):
142+
def writeBatch(batchfile, fastfiles, fastExe=None, nBatches=1):
143143
""" Write batch file, everything is written relative to the batch file"""
144144
if fastExe is None:
145145
fastExe=FAST_EXE
146146
fastExe_abs = os.path.abspath(fastExe)
147147
batchfile_abs = os.path.abspath(batchfile)
148148
batchdir = os.path.dirname(batchfile_abs)
149149
fastExe_rel = os.path.relpath(fastExe_abs, batchdir)
150-
with open(batchfile,'w') as f:
151-
for ff in fastfiles:
152-
ff_abs = os.path.abspath(ff)
153-
ff_rel = os.path.relpath(ff_abs, batchdir)
154-
l = fastExe_rel + ' '+ ff_rel
155-
f.write("%s\n" % l)
150+
def writeb(batchfile, fastfiles):
151+
with open(batchfile,'w') as f:
152+
for ff in fastfiles:
153+
ff_abs = os.path.abspath(ff)
154+
ff_rel = os.path.relpath(ff_abs, batchdir)
155+
l = fastExe_rel + ' '+ ff_rel
156+
f.write("%s\n" % l)
157+
if nBatches==1:
158+
writeb(batchfile, fastfiles)
159+
else:
160+
splits = np.array_split(fastfiles,nBatches)
161+
base, ext = os.path.splitext(batchfile)
162+
for i in np.arange(nBatches):
163+
writeb(base+'_{:d}'.format(i+1) + ext, splits[i])
164+
165+
166+
167+
168+
156169

157170
def removeFASTOuputs(workDir):
158171
# Cleaning folder

pyFAST/input_output/examples/Example_RadialInterp.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def main():
2121

2222
# --- Define output radial stations
2323
# Option 1 - Get all these locations automatically (recommended)
24-
fstFile = os.path.join(MyDir,'../../../data/NREL5MW/Main_Onshore_OF2.fst') # must correspond to the one used to generate outputs
24+
fstFile = os.path.join(MyDir,'../../../data/NREL5MW/Main_Onshore_OF.fst') # must correspond to the one used to generate outputs
2525
r_AD, r_ED, r_BD, IR_AD, IR_ED, IR_BD, R, r_hub, fst = postpro.FASTRadialOutputs(fstFile, df.columns.values)
2626

2727
# Option 2 - Get ouputs locations for each module

pyFAST/input_output/examples/Example_RadialPostPro.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def main():
2222
# --- Step2 : Average data and extrat the radial stations
2323
# Averaging here is done over 1 period (avgParam=1, avgMethod='periods')
2424
# To get the output radial stations, a .fst file is needed
25-
fstFile = os.path.join(MyDir,'../../../data/NREL5MW/Main_Onshore_OF2.fst')
25+
fstFile = os.path.join(MyDir,'../../../data/NREL5MW/Main_Onshore_OF.fst')
2626
dfRad_ED, dfRad_AD, dfRad_BD = postpro.spanwisePostPro(FST_In=fstFile, avgMethod='periods', avgParam=1, df=df)
2727

2828
# --- Step1&2 at once (when .outb and .fst are next to each other in same folder, with same name)

0 commit comments

Comments
 (0)