{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Experiment: Combine Models\n",
"\n",
"In this notebook, you can combine the difference models of PyWake and see the effects in terms of AEP and a flow map."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Install PyWake if needed**"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# Install PyWake if needed\n",
"try:\n",
" import py_wake\n",
"except ModuleNotFoundError:\n",
" !pip install git+https://gitlab.windenergy.dtu.dk/TOPFARM/PyWake.git"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Now we also import all available models**"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from py_wake.deficit_models import *\n",
"from py_wake.deficit_models.deficit_model import *\n",
"from py_wake.wind_farm_models import *\n",
"from py_wake.rotor_avg_models import *\n",
"from py_wake.superposition_models import *\n",
"from py_wake.deflection_models import *\n",
"from py_wake.turbulence_models import *\n",
"from py_wake.ground_models import *\n",
"from py_wake.deficit_models.utils import *"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Then, we set up the site, wind turbines as well as their initial positions**."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from py_wake.examples.data.iea37._iea37 import IEA37Site, IEA37_WindTurbines\n",
"\n",
"site = IEA37Site(16)\n",
"windTurbines = IEA37_WindTurbines()\n",
"x,y = site.initial_position.T"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# prepare for the model combination tool\n",
"from py_wake.utils.model_utils import get_models, get_signature\n",
"from ipywidgets import interact\n",
"from IPython.display import HTML, display, Javascript\n",
"import time\n",
"import matplotlib.pyplot as plt\n",
"\n",
"# Fix ipywidget label width\n",
"display(HTML(''''''))\n",
"\n",
"def print_signature(windFarmModel, **kwargs):\n",
" s = \"\"\"# windFarmModel autogenerated by dropdown boxes\n",
"t = time.time()\n",
"wfm = %s\n",
"sim_res = wfm(x,y)\n",
"plt.figure(figsize=(12,8))\n",
"sim_res.flow_map(wd=270).plot_wake_map()\n",
"print (wfm)\n",
"print (\"Computation time (AEP + flowmap):\", time.time()-t)\n",
"plt.title('AEP: %%.2fGWh'%%(sim_res.aep().sum()))\"\"\"% get_signature(windFarmModel, kwargs, 1)\n",
" # Write windFarmModel code to cell starting \"# windFarmModel autogenerated by dropdown boxes\"\n",
" display(Javascript(\"\"\"\n",
"for (var cell of IPython.notebook.get_cells()) {\n",
" if (cell.get_text().startsWith(\"# windFarmModel autogenerated by dropdown boxes\")){\n",
" cell.set_text(`%s`);\n",
" cell.execute();\n",
" }\n",
"}\"\"\"%s))\n",
"\n",
"# setup list of models\n",
"models = {n:[(getattr(m,'__name__',m), m) for m in get_models(cls)] \n",
" for n,cls in [('windFarmModel', WindFarmModel),\n",
" ('wake_deficitModel', WakeDeficitModel),\n",
" ('rotorAvgModel', RotorAvgModel),\n",
" ('superpositionModel', SuperpositionModel),\n",
" ('blockage_deficitModel', BlockageDeficitModel),\n",
" ('deflectionModel',DeflectionModel),\n",
" ('turbulenceModel', TurbulenceModel),\n",
" ('groundModel', GroundModel)\n",
" ]}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Combine and execute model\n",
"\n",
"Combine your model via the dropdown boxes below.\n",
"\n",
"Choosing a different model updates and executes the the code cell below which runs the wind farm model, prints the AEP and plots a flow map."
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4a1cf9f1f9274f2094c2d7e8737a8b50",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(Dropdown(description='windFarmModel', options=(('PropagateDownwind', "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# windFarmModel autogenerated by dropdown boxes\n",
"t = time.time()\n",
"wfm = PropagateDownwind(\n",
" site,\n",
" windTurbines,\n",
" wake_deficitModel=NOJDeficit(\n",
" k=0.1,\n",
" rotorAvgModel=AreaOverlapAvgModel(),\n",
" groundModel=None),\n",
" superpositionModel=LinearSum(),\n",
" deflectionModel=None,\n",
" turbulenceModel=None,\n",
" rotorAvgModel=None)\n",
"sim_res = wfm(x,y)\n",
"plt.figure(figsize=(12,8))\n",
"sim_res.flow_map(wd=270).plot_wake_map()\n",
"print (wfm)\n",
"print (\"Computation time (AEP + flowmap):\", time.time()-t)\n",
"plt.title('AEP: %.2fGWh'%(sim_res.aep().sum()))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": true
}
},
"nbformat": 4,
"nbformat_minor": 4
}