{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Single row of turbines" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "We start with the imports for this example:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "\n", "import foxes\n", "import foxes.variables as FV" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "The `foxes` setup is described in the `Overview` section. In summary, it consists of creating: \n", "\n", "1. The so-called `model book`, which contains all selectable models\n", "2. Ambient wind conditions, called `states` in `foxes` terminology\n", "3. The `wind farm`, collecting all turbine information\n", "4. The `algorithm` with its parameters and model choices\n", "\n", "Here is a simple example for a single row of turbines along the x axis and a uniform wind speed with wind direction 270°:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "# Create model book and add turbine type model:\n", "# The csv file will be searched in the file system,\n", "# and if not found, taken from static library.\n", "#\n", "# Note that we could actually skip adding the \"NREL5\"\n", "# model and use \"NREL5MW\" which already exists in the\n", "# default model book. Here this is for demonstrational\n", "# purposes, in case you have your own turbine file:\n", "mbook = foxes.ModelBook()\n", "mbook.turbine_types[\"NREL5\"] = foxes.models.turbine_types.PCtFile(\n", " \"NREL-5MW-D126-H90.csv\"\n", ")\n", "\n", "# create ambient wind conditions, a single uniform state:\n", "states = foxes.input.states.SingleStateStates(ws=9.0, wd=270.0, ti=0.12, rho=1.225)\n", "\n", "# create wind farm, a single row of turbines:\n", "farm = foxes.WindFarm()\n", "foxes.input.farm_layout.add_row(\n", " farm=farm,\n", " xy_base=[0.0, 0.0],\n", " xy_step=[800.0, 0.0],\n", " n_turbines=5,\n", " turbine_models=[\"NREL5\"],\n", " verbosity=0,\n", ")\n", "\n", "# setup the calculation algorithm:\n", "algo = foxes.algorithms.Downwind(\n", " mbook, farm, states, verbosity=0, wake_models=[\"Jensen_linear_k007\"]\n", ")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Now we can ask the `algorithm` object to run the calculation. This returns a `xarray.Dataset` object with results for each state and turbine:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "farm_results = algo.calc_farm()\n", "print(\"\\nFarm results:\\n\", farm_results)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "For a convenient summary printout we can easily convert the results into a `pandas.DataFrame`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fr = farm_results.to_dataframe()\n", "print(fr[[FV.WD, FV.AMB_REWS, FV.REWS, FV.TI, FV.AMB_P, FV.P, FV.CT]])" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Once the farm calculation results are ready, we can evaluate the wake corrected flow and all points of interest. For example, we can evaluate the wind speed along the centre line:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# infer hub height from turbine type:\n", "H = mbook.turbine_types[\"NREL5\"].H\n", "\n", "# create points of interest, shape (n_states, n_points, 3):\n", "n_points = 8000\n", "points = np.zeros((1, n_points, 3))\n", "points[:, :, 0] = np.linspace(-100.0, 15000.0, n_points)[None, :]\n", "points[:, :, 2] = H\n", "\n", "# calculate point results:\n", "point_results = algo.calc_points(farm_results, points)\n", "print(\"\\nPoint results:\\n\", point_results)\n", "\n", "# create figure:\n", "fig, ax = plt.subplots(figsize=(10, 5))\n", "ax.plot(points[0, :, 0], point_results[FV.WS][0, :])\n", "ax.set_xlabel(\"x [m]\")\n", "ax.set_ylabel(\"Wind speed [m/s]\")\n", "plt.show()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "The `foxes.output` package provides a collection of standard outputs. For example, we can visualize the flow field in a horizontal slice at hub height:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "o = foxes.output.FlowPlots2D(algo, farm_results)\n", "g = o.gen_states_fig_xy(\"WS\", resolution=10, figsize=(10, 5), verbosity=0)\n", "fig = next(g) # creates the figure for the next state, here there is only state 0\n", "plt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "foxes", "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.10.9 (main, Dec 7 2022, 01:12:00) [GCC 9.4.0]" }, "vscode": { "interpreter": { "hash": "4fb778166dae186e4d4cfa777e9f30c32eb0bc447af40b9aef55a0c1baf561be" } } }, "nbformat": 4, "nbformat_minor": 2 }