{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Pressure Plots for different theories\n\nThis example shows how to plot the pressure field for different theories\nin one single figure.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "In this example we are investigating a polystyrene particle in a viscous\noil in a standing wave.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from 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 polystyrene\n# -------------------------\n# Density\nrho_ps = 1_050  # [kg/m^3]\n# Young's modulus\nE_ps = 3.25e9  # [Pa]\n# Poisson's ratio\nnu_ps = 0.34  # [-]\n# Speed of sound (matching compressibility)\nc_ps = (E_ps / (rho_ps * 3 * (1 - 2 * nu_ps))) ** 0.5  # [m/s]\n\n# -------------------\n# Properties of Oil\n# -------------------\n# Density\nrho_oil = 923  # [kg/m^3]\n# Speed of sound\nc_oil = 1_445  # [m/s]\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 = 1e6  # [Hz]\n# Pressure\np_0 = 1e5  # [Pa]\n# Wave type\nwave_type = osaft.WaveType.STANDING\n# position\nposition = osaft.pi / 4"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Once all properties are defined we can initialize the solution instances for\nthe scattering field. We also save the solutions to a list which will make\nlooping in the next steps straightforward.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "solutions = []\n\nsolutions.append(\n    osaft.king1934.ScatteringField(\n        f=f,\n        R_0=R_0,\n        rho_s=rho_ps,\n        rho_f=rho_oil,\n        c_f=c_oil,\n        p_0=p_0,\n        wave_type=wave_type,\n        position=position,\n    ),\n)\n\n\nsolutions.append(\n    osaft.yosioka1955.ScatteringField(\n        f=f,\n        R_0=R_0,\n        rho_s=rho_ps,\n        c_s=c_ps,\n        rho_f=rho_oil,\n        c_f=c_oil,\n        p_0=p_0,\n        wave_type=wave_type,\n        position=position,\n    ),\n)\n\nsolutions.append(\n    osaft.hasegawa1969.ScatteringField(\n        f=f,\n        R_0=R_0,\n        rho_s=rho_ps,\n        E_s=E_ps,\n        nu_s=nu_ps,\n        rho_f=rho_oil,\n        c_f=c_oil,\n        p_0=p_0,\n        wave_type=wave_type,\n        position=position,\n    ),\n)\n\nsolutions.append(\n    osaft.doinikov1994rigid.ScatteringField(\n        f=f,\n        R_0=R_0,\n        rho_s=rho_ps,\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    ),\n)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "The next step is to initialise the plotter. We need a separate plotter for\nall solutions. We can now make use of the list of solutions. The respective\nplotters will be saved in a dictionary where the key is the name of\nthe solution.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "plotter = {}\nfor solution in solutions:\n    plotter[solution.name] = osaft.FluidScatteringPlot(\n        solution,\n        r_max=5 * solution.R_0,\n    )"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Now we initialise an empty figure with four subplots and pass the\n``plt.Axes`` object to the plotting function. Additionally, we will also\nchange the title of the subplot.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig, axes = plt.subplots(\n    nrows=2,\n    ncols=2,\n    figsize=(10, 10),\n    sharex=True,\n    sharey=True,\n)\n\ncount = 0\nfor name, plotter in plotter.items():\n    ax = axes.flat[count]\n    plotter.plot_pressure(\n        inst=True,\n        incident=False,\n        scattered=True,\n        ax=ax,\n    )\n    ax.set_title(name)\n\n    # remove the y and x label for non-boundary subplots\n    if count == 0:  # top left\n        ax.set_xlabel(\"\")\n    elif count == 1:  # top right\n        ax.set_xlabel(\"\")\n        ax.set_ylabel(\"\")\n    elif count == 3:  # bottom right\n        ax.set_ylabel(\"\")\n\n    count += 1\n\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
}