Example: Separated boundaries layout optimization

Example: Separated boundaries layout optimization#

"""Example: Separated boundaries layout optimization
Demonstrates the capabilities of LayoutOptimizationGridded and
LayoutOptimizationRandomSearch to optimize turbine layouts with complex
boundaries.
"""

import matplotlib.pyplot as plt
import numpy as np

from floris import FlorisModel, WindRose
from floris.optimization.layout_optimization.layout_optimization_gridded import (
    LayoutOptimizationGridded,
)
from floris.optimization.layout_optimization.layout_optimization_random_search import (
    LayoutOptimizationRandomSearch,
)


if __name__ == '__main__':
    # Load the Floris model
    fmodel = FlorisModel('../inputs/gch.yaml')

    # Set the boundaries
    # The boundaries for the turbines, specified as vertices
    boundaries = [
        [(0.0, 0.0), (0.0, 1000.0), (1000.0, 1000.0), (1000.0, 0.0), (0.0, 0.0)],
        [(1500.0, 0.0), (1500.0, 1000.0), (2500.0, 0.0), (1500.0, 0.0)],
    ]

    # Set up the wind data information
    wind_directions = np.arange(0, 360.0, 5.0)
    np.random.seed(1)
    wind_speeds = 8.0 + np.random.randn(1) * 0.0
    # Shape frequency distribution to match number of wind directions and wind speeds
    freq = (
        np.abs(
            np.sort(
                np.random.randn(len(wind_directions))
            )
        )
        .reshape( ( len(wind_directions), len(wind_speeds) ) )
    )
    freq = freq / freq.sum()
    # Set wind data in the FlorisModel
    fmodel.set(
        wind_data=WindRose(
            wind_directions=wind_directions,
            wind_speeds=wind_speeds,
            freq_table=freq,
            ti_table=0.06
        )
    )

    # Begin by placing as many turbines as possible using a gridded layout at 6D spacing
    layout_opt_gridded = LayoutOptimizationGridded(
        fmodel,
        boundaries,
        min_dist_D=6.,
        min_dist=None,
    )
    layout_opt_gridded.optimize()
    print("Gridded layout complete.")

    # Set the layout on the fmodel
    fmodel.set(layout_x=layout_opt_gridded.x_opt, layout_y=layout_opt_gridded.y_opt)

    # Update the layout using a random search optimization with 5D minimum spacing
    layout_opt_rs = LayoutOptimizationRandomSearch(
        fmodel,
        boundaries,
        min_dist_D=5.,
        seconds_per_iteration=10,
        total_optimization_seconds=60.,
        use_dist_based_init=False,
    )
    layout_opt_rs.optimize()

    layout_opt_rs.plot_layout_opt_results(
        initial_locs_plotting_dict={"label": "Gridded initial layout"},
        final_locs_plotting_dict={"label": "Random search optimized layout"},
    )

    plt.show()
import warnings
warnings.filterwarnings('ignore')
Gridded layout complete.
Using supplied initial layout for 4 individuals.
=======================================
Optimization step +0.0
Optimization time = +0.0 [s]
Mean AEP = 85.2 [GWh] (+0.00%)
Median AEP = 85.2 [GWh] (+0.00%)
Max AEP = 85.2 [GWh] (+0.00%)
Min AEP = 85.2 [GWh] (+0.00%)
=======================================
Optimizing using 4 individuals.
Optimization time: 0.0 s / 60.0 s
=======================================
Optimization step +1.0
Optimization time = +10.2 [s]
Mean AEP = 86.9 [GWh] (+1.95%)
Median AEP = 86.9 [GWh] (+1.95%)
Max AEP = 87.0 [GWh] (+2.18%)
Min AEP = 86.6 [GWh] (+1.71%)
=======================================
Optimization time: 10.2 s / 60.0 s
=======================================
Optimization step +2.0
Optimization time = +20.3 [s]
Mean AEP = 87.3 [GWh] (+2.45%)
Median AEP = 87.3 [GWh] (+2.46%)
Max AEP = 87.4 [GWh] (+2.54%)
Min AEP = 87.2 [GWh] (+2.32%)
=======================================
Optimization time: 20.3 s / 60.0 s
=======================================
Optimization step +3.0
Optimization time = +30.5 [s]
Mean AEP = 87.4 [GWh] (+2.63%)
Median AEP = 87.4 [GWh] (+2.62%)
Max AEP = 87.5 [GWh] (+2.66%)
Min AEP = 87.4 [GWh] (+2.61%)
=======================================
Optimization time: 30.5 s / 60.0 s
=======================================
Optimization step +4.0
Optimization time = +40.6 [s]
Mean AEP = 87.5 [GWh] (+2.71%)
Median AEP = 87.5 [GWh] (+2.70%)
Max AEP = 87.5 [GWh] (+2.73%)
Min AEP = 87.5 [GWh] (+2.68%)
=======================================
Optimization time: 40.6 s / 60.0 s
=======================================
Optimization step +5.0
Optimization time = +50.7 [s]
Mean AEP = 87.5 [GWh] (+2.76%)
Median AEP = 87.5 [GWh] (+2.76%)
Max AEP = 87.6 [GWh] (+2.77%)
Min AEP = 87.5 [GWh] (+2.74%)
=======================================
Optimization time: 50.7 s / 60.0 s
=======================================
Optimization step +6.0
Optimization time = +60.8 [s]
Mean AEP = 87.6 [GWh] (+2.79%)
Median AEP = 87.6 [GWh] (+2.79%)
Max AEP = 87.6 [GWh] (+2.82%)
Min AEP = 87.6 [GWh] (+2.78%)
=======================================
Final AEP = 87.6 [GWh] (+2.82%)
../../_images/34b7fccb80207cc2ecef6c8dc345b62ab6abf2371afc62ba4cb76067c0aaf5f0.png