Skip to content

Commit

Permalink
Update a subset of examples
Browse files Browse the repository at this point in the history
  • Loading branch information
rafmudaf committed Mar 5, 2024
1 parent bfcb2cb commit 32176d4
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 80 deletions.
24 changes: 12 additions & 12 deletions examples/01_opening_floris_computing_power.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import numpy as np

from floris import Floris
from floris import FlorisModel


"""
Expand All @@ -15,22 +15,22 @@

# Initialize FLORIS with the given input file.
# The Floris class is the entry point for most usage.
flowris = Floris("inputs/gch.yaml")
fmodel = FlorisModel("inputs/gch.yaml")

# Convert to a simple two turbine layout
flowris.set(layout_x=[0, 500.0], layout_y=[0.0, 0.0])
fmodel.set(layout_x=[0, 500.0], layout_y=[0.0, 0.0])

# Single wind speed and wind direction
print("\n========================= Single Wind Direction and Wind Speed =========================")

# Get the turbine powers assuming 1 wind direction and speed
# Set the yaw angles to 0 with 1 wind direction and speed
flowris.set(wind_directions=[270.0], wind_speeds=[8.0], yaw_angles=np.zeros([1, 2]))
fmodel.set(wind_directions=[270.0], wind_speeds=[8.0], yaw_angles=np.zeros([1, 2]))

flowris.run()
fmodel.run()

# Get the turbine powers
turbine_powers = flowris.get_turbine_powers() / 1000.0
turbine_powers = fmodel.get_turbine_powers() / 1000.0

print("The turbine power matrix should be of dimensions 1 findex X 2 Turbines")
print(turbine_powers)
Expand All @@ -43,9 +43,9 @@
wind_directions = np.array([270.0, 270.0, 270.0])

# 3 wind directions/ speeds
flowris.set(wind_speeds=wind_speeds, wind_directions=wind_directions, yaw_angles=np.zeros([3, 2]))
flowris.run()
turbine_powers = flowris.get_turbine_powers() / 1000.0
fmodel.set(wind_speeds=wind_speeds, wind_directions=wind_directions, yaw_angles=np.zeros([3, 2]))
fmodel.run()
turbine_powers = fmodel.get_turbine_powers() / 1000.0
print("The turbine power matrix should be of dimensions 3 findex X 2 Turbines")
print(turbine_powers)
print("Shape: ", turbine_powers.shape)
Expand All @@ -58,9 +58,9 @@
wind_speeds = np.tile([8.0, 9.0, 10.0], 3)
wind_directions = np.repeat([260.0, 270.0, 280.0], 3)

flowris.set(wind_directions=wind_directions, wind_speeds=wind_speeds, yaw_angles=np.zeros([9, 2]))
flowris.run()
turbine_powers = flowris.get_turbine_powers() / 1000.0
fmodel.set(wind_directions=wind_directions, wind_speeds=wind_speeds, yaw_angles=np.zeros([9, 2]))
fmodel.run()
turbine_powers = fmodel.get_turbine_powers() / 1000.0
print("The turbine power matrix should be of dimensions 9 WD/WS X 2 Turbines")
print(turbine_powers)
print("Shape: ", turbine_powers.shape)
34 changes: 17 additions & 17 deletions examples/02_visualizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import matplotlib.pyplot as plt
import numpy as np

import floris.tools.visualization as wakeviz
from floris.tools import FlorisInterface
import floris.visualization as wakeviz
from floris import FlorisModel


"""
Expand All @@ -12,7 +12,7 @@
we are plotting three slices of the resulting flow field:
1. Horizontal slice parallel to the ground and located at the hub height
2. Vertical slice of parallel with the direction of the wind
3. Veritical slice parallel to to the turbine disc plane
3. Vertical slice parallel to to the turbine disc plane
Additionally, an alternative method of plotting a horizontal slice
is shown. Rather than calculating points in the domain behind a turbine,
Expand All @@ -21,36 +21,36 @@
rotor.
"""

# Initialize FLORIS with the given input file via FlorisInterface.
# For basic usage, FlorisInterface provides a simplified and expressive
# Initialize FLORIS with the given input file via FlorisModel.
# For basic usage, FlorisModel provides a simplified and expressive
# entry point to the simulation routines.
fi = FlorisInterface("inputs/gch.yaml")
fmodel = FlorisModel("inputs/gch.yaml")

# The rotor plots show what is happening at each turbine, but we do not
# see what is happening between each turbine. For this, we use a
# grid that has points regularly distributed throughout the fluid domain.
# The FlorisInterface contains functions for configuring the new grid,
# The FlorisModel contains functions for configuring the new grid,
# running the simulation, and generating plots of 2D slices of the
# flow field.

# Note this visualization grid created within the calculate_horizontal_plane function will be reset
# to what existed previously at the end of the function

# Using the FlorisInterface functions, get 2D slices.
horizontal_plane = fi.calculate_horizontal_plane(
# Using the FlorisModel functions, get 2D slices.
horizontal_plane = fmodel.calculate_horizontal_plane(
x_resolution=200,
y_resolution=100,
height=90.0,
yaw_angles=np.array([[25.,0.,0.]]),
)

y_plane = fi.calculate_y_plane(
y_plane = fmodel.calculate_y_plane(
x_resolution=200,
z_resolution=100,
crossstream_dist=0.0,
yaw_angles=np.array([[25.,0.,0.]]),
)
cross_plane = fi.calculate_cross_plane(
cross_plane = fmodel.calculate_cross_plane(
y_resolution=100,
z_resolution=100,
downstream_dist=630.0,
Expand Down Expand Up @@ -82,7 +82,7 @@
# Some wake models may not yet have a visualization method included, for these cases can use
# a slower version which scans a turbine model to produce the horizontal flow
horizontal_plane_scan_turbine = wakeviz.calculate_horizontal_plane_with_turbines(
fi,
fmodel,
x_resolution=20,
y_resolution=10,
yaw_angles=np.array([[25.,0.,0.]]),
Expand All @@ -101,11 +101,11 @@

# Run the wake calculation to get the turbine-turbine interfactions
# on the turbine grids
fi.run()
fmodel.run()

# Plot the values at each rotor
fig, axes, _ , _ = wakeviz.plot_rotor_values(
fi.floris.flow_field.u,
fmodel.core.flow_field.u,
findex=0,
n_rows=1,
n_cols=3,
Expand All @@ -125,15 +125,15 @@
"type": "turbine_grid",
"turbine_grid_points": 10
}
fi.set(solver_settings=solver_settings)
fmodel.set(solver_settings=solver_settings)

# Run the wake calculation to get the turbine-turbine interfactions
# on the turbine grids
fi.run()
fmodel.run()

# Plot the values at each rotor
fig, axes, _ , _ = wakeviz.plot_rotor_values(
fi.floris.flow_field.u,
fmodel.core.flow_field.u,
findex=0,
n_rows=1,
n_cols=3,
Expand Down
34 changes: 17 additions & 17 deletions examples/03_making_adjustments.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import matplotlib.pyplot as plt
import numpy as np

import floris.tools.visualization as wakeviz
from floris.tools import FlorisInterface
import floris.visualization as wakeviz
from floris import FlorisModel


"""
Expand All @@ -19,12 +19,12 @@
MIN_WS = 1.0
MAX_WS = 8.0

