{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Doinikov 1994 Models\n\nIn this example the use of the models ``doinikov1994rigid`` and\n``doinikov1994compressible`` is explained. For this purpose, we are\nrevisiting the example of a copper particle in oil using the\n``doinikov1994rigid`` model. If you are not familiar with this example you\nmight want to start `here\n<sphx_glr_examples_publication_example_frontiers_cu_in_oil.py>`.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nfrom matplotlib import pyplot as plt\n\nimport osaft\n\n# --------\n# Geometry\n# --------\n# Radius\nR_0 = 5e-6  # [m]\n\n# --------------------\n# Properties of Copper\n# --------------------\n# Speed of sound\nc_cu = 8_930  # [m/s]\n# Density\nrho_cu = 5_100  # [kg/m^3]\n\n# -------------------\n# Properties of Water\n# -------------------\n# Speed of sound\nc_oil = 1_445  # [m/s]\n# Density\nrho_oil = 922.6  # [kg/m^3]\n# Viscosity\neta_oil = 0.03  # [Pa s]\nzeta_oil = 0  # [Pa s]\n\n# --------------------------------\n# Properties of the Acoustic Field\n# --------------------------------\n# Frequency\nf = 5e5  # [Hz]\n# Pressure\np_0 = 1e5  # [Pa]\n# Wave type\nwave_type = osaft.WaveType.STANDING\n# Position of the particle in the field\nposition = np.pi / 4  # [rad]"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "In this example we are going to explain the different option available\nto the user when computing the ARF using the models ``doinikov1994rigid``\nand ``doinikov1994compressible``. These versions make different assumptions\non the relative size of the particle radius $R_0$, the boundary\nlayer thickness $\\delta$, and the wavelength $\\lambda$.\nAlternatively, the dimensionless wavenumber $x = k_f R_0$ and the\ndimensionless viscous wavenumber $x_v = k_v R_0$ can be used to\nrepresent the different cases.\n\nThe different options are listed in the table below for the model\n``doinikov1994rigid``. The  different options are accessible through the\nkeyword arguments ``long_wavelength``, ``small_boundary_layer``,\nand ``large_boundary_layer`` in the OSAFT classes for the ARF.\n\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "+-----------------------------------------------------+---------------------------------------+---------------------+--------------------------+--------------------------+\n|                      Assumption                     |      $x, x_v$-representation    | ``long_wavelength`` | ``small_boundary_layer`` | ``large_boundary_layer`` |\n+-----------------------------------------------------+---------------------------------------+---------------------+--------------------------+--------------------------+\n|                    no assumptions                   |              --                       |      ``False``      |         ``False``        |         ``False``        |\n+-----------------------------------------------------+---------------------------------------+---------------------+--------------------------+--------------------------+\n|          $\\lambda \\gg R_0, R_0 \\gg \\delta$    |  $|x| \\ll 1, |x| \\ll |x_v|$     |       ``True``      |         ``False``        |         ``False``        |\n+-----------------------------------------------------+---------------------------------------+---------------------+--------------------------+--------------------------+\n|          $\\lambda \\gg R_0 \\gg \\delta$         |  $|x| \\ll 1 \\ll |x_v|$          |       ``True``      |         ``True``         |         ``False``        |\n+-----------------------------------------------------+---------------------------------------+---------------------+--------------------------+--------------------------+\n|          $\\lambda \\gg \\delta \\gg R_0$         |  $|x| \\ll |x_v| \\ll 1$          |       ``True``      |         ``False``        |         ``True``         |\n+-----------------------------------------------------+---------------------------------------+---------------------+--------------------------+--------------------------+\n\nFor the model ``doinikov1994compressible`` there is no ``long_wavelength``\noption. If ``small_boundary_layer`` or ``large_boundary_layer`` is\nselected, long wavelength is automatically assumed.\n\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "+------------------------------------+---------------------------------------+--------------------------+--------------------------+\n|             Assumption             | $x$, $x_v$-representation | ``small_boundary_layer`` | ``large_boundary_layer`` |\n+------------------------------------+---------------------------------------+--------------------------+--------------------------+\n|           no assumptions           |                   --                  |         ``False``        |         ``False``        |\n+------------------------------------+---------------------------------------+--------------------------+--------------------------+\n| $\\lambda \\gg R_0 \\gg \\delta$ |      $|x| \\ll 1 \\ll |x_v|$      |         ``True``         |         ``False``        |\n+------------------------------------+---------------------------------------+--------------------------+--------------------------+\n| $\\lambda \\gg \\delta \\gg R_0$ |      $|x| \\ll |x_v| \\ll 1$      |         ``False``        |         ``True``         |\n+------------------------------------+---------------------------------------+--------------------------+--------------------------+\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# General case\ngeneral_sol = osaft.doinikov1994rigid.ARF(\n    f=f,\n    R_0=R_0,\n    rho_s=rho_cu,\n    rho_f=rho_oil,\n    c_f=c_oil,\n    eta_f=eta_oil,\n    zeta_f=zeta_oil,\n    p_0=p_0,\n    wave_type=wave_type,\n    position=position,\n    long_wavelength=False,\n)\ngeneral_sol.name = \"General\"\n\n\n# Long wavelength\nlong_lambda_sol = general_sol.copy()\nlong_lambda_sol.long_wavelength = True\nlong_lambda_sol.name = \"Long wavelength\"\n\n# Long wavelength, small boundary layer\nsmall_delta_sol = long_lambda_sol.copy()\nsmall_delta_sol.small_boundary_layer = True\nsmall_delta_sol.name = \"Small boundary layer\"\n\n# Long wavelength, large boundary layer\nlarge_delta_sol = long_lambda_sol.copy()\nlarge_delta_sol.large_boundary_layer = True\nlarge_delta_sol.name = \"Large boundary layer\""
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Note that the OSAFT library defaults to the general case, however the small\nparticle solution might often be more sensible to use since it is\ncomputationally much more efficient and returns similar results over a wide\nrange of values.\n\nNext, we are going to plot the ARF over a range of values for the particle\nradius. Since computing the ARF in the general case requires solving\nintegrals we are going to set the ``multicore`` option to ``True`` when\nadding solution. This way the ARF for different points are computed in\nparallel.\n\nIn order for multiprocessing to work you need to run your code inside the\n``if __name__ == '__main__':`` clause as shown below.\nCheck the `multiprocessing example <sphx_glr_examples_tutorial_example_multicore.py>`.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "if __name__ == \"__main__\":\n\n    arf_plot = osaft.ARFPlot(\"R_0\", np.linspace(1e-6, 10e-6, 30))\n\n    arf_plot.add_solutions(\n        general_sol,\n        long_lambda_sol,\n        small_delta_sol,\n        large_delta_sol,\n        multicore=True,\n    )\n\n    fig, ax = plt.subplots(1, 2, figsize=(10, 3))\n\n    arf_plot.plot_solutions(ax=ax[0])\n    ax[0].set_xlabel(\"$R_0$ $[m]$\")\n    ax[0].set_ylim(top=0.5e-10)\n\n    arf_plot.plot_solutions(ax=ax[1])\n    ax[0].set_title(\"Plot\")\n    ax[1].set_title(\"Close Up\")\n    ax[1].set_xlabel(\"$R_0$ $[m]$\")\n    ax[1].set_xlim(left=1e-6, right=5e-6)\n    ax[1].set_ylim(bottom=-1e-12, top=6e-12)\n    ax[0].legend([], frameon=False)\n\n    fig.tight_layout()\n    plt.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
}