Pressure Plot#

This examples shows you how to plot the pressure field.

As always we start off by importing the necessary Python modules. For our example we are going to need the osaft library, and the third party package Matplotlib.

13 from matplotlib import pyplot as plt
14
15 import osaft

The next step is to define the properties for our example, these include the material properties, the properties of the acoustic field and the radius. We always assume SI-units.

The wave type is set using the osaft.WaveType enum. Currently, there are two options: osaft.WaveType.STANDING and osaft.WaveType.TRAVELLING for a plane standing wave and a plane travelling wave, respectively.

28 # --------
29 # Geometry
30 # --------
31 # Radius
32 R_0 = 5e-6  # [m]
33
34 # -----------------
35 # Properties of copper
36 # -----------------
37 # Density
38 rho_cu = 8960  # [kg/m^3]
39 # Young's modulus
40 E_cu = 130e9  # [Pa]
41 # Possion ratio
42 nu_cu = 0.34  # [-]
43
44 # -------------------
45 # Properties of Water
46 # -------------------
47 # Speed of sound
48 c_w = 1_498  # [m/s]
49 # Density
50 rho_w = 997  # [kg/m^3]
51
52 # --------------------------------
53 # Properties of the Acoustic Field
54 # --------------------------------
55 # Frequency
56 f = 5e5  # [Hz]
57 # Pressure
58 p_0 = 1e5  # [Pa]
59 # Wave type
60 wave_type = osaft.WaveType.STANDING
61 # Position of the particle in the field
62 position = osaft.pi / 4  # [rad]

Once all properties are defined we can initialize the solution instances for the scattering field. In this case we are using the model Hasegawa (1969). However, you can also chose any other model that has the scattering implemented.

70 sol = osaft.hasegawa1969.ScatteringField(
71     f=f,
72     R_0=R_0,
73     rho_s=rho_cu,
74     E_s=E_cu,
75     nu_s=nu_cu,
76     rho_f=rho_w,
77     c_f=c_w,
78     p_0=p_0,
79     wave_type=wave_type,
80     position=position,
81 )

The next step is to initialise the plotter

In the first step we want to check if the set input pressure of p_0=1e5 matches with the calculated incident pressure field. Since we are in a standing wave field and will look at the time zero. We set the position to a multiple of osaft.pi such that we are the pressure maximum or minimum

 94 sol.position = 0
 95
 96 fig, _ = plotter.plot_pressure(
 97     inst=True,
 98     tripcolor=False,
 99     incident=True,
100     scattered=False,
101 )
102 fig.tight_layout()
103 plt.show()
example pressure

Alternatively, we can also look in an evolution plot how the pressure field evolves for different phase values. The default layout is 3x3 and can be adjusted with the option layout=(n_row, n_cols). Additionally we increase the figure size with figsize=(...) to enlarge the plots.

111 # sphinx_gallery_thumbnail_number = 2
112
113 plotter.plot_pressure_evolution(
114     inst=True,
115     tripcolor=False,
116     layout=(5, 5),
117     figsize=(10, 8),
118     incident=True,
119     scattered=False,
120 )
121 plt.show()
0.00$\pi$, 0.08$\pi$, 0.17$\pi$, 0.25$\pi$, 0.33$\pi$, 0.42$\pi$, 0.50$\pi$, 0.58$\pi$, 0.67$\pi$, 0.75$\pi$, 0.83$\pi$, 0.92$\pi$, 1.00$\pi$, 1.08$\pi$, 1.17$\pi$, 1.25$\pi$, 1.33$\pi$, 1.42$\pi$, 1.50$\pi$, 1.58$\pi$, 1.67$\pi$, 1.75$\pi$, 1.83$\pi$, 1.92$\pi$, 2.00$\pi$

Now lets see what the magnitude of the scattered field is

126 plotter.plot_pressure_evolution(
127     inst=True,
128     tripcolor=False,
129     layout=(5, 5),
130     figsize=(10, 8),
131     incident=False,
132     scattered=True,
133 )
134 plt.show()
0.00$\pi$, 0.08$\pi$, 0.17$\pi$, 0.25$\pi$, 0.33$\pi$, 0.42$\pi$, 0.50$\pi$, 0.58$\pi$, 0.67$\pi$, 0.75$\pi$, 0.83$\pi$, 0.92$\pi$, 1.00$\pi$, 1.08$\pi$, 1.17$\pi$, 1.25$\pi$, 1.33$\pi$, 1.42$\pi$, 1.50$\pi$, 1.58$\pi$, 1.67$\pi$, 1.75$\pi$, 1.83$\pi$, 1.92$\pi$, 2.00$\pi$

We might be also wondering how it looks for a travelling wave. Additionally, we can change the colormap. Note here, that we set the attribute plotter.div_cmap since the data that will be plotted will contain positive and negative values. Also, it is useful to have a diverging colormap that is NOT white in the center because the scatterer is depicted white in our plots.

144 sol.wave_type = osaft.WaveType.TRAVELLING
145 plotter.div_cmap = "RdYlBu"
146
147 plotter.plot_pressure_evolution(
148     inst=True,
149     tripcolor=False,
150     layout=(5, 5),
151     figsize=(10, 8),
152     incident=False,
153     scattered=True,
154 )
155 plt.show()
0.00$\pi$, 0.08$\pi$, 0.17$\pi$, 0.25$\pi$, 0.33$\pi$, 0.42$\pi$, 0.50$\pi$, 0.58$\pi$, 0.67$\pi$, 0.75$\pi$, 0.83$\pi$, 0.92$\pi$, 1.00$\pi$, 1.08$\pi$, 1.17$\pi$, 1.25$\pi$, 1.33$\pi$, 1.42$\pi$, 1.50$\pi$, 1.58$\pi$, 1.67$\pi$, 1.75$\pi$, 1.83$\pi$, 1.92$\pi$, 2.00$\pi$

Lastly we want to animate the pressure. Keep in mind that now the wave type is travelling

161 anim = plotter.animate_pressure(scattered=True, incident=False)
162 anim.resume()
163 plt.show()

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

Estimated memory usage: 9 MB

Gallery generated by Sphinx-Gallery