Skip to content

Commit

Permalink
Update example nomenclature
Browse files Browse the repository at this point in the history
  • Loading branch information
paulf81 committed Mar 9, 2024
1 parent 485e407 commit ab399a7
Show file tree
Hide file tree
Showing 33 changed files with 408 additions and 406 deletions.
14 changes: 7 additions & 7 deletions examples/05_sweep_wind_speeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import matplotlib.pyplot as plt
import numpy as np

from floris.tools import FlorisInterface
from floris.tools import FlorisModel


"""
Expand All @@ -16,19 +16,19 @@


# Instantiate FLORIS using either the GCH or CC model
fi = FlorisInterface("inputs/gch.yaml") # GCH model matched to the default "legacy_gauss" of V2
fmodel = FlorisModel("inputs/gch.yaml") # GCH model matched to the default "legacy_gauss" of V2

# Define a two turbine farm
D = 126.
layout_x = np.array([0, D*6])
layout_y = [0, 0]
fi.set(layout_x=layout_x, layout_y=layout_y)
fmodel.set(layout_x=layout_x, layout_y=layout_y)

# Sweep wind speeds but keep wind direction fixed
ws_array = np.arange(5,25,0.5)
wd_array = 270.0 * np.ones_like(ws_array)
ti_array = 0.06 * np.ones_like(ws_array)
fi.set(wind_directions=wd_array,wind_speeds=ws_array, turbulence_intensities=ti_array)
fmodel.set(wind_directions=wd_array,wind_speeds=ws_array, turbulence_intensities=ti_array)

# Define a matrix of yaw angles to be all 0
# Note that yaw angles is now specified as a matrix whose dimensions are
Expand All @@ -38,13 +38,13 @@
n_findex = num_wd # Could be either num_wd or num_ws
num_turbine = len(layout_x)
yaw_angles = np.zeros((n_findex, num_turbine))
fi.set(yaw_angles=yaw_angles)
fmodel.set(yaw_angles=yaw_angles)

# Calculate
fi.run()
fmodel.run()

# Collect the turbine powers
turbine_powers = fi.get_turbine_powers() / 1E3 # In kW
turbine_powers = fmodel.get_turbine_powers() / 1E3 # In kW

# Pull out the power values per turbine
pow_t0 = turbine_powers[:,0].flatten()
Expand Down
16 changes: 8 additions & 8 deletions examples/06_sweep_wind_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import matplotlib.pyplot as plt
import numpy as np

from floris.tools import FlorisInterface
from floris.tools import FlorisModel


"""
Expand All @@ -20,14 +20,14 @@
"""

# Instantiate FLORIS using either the GCH or CC model
fi = FlorisInterface("inputs/gch.yaml") # GCH model matched to the default "legacy_gauss" of V2
# fi = FlorisInterface("inputs/cc.yaml") # New CumulativeCurl model
fmodel = FlorisModel("inputs/gch.yaml") # GCH model matched to the default "legacy_gauss" of V2
# fmodel = FlorisModel("inputs/cc.yaml") # New CumulativeCurl model

# Define a 5 turbine farm
D = 126.0
layout_x = np.array([0, D*6, D*12, D*18, D*24])
layout_y = [0, 0, 0, 0, 0]
fi.set(layout_x=layout_x, layout_y=layout_y)
fmodel.set(layout_x=layout_x, layout_y=layout_y)

# In this case we want to check a grid of wind speed and direction combinations
wind_speeds_to_expand = np.arange(6, 9, 1.0)
Expand All @@ -47,7 +47,7 @@
turbulence_intensities = 0.06 * np.ones_like(wd_array)

# Now reinitialize FLORIS
fi.set(
fmodel.set(
wind_speeds=ws_array,
wind_directions=wd_array,
turbulence_intensities=turbulence_intensities
Expand All @@ -61,13 +61,13 @@
n_findex = num_wd # Could be either num_wd or num_ws
num_turbine = len(layout_x)
yaw_angles = np.zeros((n_findex, num_turbine))
fi.set(yaw_angles=yaw_angles)
fmodel.set(yaw_angles=yaw_angles)

# Calculate
fi.run()
fmodel.run()

# Collect the turbine powers
turbine_powers = fi.get_turbine_powers() / 1e3 # In kW
turbine_powers = fmodel.get_turbine_powers() / 1e3 # In kW

# Show results by ws and wd
fig, axarr = plt.subplots(num_unique_ws, 1, sharex=True, sharey=True, figsize=(6, 10))
Expand Down
18 changes: 9 additions & 9 deletions examples/09_compare_farm_power_with_neighbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import matplotlib.pyplot as plt
import numpy as np

from floris.tools import FlorisInterface
from floris.tools import FlorisModel


"""
Expand All @@ -18,45 +18,45 @@


