From 32176d49afa0506df69f00ac92ddf6a4d408e8a9 Mon Sep 17 00:00:00 2001 From: Rafael M Mudafort Date: Tue, 5 Mar 2024 13:33:04 -0600 Subject: [PATCH] Update a subset of examples --- examples/01_opening_floris_computing_power.py | 24 ++++++------- examples/02_visualizations.py | 34 +++++++++---------- examples/03_making_adjustments.py | 34 +++++++++---------- examples/04_sweep_wind_directions.py | 14 ++++---- examples/07_calc_aep_from_rose.py | 20 +++++------ examples/32_plot_velocity_deficit_profiles.py | 34 +++++++++---------- 6 files changed, 80 insertions(+), 80 deletions(-) diff --git a/examples/01_opening_floris_computing_power.py b/examples/01_opening_floris_computing_power.py index 501eef902..14fed2aea 100644 --- a/examples/01_opening_floris_computing_power.py +++ b/examples/01_opening_floris_computing_power.py @@ -1,7 +1,7 @@ import numpy as np -from floris import Floris +from floris import FlorisModel """ @@ -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) @@ -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) @@ -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) diff --git a/examples/02_visualizations.py b/examples/02_visualizations.py index 496f2d41b..90e64a584 100644 --- a/examples/02_visualizations.py +++ b/examples/02_visualizations.py @@ -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 """ @@ -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, @@ -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, @@ -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.]]), @@ -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, @@ -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, diff --git a/examples/03_making_adjustments.py b/examples/03_making_adjustments.py index 5c71bba2d..e34ac8c89 100644 --- a/examples/03_making_adjustments.py +++ b/examples/03_making_adjustments.py @@ -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 """ @@ -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], @@ -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], @@ -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], @@ -58,11 +58,11 @@ # # 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], @@ -70,8 +70,8 @@ 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)) @@ -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], @@ -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], diff --git a/examples/04_sweep_wind_directions.py b/examples/04_sweep_wind_directions.py index 6cfa73612..893668bb6 100644 --- a/examples/04_sweep_wind_directions.py +++ b/examples/04_sweep_wind_directions.py @@ -2,7 +2,7 @@ import matplotlib.pyplot as plt import numpy as np -from floris.tools import FlorisInterface +from floris import FlorisModel """ @@ -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 @@ -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() diff --git a/examples/07_calc_aep_from_rose.py b/examples/07_calc_aep_from_rose.py index 18db25a71..a1405650c 100644 --- a/examples/07_calc_aep_from_rose.py +++ b/examples/07_calc_aep_from_rose.py @@ -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. """ @@ -41,13 +41,13 @@ 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, @@ -55,7 +55,7 @@ ) # 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. @@ -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 @@ -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)) diff --git a/examples/32_plot_velocity_deficit_profiles.py b/examples/32_plot_velocity_deficit_profiles.py index 9f28ce40c..559269583 100644 --- a/examples/32_plot_velocity_deficit_profiles.py +++ b/examples/32_plot_velocity_deficit_profiles.py @@ -3,9 +3,9 @@ import numpy as np from matplotlib import ticker -import floris.tools.visualization as wakeviz -from floris.tools import cut_plane, FlorisInterface -from floris.tools.visualization import VelocityProfilesFigure +import floris.visualization as wakeviz +from floris import FlorisModel +from floris.visualization import VelocityProfilesFigure from floris.utilities import reverse_rotate_coordinates_rel_west @@ -37,7 +37,7 @@ def annotate_coordinate_system(x_origin, y_origin, quiver_length): x2 = np.array([0.0, quiver_length + 0.35 * D]) x3 = np.array([90.0, 90.0]) x, y, _ = reverse_rotate_coordinates_rel_west( - fi.floris.flow_field.wind_directions, + fmodel.core.flow_field.wind_directions, x1[None, :], x2[None, :], x3[None, :], @@ -54,8 +54,8 @@ def annotate_coordinate_system(x_origin, y_origin, quiver_length): hub_height = 90.0 homogeneous_wind_speed = 8.0 - fi = FlorisInterface("inputs/gch.yaml") - fi.set(layout_x=[0.0], layout_y=[0.0]) + fmodel = FlorisModel("inputs/gch.yaml") + fmodel.set(layout_x=[0.0], layout_y=[0.0]) # ------------------------------ Single-turbine layout ------------------------------ # We first show how to sample and plot velocity deficit profiles on a single-turbine layout. @@ -63,13 +63,13 @@ def annotate_coordinate_system(x_origin, y_origin, quiver_length): downstream_dists = D * np.array([3, 5, 7]) # Sample three profiles along three corresponding lines that are all parallel to the y-axis # (cross-stream direction). The streamwise location of each line is given in `downstream_dists`. - profiles = fi.sample_velocity_deficit_profiles( + profiles = fmodel.sample_velocity_deficit_profiles( direction='cross-stream', downstream_dists=downstream_dists, homogeneous_wind_speed=homogeneous_wind_speed, ) - horizontal_plane = fi.calculate_horizontal_plane(height=hub_height) + horizontal_plane = fmodel.calculate_horizontal_plane(height=hub_height) fig, ax = plt.subplots(figsize=(6.4, 3)) wakeviz.visualize_cut_plane(horizontal_plane, ax) colors = ['b', 'g', 'c'] @@ -95,10 +95,10 @@ def annotate_coordinate_system(x_origin, y_origin, quiver_length): # Change velocity model to jensen, get the velocity deficit profiles, # and add them to the figure. - floris_dict = fi.floris.as_dict() + floris_dict = fmodel.core.as_dict() floris_dict['wake']['model_strings']['velocity_model'] = 'jensen' - fi = FlorisInterface(floris_dict) - profiles = fi.sample_velocity_deficit_profiles( + fmodel = FlorisModel(floris_dict) + profiles = fmodel.sample_velocity_deficit_profiles( direction='cross-stream', downstream_dists=downstream_dists, homogeneous_wind_speed=homogeneous_wind_speed, @@ -125,16 +125,16 @@ def annotate_coordinate_system(x_origin, y_origin, quiver_length): # (i.e. where to start sampling the profiles). wind_direction = 315.0 # Try to change this downstream_dists = D * np.array([3, 5]) - floris_dict = fi.floris.as_dict() + floris_dict = fmodel.core.as_dict() floris_dict['wake']['model_strings']['velocity_model'] = 'gauss' - fi = FlorisInterface(floris_dict) + fmodel = FlorisModel(floris_dict) # Let (x_t1, y_t1) be the location of the second turbine x_t1 = 2 * D y_t1 = -2 * D - fi.set(wind_directions=[wind_direction], layout_x=[0.0, x_t1], layout_y=[0.0, y_t1]) + fmodel.set(wind_directions=[wind_direction], layout_x=[0.0, x_t1], layout_y=[0.0, y_t1]) # Extract profiles at a set of downstream distances from the starting point (x_start, y_start) - cross_profiles = fi.sample_velocity_deficit_profiles( + cross_profiles = fmodel.sample_velocity_deficit_profiles( direction='cross-stream', downstream_dists=downstream_dists, homogeneous_wind_speed=homogeneous_wind_speed, @@ -142,7 +142,7 @@ def annotate_coordinate_system(x_origin, y_origin, quiver_length): y_start=y_t1, ) - horizontal_plane = fi.calculate_horizontal_plane(height=hub_height, x_bounds=[-2 * D, 9 * D]) + horizontal_plane = fmodel.calculate_horizontal_plane(height=hub_height, x_bounds=[-2 * D, 9 * D]) ax = wakeviz.visualize_cut_plane(horizontal_plane) colors = ['b', 'g', 'c'] for i, profile in enumerate(cross_profiles): @@ -162,7 +162,7 @@ def annotate_coordinate_system(x_origin, y_origin, quiver_length): # locations as before. We stay directly downstream of the turbine (i.e. x2 = 0). These # profiles are almost identical to the cross-stream profiles. However, we now explicitly # set the profile range. The default range is [-2 * D, 2 * D]. - vertical_profiles = fi.sample_velocity_deficit_profiles( + vertical_profiles = fmodel.sample_velocity_deficit_profiles( direction='vertical', profile_range=[-1.5 * D, 1.5 * D], downstream_dists=downstream_dists,