{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Experiment: Validation\n", "\n", "In this notebook, you can compare and validate your own `WindFarmModel` (i.e. combination of engineering submodels) with data from RANS, LES and measurements." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Install PyWake if needed**" ] }, { "cell_type": "code", "execution_count": null, "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 install some basic Python elements**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib as plt\n", "plt.rcParams.update({'figure.max_open_warning': 0})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Now we also import all available models**" ] }, { "cell_type": "code", "execution_count": null, "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 *" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "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", "\n", "# Fix ipywidget label width\n", "display(HTML(''''''))\n", "\n", "def print_signature(windFarmModel, **kwargs):\n", " s = \"\"\"# insert windFarmModel code below\n", "wfm = %s\n", "\n", "validation.add_windFarmModel('MyModelName', wfm)\"\"\"% get_signature(windFarmModel, kwargs, 1)\n", " \n", " # Write windFarmModel code to cell starting \"# insert windFarmModel code below\"\n", " display(Javascript(\"\"\"\n", "for (var cell of IPython.notebook.get_cells()) {\n", " if (cell.get_text().startsWith(\"# insert windFarmModel code below\")){\n", " cell.set_text(`%s`)\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": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from py_wake.validation.validation import Validation, ValidationSite, ValidationWindTurbines\n", "site, windTurbines = ValidationSite(), ValidationWindTurbines()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Setup Validation\n", "Instantiate new validation. This cell removes previously added `WindFarmModel`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "validation = Validation()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Add WindFarmModels\n", "Add as many windFarmModels as you wish with the function\n", "\n", "```\n", "validation.add_windFarmModel(name, windFarmModel, line_style='-')\n", "```\n", "\n", "for example:\n", "\n", "```\n", "wfm = PropagateDownwind(site, windTurbines, wake_deficitModel=NOJDeficit(k=0.04))\n", "validation.add_windFarmModel(\"NOJ(k=0.04)\", wfm, ':')\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can use the dropdown boxes here to update the code cell below. Note, that some models needs manual specification of some non-optional arguments" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "_ = interact(print_signature, **models)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the cell below:\n", "\n", "- Replace `MyModelName` with a name for the windFarmModel\n", "- Set unspecified arguments, if any\n", "- Run the cell below to add the windFarmModel to the validation" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# insert windFarmModel code below\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", "\n", "validation.add_windFarmModel('MyModelName', wfm)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# print name of added wind farm models\n", "print(validation.windFarmModel_dict.keys())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Single wake deficit validation" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "validation.plot_deficit_profile()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Single wake integrated momentum deficit validation" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "validation.plot_integrated_deficit()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Wind farm power validation" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "validation.plot_multiwake_power()" ] } ], "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": false } }, "nbformat": 4, "nbformat_minor": 4 }