-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update UncertainFlorisModel to work with new Parallel framework (#983)
* Update uncertain floris model to accept par floris * Raise an error in old parallel floris model blocking passing in uncertain floris model * Add an example of parallelized uncertain floris
- Loading branch information
Showing
3 changed files
with
107 additions
and
11 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
examples/examples_uncertain/003_uncertain_model_with_parallelization.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
"""Example: Uncertain Model With Parallelization | ||
This example demonstrates how to combined the parallelized model with the uncertain model | ||
""" | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
from floris import ( | ||
FlorisModel, | ||
TimeSeries, | ||
UncertainFlorisModel, | ||
) | ||
from floris.parallel_floris_model_2 import ParallelFlorisModel | ||
|
||
|
||
# Following the refactoring of ParallelFlorisModel, the UncertainFlorisModel can be | ||
# parallelized by passing the ParallelFlorisModel as the model to be run. This example | ||
# demonstrates the usage. Demonstrating the result obtained from the UncertainFlorisModel | ||
# with and without parallelization is the same. The results are compared to the nomimal | ||
# results. | ||
|
||
# Instantiate a FlorisModel and ParallelFlorisModel using the GCH model | ||
fmodel = FlorisModel("../inputs/gch.yaml") | ||
pfmodel = ParallelFlorisModel("../inputs/gch.yaml") | ||
|
||
# Use the above model to declare a serial and parallel UncertainFlorisModel | ||
ufmodel = UncertainFlorisModel(fmodel) | ||
pufmodel = UncertainFlorisModel(pfmodel) | ||
|
||
|
||
# Define an inflow where wind direction is swept while | ||
# wind speed and turbulence intensity are held constant | ||
wind_directions = np.arange(240.0, 300.0, 1.0) | ||
time_series = TimeSeries( | ||
wind_directions=wind_directions, | ||
wind_speeds=8.0, | ||
turbulence_intensities=0.06, | ||
) | ||
|
||
# Define a two turbine farm and apply the inflow | ||
D = 126.0 | ||
layout_x = np.array([0, D * 6]) | ||
layout_y = [0, 0] | ||
|
||
# Apply to fmodel, ufmodel, and pufmodel | ||
fmodel.set( | ||
layout_x=layout_x, | ||
layout_y=layout_y, | ||
wind_data=time_series, | ||
) | ||
|
||
ufmodel.set( | ||
layout_x=layout_x, | ||
layout_y=layout_y, | ||
wind_data=time_series, | ||
) | ||
|
||
pufmodel.set( | ||
layout_x=layout_x, | ||
layout_y=layout_y, | ||
wind_data=time_series, | ||
) | ||
|
||
# Run the models | ||
fmodel.run() | ||
ufmodel.run() | ||
pufmodel.run() | ||
|
||
# Collect the farm power results from each model | ||
farm_powers_nom = fmodel.get_farm_power() / 1e3 | ||
farm_powers_unc = ufmodel.get_farm_power() / 1e3 | ||
farm_powers_punc = pufmodel.get_farm_power() / 1e3 | ||
|
||
# Compare the results | ||
fig, ax = plt.subplots() | ||
ax.plot(wind_directions, farm_powers_nom.flatten(), 'k-', label="Nominal power") | ||
ax.plot(wind_directions, farm_powers_unc.flatten(), 'bs-', label="Uncertain power") | ||
ax.plot(wind_directions, farm_powers_punc.flatten(), 'r.--', label="Parallel uncertain power") | ||
ax.grid(True) | ||
ax.legend() | ||
ax.set_xlabel("Wind Direction (deg)") | ||
ax.set_ylabel("Power (kW)") | ||
|
||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters