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 foxes
import foxes.variables as FV
import matplotlib.pyplot as plt
import numpy as np
from iwopy import create_optimizer

from foxes_opt.objectives import MaxFarmPower
from foxes_opt.problems import OptFarmVars
/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/d23fca89754edc5c9024fe0c3dca889020dfa90a87ef257018072a683ccbe2da.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
----------------------------------------------

Next, we setup the solver:

solver = create_optimizer(
    family="pymoo",
    optimizer="GA",
    problem=problem,
    vectorize=True,
    pop_size=100,
    seed=42,
    termination="iterations",
    max_iterations=100,
)
solver.initialize()
solver.print_info()
Loading pymoo
pymoo successfully loaded
Initializing Optimizer_pymoo
Selecting sampling: float_random (FloatRandomSampling)
Selecting algorithm: GA (GA)
Selecting termination: iterations (MaximumGenerationTermination)

Problem:
--------
  name         : opt_yawm
  n_vars_int   : 0
  n_vars_float : 9
  n_objectives : 1
  n_obj_cmptns : 1
  n_constraints: 0
  n_con_cmptns : 0

Algorithm:
----------
  pop_size: 100

Termination:
------------
  type: iterations
  n_max_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.670890E-01 | -3.230743E-01
     2 |      200 | -2.960924E-01 | -3.292602E-01
     3 |      300 | -3.099930E-01 | -3.345403E-01
     4 |      400 | -3.201088E-01 | -3.395287E-01
     5 |      500 | -3.273570E-01 | -3.396750E-01
     6 |      600 | -3.335849E-01 | -3.401461E-01
     7 |      700 | -3.374181E-01 | -3.428765E-01
     8 |      800 | -3.396766E-01 | -3.429191E-01
     9 |      900 | -3.410620E-01 | -3.430328E-01
    10 |     1000 | -3.420312E-01 | -3.437494E-01
    11 |     1100 | -3.427412E-01 | -3.443690E-01
    12 |     1200 | -3.433163E-01 | -3.443819E-01
    13 |     1300 | -3.437502E-01 | -3.447267E-01
    14 |     1400 | -3.440460E-01 | -3.450901E-01
    15 |     1500 | -3.443020E-01 | -3.450901E-01
    16 |     1600 | -3.445020E-01 | -3.450901E-01
    17 |     1700 | -3.446790E-01 | -3.451949E-01
    18 |     1800 | -3.448447E-01 | -3.452171E-01
    19 |     1900 | -3.449986E-01 | -3.454152E-01
    20 |     2000 | -3.450920E-01 | -3.454152E-01
    21 |     2100 | -3.451447E-01 | -3.454163E-01
    22 |     2200 | -3.452229E-01 | -3.454615E-01
    23 |     2300 | -3.452791E-01 | -3.454615E-01
    24 |     2400 | -3.453350E-01 | -3.454656E-01
    25 |     2500 | -3.453846E-01 | -3.454804E-01
    26 |     2600 | -3.454155E-01 | -3.454804E-01
    27 |     2700 | -3.454380E-01 | -3.454813E-01
    28 |     2800 | -3.454550E-01 | -3.454819E-01
    29 |     2900 | -3.454618E-01 | -3.454854E-01
    30 |     3000 | -3.454689E-01 | -3.454925E-01
    31 |     3100 | -3.454749E-01 | -3.454959E-01
    32 |     3200 | -3.454796E-01 | -3.454975E-01
    33 |     3300 | -3.454839E-01 | -3.455113E-01
    34 |     3400 | -3.454894E-01 | -3.455113E-01
    35 |     3500 | -3.454944E-01 | -3.455168E-01
    36 |     3600 | -3.454995E-01 | -3.455200E-01
    37 |     3700 | -3.455037E-01 | -3.455200E-01
    38 |     3800 | -3.455080E-01 | -3.455204E-01
    39 |     3900 | -3.455113E-01 | -3.455252E-01
    40 |     4000 | -3.455139E-01 | -3.455252E-01
    41 |     4100 | -3.455168E-01 | -3.455252E-01
    42 |     4200 | -3.455195E-01 | -3.455252E-01
    43 |     4300 | -3.455212E-01 | -3.455259E-01
    44 |     4400 | -3.455223E-01 | -3.455259E-01
    45 |     4500 | -3.455235E-01 | -3.455261E-01
    46 |     4600 | -3.455244E-01 | -3.455274E-01
    47 |     4700 | -3.455250E-01 | -3.455274E-01
    48 |     4800 | -3.455255E-01 | -3.455282E-01
    49 |     4900 | -3.455261E-01 | -3.455282E-01
    50 |     5000 | -3.455265E-01 | -3.455291E-01
    51 |     5100 | -3.455270E-01 | -3.455293E-01
    52 |     5200 | -3.455274E-01 | -3.455293E-01
    53 |     5300 | -3.455279E-01 | -3.455293E-01
    54 |     5400 | -3.455281E-01 | -3.455293E-01
    55 |     5500 | -3.455284E-01 | -3.455295E-01
    56 |     5600 | -3.455287E-01 | -3.455296E-01
    57 |     5700 | -3.455289E-01 | -3.455296E-01
    58 |     5800 | -3.455291E-01 | -3.455297E-01
    59 |     5900 | -3.455293E-01 | -3.455300E-01
    60 |     6000 | -3.455295E-01 | -3.455302E-01
    61 |     6100 | -3.455296E-01 | -3.455302E-01
    62 |     6200 | -3.455297E-01 | -3.455304E-01
    63 |     6300 | -3.455298E-01 | -3.455322E-01
    64 |     6400 | -3.455299E-01 | -3.455323E-01
    65 |     6500 | -3.455301E-01 | -3.455323E-01
    66 |     6600 | -3.455303E-01 | -3.455323E-01
    67 |     6700 | -3.455305E-01 | -3.455323E-01
    68 |     6800 | -3.455308E-01 | -3.455328E-01
    69 |     6900 | -3.455312E-01 | -3.455328E-01
    70 |     7000 | -3.455317E-01 | -3.455329E-01
    71 |     7100 | -3.455322E-01 | -3.455329E-01
    72 |     7200 | -3.455324E-01 | -3.455329E-01
    73 |     7300 | -3.455325E-01 | -3.455329E-01
    74 |     7400 | -3.455326E-01 | -3.455331E-01
    75 |     7500 | -3.455328E-01 | -3.455331E-01
    76 |     7600 | -3.455329E-01 | -3.455332E-01
    77 |     7700 | -3.455329E-01 | -3.455332E-01
    78 |     7800 | -3.455329E-01 | -3.455332E-01
    79 |     7900 | -3.455330E-01 | -3.455332E-01
    80 |     8000 | -3.455330E-01 | -3.455332E-01
    81 |     8100 | -3.455331E-01 | -3.455332E-01
    82 |     8200 | -3.455331E-01 | -3.455332E-01
    83 |     8300 | -3.455332E-01 | -3.455333E-01
    84 |     8400 | -3.455332E-01 | -3.455333E-01
    85 |     8500 | -3.455332E-01 | -3.455334E-01
    86 |     8600 | -3.455332E-01 | -3.455334E-01
    87 |     8700 | -3.455332E-01 | -3.455334E-01
    88 |     8800 | -3.455332E-01 | -3.455334E-01
    89 |     8900 | -3.455333E-01 | -3.455334E-01
    90 |     9000 | -3.455333E-01 | -3.455334E-01
    91 |     9100 | -3.455333E-01 | -3.455334E-01
    92 |     9200 | -3.455334E-01 | -3.455334E-01
    93 |     9300 | -3.455334E-01 | -3.455334E-01
    94 |     9400 | -3.455334E-01 | -3.455334E-01
    95 |     9500 | -3.455334E-01 | -3.455334E-01
    96 |     9600 | -3.455334E-01 | -3.455334E-01
    97 |     9700 | -3.455334E-01 | -3.455334E-01
    98 |     9800 | -3.455334E-01 | -3.455334E-01
    99 |     9900 | -3.455334E-01 | -3.455334E-01
   100 |    10000 | -3.455334E-01 | -3.455334E-01
