Exemplo n.º 1
0
def writeFastFarm(outputFile,
                  templateFile,
                  xWT,
                  yWT,
                  zWT,
                  FFTS=None,
                  OutListT1=None):
    """ Write FastFarm input file based on a template, a TurbSimFile and the Layout
    
    outputFile: .fstf file to be written
    templateFile: .fstf file that will be used to generate the output_file
    XWT,YWT,ZWT: positions of turbines
    FFTS: FastFarm TurbSim parameters as returned by fastFarmTurbSimExtent
    """
    # --- Read template fast farm file
    fst = weio.FASTInputFile(templateFile)
    # --- Replace box extent values
    if FFTS is not None:
        fst['Mod_AmbWind'] = 2
        for k in [
                'DT', 'DT_High', 'NX_Low', 'NY_Low', 'NZ_Low', 'X0_Low',
                'Y0_Low', 'Z0_Low', 'dX_Low', 'dY_Low', 'dZ_Low', 'NX_High',
                'NY_High', 'NZ_High'
        ]:
            if isinstance(FFTS[k], int):
                fst[k] = FFTS[k]
            else:
                fst[k] = np.around(FFTS[k], 3)
        fst['WrDisDT'] = FFTS['DT']

    # --- Set turbine names, position, and box extent
    nWT = len(xWT)
    fst['NumTurbines'] = nWT
    if FFTS is not None:
        nCol = 10
    else:
        nCol = 4
    ref_path = fst['WindTurbines'][0, 3]
    WT = np.array([''] * nWT * nCol, dtype='object').reshape((nWT, nCol))
    for iWT, (x, y, z) in enumerate(zip(xWT, yWT, zWT)):
        WT[iWT, 0] = x
        WT[iWT, 1] = y
        WT[iWT, 2] = z
        WT[iWT, 3] = insertTN(ref_path, iWT + 1, nWT)
        if FFTS is not None:
            WT[iWT, 4] = FFTS['X0_High'][iWT]
            WT[iWT, 5] = FFTS['Y0_High'][iWT]
            WT[iWT, 6] = FFTS['Z0_High']
            WT[iWT, 7] = FFTS['dX_High']
            WT[iWT, 8] = FFTS['dY_High']
            WT[iWT, 9] = FFTS['dZ_High']
    fst['WindTurbines'] = WT

    fst.write(outputFile)
    if OutListT1 is not None:
        setFastFarmOutputs(outputFile, OutListT1)
Exemplo n.º 2
0
def plotFastFarmSetup(fastFarmFile):
    """ """
    import matplotlib.pyplot as plt
    fst = weio.FASTInputFile(fastFarmFile)

    fig = plt.figure(figsize=(13.5, 10))
    ax = fig.add_subplot(111, aspect="equal")

    WT = fst['WindTurbines']
    x = WT[:, 0].astype(float)
    y = WT[:, 1].astype(float)

    if fst['Mod_AmbWind'] == 2:
        xmax_low = fst['X0_Low'] + fst['DX_Low'] * fst['NX_Low']
        ymax_low = fst['Y0_Low'] + fst['DY_Low'] * fst['NY_Low']
        # low-res box
        ax.plot(
            [fst['X0_Low'], xmax_low, xmax_low, fst['X0_Low'], fst['X0_Low']],
            [fst['Y0_Low'], fst['Y0_Low'], ymax_low, ymax_low, fst['Y0_Low']],
            '--k',
            lw=2,
            label='Low')
        X0_High = WT[:, 4].astype(float)
        Y0_High = WT[:, 5].astype(float)
        dX_High = WT[:, 7].astype(float)[0]
        dY_High = WT[:, 8].astype(float)[0]
        nX_High = fst['NX_High']
        nY_High = fst['NY_High']
        # high-res boxes
        for wt in range(len(x)):
            xmax_high = X0_High[wt] + dX_High * nX_High
            ymax_high = Y0_High[wt] + dY_High * nY_High
            ax.plot(
                [X0_High[wt], xmax_high, xmax_high, X0_High[wt], X0_High[wt]],
                [Y0_High[wt], Y0_High[wt], ymax_high, ymax_high, Y0_High[wt]],
                '-',
                label="HighT{0}".format(wt + 1))
            ax.plot(x[wt],
                    y[wt],
                    'x',
                    ms=8,
                    mew=2,
                    label="WT{0}".format(wt + 1))
    else:
        for wt in range(len(x)):
            ax.plot(x[wt],
                    y[wt],
                    'x',
                    ms=8,
                    mew=2,
                    label="WT{0}".format(wt + 1))
        #
    plt.legend(bbox_to_anchor=(1.05, 1.015), frameon=False)
    ax.set_xlabel("x-location [m]")
    ax.set_ylabel("y-location [m]")
    fig.tight_layout
