Note
Click here to download the full example code
Possible Numerical Problems#
As with an numerical software, it is possible that the numerics run into problems for certain set of parameters. Luckily, for the usual range of parameters relevant in acoustofluidics there seem to be few problems in OSAFT. In our automated tests, we test every model in this relevant parameter range. Nevertheless, it is still possible to run into numerical problems. In this example, we show when these problems could arise and how they can be dealt with.
In this example we investigate a heavy particle in a highly viscous
fluid. We are using the model doinikov1994rigid
. For high
viscosities ( \(\eta_f \approx 0.5 \mathrm{Pa s}\)) and very small
particles (\(R_0= 500\mathrm{nm}\)) this solution can become unstable.
We are comparing the general solution of this model with the long
wavelength approximation.
20 import numpy as np
21 from matplotlib import pyplot as plt
22
23 import osaft
24
25 general = osaft.doinikov1994rigid.ARF(
26 f=1e5,
27 R_0=5e-7,
28 rho_s=5e4,
29 rho_f=1e3,
30 c_f=1500,
31 eta_f=1e-3,
32 zeta_f=0,
33 p_0=1e5,
34 wave_type=osaft.WaveType.STANDING,
35 position=osaft.pi / 4,
36 )
37
38 approx = general.copy()
39 approx.long_wavelength = True
40
41 general.name = "General"
42 approx.name = "Long Wavelength"
The ARF on the particle is computed for different values of viscosity. The
general solution becomes unstable as we pass a viscosity of
\(\eta_f \approx 0.1 \mathrm{Pa s}\) the solution becomes unstable.
In order for multiprocessing to work you need to run your code inside the
if __name__ == '__main__':
clause as shown below.
Check the
multiprocessing example.
54 if __name__ == "__main__":
55
56 arf_plot = osaft.ARFPlot("eta_f", np.logspace(-3, -0.5, num=16))
57 arf_plot.add_solutions(approx, multicore=False)
58 arf_plot.add_solutions(general, multicore=True)
59
60 fig, ax = arf_plot.plot_solutions(plot_method=plt.semilogx, marker="o")
61 ax.set_xlabel("$\\eta_f$ $\\mathrm{[Pa s]}$")
62 plt.show()
63
64 print(f"{approx.eta_f = }")
65 print(f"{abs(approx.x):.3e} << 1")
66 print(f"{abs(approx.x):.3e} << {abs(approx.x_v):.3e}")
/home/docs/checkouts/readthedocs.org/user_builds/osaft/checkouts/stable/osaft/plotting/datacontainers/arf_datacontainer.py:56: AssumptionWarning: Theory might not be valid anymore!
self._arf = self._compute_arf_single_process(attr_name, values)
approx.eta_f = 0.31622776601683794
2.094e-04 << 1
2.094e-04 << 2.229e-02
If one runs into numerical issues, the easiest remedy is to choose a
different model or a different approximation of a model. In this case here
the long_wavelength
solution seems to be more suitable. In particular,
since the assumption of a long wavelength, i.e.
\(x \ll 1\), \(x \ll x_v\), still holds. We can confirm this
easily using the OSAFT library.
Total running time of the script: ( 1 minutes 23.049 seconds)
Estimated memory usage: 9 MB