Frontiers: Air Bubble in Water#

This example corresponds to section 3.4 in our publication. In this example we study the acoustic radiation force (ARF) on an air bubble suspended in water.

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 packages NumPy and Matplotlib.

16 import numpy as np
17 from matplotlib import pyplot as plt
18
19 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.

32 # --------
33 # Geometry
34 # --------
35 # Radius
36 R_0 = 5e-6  # [m]
37
38 # -----------------
39 # Properties of Air
40 # -----------------
41 # Speed of sound
42 c_air = 343  # [m/s]
43 # Density
44 rho_air = 1.225  # [kg/m^3]
45
46 # -------------------
47 # Properties of Water
48 # -------------------
49 # Speed of sound
50 c_w = 1_498  # [m/s]
51 # Density
52 rho_w = 997  # [kg/m^3]
53
54 # --------------------------------
55 # Properties of the Acoustic Field
56 # --------------------------------
57 # Frequency
58 f = 5e5  # [Hz]
59 # Pressure
60 p_0 = 1e5  # [Pa]
61 # Wave type
62 wave_type = osaft.WaveType.STANDING
63 # Position of the particle in the field
64 position = np.pi / 4  # [rad]

Once all properties are defined we can initialize the solution instances. osaft.yosioka1995.ARF() is the class for computing the ARF using the model by Yosioka and Kawasima (1955).

Here we give the instances different names 'General' and 'Bubble' by setting the name attribute. This makes sure we can later distinguish them when the solutions are plotted.

75 # General
76 yosioka = osaft.yosioka1955.ARF(
77     f=f,
78     R_0=R_0,
79     rho_s=rho_air,
80     c_s=c_air,
81     rho_f=rho_w,
82     c_f=c_w,
83     p_0=p_0,
84     wave_type=wave_type,
85     position=position,
86 )
87 yosioka.name = "General"
88
89 # Small bubble approximation
90 yosioka_bubble = yosioka.copy()
91 yosioka_bubble.small_particle = True
92 yosioka_bubble.bubble_solution = True
93 yosioka_bubble.name = "Bubble"

With the class osaft.yosioka1955.ARF() it is also possible to plot the acoustic fields. Here, we first set the frequency to 6.5e5 Hz. Then we initialize a osaft.FluidScatteringPlot() instance which will plot the acoustic field in the fluid. The class takes the model as an argument and the radius range r_max that is plotted. For more option see the documentation.

The method plot() will then generate the plot. As always with Matplotlib, we need to call plt.show() to display it.

106 # Setting frequency close to resonance
107 yosioka.f = 6.5e5
108
109 # Initializing plotting class
110 scattering_plot = osaft.FluidScatteringPlot(yosioka, r_max=3 * yosioka.R_0)
111
112 # Plot scattering field
113 fig, ax = scattering_plot.plot_velocity()
114
115 plt.show()
example frontiers air bubble in water

To animate the acoustic field we can call the method animate(). Setting incident = False means that we are only animating the scattered field but not the incident field.

123 anim = scattering_plot.animate_velocity(
124     frames=20,
125     interval=100,
126     incident=False,
127 )
128
129 plt.show()

Finally, we want to compare the general solution for the ARF with the approximate solution for a bubble. To plot the ARF we need to initialize osaft.ARFPlot() instance. With the method add_solutions() we can add our models to the plotter. With set_abscissa() we define the variable that we want to plot the ARF against. Here we select the frequency f. Finally, osaft.ARFPlot.plot_solutions() will generate the plot. Again, we call plt.show() to display it.

141 # sphinx_gallery_thumbnail_number = -1
142 # Initializing plotting class
143 arf_plot = osaft.ARFPlot()
144
145 # Add solutions to be plotted
146 arf_plot.add_solutions(yosioka, yosioka_bubble)
147
148 # Define independent plotting variable (in this case the frequency)
149 arf_plot.set_abscissa(x_values=np.linspace(1e5, 1e6, 300), attr_name="f")
150
151 # Plot the ARF
152 fig, ax = arf_plot.plot_solutions()
153
154 # Setting the axis labels
155 ax.set_xlabel(r"$f$ $\mathrm{[Hz]}$")
156
157 plt.show()
example frontiers air bubble in water

Note

It is only possible to plot the ARF against properties that wrap an underlying PassiveVariable, i.e. an input parameter of the model. You can get a list of all input variables using the method input_variables().

167 print(f"{yosioka.input_variables() = }")
yosioka.input_variables() = ['small_particle', 'bubble_solution', 'position', 'p_0', 'wave_type', 'rho_s', 'c_s', 'rho_f', 'c_f', 'R_0', 'f', 'N_max']

Total running time of the script: ( 0 minutes 12.920 seconds)

Estimated memory usage: 9 MB

Gallery generated by Sphinx-Gallery