{ "cells": [ { "cell_type": "markdown", "id": "eecc8e70", "metadata": {}, "source": [ "# Nested turbine type specific optimization\n", "\n", "In this example, a nested optimization is performed accounting for the layout and the turbine types. The inner layer solves the layout optimization problem with a gradient-based solver, and the outer layer changes the turbine types with a gradient-free (random-search) solver. In this case, the boundaries are not specific to the wind turbine and a spacing and circular boundary contraints are used.\n", "\n", "The objective function is to minimize the wake losses produced by neighbouring wind turbines." ] }, { "cell_type": "markdown", "id": "b7069995", "metadata": {}, "source": [ "**Install TOPFARM if needed**" ] }, { "cell_type": "code", "execution_count": 18, "id": "46898a59", "metadata": {}, "outputs": [], "source": [ "# Install TopFarm if needed\n", "import importlib\n", "if not importlib.util.find_spec(\"topfarm\"):\n", " !pip install git+https://gitlab.windenergy.dtu.dk/TOPFARM/TopFarm2.git" ] }, { "cell_type": "markdown", "id": "edc4ac30", "metadata": {}, "source": [ "Loading Python dependencies." ] }, { "cell_type": "code", "execution_count": 19, "id": "25330568", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "markdown", "id": "be864b04", "metadata": {}, "source": [ "Loading PyWake dependencies. We import the two turbines to use (Vestas V80 and the DTU 10MW reference turbine) as well as the site (IEA37) and the wake deficit model (IEA37SimpleBastankhahGaussian) to use for the optimization." ] }, { "cell_type": "code", "execution_count": 20, "id": "1a591c67", "metadata": {}, "outputs": [], "source": [ "from py_wake.examples.data.iea37._iea37 import IEA37Site\n", "from py_wake.wind_turbines import WindTurbines\n", "from py_wake.examples.data.hornsrev1 import V80\n", "from py_wake.examples.data.dtu10mw import DTU10MW\n", "from py_wake.deficit_models.gaussian import IEA37SimpleBastankhahGaussian\n", "from py_wake.utils.gradients import autograd" ] }, { "cell_type": "markdown", "id": "332e3aff", "metadata": {}, "source": [ "Loading TOPFARM dependencies." ] }, { "cell_type": "code", "execution_count": 21, "id": "ac0a5e80", "metadata": {}, "outputs": [], "source": [ "import topfarm\n", "from topfarm.cost_models.cost_model_wrappers import CostModelComponent\n", "from topfarm import TopFarmProblem\n", "from topfarm.easy_drivers import EasyRandomSearchDriver, EasyScipyOptimizeDriver\n", "from topfarm.drivers.random_search_driver import randomize_turbine_type\n", "from topfarm.constraint_components.boundary import CircleBoundaryConstraint\n", "from topfarm.constraint_components.spacing import SpacingConstraint, SpacingTypeConstraint\n", "from topfarm.plotting import XYPlotComp, TurbineTypePlotComponent, NoPlot" ] }, { "cell_type": "markdown", "id": "0d25b981", "metadata": {}, "source": [ "We first define the site and initial positions for the optimization problem." ] }, { "cell_type": "code", "execution_count": 22, "id": "38324412", "metadata": {}, "outputs": [], "source": [ "# Site definition\n", "n_wt = 9\n", "site = IEA37Site(n_wt, ti=0.05)\n", "wt_x = site.initial_position[:, 0]\n", "wt_y = site.initial_position[:, 1]" ] }, { "cell_type": "code", "execution_count": 23, "id": "e89cc2d9", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.DataArray (sector: 12)>\n", "array([0.03275556, 0.03466667, 0.04457778, 0.08075556, 0.10533333,\n", " 0.15191111, 0.08742222, 0.0512 , 0.08915556, 0.23697778,\n", " 0.05386667, 0.03422222])\n", "Coordinates:\n", " * sector (sector) int64 0 1 2 3 4 5 6 7 8 9 10 11\n", "Attributes:\n", " description: Probability of wind flow case (i.e. wind direction and wind...