{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Scatterer: Acoustic velocity plots with arrows\n\nThis example shows how to plot the acoustic velocity and also add arrows within\nthe plot showcasing the magnitude and direction of the acoustic fluid velocity.\n\nThis example is very similiar to `the example of quiver plots in a fluid\n<sphx_glr_examples_tutorial_example_quiver_fluid.py>`. Therefore, we will keep\nthe text very short here. If you want to have more explanations, check out the\nlinked example.\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 = 30e-6  # [m]\n\n# ---------------------------\n# Properties of the Scatterer\n# ---------------------------\n# Speed of sound\nc_sc = 350  # [m/s]\n# Density\nrho_sc = 1_020  # [kg/m^3]\n\n# ---------------------------\n# Properties of Water\n# ---------------------------\n# Speed of sound\nc_water = 1_500  # [m/s]\n# Density\nrho_water = 997  # [kg/m^3]\n\n# --------------------------------\n# Properties of the Acoustic Field\n# --------------------------------\n# Frequency\nf = 1e7  # [Hz]\n# Pressure\np_0 = 1e5  # [Pa]\n# Wave type\nwave_type = osaft.WaveType.TRAVELLING\n# Position of the particle in the field\nposition = osaft.pi / 4  # [rad]\n\n# ----------------\n# Truncation Limit\n# ----------------\n# Number of scattering modes that are considered\nN_max = 5"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Initialization of the ``ScatteringField`` class of the ``yosioka1955``\nsolution\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "sol = osaft.yosioka1955.ScatteringField(\n    f=f,\n    R_0=R_0,\n    rho_s=rho_sc,\n    c_s=c_sc,\n    rho_f=rho_water,\n    c_f=c_water,\n    p_0=p_0,\n    wave_type=wave_type,\n    position=position,\n    N_max=N_max,\n)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Initialization of plotter object\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "plotter = osaft.ParticleScatteringPlot(sol, cmap=\"plasma\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Acoustic velocity and quiver arrows\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig, ax = plotter.plot_velocity(\n    symmetric=True,\n    inst=True,\n    quiver_color=\"white\",\n)\nax.set_title(\"Acoustic Velocity Magnitude + Quiver\")\nfig.tight_layout()\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Evolution plot\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig, _ = plotter.plot_velocity_evolution(\n    quiver_color=\"white\",\n    tripcolor=True,\n    figsize=(12, 12),\n)\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Animated velocity arrows for second mode only\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "anim = plotter.animate_velocity(quiver_color=\"white\", mode=2)\nanim.resume()\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Animated velocity arrows for all modes\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "anim = plotter.animate_velocity(quiver_color=\"white\")\nanim.resume()\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
}