Пример #1
0
def PowerCurveParametricExample1():
    """ Example to run a set of FAST simulations to determine a power curve.
    In this example, the WS, RPM and Pitch are set within a for loop.
    If the controller and generator are active, these are just "initial conditions".
    Additional parameters may be set by adjusting the BaseDict.

    This script is based on a reference directory which contains a reference main input file (.fst)
    Everything is copied to a working directory.
    The different fast inputs are generated based on a list of dictionaries, named `PARAMS`.
    For each dictionary:
       - they keys are "path" to a input parameter, e.g. `EDFile|RotSpeed`  or `TMax`.
           These should correspond to whater name of the variable is used in the FAST inputs files.
       - they values are the values corresponding to this parameter
    """
    # --- Parameters for this script
    FAST_EXE  = os.path.join(MyDir, '../../../data/openfast.exe') # Location of a FAST exe (and dll)
    ref_dir   = os.path.join(MyDir, '../../../data/NREL5MW/')     # Folder where the fast input files are located (will be copied)
    main_file = 'Main_Onshore_OF2.fst'               # Main file in ref_dir, used as a template
    work_dir  = '_NREL5MW_PowerCurveParametric/'     # Output folder (will be created)

    # --- Defining the parametric study  (list of dictionnaries with keys as FAST parameters)
    WS    = [3,5,7,9 ,11,13,15]
    RPM   = [5,6,7,10,10,10,10] # initial conditions
    PITCH = [0,0,0,0 ,5 ,10,15] # initial conditions
    BaseDict = {'TMax': 100, 'DT': 0.01, 'DT_Out': 0.1}
    #BaseDict = case_gen.paramsNoController(BaseDict)
    #BaseDict = case_gen.paramsStiff(BaseDict)
    #BaseDict = case_gen.paramsNoGen(BaseDict)
    PARAMS=[]
    for wsp,rpm,pitch in zip(WS,RPM,PITCH): # NOTE: same length of WS and RPM otherwise do multiple for loops
        p=BaseDict.copy()
        p['EDFile|RotSpeed']       = rpm
        p['EDFile|BlPitch(1)']     = pitch
        p['EDFile|BlPitch(2)']     = pitch
        p['EDFile|BlPitch(3)']     = pitch
        p['InflowFile|HWindSpeed'] = wsp
        p['InflowFile|WindType']   = 1 # Setting steady wind
        p['__name__']              = 'ws{:04.1f}'.format(p['InflowFile|HWindSpeed'])
        PARAMS.append(p)

    # --- Generating all files in a workdir
    fastFiles=case_gen.templateReplace(PARAMS, ref_dir, work_dir, removeRefSubFiles=True, main_file=main_file)
    print(fastFiles)

    # --- Creating a batch script just in case
    runner.writeBatch(os.path.join(work_dir,'_RUN_ALL.bat'), fastFiles,fastExe=FAST_EXE)
    # --- Running the simulations
    print('>>> Running {} simulations in {} ...'.format(len(fastFiles), work_dir))
    runner.run_fastfiles(fastFiles, fastExe=FAST_EXE, parallel=True, showOutputs=False, nCores=2)

    # --- Simple Postprocessing
    outFiles = [os.path.splitext(f)[0]+'.outb' for f in fastFiles]

    avg_results = postpro.averagePostPro(outFiles,avgMethod='constantwindow',avgParam=10, ColMap = {'WS_[m/s]':'Wind1VelX_[m/s]'},ColSort='WS_[m/s]')
    print('>>> Average results:')
    print(avg_results)
    avg_results.to_csv('_PowerCurve1.csv',sep='\t',index=False)
