Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples and documentation for ParFlorisModel #990

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ parts:
- caption: User Reference
chapters:
- file: intro_concepts
- file: advanced_concepts
- file: wind_data_user
- file: floris_models
- file: advanced_concepts
- file: heterogeneous_map
- file: floating_wind_turbine
- file: turbine_interaction
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced_concepts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"# Advanced Concepts\n",
"\n",
"More information regarding the numerical and computational formulation in FLORIS\n",
"are detailed here. See [](concepts_intro) for a guide on the basics."
"are detailed here. See [Introductory Concepts](intro_concepts) for a guide on the basics."
]
},
{
Expand Down
277 changes: 277 additions & 0 deletions docs/floris_models.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/intro_concepts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"id": "86e53920",
"metadata": {},
"source": [
"(concepts_intro)=\n",
"(intro_concepts)=\n",
"# Introductory Concepts\n",
"\n",
"FLORIS is a Python-based software library for calculating wind farm performance considering\n",
Expand Down
95 changes: 95 additions & 0 deletions examples/009_parallel_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
"""Example 9: Parallel Models

This example demonstrates how to use the ParFlorisModel class to parallelize the
calculation of the FLORIS model. ParFlorisModel inherits from the FlorisModel
and so can be used in the same way with a consistent interface. ParFlorisModel
replaces the ParallelFlorisModel, which will be deprecated in a future release.

"""

import numpy as np

from floris import (
FlorisModel,
ParFlorisModel,
TimeSeries,
UncertainFlorisModel,
)


# When using parallel optimization it is important the "root" script include this
# if __name__ == "__main__": block to avoid problems
if __name__ == "__main__":
# Instantiate the FlorisModel
fmodel = FlorisModel("inputs/gch.yaml")

# The ParFlorisModel can be instantiated either from a FlorisModel or from
# the input file.
pfmodel_1 = ParFlorisModel("inputs/gch.yaml") # Via input file
pfmodel_2 = ParFlorisModel(fmodel) # Via FlorisModel

# The ParFlorisModel has additional inputs which define the parallelization
# but don't affect the output.
pfmodel_3 = ParFlorisModel(
fmodel,
interface="multiprocessing", # Default
max_workers=2, # Defaults to num_cpu
n_wind_condition_splits=2, # Defaults to max_workers
)

# Define a simple inflow
time_series = TimeSeries(
wind_speeds=np.arange(1, 25, 0.5), wind_directions=270.0, turbulence_intensities=0.06
)

# Demonstrate that interface and results are the same
fmodel.set(wind_data=time_series)
pfmodel_1.set(wind_data=time_series)
pfmodel_2.set(wind_data=time_series)
pfmodel_3.set(wind_data=time_series)

fmodel.run()
pfmodel_1.run()
pfmodel_2.run()
pfmodel_3.run()

# Compare the results
powers_fmodel = fmodel.get_turbine_powers()
powers_pfmodel_1 = pfmodel_1.get_turbine_powers()
powers_pfmodel_2 = pfmodel_2.get_turbine_powers()
powers_pfmodel_3 = pfmodel_3.get_turbine_powers()

print(
f"Testing if outputs of fmodel and pfmodel_1 are "
f"close: {np.allclose(powers_fmodel, powers_pfmodel_1)}"
)
print(
f"Testing if outputs of fmodel and pfmodel_2 are "
f"close: {np.allclose(powers_fmodel, powers_pfmodel_2)}"
)
print(
f"Testing if outputs of fmodel and pfmodel_3 are "
f"close: {np.allclose(powers_fmodel, powers_pfmodel_3)}"
)

# Because ParFlorisModel is a subclass of FlorisModel, it can also be used as
# an input to the UncertainFlorisModel class. This allows for parallelization of
# the uncertainty calculations.
ufmodel = UncertainFlorisModel(fmodel)
pufmodel = UncertainFlorisModel(pfmodel_1)

# Demonstrate matched results
ufmodel.set(wind_data=time_series)
pufmodel.set(wind_data=time_series)

ufmodel.run()
pufmodel.run()

powers_ufmodel = ufmodel.get_turbine_powers()
powers_pufmodel = pufmodel.get_turbine_powers()

print("--------------------")
print(
f"Testing if outputs of ufmodel and pufmodel are "
f"close: {np.allclose(powers_ufmodel, powers_pufmodel)}"
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Example 9: Compare farm power with neighboring farm
"""Example 10: Compare farm power with neighboring farm

This example demonstrates how to use turbine_weights to define a set of turbines belonging
to a neighboring farm which impacts the power production of the farm under consideration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from floris.optimization.yaw_optimization.yaw_optimizer_sr import YawOptimizationSR


# When using parallel optimization it is importat the "root" script include this
# When using parallel optimization it is important the "root" script include this
# if __name__ == "__main__": block to avoid problems
if __name__ == "__main__":

Expand Down
Loading