|
| 1 | +import numpy as np |
| 2 | +import os |
| 3 | + |
| 4 | +import pyFAST.case_generation.case_gen as case_gen |
| 5 | +import pyFAST.case_generation.runner as case_gen |
| 6 | +import pyFAST.input_output.postpro as postpro |
| 7 | + |
| 8 | +# Get current directory so this script can be called from any location |
| 9 | +MyDir=os.path.dirname(__file__) |
| 10 | + |
| 11 | +def PowerCurveParametricExample1(): |
| 12 | + """ Example to run a set of FAST simulations to determine a power curve. |
| 13 | + In this example, the WS, RPM and Pitch are set within a for loop. |
| 14 | + If the controller and generator are active, these are just "initial conditions". |
| 15 | + Additional parameters may be set by adjusting the BaseDict. |
| 16 | +
|
| 17 | + This script is based on a reference directory which contains a reference main input file (.fst) |
| 18 | + Everything is copied to a working directory. |
| 19 | + The different fast inputs are generated based on a list of dictionaries, named `PARAMS`. |
| 20 | + For each dictionary: |
| 21 | + - they keys are "path" to a input parameter, e.g. `EDFile|RotSpeed` or `TMax`. |
| 22 | + These should correspond to whater name of the variable is used in the FAST inputs files. |
| 23 | + - they values are the values corresponding to this parameter |
| 24 | + """ |
| 25 | + # --- Parameters for this script |
| 26 | + FAST_EXE = os.path.join(MyDir, '../../../data/openfast.exe') # Location of a FAST exe (and dll) |
| 27 | + 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 |
| 29 | + work_dir = '_NREL5MW_PowerCurveParametric/' # Output folder (will be created) |
| 30 | + |
| 31 | + # --- Defining the parametric study (list of dictionnaries with keys as FAST parameters) |
| 32 | + WS = [3,5,7,9 ,11,13,15] |
| 33 | + RPM = [5,6,7,10,10,10,10] # initial conditions |
| 34 | + PITCH = [0,0,0,0 ,5 ,10,15] # initial conditions |
| 35 | + BaseDict = {'TMax': 100, 'DT': 0.01, 'DT_Out': 0.1} |
| 36 | + #BaseDict = case_gen.paramsNoController(BaseDict) |
| 37 | + #BaseDict = case_gen.paramsStiff(BaseDict) |
| 38 | + #BaseDict = case_gen.paramsNoGen(BaseDict) |
| 39 | + PARAMS=[] |
| 40 | + for wsp,rpm,pitch in zip(WS,RPM,PITCH): # NOTE: same length of WS and RPM otherwise do multiple for loops |
| 41 | + p=BaseDict.copy() |
| 42 | + p['EDFile|RotSpeed'] = rpm |
| 43 | + p['EDFile|BlPitch(1)'] = pitch |
| 44 | + p['EDFile|BlPitch(2)'] = pitch |
| 45 | + p['EDFile|BlPitch(3)'] = pitch |
| 46 | + p['InflowFile|HWindSpeed'] = wsp |
| 47 | + p['InflowFile|WindType'] = 1 # Setting steady wind |
| 48 | + p['__name__'] = 'ws{:04.1f}'.format(p['InflowFile|HWindSpeed']) |
| 49 | + PARAMS.append(p) |
| 50 | + |
| 51 | + # --- Generating all files in a workdir |
| 52 | + fastFiles=case_gen.templateReplace(PARAMS, ref_dir, work_dir, removeRefSubFiles=True, main_file=main_file) |
| 53 | + print(fastFiles) |
| 54 | + |
| 55 | + # --- Creating a batch script just in case |
| 56 | + runner.writeBatch(os.path.join(work_dir,'_RUN_ALL.bat'), fastFiles,fastExe=FAST_EXE) |
| 57 | + # --- Running the simulations |
| 58 | + print('>>> Running {} simulations in {} ...'.format(len(fastFiles), work_dir)) |
| 59 | + runner.run_fastfiles(fastFiles, fastExe=FAST_EXE, parallel=True, showOutputs=False, nCores=2) |
| 60 | + |
| 61 | + # --- Simple Postprocessing |
| 62 | + outFiles = [os.path.splitext(f)[0]+'.outb' for f in fastFiles] |
| 63 | + |
| 64 | + avg_results = postpro.averagePostPro(outFiles,avgMethod='constantwindow',avgParam=10, ColMap = {'WS_[m/s]':'Wind1VelX_[m/s]'},ColSort='WS_[m/s]') |
| 65 | + print('>>> Average results:') |
| 66 | + print(avg_results) |
| 67 | + avg_results.to_csv('_PowerCurve1.csv',sep='\t',index=False) |
| 68 | + |
| 69 | + |
| 70 | +def PowerCurveParametricExample2(): |
| 71 | + """ Example to run a set of FAST simulations to determine a power curve. |
| 72 | + In this example, the WS, RPM and Pitch are set within a for loop. |
| 73 | + If the controller and generator are active, these are just "initial conditions". |
| 74 | + Additional parameters may be set by adjusting the BaseDict. |
| 75 | +
|
| 76 | + This script is based on a reference directory which contains a reference main input file (.fst) |
| 77 | + Everything is copied to a working directory. |
| 78 | + The different fast inputs are generated based on a list of dictionaries, named `PARAMS`. |
| 79 | + For each dictionary: |
| 80 | + - they keys are "path" to a input parameter, e.g. `EDFile|RotSpeed` or `TMax`. |
| 81 | + These should correspond to whater name of the variable is used in the FAST inputs files. |
| 82 | + - they values are the values corresponding to this parameter |
| 83 | + """ |
| 84 | + # --- Parameters for this script |
| 85 | + FAST_EXE = os.path.join(MyDir, '../../../data/openfast.exe') # Location of a FAST exe (and dll) |
| 86 | + 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 |
| 88 | + work_dir = '_NREL5MW_PowerCurveParametric2/' # Output folder (will be created) |
| 89 | + out_Ext = '.outb' # Output extension |
| 90 | + |
| 91 | + # --- Defining the parametric study (list of dictionnaries with keys as FAST parameters) |
| 92 | + WS = [3,5,7,9 ,11,13,15] |
| 93 | + RPM = [5,6,7,10,10,10,10] |
| 94 | + PITCH = [0,0,0,0 ,5 ,10,15] |
| 95 | + BaseDict = {'TMax': 10, 'DT': 0.01, 'DT_Out': 0.1} |
| 96 | + PARAMS = case_gen.paramsWS_RPM_Pitch(WS, RPM, PITCH, baseDict=BaseDict, flatInputs=True) |
| 97 | + |
| 98 | + # --- Generating all files in a workdir |
| 99 | + fastFiles = case_gen.templateReplace(PARAMS, ref_dir, work_dir, removeRefSubFiles=True, removeAllowed=True, main_file=main_file) |
| 100 | + |
| 101 | + # --- Creating a batch script just in case |
| 102 | + runner.writeBatch(os.path.join(work_dir,'_RUN_ALL.bat'), fastFiles,fastExe=FAST_EXE) |
| 103 | + |
| 104 | + # --- Running the simulations |
| 105 | + runner.run_fastfiles(fastFiles, fastExe=FAST_EXE, parallel=True, showOutputs=False, nCores=2) |
| 106 | + |
| 107 | + # --- Simple Postprocessing |
| 108 | + outFiles = [os.path.splitext(f)[0]+out_Ext for f in fastFiles] |
| 109 | + avg_results = postpro.averagePostPro(outFiles,avgMethod='constantwindow',avgParam=10, ColMap = {'WS_[m/s]':'Wind1VelX_[m/s]'},ColSort='WS_[m/s]') |
| 110 | + print('>>> Average results:') |
| 111 | + print(avg_results) |
| 112 | + avg_results.to_csv('_PowerCurve2.csv',sep='\t',index=False) |
| 113 | + |
| 114 | + |
| 115 | + |
| 116 | +if __name__=='__main__': |
| 117 | + PowerCurveParametricExample1() |
| 118 | + PowerCurveParametricExample2() |
| 119 | + |
| 120 | +if __name__=='__test__': |
| 121 | + # Need openfast.exe, doing nothin |
| 122 | + pass |
| 123 | + |
0 commit comments