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:4: 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 frame choice yawed, which realizes the wake bending for yawed conditions:

algo = foxes.algorithms.Downwind(
    farm,
    states,
    rotor_model="grid25",
    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 | -3.639617E-01 | -4.533271E-01
     2 |      200 | -4.047215E-01 | -4.533271E-01
     3 |      300 | -4.279116E-01 | -4.757470E-01
     4 |      400 | -4.433631E-01 | -4.757470E-01
     5 |      500 | -4.578166E-01 | -4.862460E-01
     6 |      600 | -4.697552E-01 | -4.862460E-01
     7 |      700 | -4.777542E-01 | -4.921418E-01
     8 |      800 | -4.835812E-01 | -4.931149E-01
     9 |      900 | -4.881977E-01 | -4.998521E-01
    10 |     1000 | -4.917253E-01 | -4.998521E-01
    11 |     1100 | -4.944844E-01 | -5.004665E-01
    12 |     1200 | -4.967636E-01 | -5.007790E-01
    13 |     1300 | -4.986847E-01 | -5.015689E-01
    14 |     1400 | -4.999407E-01 | -5.015689E-01
    15 |     1500 | -5.005841E-01 | -5.019827E-01
    16 |     1600 | -5.010777E-01 | -5.023607E-01
    17 |     1700 | -5.015290E-01 | -5.024389E-01
    18 |     1800 | -5.018961E-01 | -5.031638E-01
    19 |     1900 | -5.022209E-01 | -5.032111E-01
    20 |     2000 | -5.024577E-01 | -5.032111E-01
    21 |     2100 | -5.026423E-01 | -5.032428E-01
    22 |     2200 | -5.028688E-01 | -5.034749E-01
    23 |     2300 | -5.030536E-01 | -5.034749E-01
    24 |     2400 | -5.031697E-01 | -5.034826E-01
    25 |     2500 | -5.032721E-01 | -5.034826E-01
    26 |     2600 | -5.033514E-01 | -5.034827E-01
    27 |     2700 | -5.034086E-01 | -5.036019E-01
    28 |     2800 | -5.034519E-01 | -5.036351E-01
    29 |     2900 | -5.034875E-01 | -5.036351E-01
    30 |     3000 | -5.035302E-01 | -5.036367E-01
    31 |     3100 | -5.035743E-01 | -5.036604E-01
    32 |     3200 | -5.036017E-01 | -5.036671E-01
    33 |     3300 | -5.036157E-01 | -5.036693E-01
    34 |     3400 | -5.036313E-01 | -5.036765E-01
    35 |     3500 | -5.036472E-01 | -5.036848E-01
    36 |     3600 | -5.036609E-01 | -5.036848E-01
    37 |     3700 | -5.036674E-01 | -5.036877E-01
    38 |     3800 | -5.036731E-01 | -5.036937E-01
    39 |     3900 | -5.036769E-01 | -5.036937E-01
    40 |     4000 | -5.036803E-01 | -5.036937E-01
    41 |     4100 | -5.036842E-01 | -5.036966E-01
    42 |     4200 | -5.036879E-01 | -5.037035E-01
    43 |     4300 | -5.036910E-01 | -5.037074E-01
    44 |     4400 | -5.036937E-01 | -5.037089E-01
    45 |     4500 | -5.036965E-01 | -5.037100E-01
    46 |     4600 | -5.036989E-01 | -5.037100E-01
    47 |     4700 | -5.037026E-01 | -5.037100E-01
    48 |     4800 | -5.037055E-01 | -5.037121E-01
    49 |     4900 | -5.037074E-01 | -5.037128E-01
    50 |     5000 | -5.037088E-01 | -5.037128E-01
    51 |     5100 | -5.037102E-01 | -5.037153E-01
    52 |     5200 | -5.037109E-01 | -5.037161E-01
    53 |     5300 | -5.037120E-01 | -5.037165E-01
    54 |     5400 | -5.037129E-01 | -5.037167E-01
    55 |     5500 | -5.037136E-01 | -5.037167E-01
    56 |     5600 | -5.037144E-01 | -5.037169E-01
    57 |     5700 | -5.037152E-01 | -5.037175E-01
    58 |     5800 | -5.037160E-01 | -5.037175E-01
    59 |     5900 | -5.037165E-01 | -5.037176E-01
    60 |     6000 | -5.037169E-01 | -5.037182E-01
    61 |     6100 | -5.037171E-01 | -5.037182E-01
    62 |     6200 | -5.037174E-01 | -5.037182E-01
    63 |     6300 | -5.037176E-01 | -5.037184E-01
    64 |     6400 | -5.037177E-01 | -5.037184E-01
    65 |     6500 | -5.037179E-01 | -5.037184E-01
    66 |     6600 | -5.037180E-01 | -5.037184E-01
    67 |     6700 | -5.037182E-01 | -5.037185E-01
    68 |     6800 | -5.037182E-01 | -5.037185E-01
    69 |     6900 | -5.037183E-01 | -5.037186E-01
    70 |     7000 | -5.037184E-01 | -5.037186E-01
    71 |     7100 | -5.037184E-01 | -5.037187E-01
    72 |     7200 | -5.037185E-01 | -5.037187E-01
    73 |     7300 | -5.037185E-01 | -5.037187E-01
    74 |     7400 | -5.037186E-01 | -5.037187E-01
    75 |     7500 | -5.037186E-01 | -5.037187E-01
    76 |     7600 | -5.037186E-01 | -5.037188E-01
    77 |     7700 | -5.037187E-01 | -5.037188E-01
    78 |     7800 | -5.037187E-01 | -5.037192E-01
    79 |     7900 | -5.037187E-01 | -5.037192E-01
    80 |     8000 | -5.037187E-01 | -5.037192E-01
    81 |     8100 | -5.037188E-01 | -5.037192E-01
    82 |     8200 | -5.037188E-01 | -5.037192E-01
    83 |     8300 | -5.037189E-01 | -5.037192E-01
    84 |     8400 | -5.037189E-01 | -5.037193E-01
    85 |     8500 | -5.037190E-01 | -5.037193E-01
    86 |     8600 | -5.037191E-01 | -5.037194E-01
    87 |     8700 | -5.037192E-01 | -5.037194E-01
    88 |     8800 | -5.037192E-01 | -5.037194E-01
    89 |     8900 | -5.037193E-01 | -5.037194E-01
    90 |     9000 | -5.037193E-01 | -5.037196E-01
    91 |     9100 | -5.037193E-01 | -5.037196E-01
    92 |     9200 | -5.037194E-01 | -5.037196E-01
    93 |     9300 | -5.037194E-01 | -5.037196E-01
    94 |     9400 | -5.037195E-01 | -5.037196E-01
    95 |     9500 | -5.037195E-01 | -5.037196E-01
    96 |     9600 | -5.037196E-01 | -5.037196E-01
    97 |     9700 | -5.037196E-01 | -5.037197E-01
    98 |     9800 | -5.037196E-01 | -5.037197E-01
    99 |     9900 | -5.037196E-01 | -5.037197E-01
   100 |    10000 | -5.037196E-01 | -5.037197E-01
Optimizer_pymoo: Optimization run finished
  Success: True
  Best maximize_power = 22667.388445734177
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.375223e-02
    1: YAWM_0001 = -3.710323e-02
    2: YAWM_0002 = 2.152644e-02
    3: YAWM_0003 = -8.049195e-03
    4: YAWM_0004 = 2.929254e-02
    5: YAWM_0005 = 2.058221e-02
    6: YAWM_0006 = -5.697061e-02
    7: YAWM_0007 = -9.110859e-03
    8: YAWM_0008 = -1.854950e-02
----------------------------
  Objectives:
    0: maximize_power = 2.266739e+04
----------------------------
  Success: True
----------------------------
X Y AMB_WD YAWM TI REWS P
state turbine
0 0 500.0 500.0 270.0 -0.013752 0.06 9.000000 2518.599879
1 700.0 1100.0 270.0 -0.037103 0.06 8.999998 2518.597705
2 900.0 1700.0 270.0 0.021526 0.06 8.999999 2518.599228
3 1800.0 500.0 270.0 -0.008049 0.06 9.000000 2518.599892
4 2000.0 1100.0 270.0 0.029293 0.06 8.999999 2518.598570
5 2200.0 1700.0 270.0 0.020582 0.06 8.999999 2518.599294
6 3100.0 500.0 270.0 -0.056971 0.06 8.999996 2518.594590
7 3300.0 1100.0 270.0 -0.009111 0.06 9.000000 2518.599862
8 3500.0 1700.0 270.0 -0.018549 0.06 9.000000 2518.599426

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/57cfb81fb6e60aee9eda0a2110214412e628d0e3887fa374464dca82a4669e90.png

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