Wake steering

This example demonstrates how to optimize the yaw angles of wind turbine rotors, such that the wakes are steered away from downwind turbines.

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import foxes
import foxes.variables as FV
from iwopy.interfaces.pymoo import Optimizer_pymoo
from foxes_opt.problems import OptFarmVars
from foxes_opt.objectives import MaxFarmPower
/home/runner/work/foxes-opt/foxes-opt/.venv/lib/python3.10/site-packages/foxes/core/engine.py:6: TqdmExperimentalWarning: Using `tqdm.autonotebook.tqdm` in notebook mode. Use `tqdm.tqdm` instead to force console mode (e.g. in jupyter console)
  from tqdm.autonotebook import tqdm

Let’s create the foxes engine, which will be used for all calculations:

engine = foxes.Engine.new(
    "process",
    chunk_size_states=500,
    chunk_size_points=5000,
    verbosity=0,
)

In this example we are looking at a small 3 x 3 regualar wind farm with NREL5MW turbines:

farm = foxes.WindFarm()
foxes.input.farm_layout.add_grid(
    farm,
    xy_base=np.array([500.0, 500.0]),
    step_vectors=np.array([[1300.0, 0], [200, 600.0]]),
    steps=(3, 3),
    turbine_models=["opt_yawm", "yawm2yaw", "NREL5MW"],
    verbosity=0,
)

ax = foxes.output.FarmLayoutOutput(farm).get_figure()
plt.show()
plt.close(ax.get_figure())
../_images/a6ce690d35ee6575ea995c92a6f4c99fc2dda431365dae4f077c2b8730ab0c57.png

Notice how the name of the optimization model opt_yawm, which will be defined shortly, appears in the list of turbine models. The idea is as follows:

  • First, the optimizer sets the FV.YAWM variable, representing yaw misalignment in degrees, i.e., a delta yaw value from greedy conditions

  • Then, the model yawm2yaw translates this into the absolute yaw value, i.e., the absolute turbine axis orientation, expressed in degrees

  • This setting is then used for thrust and power calculations, by the turbine type model NREL5MW.

We are considering sinlge-state uniform inflow conditions:

states = foxes.input.states.SingleStateStates(ws=9, wd=270, ti=0.06, rho=1.225)

The algorithm is defined next, including a TI wake model and the Bastankhah2016 wake model. Also notice the wake deflection choice Jimenez, which realizes the wake bending for yawed conditions:

algo = foxes.algorithms.Downwind(
    farm,
    states,
    wake_models=["IECTI2019k_quadratic_ambka02", "Bastankhah2014_vector_ambka04"],
    wake_deflection="Jimenez",
    verbosity=0,
)

The optimization problem is power maximization by finding the optimal value of the variable FV.YAWM for each turbine:

problem = OptFarmVars("opt_yawm", algo)
problem.add_var(FV.YAWM, float, 0.0, -40.0, 40.0, level="turbine")
problem.add_objective(MaxFarmPower(problem))
problem.initialize()
Problem 'opt_yawm': Optimization variable list

        name   var   type  index    level  state  turbine  sel_turbine  init  \
0  YAWM_0000  YAWM  float      0  turbine     -1        0            0   0.0   
1  YAWM_0001  YAWM  float      1  turbine     -1        1            1   0.0   
2  YAWM_0002  YAWM  float      2  turbine     -1        2            2   0.0   
3  YAWM_0003  YAWM  float      3  turbine     -1        3            3   0.0   
4  YAWM_0004  YAWM  float      4  turbine     -1        4            4   0.0   
5  YAWM_0005  YAWM  float      5  turbine     -1        5            5   0.0   
6  YAWM_0006  YAWM  float      6  turbine     -1        6            6   0.0   
7  YAWM_0007  YAWM  float      7  turbine     -1        7            7   0.0   
8  YAWM_0008  YAWM  float      8  turbine     -1        8            8   0.0   

    min   max model_key  
0 -40.0  40.0  opt_yawm  
1 -40.0  40.0  opt_yawm  
2 -40.0  40.0  opt_yawm  
3 -40.0  40.0  opt_yawm  
4 -40.0  40.0  opt_yawm  
5 -40.0  40.0  opt_yawm  
6 -40.0  40.0  opt_yawm  
7 -40.0  40.0  opt_yawm  
8 -40.0  40.0  opt_yawm  

Problem 'opt_yawm' (OptFarmVars): Initializing
----------------------------------------------
  n_vars_int  : 0
  n_vars_float: 9
----------------------------------------------
  n_objectives: 1
  n_obj_cmptns: 1
----------------------------------------------
  n_constraints: 0
  n_con_cmptns: 0
----------------------------------------------

Next, we setup the solver:

solver = Optimizer_pymoo(
    problem,
    problem_pars=dict(vectorize=True),
    algo_pars=dict(type="GA", pop_size=100, seed=42),
    setup_pars=dict(),
    term_pars=("n_gen", 100),
)
solver.initialize()
solver.print_info()
Loading pymoo
pymoo successfully loaded
Initializing Optimizer_pymoo
Selecting sampling: float_random (FloatRandomSampling)
Selecting algorithm: GA (GA)

