Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
df_sowfa = df_sowfa[df_sowfa.num_turbines == num_turbines]
# Limit to wind speed
df_sowfa = df_sowfa[df_sowfa.sowfa_U0 == sowfa_U0]
# Limit to turbulence
df_sowfa = df_sowfa[df_sowfa.sowfa_TI == sowfa_TI]
# Limit to aligned
df_sowfa = df_sowfa[df_sowfa.yaw.apply(lambda x: np.max(np.abs(x))) == 0.0]
# Load the saved FLORIS interfaces
fi_dict = pickle.load(open("../floris_models.p", "rb"))
# Add the direct BLONDEL implementation
fi_b = wfct.floris_interface.FlorisInterface("../../other_jsons/input_blondel.json")
fi_dict["blondel"] = (fi_b, "c", "*")
# Resimulate the SOWFA cases
for floris_label in fi_dict:
(fi, floris_color, floris_marker) = fi_dict[floris_label]
df_sowfa[floris_label] = 0
df_sowfa[floris_label] = df_sowfa[floris_label].astype(object)
for i, row in df_sowfa.iterrows():
# Match the layout, wind_speed and TI
fi.reinitialize_flow_field(
layout_array=[row.layout_x, row.layout_y],
wind_speed=[row.floris_U0],
turbulence_intensity=[row.floris_TI],
)
# See https://floris.readthedocs.io for documentation
import os
import numpy as np
import matplotlib.pyplot as plt
import floris.tools as wfct
import floris.tools.optimization.pyoptsparse as opt
# Initialize the FLORIS interface fi
file_dir = os.path.dirname(os.path.abspath(__file__))
fi = wfct.floris_interface.FlorisInterface(
os.path.join(file_dir, "../../../example_input.json")
)
boundaries = [[0.0, 0.0], [0.0, 1000.0], [1000.0, 1000.0], [1000.0, 0.0]]
# Set turbine locations to 4 turbines in a rectangle
D = fi.floris.farm.turbines[0].rotor_diameter
layout_x = [0, 0, 6 * D, 6 * D]
layout_y = [0, 5 * D, 0, 5 * D]
fi.reinitialize_flow_field(layout_array=(layout_x, layout_y))
# wd = np.arange(0., 360., 60.)
# wd = [0, 90, 180, 270]
wd = [270]
np.random.seed(1)
ws = 8.0 + np.random.randn(len(wd)) * 0.5
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
# See read the https://floris.readthedocs.io for documentation
import matplotlib.pyplot as plt
import floris.tools as wfct
import numpy as np
# from floris.utilities import Vec3
# Initialize the FLORIS interface fi, use default gauss model
fi = wfct.floris_interface.FlorisInterface("example_input.json")
fi_gch = wfct.floris_interface.FlorisInterface("example_input.json")
# Force dm to 1.0
fi.floris.farm.wake._deflection_model.dm = 1.0
fi_gch.floris.farm.wake._deflection_model.dm = 1.0
# Set up gch
fi_gch.floris.farm.wake.velocity_model = "gauss_curl_hybrid"
fi_gch.floris.farm.wake.deflection_model = "gauss_curl_hybrid"
fi_gch.floris.farm.wake.velocity_models["gauss_curl_hybrid"].use_yar = False
fi_gch.floris.farm.wake.deflection_models["gauss_curl_hybrid"].use_ss = False
# Change the layout
D = fi.floris.farm.flow_field.turbine_map.turbines[0].rotor_diameter
layout_x = [0, 7*D, 14*D]
layout_y = [0, 0, 0]
yaw_angles = [0, 0, 0]
fi.reinitialize_flow_field(layout_array=([0,dist_downstream*D],[0,0]),turbulence_intensity=[ti])
fi.calculate_wake([0,0])
base_power = fi.get_turbine_power()[1]/1000.
fi.calculate_wake([yaw_angle,0])
power_out[ti_idx] = 100 * (fi.get_turbine_power()[1]/1000. - base_power) / base_power
return ti_values, power_out
# Set up the models ....
# ======================
fi_dict = dict()
color_dict = dict()
label_dict = dict()
# Gauss Class -- Current Default
fi_g = wfct.floris_interface.FlorisInterface("../example_input.json")
fi_dict['g'] = fi_g
color_dict['g'] = 'r^-'
label_dict['g'] = 'current_default'
# Gauss_Legacy Class with GCH disabled and deflection multiplier = 1.2
fi_gl = wfct.floris_interface.FlorisInterface("../other_jsons/input_legacy.json")
fi_dict['gl'] = fi_gl
color_dict['gl'] = 'bo--'
label_dict['gl'] = 'gauss_legacy'
# Set up a saved gauss
saved_gauss = dict()
saved_gauss[(10,0)] = [np.array([0.04 , 0.045, 0.05 , 0.055, 0.06 , 0.065, 0.07 , 0.075, 0.08 ,
0.085, 0.09 , 0.095, 0.1 , 0.105, 0.11 , 0.115, 0.12 , 0.125,
0.13 , 0.135, 0.14 , 0.145]) ,np.array([ 710.37278464, 761.44551604, 810.51984522, 857.39042285,
# Load the SOWFA case in
si = wfct.sowfa_utilities.SowfaInterface("sowfa_example")
# Plot the SOWFA flow and turbines using the input information
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, figsize=(5, 8.5))
sowfa_flow_data = si.flow_data
hor_plane = si.get_hor_plane(90)
wfct.visualization.visualize_cut_plane(
hor_plane, ax=ax2, minSpeed=minspeed, maxSpeed=maxspeed
)
vis.plot_turbines(ax2, si.layout_x, si.layout_y, si.yaw_angles, si.D)
ax2.set_title("SOWFA")
ax2.set_ylabel("y location [m]")
# Load the FLORIS case in
fi = wfct.floris_interface.FlorisInterface("../example_input.json")
fi.calculate_wake()
# Plot the original FLORIS flow and turbines using the input information
hor_plane_orig = fi.get_hor_plane(90)
wfct.visualization.visualize_cut_plane(
hor_plane_orig, ax=ax1, minSpeed=minspeed, maxSpeed=maxspeed
)
vis.plot_turbines(
ax1,
fi.layout_x,
fi.layout_y,
fi.get_yaw_angles(),
fi.floris.farm.turbine_map.turbines[0].rotor_diameter,
)
ax1.set_title("FLORIS - Original")
ax1.set_ylabel("y location [m]")
# License for the specific language governing permissions and limitations under
# the License.
# See https://floris.readthedocs.io for documentation
# This example illustrates changing the properties of some of the turbines
# This can be used to setup farms of different turbines
import matplotlib.pyplot as plt
import floris.tools as wfct
# Initialize the FLORIS interface fi
fi = wfct.floris_interface.FlorisInterface("../example_input.json")
# Set to 2x2 farm
fi.reinitialize_flow_field(layout_array=[[0, 0, 600, 600], [0, 300, 0, 300]])
# Change turbine 0 and 3 to have a 35 m rotor diameter
fi.change_turbine([0, 3], {"rotor_diameter": 35})
# Calculate wake
fi.calculate_wake()
# Get horizontal plane at default height (hub-height)
hor_plane = fi.get_hor_plane()
# Plot and show
fig, ax = plt.subplots()
wfct.visualization.visualize_cut_plane(hor_plane, ax=ax)
label_dict = dict()
# Gauss Class -- Current Default
fi_g = wfct.floris_interface.FlorisInterface("../example_input.json")
fi_dict['g'] = fi_g
color_dict['g'] = 'r^-'
label_dict['g'] = 'current_default'
# Gauss_Legacy Class with GCH disabled and deflection multiplier = 1.2
fi_gl = wfct.floris_interface.FlorisInterface("../other_jsons/input_legacy.json")
fi_dict['gl'] = fi_gl
color_dict['gl'] = 'bo--'
label_dict['gl'] = 'gauss_legacy'
# Gauss_Legacy Class with GCH disabled and deflection multiplier = 1.2
fi_gm = wfct.floris_interface.FlorisInterface("../other_jsons/input_merge.json")
fi_dict['gm'] = fi_gm
color_dict['gm'] = 'go--'
label_dict['gm'] = 'gauss_blondel_merge'
# Set up a saved gauss
saved_gauss = dict()
saved_gauss[(10,0)] = [np.array([-1. , -0.75, -0.5 , -0.25, 0. , 0.25, 0.5 , 0.75, 1. ]) ,np.array([1533.60441684, 1365.62088487, 1155.08543545, 973.56022679,
901.95198686, 973.56022679, 1155.08543545, 1365.62088487,
1533.60441684]) ]
saved_gauss[(10,20)] = [np.array([-1. , -0.75, -0.5 , -0.25, 0. , 0.25, 0.5 , 0.75, 1. ]) ,np.array([1240.69409842, 1054.31942699, 964.51369145, 1018.28384293,
1187.46445136, 1389.68299861, 1549.58603932, 1639.79197365,
1676.52144747]) ]
saved_gauss[(6,0)] = [np.array([-1. , -0.75, -0.5 , -0.25, 0. , 0.25, 0.5 , 0.75, 1. ]) ,np.array([1582.68316317, 1366.9223727 , 1026.53731597, 692.43879565,
548.24645338, 692.43879565, 1026.53731597, 1366.9223727 ,
1582.68316317]) ]
saved_gauss[(6,20)] = [np.array([-1. , -0.75, -0.5 , -0.25, 0. , 0.25, 0.5 , 0.75, 1. ]) ,np.array([1331.00738281, 987.67770715, 695.83692699, 647.76067736,
# the License.
# See https://floris.readthedocs.io for documentation
# This example shows a quick illustration of using different wake models
# Note that for using the Jensen or Multizone model, even if not studying
# wake steering, it's important to couple with the Jimenez model of deflection
# to avoid software errors in functions only defined for gaussian models
import matplotlib.pyplot as plt
import floris.tools as wfct
# Initialize the FLORIS interface for 4 seperate models defined as JSONS
fi_jensen = wfct.floris_interface.FlorisInterface("../other_jsons/jensen.json")
fi_mz = wfct.floris_interface.FlorisInterface("../other_jsons/multizone.json")
fi_gauss = wfct.floris_interface.FlorisInterface("../other_jsons/input_legacy.json")
fi_gch = wfct.floris_interface.FlorisInterface("../example_input.json")
fig, axarr = plt.subplots(2, 4, figsize=(16, 4))
# Use a python for loop to iterate over the models and plot a horizontal cut through
# of the models for an aligned and yaw case to show some differences
for idx, (fi, name) in enumerate(
zip(
[fi_jensen, fi_mz, fi_gauss, fi_gch], ["Jensen", "Multizone", "Gaussian", "GCH"]
)
):
# Aligned case
HH = fi.floris.farm.flow_field.turbine_map.turbines[0].hub_height
D = fi.floris.farm.turbines[0].rotor_diameter
wind_speed_mod = 0.3
# Match SOWFA
fi.reinitialize_flow_field(wind_speed=[si.precursor_wind_speed - wind_speed_mod],
wind_direction=[si.precursor_wind_dir],
layout_array=(si.layout_x, si.layout_y)
)
# Calculate wake
fi.calculate_wake(yaw_angles=si.yaw_angles)
# Repeat for Blondel
fi_b = wfct.floris_interface.FlorisInterface("example_input.json")
fi_b.floris.farm.set_wake_model('blondel')
fi_b.reinitialize_flow_field(
wind_speed=[si.precursor_wind_speed - wind_speed_mod],
wind_direction=[si.precursor_wind_dir],
layout_array=(si.layout_x, si.layout_y)
)
fi_b.calculate_wake(yaw_angles=si.yaw_angles)
# Repeat for Ishihara-Qian
fi_iq = wfct.floris_interface.FlorisInterface("example_input.json")
fi_iq.floris.farm.set_wake_model('ishihara')
fi_iq.reinitialize_flow_field(
wind_speed=[si.precursor_wind_speed - wind_speed_mod],
fi.calculate_wake()
powers[d_idx] = fi.get_turbine_power()[t] / 1000.0
ax.plot(diameters, powers, "k")
ax.axhline(init_power[t], color="r", ls=":")
ax.axvline(126, color="r", ls=":")
ax.set_title("T%d" % t)
ax.set_xlim([80, 160])
ax.set_ylim([200, 3000])
ax.set_xlabel("Diameter T%d" % t)
ax.set_ylabel("Power")
plt.suptitle("Adjusting Both T0 and T1 Diameters")
# Waked, adjust T0 diameter
fi = wfct.floris_interface.FlorisInterface("../example_input.json")
fi.reinitialize_flow_field(layout_array=[[0, 500], [0, 0]])
# Calculate wake
fi.calculate_wake()
init_power = np.array(fi.get_turbine_power()) / 1000.0
fig, axarr = plt.subplots(1, 3, sharex=False, sharey=False, figsize=(15, 5))
# Show the hub-height slice in the 3rd pane
hor_plane = fi.get_hor_plane()
wfct.visualization.visualize_cut_plane(hor_plane, ax=axarr[2])
for t in range(2):
ax = axarr[t]