"""
Doinikov 2021 Viscous - Streaming Plots
=======================================

In this example we demonstrate how the microstreaming fields around the
particle can be plotted from the model from Doinikov (2021).
"""

from matplotlib import pyplot as plt

import osaft

# %%
# In this example we compare the streamlines around a polystyrene particle
# suspended in water and a polystyrene particle suspended in oil.

# -----------------
# Properties of Oil
# -----------------
# Speed of sound
c_oil = 1_400  # [m/s]
# Density
rho_oil = 900  # [kg/m^3]
# Shear viscosity
eta_oil = 0.04  # [Pa s]
# Bulk viscosity (neglected)
zeta_oil = 0  # [Pa s]

# -------------------
# Properties of Water
# -------------------
# Speed of sound
c_w = 1_498  # [m/s]
# Density
rho_w = 997  # [kg/m^3]
# Shear viscosity
eta_w = 0.0089  # [Pa s]
# Bulk viscosity (neglected)
zeta_w = 0  # [Pa s]

# --------------------------------------
# Properties of the polystyrene particle
# --------------------------------------
# Radius
R_0 = 5e-6  # [m]
# Density
rho_ps = 1_050  # [kg/m^3]
# Young's modulus
E_ps = 3.25e9  # [Pa]
# Poisson's ratio
nu_ps = 0.34  # [-]

# --------------------------------
# Properties of the acoustic field
# --------------------------------
# Frequency
f = 1e6  # [Hz]
# Wavetype
wt = osaft.WaveType.STANDING
# Position
h = 0  # [rad]
# Pressure amplitude
p_0 = 1e6  # [Pa]

# %%
# For the plotting of streaming fields we use the `StreamingField` classes
# of the model `doinikov2021viscous`

doinikov_oil = osaft.doinikov2021viscous.StreamingField(
    f=f, R_0=R_0,
    rho_s=rho_ps, E_s=E_ps, nu_s=nu_ps,
    rho_f=rho_oil, c_f=c_oil,
    eta_f=eta_oil, zeta_f=zeta_oil,
    p_0=p_0, wave_type=wt,
    position=h,
    N_max=3,
)

doinikov_water = osaft.doinikov2021viscous.ARF(
    f=f, R_0=R_0,
    rho_s=rho_ps, E_s=E_ps, nu_s=nu_ps,
    rho_f=rho_w, c_f=c_w,
    eta_f=eta_w, zeta_f=zeta_w,
    p_0=p_0, wave_type=wt,
    position=h,
    N_max=3,
)


# %%
# Analogous to the scattering field, the OSAFT library provides plotting
# method for the streamlines of the streamingfield.

plot_water = osaft.FluidStreamingPlot(
    doinikov_water, r_max=4 * R_0,
)

plot_oil = osaft.FluidStreamingPlot(
    doinikov_oil, r_max=4 * R_0,
)

if __name__ == '__main__':

    fig, ax = plt.subplots(1, 2, subplot_kw={'projection': 'polar'})
    plot_water.plot_streamlines(ax=ax[0])
    plot_oil.plot_streamlines(ax=ax[1])

    ax[0].set_title('Water')
    ax[1].set_title('Oil')
    fig.tight_layout()

    plt.show()
