{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Hasegawa (1979) Figure 3\nIn this example we recreate Figure 3 from Hasegawa's 1979 paper.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "First, we need to get an instance of our solution class. In this case\n``osaft.hasegawa1969.ARF()``. The steps are the same as in the earlier\nexamples. Note that we set ``N_max = 12``. ``N_max`` is the highest\nvibration mode of the sphere still considered in the computation.\nIn this example we need to consider many modes since\nthe wavelength is of similar length as the particle diameter.\nThis is usually not the case and the default value of ``N_max = 5`` is\nmore than sufficient to get an accurate value for the ARF.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport numpy as np\n\nimport osaft\n\n# --------\n# Geometry\n# --------\n# Radius\nR_0 = 1e-6  # [m]\n\n# ----------------------------\n# Properties of Brass Particle\n# ----------------------------\nrho_s = 8100  # [kg/m^3]\nE_s = 88e9  # [Pa]\nnu_s = 0.301  # [-]\n# -------------------\n# Properties of Water\n# -------------------\nrho_f = 1000  # [kg/m^3]\nc_f = 1500  # [m/s]\n\n# --------------------------------\n# Properties of the Acoustic Field\n# --------------------------------\npos = osaft.pi / 4\nf = 1e6\np_0 = 1e5\nwave_type = osaft.WaveType.STANDING\nN_max = 12\n\nhasegawa = osaft.hasegawa1969.ARF(\n    rho_s=rho_s,\n    E_s=E_s,\n    nu_s=nu_s,\n    rho_f=rho_f,\n    c_f=c_f,\n    position=pos,\n    f=f,\n    R_0=R_0,\n    p_0=p_0,\n    wave_type=wave_type,\n    N_max=N_max,\n)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "We need to plot the ARF over a range of values of $k_f R_0$. For\nthis we are changing the radius $R_0$ while keeping all other\nparameters constant.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "N = 100\nR_min = 1e-6\nR_max = 10 / hasegawa.k_f\nR0_values = np.linspace(R_min, R_max, N)\nkr_values = hasegawa.k_f * R0_values"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Here we initiate the plot and add the solution.\nIn the first argument (``x_values``) we define the values for\nwhich the second argument (``attr_name``) should be evaluated.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "arf_plot = osaft.ARFPlot(x_values=R0_values, attr_name=\"R_0\")\narf_plot.add_solutions(hasegawa)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "In his article Hasegawa does not plot the ARF itself but normalized it\nw.r.t. to the acoustic energy density and the cross-sectional area of the\nsphere.\n\n\\begin{align}Y_\\text{ST} = (F^\\text{rad} / \\pi R_0^2 E_\\text{ac})\\end{align}\n\nWe therefore define a normalization function that depends on our variable\n``R_0`` that we are going to plot the ARF over and we will later pass it\nto ``plot_solutions``.\nNote that the factor of ``1/2`` stems from the fact that Hasegawa has\ndefined the energy w.r.t. to a single propagating wave and not the overall\npressure amplitude of the standing wave.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "def normalization(radius):\n    return 1 / 2 * hasegawa.field.E_ac * osaft.pi * radius**2"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Finally, we plot the figure. Here we use ``plt.subplots()`` to get a figure\nwith the correct aspect ratio and pass the ``Axes`` instance ``ax`` to\n``plot_solutions``.\nWe can directly pass ``display_values`` to the ``plot_solutions`` method,\nin order to plot over the values of $k_f R_0$ instead of the radius.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig, ax = plt.subplots(figsize=(3, 5))\narf_plot.plot_solutions(\n    ax=ax,\n    display_values=kr_values,\n    color=\"black\",\n    normalization=normalization,\n)\nax.set_xlabel(r\"$ka$\")\nax.set_ylabel(\"$Y_{ST}$\")\nax.axhline(0, color=\"k\")\nax.set_xlim(left=0, right=10)\nax.set_ylim(bottom=-1, top=3.5)\nax.set_xticks([0, 2, 4, 6, 8])\nax.set_yticks([-1, 0, 1, 2, 3])\nax.legend([\"Brass\"])\nfig.tight_layout()\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.9.15"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}