Problem:
--------
  vectorize: True

Algorithm:
----------
  type: GA
  pop_size: 100
  seed: 42

Termination:
------------
  n_gen: 100

Now everything is setup, and we can solve the problem:

with engine:
    results = solver.solve()
    solver.finalize(results)
=================================================
n_gen  |  n_eval  |     f_avg     |     f_min    
=================================================
     1 |      100 | -2.885027E-01 | -3.341026E-01
     2 |      200 | -3.121190E-01 | -3.374290E-01
     3 |      300 | -3.239418E-01 | -3.412651E-01
     4 |      400 | -3.315182E-01 | -3.428295E-01
     5 |      500 | -3.371477E-01 | -3.447472E-01
     6 |      600 | -3.412742E-01 | -3.470593E-01
     7 |      700 | -3.439339E-01 | -3.479742E-01
     8 |      800 | -3.455953E-01 | -3.482524E-01
     9 |      900 | -3.467618E-01 | -3.486922E-01
    10 |     1000 | -3.475367E-01 | -3.496493E-01
    11 |     1100 | -3.482524E-01 | -3.502718E-01
    12 |     1200 | -3.489285E-01 | -3.507322E-01
    13 |     1300 | -3.495330E-01 | -3.508365E-01
    14 |     1400 | -3.499354E-01 | -3.508810E-01
    15 |     1500 | -3.501660E-01 | -3.510656E-01
    16 |     1600 | -3.504237E-01 | -3.510656E-01
    17 |     1700 | -3.506469E-01 | -3.510656E-01
    18 |     1800 | -3.507961E-01 | -3.511768E-01
    19 |     1900 | -3.509102E-01 | -3.512246E-01
    20 |     2000 | -3.510016E-01 | -3.512246E-01
    21 |     2100 | -3.510692E-01 | -3.512246E-01
    22 |     2200 | -3.511300E-01 | -3.513032E-01
    23 |     2300 | -3.511765E-01 | -3.513198E-01
    24 |     2400 | -3.512161E-01 | -3.513470E-01
    25 |     2500 | -3.512469E-01 | -3.513470E-01
    26 |     2600 | -3.512763E-01 | -3.513788E-01
    27 |     2700 | -3.513013E-01 | -3.513957E-01
    28 |     2800 | -3.513230E-01 | -3.513957E-01
    29 |     2900 | -3.513329E-01 | -3.513957E-01
    30 |     3000 | -3.513477E-01 | -3.513957E-01
    31 |     3100 | -3.513636E-01 | -3.514034E-01
    32 |     3200 | -3.513759E-01 | -3.514244E-01
    33 |     3300 | -3.513858E-01 | -3.514244E-01
    34 |     3400 | -3.513957E-01 | -3.514296E-01
    35 |     3500 | -3.514035E-01 | -3.514391E-01
    36 |     3600 | -3.514123E-01 | -3.514391E-01
    37 |     3700 | -3.514182E-01 | -3.514391E-01
    38 |     3800 | -3.514237E-01 | -3.514391E-01
    39 |     3900 | -3.514272E-01 | -3.514407E-01
    40 |     4000 | -3.514300E-01 | -3.514413E-01
    41 |     4100 | -3.514328E-01 | -3.514434E-01
    42 |     4200 | -3.514355E-01 | -3.514489E-01
    43 |     4300 | -3.514383E-01 | -3.514489E-01
    44 |     4400 | -3.514407E-01 | -3.514497E-01
    45 |     4500 | -3.514425E-01 | -3.514497E-01
    46 |     4600 | -3.514445E-01 | -3.514528E-01
    47 |     4700 | -3.514462E-01 | -3.514537E-01
    48 |     4800 | -3.514480E-01 | -3.514537E-01
    49 |     4900 | -3.514496E-01 | -3.514543E-01
    50 |     5000 | -3.514505E-01 | -3.514553E-01
    51 |     5100 | -3.514516E-01 | -3.514553E-01
    52 |     5200 | -3.514526E-01 | -3.514553E-01
    53 |     5300 | -3.514537E-01 | -3.514556E-01
    54 |     5400 | -3.514542E-01 | -3.514574E-01
    55 |     5500 | -3.514546E-01 | -3.514574E-01
    56 |     5600 | -3.514552E-01 | -3.514575E-01
    57 |     5700 | -3.514557E-01 | -3.514576E-01
    58 |     5800 | -3.514563E-01 | -3.514578E-01
    59 |     5900 | -3.514569E-01 | -3.514586E-01
    60 |     6000 | -3.514573E-01 | -3.514594E-01
    61 |     6100 | -3.514577E-01 | -3.514600E-01
    62 |     6200 | -3.514581E-01 | -3.514601E-01
    63 |     6300 | -3.514585E-01 | -3.514601E-01
    64 |     6400 | -3.514589E-01 | -3.514601E-01
    65 |     6500 | -3.514593E-01 | -3.514601E-01
    66 |     6600 | -3.514596E-01 | -3.514601E-01
    67 |     6700 | -3.514598E-01 | -3.514606E-01
    68 |     6800 | -3.514600E-01 | -3.514606E-01
    69 |     6900 | -3.514601E-01 | -3.514606E-01
    70 |     7000 | -3.514601E-01 | -3.514606E-01
    71 |     7100 | -3.514602E-01 | -3.514606E-01
    72 |     7200 | -3.514604E-01 | -3.514606E-01
    73 |     7300 | -3.514605E-01 | -3.514606E-01
    74 |     7400 | -3.514606E-01 | -3.514606E-01
    75 |     7500 | -3.514606E-01 | -3.514607E-01
    76 |     7600 | -3.514606E-01 | -3.514607E-01
    77 |     7700 | -3.514606E-01 | -3.514607E-01
    78 |     7800 | -3.514606E-01 | -3.514607E-01
    79 |     7900 | -3.514606E-01 | -3.514607E-01
    80 |     8000 | -3.514606E-01 | -3.514607E-01
    81 |     8100 | -3.514607E-01 | -3.514607E-01
    82 |     8200 | -3.514607E-01 | -3.514607E-01
    83 |     8300 | -3.514607E-01 | -3.514607E-01
    84 |     8400 | -3.514607E-01 | -3.514607E-01
    85 |     8500 | -3.514607E-01 | -3.514607E-01
    86 |     8600 | -3.514607E-01 | -3.514607E-01
    87 |     8700 | -3.514607E-01 | -3.514607E-01
    88 |     8800 | -3.514607E-01 | -3.514607E-01
    89 |     8900 | -3.514607E-01 | -3.514607E-01
    90 |     9000 | -3.514607E-01 | -3.514607E-01
    91 |     9100 | -3.514607E-01 | -3.514607E-01
    92 |     9200 | -3.514607E-01 | -3.514607E-01
    93 |     9300 | -3.514607E-01 | -3.514607E-01
    94 |     9400 | -3.514607E-01 | -3.514607E-01
    95 |     9500 | -3.514607E-01 | -3.514607E-01
    96 |     9600 | -3.514607E-01 | -3.514607E-01
    97 |     9700 | -3.514607E-01 | -3.514607E-01
    98 |     9800 | -3.514607E-01 | -3.514607E-01
    99 |     9900 | -3.514607E-01 | -3.514607E-01
   100 |    10000 | -3.514607E-01 | -3.514607E-01