Optimizer_pymoo: Optimization run finished
  Success: True
  Best maximize_power = 15549.004325494383
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 = 1.608272e+01
    1: YAWM_0001 = 7.819832e+00
    2: YAWM_0002 = -7.854306e+00
    3: YAWM_0003 = -9.333336e+00
    4: YAWM_0004 = -9.149540e+00
    5: YAWM_0005 = 9.157319e+00
    6: YAWM_0006 = 1.000861e-01
    7: YAWM_0007 = 2.852827e-01
    8: YAWM_0008 = -2.777706e-01
----------------------------
  Objectives:
    0: maximize_power = 1.554900e+04
----------------------------
  Success: True
----------------------------
X Y AMB_WD YAWM TI REWS P
state turbine
0 0 500.0 500.0 270.0 16.082721 0.060000 8.604143 2222.697102
1 700.0 1100.0 270.0 7.819832 0.060000 8.822945 2386.251701
2 900.0 1700.0 270.0 -7.854306 0.060000 8.821392 2385.090259
3 1800.0 500.0 270.0 -9.333336 0.078154 7.808660 1659.376450
4 2000.0 1100.0 270.0 -9.149540 0.099327 7.428681 1437.506711
5 2200.0 1700.0 270.0 9.157319 0.099223 7.429930 1438.235904
6 3100.0 500.0 270.0 0.100086 0.098057 7.340309 1385.906551
7 3300.0 1100.0 270.0 0.285283 0.105596 7.221875 1316.752718
8 3500.0 1700.0 270.0 -0.277771 0.105540 7.222618 1317.186930

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/4a4b4e4ac663b505f2aee670221edb0df58bccceac8c1ac70b4e03bec655ade1.png

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