Пример #2
0
def main():
    # --- Main Parameters
    ref_dir = os.path.join(
        MyDir, '../../../data/NREL5MW/'
    )  # Folder where the fast input files are located (will be copied)
    FAST_EXE = os.path.join(
        MyDir,
        '../../../data/openfast.exe')  # Location of a FAST exe (and dll)
    main_file = 'Main_Onshore_OF2.fst'  # Main file in ref_dir, used as a template
    work_dir = '_NREL5MW_ParametricExcel/'  # Output folder (will be created)
    parametricFile = 'ParametricExcel.xlsx'  # Excel file containing set of parameters

    # --- Reading Excel file, converting it to a list of dictionaries, and generate input files
    dfs = io.excel_file.ExcelFile(parametricFile).toDataFrame()
    df = dfs[list(dfs.keys())[0]]
    PARAMS = df.to_dict('records')
    print(df)
    fastFiles = case_gen.templateReplace(PARAMS,
                                         ref_dir,
                                         outputDir=work_dir,
                                         removeRefSubFiles=True,
                                         removeAllowed=False,
                                         main_file=main_file)

    # --- Running fast simulations
    print('>>> Running {} simulations in {} ...'.format(
        len(fastFiles), work_dir))
    runner.writeBatch(os.path.join(work_dir, '_RUN_ALL.bat'),
                      fastFiles,
                      fastExe=FAST_EXE)
    runner.run_fastfiles(fastFiles,
                         showOutputs=False,
                         fastExe=FAST_EXE,
                         nCores=4)

    # --- Postpro - Computing averages at the end of the simluation
    print('>>> Postprocessing...')
    outFiles = [os.path.splitext(f)[0] + '.outb' for f in fastFiles]
    ColKeepStats = [
        'RotSpeed_[rpm]', 'BldPitch1_[deg]', 'RtAeroCp_[-]', 'RtAeroCt_[-]',
        'Wind1VelX_[m/s]'
    ]
    result = postpro.averagePostPro(outFiles,
                                    avgMethod='constantwindow',
                                    avgParam=5,
                                    ColKeep=ColKeepStats,
                                    ColSort='RotSpeed_[rpm]')
    result.to_csv('ParametricExcel_Summary.csv', sep='\t', index=False)
    print('Average values saved to _ParametricExcel_Summary.csv')
Пример #3
0
def PowerCurveParametricExample2():
    """ Example to run a set of FAST simulations to determine a power curve.
    In this example, the WS, RPM and Pitch are set within a for loop.
    If the controller and generator are active, these are just "initial conditions".
    Additional parameters may be set by adjusting the BaseDict.

    This script is based on a reference directory which contains a reference main input file (.fst)
    Everything is copied to a working directory.
    The different fast inputs are generated based on a list of dictionaries, named `PARAMS`.
    For each dictionary:
       - they keys are "path" to a input parameter, e.g. `EDFile|RotSpeed`  or `TMax`.
           These should correspond to whater name of the variable is used in the FAST inputs files.
       - they values are the values corresponding to this parameter
    """
    # --- Parameters for this script
    FAST_EXE  = os.path.join(MyDir, '../../../data/openfast.exe') # Location of a FAST exe (and dll)
    ref_dir   = os.path.join(MyDir, '../../../data/NREL5MW/')     # Folder where the fast input files are located (will be copied)
    main_file = 'Main_Onshore_OF2.fst'                # Main file in ref_dir, used as a template
    work_dir  = '_NREL5MW_PowerCurveParametric2/'     # Output folder (will be created)
    out_Ext   = '.outb' # Output extension

    # --- Defining the parametric study  (list of dictionnaries with keys as FAST parameters)
    WS    = [3,5,7,9 ,11,13,15]
    RPM   = [5,6,7,10,10,10,10] 
    PITCH = [0,0,0,0 ,5 ,10,15] 
    BaseDict = {'TMax': 10, 'DT': 0.01, 'DT_Out': 0.1}
    PARAMS = case_gen.paramsWS_RPM_Pitch(WS, RPM, PITCH, baseDict=BaseDict, flatInputs=True)

    # --- Generating all files in a workdir
    fastFiles = case_gen.templateReplace(PARAMS, ref_dir, work_dir, removeRefSubFiles=True, removeAllowed=True, main_file=main_file)

    # --- Creating a batch script just in case
    runner.writeBatch(os.path.join(work_dir,'_RUN_ALL.bat'), fastFiles,fastExe=FAST_EXE)

    # --- Running the simulations
    runner.run_fastfiles(fastFiles, fastExe=FAST_EXE, parallel=True, showOutputs=False, nCores=2)

    # --- Simple Postprocessing
    outFiles = [os.path.splitext(f)[0]+out_Ext for f in fastFiles]
    avg_results = postpro.averagePostPro(outFiles,avgMethod='constantwindow',avgParam=10, ColMap = {'WS_[m/s]':'Wind1VelX_[m/s]'},ColSort='WS_[m/s]')
    print('>>> Average results:')
    print(avg_results)
    avg_results.to_csv('_PowerCurve2.csv',sep='\t',index=False)
