Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

hyeye archive

[FLORIS] FlorisInterface 초기화, Run Optimization using the Serial-Refine method 본문

Simulator

[FLORIS] FlorisInterface 초기화, Run Optimization using the Serial-Refine method

hyeye_ 2023. 9. 27. 12:06

터빈 레이아웃 

1X3 터빈 레이아웃

  • wake model : Gauss Curl Hybrid model
  • turbine : NREL 5MW
  • diameter : 126.0 m
  • cut-in / rate / cut-out wind speed : 3 / 11.4 / 25 (m/s)
  • layout_x : [5*D, 10*D, 15*D]
  • layout_y : [500., 500., 500.]

 

바람장 조건

  • 3 <= wind speed <=12 (m/s)
  • 180 <= wind direction <= 360 (deg)

 

결과

 

Code

# import library
import numpy as np
import pandas as pd
import os

import matplotlib.pyplot as plt

from floris.tools import FlorisInterface
from floris.tools.optimization.yaw_optimization.yaw_optimizer_sr import YawOptimizationSR
from floris.tools.visualization import visualize_cut_plane


#%% Initialization
# Initialize FLORIS with the given input file via FlorisInterface.
fi = FlorisInterface("./gch.yaml")

# Convert to a simple three-turbine layout and wind conditions
D = 126.0
wd = np.arange(180.0, 360.0, 5.0)

fi.reinitialize(
        layout_x=[5*D, 10*D, 15*D],
        layout_y=[500., 500., 500.])

# Using the FlorisInterface functions, get 2D slices.
horizontal_plane = fi.calculate_horizontal_plane(x_resolution=200, y_resolution=100, height=90.0)
visualize_cut_plane(horizontal_plane, title="Horizontal")
plt.show()

# Initialize an empty list to store legend labels
legend_labels = []

# Create a single plot for yaw results
fig, axarr = plt.subplots(3, 1, sharex=True, sharey=False, figsize=(8, 8))


#%% Optimization 
# Loop over wind speeds
for ws in range(3, 13):
    fi.reinitialize(
        wind_directions=wd,
        wind_speeds=[ws])

    # Initialize optimizer object and run optimization using the Serial-Refine method
    yaw_opt = YawOptimizationSR(fi)
    df_opt = yaw_opt.optimize()

    print("Optimization results : ")
    print(df_opt)

    # Split out the turbine results
    for t in range(3):
        df_opt['t%d' % t] = df_opt.yaw_angles_opt.apply(lambda x: x[t])

    # Add the legend label for this wind speed
    legend_labels.append(f'WS={ws} m/s')

    # Plot yaw offset for T1
    ax1 = axarr[0]
    ax1.plot(df_opt.wind_direction, df_opt['t0'], label='WS={ws} m/s'.format(ws=ws))
    ax1.set_title('T0')
    ax1.legend(legend_labels)
    ax1.grid(True)

    # Plot yaw offset for T2
    ax2 = axarr[1]
    ax2.plot(df_opt.wind_direction, df_opt['t1'], label='WS={ws} m/s'.format(ws=ws))
    ax2.set_title('T1')
    ax2.set_ylabel('Yaw Offset (deg)')
    ax2.grid(True)

    # Plot yaw offset for T3
    ax3 = axarr[2]
    ax3.plot(df_opt.wind_direction, df_opt['t2'], label='WS={ws} m/s'.format(ws=ws))
    ax3.set_title('T2')
    ax3.set_xlabel('Wind Direction (deg)')
    ax3.grid(True)

    # save result
    df_yaw_t0 = pd.DataFrame([df_opt['t0']]).T
    df_yaw_t1 = pd.DataFrame([df_opt['t1']]).T
    df_yaw_t2 = pd.DataFrame([df_opt['t2']]).T
    df_wd = pd.DataFrame([wd]).T

    data = pd.concat([df_wd, df_yaw_t0, df_yaw_t1, df_yaw_t2], axis=1)
    data.columns = ['WD', 'yaw_T0', 'yaw_T1', 'yaw_T2']
    data.to_csv('./result/{ws}_ms.csv'.format(ws=ws), header=True, index=False)

    # save control region
    any_nonzero_yaw = (data[['yaw_T0','yaw_T1','yaw_T2']] != 0).any(axis=1)

    if any_nonzero_yaw.any():
        data_nonzero = data[any_nonzero_yaw]

    data_nonzero['ws'] = ws

    data_nonzero.columns = ['WD', 'yaw_TO', 'yaw_T1', 'yaw_T2', 'WS']

    if not os.path.isfile('./result/control_region.csv'):
        data_nonzero.to_csv('./result/control_region.csv', mode='a', header=True, index=False)
    else:
        data_nonzero.to_csv('./result/control_region.csv', mode='a', header=False, index=False)

# Show the results
plt.show()