Optimizer_pymoo: Optimization run finished
  Success: True
  Best maximize_power = 15815.732334201548
print()
print(results)

fr = results.problem_results.to_dataframe()
fr[[FV.X, FV.Y, FV.AMB_WD, FV.YAWM, FV.TI, FV.REWS, FV.P]]
Results problem 'opt_yawm':
----------------------------
  Float variables:
    0: YAWM_0000 = 2.076629e+01
    1: YAWM_0001 = 1.128139e+01
    2: YAWM_0002 = -1.127253e+01
    3: YAWM_0003 = -1.253788e+01
    4: YAWM_0004 = -1.229692e+01
    5: YAWM_0005 = 1.228201e+01
    6: YAWM_0006 = 2.193854e-01
    7: YAWM_0007 = 4.470895e-01
    8: YAWM_0008 = -4.268675e-01
----------------------------
  Objectives:
    0: maximize_power = 1.581573e+04
----------------------------
  Success: True
----------------------------
X Y AMB_WD YAWM TI REWS P
state turbine
0 0 500.0 500.0 270.0 20.766292 0.060000 9.000000 2241.287477
1 700.0 1100.0 270.0 11.281386 0.060000 8.826104 2308.437756
2 900.0 1700.0 270.0 -11.272526 0.060000 8.826377 2308.764665
3 1800.0 500.0 270.0 -12.537877 0.070930 7.997996 1699.825469
4 2000.0 1100.0 270.0 -12.296916 0.089333 7.613155 1481.031499
5 2200.0 1700.0 270.0 12.282013 0.089357 7.613108 1481.160008
6 3100.0 500.0 270.0 0.219385 0.087596 7.501558 1480.039710
7 3300.0 1100.0 270.0 0.447090 0.094043 7.377976 1407.818061
8 3500.0 1700.0 270.0 -0.426867 0.094087 7.377192 1407.367688

Finally, we can visualize the result by looking at the flow field:

with engine:
    o = foxes.output.FlowPlots2D(algo, results.problem_results)
    plot_data = o.get_mean_data_xy("WS", resolution=10, xmax=5000)

fig = o.get_mean_fig_xy(plot_data)
plt.show()
../_images/f5c25ad5194c3ef14d6a030dfef72b565ea7f9641f99943e658aea2d5912268e.png

Clearly the turbines are trying to avoid hitting downwind turbines with their wakes.