Fluid: Acoustic velocity plots with arrows#

This example shows how to plot the acoustic velocity and also add arrows within In this example we illustrate how we can use arrow plots to illustrate both magnitude and direction of the acoustic particle velocity.

In this example we study a glass sphere in a viscous fluid.

13 from matplotlib import pyplot as plt
14
15 import osaft
16
17 # --------
18 # Geometry
19 # --------
20 # Radius
21 R_0 = 50e-6  # [m]
22
23 # -------------------
24 # Properties of Glass
25 # -------------------
26 # Speed of sound
27 c_1_glass = 4_521  # [m/s]
28 c_2_glass = 2_226  # [m/s]
29 # Density
30 rho_glass = 2_240  # [kg/m^3]
31
32 # ---------------------------
33 # Properties of Viscous Fluid
34 # ---------------------------
35 # Speed of sound
36 c_oil = 1_400  # [m/s]
37 # Density
38 rho_oil = 900  # [kg/m^3]
39 # Viscosity
40 eta_oil = 0.04  # [Pa s]
41 zeta_oil = 0  # [Pa s]
42
43 # --------------------------------
44 # Properties of the Acoustic Field
45 # --------------------------------
46 # Frequency
47 f = 10e5  # [Hz]
48 # Pressure
49 p_0 = 1e5  # [Pa]
50 # Wave type
51 wave_type = osaft.WaveType.STANDING
52 # Position of the particle in the field
53 position = osaft.pi / 4  # [rad]

Here, we are given the primary and the secondary wave speed of glass only. The model doinikov2021viscous, however, takes the Young’s modulus and the Poisson’s ratio as input parameters. We therefore have to convert the properties. The ElasticSolid class offers such conversion methods.

62 E_s = osaft.ElasticSolid.E_from_wave_speed(c_1_glass, c_2_glass, rho_glass)
63 nu_s = osaft.ElasticSolid.nu_from_wave_speed(c_1_glass, c_2_glass)
64
65 sol = osaft.doinikov2021viscous.ScatteringField(
66     f=f,
67     R_0=R_0,
68     rho_s=rho_glass,
69     E_s=E_s,
70     nu_s=nu_s,
71     rho_f=rho_oil,
72     c_f=c_oil,
73     eta_f=eta_oil,
74     zeta_f=zeta_oil,
75     p_0=p_0,
76     wave_type=wave_type,
77     position=position,
78 )

The next step is to initialise the plotter for the fluid. The option n_quiver_points let’s use decide how many arrows along the z-direction and x-direction shall be plotted. If you chose the plotting option symmetric=False then the arrows along the x-direction will be halved. It is set in the constructor of the plotter, because the solution for the quiver arrows is stored within the class and it depends on the number of points. A change of this parameter will invoke new computation of the quiver directions. Per default it is set to n_quiver_points=21. It is advisable to use an odd number if you like to change the parameter because this ensures that have a point at z=0, x=0.

93 plotter = osaft.FluidScatteringPlot(sol, r_max=3 * sol.R_0, cmap="Oranges")

Let’s start by simply plotting the acoustic velocity for phase=0. In order to also show the arrows within the plot we need to add the option quiver_color='____'. Per default quiver_color = None such that no arrows will be overlayed.

101 fig, ax = plotter.plot_velocity(quiver_color="black", symmetric=False)
102 ax.set_title("Acoustic Velocity Magnitude + Quiver")
103 fig.tight_layout()
104 plt.show()
Acoustic Velocity Magnitude + Quiver

We can also have a look at first four modes and look how the velocity behaves for each of them individually. We start by creating a plt.subplots(...) with two rows and two columns.

111 fig, Axes = plt.subplots(2, 2, figsize=(12, 10))
112
113 # Now we loop over each of the ``plt.Axes`` within the ``Axes`` array and
114 # depict a different mode.
115
116 for i, ax in enumerate(Axes.flatten()):
117     plotter.plot_velocity(mode=i, ax=ax, quiver_color="black")
118     ax.set_title(f"Mode #{i}")
119
120 fig.tight_layout()
121 plt.show()
Mode #0, Mode #1, Mode #2, Mode #3

The quiver_color=... option is also available for the plotter.plot_velocity_evolution(quiver_color=...). Let’s check first if the incident acoustic field is depicted right. Therefore, we set incident=True and scattered=False.

130 plotter.plot_velocity_evolution(
131     quiver_color="black",
132     mode=None,
133     incident=True,
134     scattered=False,
135     symmetric=False,
136     layout=(3, 3),
137     figsize=(12, 12),
138 )
139 plt.show()
0.00$\pi$, 0.25$\pi$, 0.50$\pi$, 0.75$\pi$, 1.00$\pi$, 1.25$\pi$, 1.50$\pi$, 1.75$\pi$, 2.00$\pi$

And also for plotter.animate_velocity(quiver_color=...).

144 anim = plotter.animate_velocity(
145     frames=100,
146     interval=50,
147     quiver=True,
148     quiver_color="black",
149     mode=None,
150     incident=False,
151     scattered=True,
152 )
153 plt.show()

Total running time of the script: ( 1 minutes 9.507 seconds)

Estimated memory usage: 9 MB

Gallery generated by Sphinx-Gallery