Note
Click here to download the full example code
Pressure Plots for different theories#
This example shows how to plot the pressure field for different theories in one single figure.
In this example we are investigating a polystyrene particle in a viscous oil in a standing wave.
13 from matplotlib import pyplot as plt
14
15 import osaft
16
17 # --------
18 # Geometry
19 # --------
20 # Radius
21 R_0 = 5e-6 # [m]
22
23 # -------------------------
24 # Properties of polystyrene
25 # -------------------------
26 # Density
27 rho_ps = 1_050 # [kg/m^3]
28 # Young's modulus
29 E_ps = 3.25e9 # [Pa]
30 # Poisson's ratio
31 nu_ps = 0.34 # [-]
32 # Speed of sound (matching compressibility)
33 c_ps = (E_ps / (rho_ps * 3 * (1 - 2 * nu_ps))) ** 0.5 # [m/s]
34
35 # -------------------
36 # Properties of Oil
37 # -------------------
38 # Density
39 rho_oil = 923 # [kg/m^3]
40 # Speed of sound
41 c_oil = 1_445 # [m/s]
42 # Viscosity
43 eta_oil = 0.03 # [Pa s]
44 zeta_oil = 0 # [Pa s]
45
46 # --------------------------------
47 # Properties of the Acoustic Field
48 # --------------------------------
49 # Frequency
50 f = 1e6 # [Hz]
51 # Pressure
52 p_0 = 1e5 # [Pa]
53 # Wave type
54 wave_type = osaft.WaveType.STANDING
55 # position
56 position = osaft.pi / 4
Once all properties are defined we can initialize the solution instances for the scattering field. We also save the solutions to a list which will make looping in the next steps straightforward.
63 solutions = []
64
65 solutions.append(
66 osaft.king1934.ScatteringField(
67 f=f,
68 R_0=R_0,
69 rho_s=rho_ps,
70 rho_f=rho_oil,
71 c_f=c_oil,
72 p_0=p_0,
73 wave_type=wave_type,
74 position=position,
75 ),
76 )
77
78
79 solutions.append(
80 osaft.yosioka1955.ScatteringField(
81 f=f,
82 R_0=R_0,
83 rho_s=rho_ps,
84 c_s=c_ps,
85 rho_f=rho_oil,
86 c_f=c_oil,
87 p_0=p_0,
88 wave_type=wave_type,
89 position=position,
90 ),
91 )
92
93 solutions.append(
94 osaft.hasegawa1969.ScatteringField(
95 f=f,
96 R_0=R_0,
97 rho_s=rho_ps,
98 E_s=E_ps,
99 nu_s=nu_ps,
100 rho_f=rho_oil,
101 c_f=c_oil,
102 p_0=p_0,
103 wave_type=wave_type,
104 position=position,
105 ),
106 )
107
108 solutions.append(
109 osaft.doinikov1994rigid.ScatteringField(
110 f=f,
111 R_0=R_0,
112 rho_s=rho_ps,
113 rho_f=rho_oil,
114 c_f=c_oil,
115 eta_f=eta_oil,
116 zeta_f=zeta_oil,
117 p_0=p_0,
118 wave_type=wave_type,
119 position=position,
120 ),
121 )
The next step is to initialise the plotter. We need a separate plotter for all solutions. We can now make use of the list of solutions. The respective plotters will be saved in a dictionary where the key is the name of the solution.
129 plotter = {}
130 for solution in solutions:
131 plotter[solution.name] = osaft.FluidScatteringPlot(
132 solution,
133 r_max=5 * solution.R_0,
134 )
Now we initialise an empty figure with four subplots and pass the
plt.Axes
object to the plotting function. Additionally, we will also
change the title of the subplot.
143 fig, axes = plt.subplots(
144 nrows=2,
145 ncols=2,
146 figsize=(10, 10),
147 sharex=True,
148 sharey=True,
149 )
150
151 count = 0
152 for name, plotter in plotter.items():
153 ax = axes.flat[count]
154 plotter.plot_pressure(
155 inst=True,
156 incident=False,
157 scattered=True,
158 ax=ax,
159 )
160 ax.set_title(name)
161
162 # remove the y and x label for non-boundary subplots
163 if count == 0: # top left
164 ax.set_xlabel("")
165 elif count == 1: # top right
166 ax.set_xlabel("")
167 ax.set_ylabel("")
168 elif count == 3: # bottom right
169 ax.set_ylabel("")
170
171 count += 1
172
173 fig.tight_layout()
174 plt.show()
Total running time of the script: ( 0 minutes 2.014 seconds)
Estimated memory usage: 9 MB