# Initialize FLORIS with the given input file via FlorisInterface
fi = FlorisInterface("inputs/gch.yaml")
# Initialize FLORIS with the given input file via FlorisModel
fmodel = FlorisModel("inputs/gch.yaml")


# Plot a horizatonal slice of the initial configuration
horizontal_plane = fi.calculate_horizontal_plane(height=90.0)
horizontal_plane = fmodel.calculate_horizontal_plane(height=90.0)
wakeviz.visualize_cut_plane(
horizontal_plane,
ax=axarr[0],
Expand All @@ -34,7 +34,7 @@
)

# Change the wind speed
horizontal_plane = fi.calculate_horizontal_plane(ws=[7.0], height=90.0)
horizontal_plane = fmodel.calculate_horizontal_plane(ws=[7.0], height=90.0)
wakeviz.visualize_cut_plane(
horizontal_plane,
ax=axarr[1],
Expand All @@ -45,8 +45,8 @@


# Change the wind shear, reset the wind speed, and plot a vertical slice
fi.set(wind_shear=0.2, wind_speeds=[8.0])
y_plane = fi.calculate_y_plane(crossstream_dist=0.0)
fmodel.set(wind_shear=0.2, wind_speeds=[8.0])
y_plane = fmodel.calculate_y_plane(crossstream_dist=0.0)
wakeviz.visualize_cut_plane(
y_plane,
ax=axarr[2],
Expand All @@ -58,20 +58,20 @@
# # Change the farm layout
N = 3 # Number of turbines per row and per column
X, Y = np.meshgrid(
5.0 * fi.floris.farm.rotor_diameters[0,0] * np.arange(0, N, 1),
5.0 * fi.floris.farm.rotor_diameters[0,0] * np.arange(0, N, 1),
5.0 * fmodel.core.farm.rotor_diameters[0,0] * np.arange(0, N, 1),
5.0 * fmodel.core.farm.rotor_diameters[0,0] * np.arange(0, N, 1),
)
fi.set(layout_x=X.flatten(), layout_y=Y.flatten(), wind_directions=[270.0])
horizontal_plane = fi.calculate_horizontal_plane(height=90.0)
fmodel.set(layout_x=X.flatten(), layout_y=Y.flatten(), wind_directions=[270.0])
horizontal_plane = fmodel.calculate_horizontal_plane(height=90.0)
wakeviz.visualize_cut_plane(
horizontal_plane,
ax=axarr[3],
title="3x3 Farm",
min_speed=MIN_WS,
max_speed=MAX_WS
)
wakeviz.add_turbine_id_labels(fi, axarr[3], color="w", backgroundcolor="k")
wakeviz.plot_turbines_with_fi(fi, axarr[3])
wakeviz.add_turbine_id_labels(fmodel, axarr[3], color="w", backgroundcolor="k")
wakeviz.plot_turbines_with_fmodel(fmodel, axarr[3])

# Change the yaw angles and configure the plot differently
yaw_angles = np.zeros((1, N * N))
Expand All @@ -86,7 +86,7 @@
yaw_angles[:,4] = 30.0
yaw_angles[:,7] = -30.0

horizontal_plane = fi.calculate_horizontal_plane(yaw_angles=yaw_angles, height=90.0)
horizontal_plane = fmodel.calculate_horizontal_plane(yaw_angles=yaw_angles, height=90.0)
wakeviz.visualize_cut_plane(
horizontal_plane,
ax=axarr[4],
Expand All @@ -95,11 +95,11 @@
min_speed=MIN_WS,
max_speed=MAX_WS
)
wakeviz.plot_turbines_with_fi(fi, axarr[4], yaw_angles=yaw_angles, color="c")
wakeviz.plot_turbines_with_fmodel(fmodel, axarr[4], yaw_angles=yaw_angles, color="c")


# Plot the cross-plane of the 3x3 configuration
cross_plane = fi.calculate_cross_plane(yaw_angles=yaw_angles, downstream_dist=610.0)
cross_plane = fmodel.calculate_cross_plane(yaw_angles=yaw_angles, downstream_dist=610.0)
wakeviz.visualize_cut_plane(
cross_plane,
ax=axarr[5],
Expand Down
14 changes: 7 additions & 7 deletions examples/04_sweep_wind_directions.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 import FlorisModel


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

# 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
wd_array = np.arange(250,291,1.)
ws_array = 8.0 * np.ones_like(wd_array)
fi.set(wind_directions=wd_array, wind_speeds=ws_array)
fmodel.set(wind_directions=wd_array, wind_speeds=ws_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 @@ -37,13 +37,13 @@
n_findex = num_wd # Could be either num_wd or num_ws
num_turbine = len(layout_x) # Number of turbines
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
20 changes: 10 additions & 10 deletions examples/07_calc_aep_from_rose.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import pandas as pd
from scipy.interpolate import NearestNDInterpolator

from floris.tools import FlorisInterface
from floris import FlorisModel


"""
This example demonstrates how to calculate the Annual Energy Production (AEP)
of a wind farm using wind rose information stored in a .csv file.
The wind rose information is first loaded, after which we initialize our Floris
Interface. A 3 turbine farm is generated, and then the turbine wakes and powers
The wind rose information is first loaded, after which we initialize our FlorisModel.
A 3 turbine farm is generated, and then the turbine wakes and powers
are calculated across all the wind directions. Finally, the farm power is
converted to AEP and reported out.
"""
Expand Down Expand Up @@ -41,21 +41,21 @@
freq = freq / np.sum(freq)

# Load the FLORIS object
fi = FlorisInterface("inputs/gch.yaml") # GCH model
# fi = FlorisInterface("inputs/cc.yaml") # CumulativeCurl model
fmodel = FlorisModel("inputs/gch.yaml") # GCH model
# fmodel = FlorisModel("inputs/cc.yaml") # CumulativeCurl model

# Assume a three-turbine wind farm with 5D spacing. We reinitialize the
# floris object and assign the layout, wind speed and wind direction arrays.
D = fi.floris.farm.rotor_diameters[0] # Rotor diameter for the NREL 5 MW
fi.set(
D = fmodel.core.farm.rotor_diameters[0] # Rotor diameter for the NREL 5 MW
fmodel.set(
layout_x=[0.0, 5 * D, 10 * D],
layout_y=[0.0, 0.0, 0.0],
wind_directions=wind_directions,
wind_speeds=wind_speeds,
)

# Compute the AEP using the default settings
aep = fi.get_farm_AEP(freq=freq)
aep = fmodel.get_farm_AEP(freq=freq)
print("Farm AEP (default options): {:.3f} GWh".format(aep / 1.0e9))

# Compute the AEP again while specifying a cut-in and cut-out wind speed.
Expand All @@ -64,7 +64,7 @@
# prevent unexpected behavior for zero/negative and very high wind speeds.
# In this example, the results should not change between this and the default
# call to 'get_farm_AEP()'.
aep = fi.get_farm_AEP(
aep = fmodel.get_farm_AEP(
freq=freq,
cut_in_wind_speed=3.0, # Wakes are not evaluated below this wind speed
cut_out_wind_speed=25.0, # Wakes are not evaluated above this wind speed
Expand All @@ -74,5 +74,5 @@
# Finally, we can also compute the AEP while ignoring all wake calculations.
# This can be useful to quantity the annual wake losses in the farm. Such
# calculations can be facilitated by enabling the 'no_wake' handle.
aep_no_wake = fi.get_farm_AEP(freq, no_wake=True)
aep_no_wake = fmodel.get_farm_AEP(freq, no_wake=True)
print("Farm AEP (no_wake=True): {:.3f} GWh".format(aep_no_wake / 1.0e9))
Loading

0 comments on commit 32176d4

Please sign in to comment.