# Instantiate FLORIS using either the GCH or CC model
fi = FlorisInterface("inputs/gch.yaml") # GCH model matched to the default "legacy_gauss" of V2
fmodel = FlorisModel("inputs/gch.yaml") # GCH model matched to the default "legacy_gauss" of V2

# Define a 4 turbine farm turbine farm
D = 126.
layout_x = np.array([0, D*6, 0, D*6])
layout_y = [0, 0, D*3, D*3]
fi.set(layout_x=layout_x, layout_y=layout_y)
fmodel.set(layout_x=layout_x, layout_y=layout_y)

# Define a simple wind rose with just 1 wind speed
wd_array = np.arange(0,360,4.)
ws_array = 8.0 * np.ones_like(wd_array)
turbulence_intensities = 0.06 * np.ones_like(wd_array)
fi.set(
fmodel.set(
wind_directions=wd_array,
wind_speeds=ws_array,
turbulence_intensities=turbulence_intensities
)


# Calculate
fi.run()
fmodel.run()

# Collect the farm power
farm_power_base = fi.get_farm_power() / 1E3 # In kW
farm_power_base = fmodel.get_farm_power() / 1E3 # In kW

# Add a neighbor to the east
layout_x = np.array([0, D*6, 0, D*6, D*12, D*15, D*12, D*15])
layout_y = np.array([0, 0, D*3, D*3, 0, 0, D*3, D*3])
fi.set(layout_x=layout_x, layout_y=layout_y)
fmodel.set(layout_x=layout_x, layout_y=layout_y)

# Define the weights to exclude the neighboring farm from calcuations of power
turbine_weights = np.zeros(len(layout_x), dtype=int)
turbine_weights[0:4] = 1.0

# Calculate
fi.run()
fmodel.run()

# Collect the farm power with the neightbor
farm_power_neighbor = fi.get_farm_power(turbine_weights=turbine_weights) / 1E3 # In kW
farm_power_neighbor = fmodel.get_farm_power(turbine_weights=turbine_weights) / 1E3 # In kW

# Show the farms
fig, ax = plt.subplots()
Expand Down
12 changes: 6 additions & 6 deletions examples/10_opt_yaw_single_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import matplotlib.pyplot as plt
import numpy as np

from floris.tools import FlorisInterface
from floris.tools import FlorisModel
from floris.tools.optimization.yaw_optimization.yaw_optimizer_sr import YawOptimizationSR


Expand All @@ -16,25 +16,25 @@
"""

# Load the default example floris object
fi = FlorisInterface("inputs/gch.yaml") # GCH model matched to the default "legacy_gauss" of V2
# fi = FlorisInterface("inputs/cc.yaml") # New CumulativeCurl model
fmodel = FlorisModel("inputs/gch.yaml") # GCH model matched to the default "legacy_gauss" of V2
# fmodel = FlorisModel("inputs/cc.yaml") # New CumulativeCurl model

# Reinitialize as a 3-turbine farm with range of WDs and 1 WS
wd_array = np.arange(0.0, 360.0, 3.0)
ws_array = 8.0 * np.ones_like(wd_array)
turbulence_intensities = 0.06 * np.ones_like(wd_array)
D = 126.0 # Rotor diameter for the NREL 5 MW
fi.set(
fmodel.set(
layout_x=[0.0, 5 * D, 10 * D],
layout_y=[0.0, 0.0, 0.0],
wind_directions=wd_array,
wind_speeds=ws_array,
turbulence_intensities=turbulence_intensities,
)
print(fi.floris.farm.rotor_diameters)
print(fmodel.core.farm.rotor_diameters)

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

print("Optimization results:")
Expand Down
14 changes: 7 additions & 7 deletions examples/11_opt_yaw_multiple_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import matplotlib.pyplot as plt
import numpy as np

from floris.tools import FlorisInterface
from floris.tools import FlorisModel
from floris.tools.optimization.yaw_optimization.yaw_optimizer_sr import YawOptimizationSR


Expand All @@ -16,8 +16,8 @@
"""

# Load the default example floris object
fi = FlorisInterface("inputs/gch.yaml") # GCH model matched to the default "legacy_gauss" of V2
# fi = FlorisInterface("inputs/cc.yaml") # New CumulativeCurl model
fmodel = FlorisModel("inputs/gch.yaml") # GCH model matched to the default "legacy_gauss" of V2
# fmodel = FlorisModel("inputs/cc.yaml") # New CumulativeCurl model

# Define arrays of ws/wd
wind_speeds_to_expand = np.arange(2.0, 18.0, 1.0)
Expand All @@ -36,7 +36,7 @@

# Reinitialize as a 3-turbine farm with range of WDs and WSs
D = 126.0 # Rotor diameter for the NREL 5 MW
fi.set(
fmodel.set(
layout_x=[0.0, 5 * D, 10 * D],
layout_y=[0.0, 0.0, 0.0],
wind_directions=wd_array,
Expand All @@ -55,7 +55,7 @@
# but has no effect on the predicted power uplift from wake steering.
# Hence, it should mostly be used when actually synthesizing a practicable
# wind farm controller.
yaw_opt = YawOptimizationSR(fi)
yaw_opt = YawOptimizationSR(fmodel)
df_opt = yaw_opt.optimize()

print("Optimization results:")
Expand All @@ -74,7 +74,7 @@
figsize=(10, 8)
)
jj = 0
for ii, ws in enumerate(np.unique(fi.floris.flow_field.wind_speeds)):
for ii, ws in enumerate(np.unique(fmodel.core.flow_field.wind_speeds)):
xi = np.remainder(ii, 4)
if ((ii > 0) & (xi == 0)):
jj += 1
Expand Down Expand Up @@ -104,7 +104,7 @@
figsize=(10, 8)
)
jj = 0
for ii, ws in enumerate(np.unique(fi.floris.flow_field.wind_speeds)):
for ii, ws in enumerate(np.unique(fmodel.core.flow_field.wind_speeds)):
xi = np.remainder(ii, 4)
if ((ii > 0) & (xi == 0)):
jj += 1
Expand Down
42 changes: 21 additions & 21 deletions examples/12_optimize_yaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
import pandas as pd

from floris.tools import FlorisInterface
from floris.tools import FlorisModel
from floris.tools.optimization.yaw_optimization.yaw_optimizer_sr import YawOptimizationSR


Expand All @@ -26,18 +26,18 @@

def load_floris():
# Load the default example floris object
fi = FlorisInterface("inputs/gch.yaml") # GCH model matched to the default "legacy_gauss" of V2
# fi = FlorisInterface("inputs/cc.yaml") # New CumulativeCurl model
fmodel = FlorisModel("inputs/gch.yaml") # GCH model matched to the default "legacy_gauss" of V2
# fmodel = FlorisModel("inputs/cc.yaml") # New CumulativeCurl model

# Specify wind farm layout and update in the floris object
N = 5 # number of turbines per row and per column
X, Y = np.meshgrid(
5.0 * fi.floris.farm.rotor_diameters_sorted[0][0] * np.arange(0, N, 1),
5.0 * fi.floris.farm.rotor_diameters_sorted[0][0] * np.arange(0, N, 1),
5.0 * fmodel.core.farm.rotor_diameters_sorted[0][0] * np.arange(0, N, 1),
5.0 * fmodel.core.farm.rotor_diameters_sorted[0][0] * np.arange(0, N, 1),
)
fi.set(layout_x=X.flatten(), layout_y=Y.flatten())
fmodel.set(layout_x=X.flatten(), layout_y=Y.flatten())

return fi
return fmodel


def load_windrose():
Expand All @@ -49,11 +49,11 @@ def load_windrose():
return df


def calculate_aep(fi, df_windrose, column_name="farm_power"):
def calculate_aep(fmodel, df_windrose, column_name="farm_power"):
from scipy.interpolate import NearestNDInterpolator

# Define columns
nturbs = len(fi.layout_x)
nturbs = len(fmodel.layout_x)
yaw_cols = ["yaw_{:03d}".format(ti) for ti in range(nturbs)]

if "yaw_000" not in df_windrose.columns:
Expand All @@ -64,16 +64,16 @@ def calculate_aep(fi, df_windrose, column_name="farm_power"):
ws_array = np.array(df_windrose["ws"], dtype=float)
turbulence_intensities = 0.06 * np.ones_like(wd_array)
yaw_angles = np.array(df_windrose[yaw_cols], dtype=float)
fi.set(
fmodel.set(
wind_directions=wd_array,
wind_speeds=ws_array,
turbulence_intensities=turbulence_intensities,
yaw_angles=yaw_angles
)

# Calculate FLORIS for every WD and WS combination and get the farm power
fi.run()
farm_power_array = fi.get_farm_power()
fmodel.run()
farm_power_array = fmodel.get_farm_power()

# Now map FLORIS solutions to dataframe
interpolant = NearestNDInterpolator(
Expand All @@ -94,17 +94,17 @@ def calculate_aep(fi, df_windrose, column_name="farm_power"):
df_windrose = load_windrose()

# Load FLORIS
fi = load_floris()
ws_array = 8.0 * np.ones_like(fi.floris.flow_field.wind_directions)
fi.set(wind_speeds=ws_array)
nturbs = len(fi.layout_x)
fmodel = load_floris()
ws_array = 8.0 * np.ones_like(fmodel.core.flow_field.wind_directions)
fmodel.set(wind_speeds=ws_array)
nturbs = len(fmodel.layout_x)

# First, get baseline AEP, without wake steering
start_time = timerpc()
print(" ")
print("===========================================================")
print("Calculating baseline annual energy production (AEP)...")
aep_bl = calculate_aep(fi, df_windrose, "farm_power_baseline")
aep_bl = calculate_aep(fmodel, df_windrose, "farm_power_baseline")
t = timerpc() - start_time
print("Baseline AEP: {:.3f} GWh. Time spent: {:.1f} s.".format(aep_bl, t))
print("===========================================================")
Expand All @@ -116,13 +116,13 @@ def calculate_aep(fi, df_windrose, column_name="farm_power"):
wd_array = np.arange(0.0, 360.0, 5.0)
ws_array = 8.0 * np.ones_like(wd_array)
turbulence_intensities = 0.06 * np.ones_like(wd_array)
fi.set(
fmodel.set(
wind_directions=wd_array,
wind_speeds=ws_array,
turbulence_intensities=turbulence_intensities,
)
yaw_opt = YawOptimizationSR(
fi=fi,
fmodel=fmodel,
minimum_yaw_angle=0.0, # Allowable yaw angles lower bound
maximum_yaw_angle=20.0, # Allowable yaw angles upper bound
Ny_passes=[5, 4],
Expand All @@ -132,7 +132,7 @@ def calculate_aep(fi, df_windrose, column_name="farm_power"):
df_opt = yaw_opt.optimize()
end_time = timerpc()
t_tot = end_time - start_time
t_fi = yaw_opt.time_spent_in_floris
t_fmodel = yaw_opt.time_spent_in_floris

print("Optimization finished in {:.2f} seconds.".format(t_tot))
print(" ")
Expand Down Expand Up @@ -171,7 +171,7 @@ def calculate_aep(fi, df_windrose, column_name="farm_power"):
start_time = timerpc()
print("==================================================================")
print("Calculating annual energy production (AEP) with wake steering...")
aep_opt = calculate_aep(fi, df_windrose, "farm_power_opt")
aep_opt = calculate_aep(fmodel, df_windrose, "farm_power_opt")
aep_uplift = 100.0 * (aep_opt / aep_bl - 1)
t = timerpc() - start_time
print("Optimal AEP: {:.3f} GWh. Time spent: {:.1f} s.".format(aep_opt, t))
Expand Down
Loading

0 comments on commit ab399a7

Please sign in to comment.