Exemplo n.º 3
0
def spanwisePostProFF(fastfarm_input,
                      avgMethod='constantwindow',
                      avgParam=30,
                      D=1,
                      df=None,
                      fastfarm_out=None):
    """ 
    Opens a FASTFarm output file, extract the radial data, average them and returns spanwise data

    D: diameter TODO, extract it from the main file

    See faslibt.averageDF for `avgMethod` and `avgParam`.
    """
    # --- Opening ouputfile
    if df is None:
        df = weio.read(fastfarm_out).toDataFrame()

    # --- Opening input file and extracting inportant variables
    if fastfarm_input is None:
        # We don't have an input file, guess numbers of turbine, diameters, Nodes...
        cols, sIdx = fastlib.find_matching_pattern(df.columns.values, 'T(\d+)')
        nWT = np.array(sIdx).astype(int).max()
        cols, sIdx = fastlib.find_matching_pattern(df.columns.values, 'D(\d+)')
        nD = np.array(sIdx).astype(int).max()
        cols, sIdx = fastlib.find_matching_pattern(df.columns.values, 'N(\d+)')
        nr = np.array(sIdx).astype(int).max()
        vr = None
        vD = None
        D = 0
    else:
        main = weio.FASTInputFile(fastfarm_input)
        iOut = main['OutRadii']
        dr = main[
            'dr']  # Radial increment of radial finite-difference grid (m)
        OutDist = main[
            'OutDist']  # List of downstream distances for wake output for an individual rotor
        WT = main['WindTurbines']
        nWT = len(WT)
        vr = dr * np.array(iOut)
        vD = np.array(OutDist)
        nr = len(iOut)
        nD = len(vD)

    # --- Extracting time series of radial data only
    colRadial = SensorsFARMRadial(nWT=nWT,
                                  nD=nD,
                                  nR=nr,
                                  signals=df.columns.values)
    colRadial = ['Time_[s]'] + colRadial
    dfRadialTime = df[
        colRadial]  # TODO try to do some magic with it, display it with a slider

    # --- Averaging data
    dfAvg = fastlib.averageDF(df, avgMethod=avgMethod, avgParam=avgParam)

    # --- Extract radial data
    ColsInfo, nrMax = spanwiseColFastFarm(df.columns.values, nWT=nWT, nD=nD)
    dfRad = fastlib.extract_spanwise_data(ColsInfo,
                                          nrMax,
                                          df=None,
                                          ts=dfAvg.iloc[0])
    #dfRad       = fastlib.insert_radial_columns(dfRad, vr)
    if vr is None:
        dfRad.insert(0, 'i_[#]', np.arange(nrMax) + 1)
    else:
        dfRad.insert(0, 'r_[m]', vr[:nrMax])
    dfRad['i/n_[-]'] = np.arange(nrMax) / nrMax

    # --- Extract downstream data
    ColsInfo, nDMax = diameterwiseColFastFarm(df.columns.values, nWT=nWT)
    dfDiam = fastlib.extract_spanwise_data(ColsInfo,
                                           nDMax,
                                           df=None,
                                           ts=dfAvg.iloc[0])
    #dfDiam      = fastlib.insert_radial_columns(dfDiam)
    if vD is None:
        dfDiam.insert(0, 'i_[#]', np.arange(nDMax) + 1)
    else:
        dfDiam.insert(0, 'x_[m]', vD[:nDMax])
    dfDiam['i/n_[-]'] = np.arange(nDMax) / nDMax
    return dfRad, dfRadialTime, dfDiam
Exemplo n.º 4
0
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Local
import weio

from welib.FEM.graph import *
from welib.tools.clean_exceptions import *
# import welib.FEM.fem_model as fem

if __name__ == '__main__':
    filename = '../../data/Monopile/MT100_HD.dat'
    filename = '../../data/Monopile/TetraSpar_HydroDyn_v2.dat'

    hd = weio.FASTInputFile(filename)
    hd.write('Out.dat')

    Graph = hd.toGraph(hd)

    Graph.divideElements(3)

    print(Graph)

    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib import collections as mc
    from mpl_toolkits.mplot3d import Axes3D
    fig = plt.figure()
    ax = fig.add_subplot(1, 2, 1, projection='3d')
    lines = Graph.toLines(output='coord')
    for l in lines: