{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Dihedral angle effect\n\nEffect of dihedral on the lift coefficient slope of rectangular wings.\n\n## References\n.. [1] Katz, J. et al., *Low-Speed Aerodynamics*, 2nd ed, Cambridge University\n   Press, 2001: figure 12.21\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import time\n\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nimport ezaero.vlm.steady as vlm\n\nstart = time.time()\n\n# dihedral angles grid\ndeltas = np.array([-45, -30, -15, 0, 15, 30]) * np.pi / 180\n\n# define mesh parameters and flight conditions\nmesh = vlm.MeshParameters(m=8, n=30)\n# slope for each dihedral calculated using two flight conditions\nflcond_0 = vlm.FlightConditions(ui=100.0, aoa=0.0, rho=1.0)\nflcond_1 = vlm.FlightConditions(ui=100.0, aoa=np.pi / 180, rho=1.0)\ncla_list = []  # container for the lift coefficient slope\nfor delta in deltas:\n    # The figure in the book uses an aspect ratio of 4. It does not\n    # correspond to the planform, but the \"real\" wingspan, hence we project\n    # the wingspan with the dihedral angle\n    bp = 4 * np.cos(delta)\n    # define rectangular wing (same cr and ct), with no sweep (theta).\n    wing = vlm.WingParameters(\n        root_chord=1.0,\n        tip_chord=1.0,\n        planform_wingspan=bp,\n        sweep_angle=0,\n        dihedral_angle=delta,\n    )\n    res_0 = vlm.Simulation(wing=wing, mesh=mesh, flight_conditions=flcond_0).run()\n    res_1 = vlm.Simulation(wing=wing, mesh=mesh, flight_conditions=flcond_1).run()\n    d_cl = res_1.cl_wing - res_0.cl_wing\n    d_alpha = flcond_1.aoa - flcond_0.aoa\n    slope = d_cl / d_alpha * np.cos(delta)  # project load\n    cla_list.append(slope)\n\nend = time.time()\nelapsed = end - start\n\nprint(\"Elapsed time: {} s\".format(elapsed))\n\nfig = plt.figure()\nplt.plot(deltas * 180 / np.pi, cla_list, \"o-\")\nplt.xlabel(r\"$\\delta$[deg]\")\nplt.ylabel(r\"CL$_\\alpha$\")\nplt.ylim(0, 4)\nplt.grid()\nplt.xlim(deltas.min() * 180 / np.pi, deltas.max() * 180 / np.pi)\nplt.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "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.7.3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}