Пример #4
0
def ParametricExample():
    """ Example to run a set of OpenFAST simulations (parametric study)

    This script uses a reference directory (`ref_dir`) which contains a reference input file (.fst)
    1) The reference directory is copied to a working directory (`out_dir`).
    2) All the fast input files are generated in this directory based on a list of dictionaries (`PARAMS`).
    For each dictionary in this list:
       - The keys are "path" to a input parameter, e.g. `EDFile|RotSpeed`  or `FAST|TMax`.
         These should correspond to the variables used in the FAST inputs files.
       - The values are the values corresponding to this parameter
    For instance:
         PARAMS[0]['DT']                    = 0.01
         PARAMS[0]['EDFile|RotSpeed']       = 5
         PARAMS[0]['InflowFile|HWindSpeed'] = 10

    3) The simulations are run, successively distributed on `nCores` CPUs.
    4) The output files are read, and averaged based on a method (e.g. average over a set of periods,
        see averagePostPro in postpro for the different averaging methods).
       A pandas DataFrame is returned

    """
    # --- Parameters for this script
    ref_dir = 'NREL5MW/'  # Folder where the fast input files are located (will be copied)
    out_dir = 'NREL5MW_Parametric/'  # Output folder (will be created)
    main_file = 'Main_Onshore_OF2.fst'  # Main file in ref_dir, used as a template
    FAST_EXE = 'openfast2.3_x64s.exe'  # Location of a FAST exe (and dll)

    # --- Defining the parametric study  (list of dictionnaries with keys as FAST parameters)
    WS = [3, 5, 6, 7]
    RPM = [10, 12, 13, 15]
    BaseDict = {'TMax': 10, 'DT': 0.01, 'DT_Out': 0.1}
    BaseDict = case_gen.paramsNoController(BaseDict)  # Remove the controller
    #BaseDict = case_gen.paramsControllerDLL(BaseDict) # Activate the controller
    #BaseDict = case_gen.paramsStiff(BaseDict)         # Make the turbine stiff (except generator)
    #BaseDict = case_gen.paramsNoGen(BaseDict)         # Remove the Generator DOF
    PARAMS = []
    for i, (wsp, rpm) in enumerate(
            zip(WS, RPM)
    ):  # NOTE: same length of WS and RPM otherwise do multiple for loops
        p = BaseDict.copy()
        #p['AeroFile|TwrAero']       = True
        #p['EDFile|BldFile(1)|AdjBlMs'] =1.1
        #p['EDFile|BldFile(2)|AdjBlMs'] =1.1
        #p['EDFile|BldFile(3)|AdjBlMs'] =1.1
        p['EDFile|RotSpeed'] = rpm
        p['InflowFile|HWindSpeed'] = wsp
        p['InflowFile|WindType'] = 1  # Setting steady wind
        p['__name__'] = '{:03d}_ws{:04.1f}_om{:04.2f}'.format(
            i, p['InflowFile|HWindSpeed'], p['EDFile|RotSpeed'])
        PARAMS.append(p)
        i = i + 1
    # --- Generating all files in a output directory
    fastfiles = case_gen.templateReplace(PARAMS,
                                         ref_dir,
                                         outputDir=out_dir,
                                         removeRefSubFiles=True,
                                         main_file=main_file,
                                         oneSimPerDir=False)
    print(fastfiles)

    # --- Creating a batch script just in case
    runner.writeBatch(os.path.join(out_dir, '_RUN_ALL.bat'),
                      fastfiles,
                      fastExe=FAST_EXE)
    # --- Running the simulations
    runner.run_fastfiles(fastfiles,
                         fastExe=FAST_EXE,
                         parallel=True,
                         showOutputs=False,
                         nCores=4)

    # --- Simple Postprocessing
    # (averaging each signal over the last period for each simulation)
    outFiles = [os.path.splitext(f)[0] + '.outb' for f in fastfiles]
    avg_results = postpro.averagePostPro(
        outFiles,
        avgMethod='periods',
        avgParam=1,
        ColMap={'WS_[m/s]': 'Wind1VelX_[m/s]'},
        ColSort='WS_[m/s]')
    avg_results.drop('Time_[s]', axis=1, inplace=True)
    print(avg_results)
    return avg_results