To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit 12da6dae authored by Cyrill Mast's avatar Cyrill Mast
Browse files

uncomment plots

parent bc2c6da5
Pipeline #91937 passed with stages
in 6 minutes and 49 seconds
import unittest
import numpy as np
from gorkov import (
log, pi)
from test_Yosioka import TestYosioka
import matplotlib.pyplot as plt
from matplotlib import rc
rc('font', **{'family': 'sans-serif', 'sans-serif': ['Helvetica']})
# for Palatino and other serif fonts use:
# rc('font',**{'family':'serif','serif':['Palatino']})
rc('text', usetex=True)
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
logger = log
class TestYosiokaPlots(TestYosioka):
t = TestYosioka()
t.setUp()
def test_plot_coefficients(self) -> None:
n = np.arange(10)
K_n = []
M_n = []
coeffs = [K_n, M_n]
self.t.cls_general.wave_type = "traveling"
self.t.cls_general.position = 1e-4
for N in n:
K_n.append(abs(self.t.cls_general.K_n(N)))
M_n.append(abs(self.t.cls_general.M_n(N)))
for c in coeffs:
c /= c[0]
fig, ax = plt.subplots()
ax.set_xlabel(r"Order $n$")
ax.set_ylabel(r"Absolute value of the complex coefficients")
ax.set_title(r"The coefficients $K_{n}$ and $M_{n}$")
for i, c in enumerate(coeffs):
print(c)
ax.scatter(n, c, linestyle=self.line_palette[i])
ax.set_yscale('log')
# ax.set_xscale('log')
ax.legend([r"$K_n$", r"$M_n$"])
# ax.semilogy(n, abs(B_n_real), linestyle=self.line_palette[1])
# ax.semilogy(n, abs(K_n_real), linestyle=self.line_palette[2])
# ax.semilogy(n, abs(M_n_real), linestyle=self.line_palette[3])
plt.show()
def test_small_spheres(self) -> None:
plt.style.use("ggplot")
fig, ax = plt.subplots()
ax.set_xlabel(r"$(k_{f} a)^{2}$")
ax.set_ylabel(r"Deviation to general solution in \%")
ax.set_title(r"Small Sphere Approximation")
self.t.sphere_change_parameters()
self.t.wave_type = "traveling"
self.t.assign_parameters()
radius = np.linspace(4e-3, 1e-9, int(1e2))
sol_general = []
sol_sphere = []
ka_squared = []
for r in radius:
self.t.R_0 = r
self.t.assign_parameters()
ka_squared.append((self.t.R_0 * self.t.compute_k_f()) ** 2)
sol_general.append(self.t.cls_general.acoustic_radiation_force())
sol_sphere.append((self.t.cls_sphere.acoustic_radiation_force()))
sol_sphere_normalized = [
100 * abs(sol_sphere[i] - sol_general[i])
/ sol_general[i] for i in range(len(sol_sphere))
]
ax.semilogx(
ka_squared,
sol_sphere_normalized,
label="small spheres",
color="b")
ax.set_ylim(-10, 100)
ax.set_xlim(1e-3, 1.05)
plt.legend()
plt.show()
def test_bubbles(self) -> None:
plt.style.use("ggplot")
fig, ax = plt.subplots()
ax.set_xlabel(r"$(k_{f} a)^{2}$")
ax.set_ylabel(r"Deviation to general solution in \%")
ax.set_title(r"Bubble Approximation")
self.t.bubble_change_parameters()
self.t.wave_type = "standing"
self.t.assign_parameters()
numbers = np.linspace(1, 100, 100)
radi = self.t.compute_xlambda() / self.t.f
radius = [n * radi for n in numbers]
sol_general = []
sol_bubble = []
ka_squared = []
for r in radius:
self.t.R_0 = r
self.t.assign_parameters()
ka_squared.append((self.t.R_0 * self.t.compute_k_f()) ** 2)
sol_general.append(self.t.cls_general.acoustic_radiation_force())
sol_bubble.append((self.t.cls_bubble.acoustic_radiation_force()))
sol_bubble_normalized = [
abs((sol_bubble[i] - sol_general[i])
/ sol_general[i]) for i in range(len(sol_bubble))
]
ax.plot(ka_squared,
sol_bubble_normalized,
label="bubbles approximation - normalized",
color="b")
# ax.set_xlim(0)
ax.relim()
plt.legend()
plt.show()
print(self.t.compute_xlambda())
def test_frequency_sweep(self) -> None:
"""
Recreates Fig. 2 from the Yosioka paper
"""
plt.style.use("ggplot")
fig, ax = plt.subplots()
ax.set_xlabel(r"$\frac{k^{*} a}{\sqrt{3 \lambda}}$")
ax.set_ylabel(r"Amplitude of the ARF")
ax.set_title("Bubble Approximation")
self.t.bubble_change_parameters()
self.t.wave_type = "traveling"
self.t.assign_parameters()
frequency = np.linspace(1e3, 2e5, int(1e2))
sol_general = []
sol_bubble = []
x_data = []
for f in frequency:
self.t.f = f
self.t.assign_parameters()
x_data.append(
(self.t.R_0 * self.t.compute_k_s())
/ (np.sqrt(3 * self.t.compute_xlambda())))
sol_general.append(self.t.cls_general.acoustic_radiation_force())
sol_bubble.append(self.t.cls_bubble.acoustic_radiation_force())
ax.semilogy(
x_data,
sol_bubble,
label="bubble approximation",
color="b",
linestyle="-.")
ax.semilogy(
x_data,
sol_general,
label="general solution",
color="r",
linestyle=":")
plt.legend()
plt.show()
def test_arf_traveling(self) -> None:
self.t.sphere_change_parameters()
self.t.assign_parameters()
plt.style.use("ggplot")
fig, ax = plt.subplots()
ax.set_xlabel(r"Position")
ax.set_ylabel(r"Amplitude of the ARF (N)")
ax.set_title(r"ARF on different locations")
pos = np.linspace(-1e-2, 1e-2, int(1e3))
legend = []
for i, key in enumerate(self.t.cls_dict):
try:
self.t.cls_dict[key].wave_type = "traveling"
if key == "bubble" or key == "king" or key == "special":
raise NotImplementedError
arf = []
for p in pos:
self.t.cls_dict[key].position = p
arf.append(
self.t.cls_dict[key].acoustic_radiation_force())
ax.plot(pos, arf, linestyle=self.line_palette[i])
legend.append(key)
except NotImplementedError:
pass
ax.legend(legend)
plt.show()
def test_arf_standing(self) -> None:
self.t.sphere_change_parameters()
self.t.assign_parameters()
plt.style.use("ggplot")
fig, ax = plt.subplots()
ax.set_xlabel(r"Position (m)")
ax.set_ylabel(r"Amplitude of the ARF (N)")
ax.set_title(r"ARF on different locations")
pos = np.linspace(-1e-2, 1e-2, int(1e3))
legend = []
for i, key in enumerate(self.t.cls_dict):
try:
if key == "bubble" or key == "king":
raise NotImplementedError
self.t.cls_dict[key].wave_type = "standing"
arf = []
for p in pos:
self.t.cls_dict[key].position = p
arf.append(
(self.t.cls_dict[key].acoustic_radiation_force()))
ax.plot(pos, arf, linestyle=self.line_palette[i])
legend.append(key)
except NotImplementedError:
pass
ax.legend(legend)
plt.show()
# -------------------------------------------------------------------------
# Scattering field
# -------------------------------------------------------------------------
def test_potentials(self) -> None:
self.t.cls_general.wave_type = 'traveling'
self.t.cls_general.n_max = 3
acc = 30
theta = np.linspace(0, 2 * pi, acc)
t = np.linspace(0, 5e-6, acc)
phi = np.zeros((len(theta), len(t)))
for ix, dx in enumerate(theta):
for it, dt in enumerate(t):
phi[ix][it] = self.t.cls_general.Phi_1(1e-6, dx, dt).real
theta, t = np.meshgrid(theta, t)
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
ax.plot_surface(theta, t, phi, antialiased=True)
plt.show()
def test_velocities(self) -> None:
self.t.cls_general.wave_type = 'traveling'
self.t.cls_general.n_max = 3
acc = 30
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
ax.set_xlabel("radius")
ax.set_ylabel("theta")
ax.set_zlabel("Velocity")
plt.ion()
plt.show()
t = np.linspace(5e-7, 5e-5, acc)
for dt in t:
vel = np.zeros([acc, acc])
theta = np.linspace(0, 2 * pi, acc)
r = np.linspace(1e-9, 1e-6, acc)
for i_t, val_t in enumerate(theta):
for i_r, val_r in enumerate(r):
a = self.t.cls_general.radial_particle_velocity(
r=val_r, theta=val_t, t=dt)
vel[i_r][i_t] = a
angle, radius = np.meshgrid(theta, r)
ax.plot_surface(angle, radius, vel)
plt.pause(0.00000001)
ax.clear()
if __name__ == '__main__':
unittest.main()
# import unittest
# import numpy as np
# from gorkov import (
# log, pi)
# from test_Yosioka import TestYosioka
#
# import matplotlib.pyplot as plt
# from matplotlib import rc
#
# rc('font', **{'family': 'sans-serif', 'sans-serif': ['Helvetica']})
# # for Palatino and other serif fonts use:
# # rc('font',**{'family':'serif','serif':['Palatino']})
# rc('text', usetex=True)
# plt.rc('text', usetex=True)
# plt.rc('font', family='serif')
#
# logger = log
#
#
# class TestYosiokaPlots(TestYosioka):
# t = TestYosioka()
# t.setUp()
#
# def test_plot_coefficients(self) -> None:
# n = np.arange(10)
# K_n = []
# M_n = []
# coeffs = [K_n, M_n]
# self.t.cls_general.wave_type = "traveling"
# self.t.cls_general.position = 1e-4
# for N in n:
# K_n.append(abs(self.t.cls_general.K_n(N)))
# M_n.append(abs(self.t.cls_general.M_n(N)))
# for c in coeffs:
# c /= c[0]
# fig, ax = plt.subplots()
# ax.set_xlabel(r"Order $n$")
# ax.set_ylabel(r"Absolute value of the complex coefficients")
# ax.set_title(r"The coefficients $K_{n}$ and $M_{n}$")
# for i, c in enumerate(coeffs):
# print(c)
# ax.scatter(n, c, linestyle=self.line_palette[i])
# ax.set_yscale('log')
# # ax.set_xscale('log')
# ax.legend([r"$K_n$", r"$M_n$"])
# # ax.semilogy(n, abs(B_n_real), linestyle=self.line_palette[1])
# # ax.semilogy(n, abs(K_n_real), linestyle=self.line_palette[2])
# # ax.semilogy(n, abs(M_n_real), linestyle=self.line_palette[3])
#
# plt.show()
#
# def test_small_spheres(self) -> None:
# plt.style.use("ggplot")
# fig, ax = plt.subplots()
# ax.set_xlabel(r"$(k_{f} a)^{2}$")
# ax.set_ylabel(r"Deviation to general solution in \%")
# ax.set_title(r"Small Sphere Approximation")
# self.t.sphere_change_parameters()
# self.t.wave_type = "traveling"
# self.t.assign_parameters()
#
# radius = np.linspace(4e-3, 1e-9, int(1e2))
# sol_general = []
# sol_sphere = []
# ka_squared = []
# for r in radius:
# self.t.R_0 = r
# self.t.assign_parameters()
# ka_squared.append((self.t.R_0 * self.t.compute_k_f()) ** 2)
# sol_general.append(self.t.cls_general.acoustic_radiation_force())
# sol_sphere.append((self.t.cls_sphere.acoustic_radiation_force()))
# sol_sphere_normalized = [
# 100 * abs(sol_sphere[i] - sol_general[i])
# / sol_general[i] for i in range(len(sol_sphere))
# ]
# ax.semilogx(
# ka_squared,
# sol_sphere_normalized,
# label="small spheres",
# color="b")
# ax.set_ylim(-10, 100)
# ax.set_xlim(1e-3, 1.05)
# plt.legend()
# plt.show()
#
# def test_bubbles(self) -> None:
# plt.style.use("ggplot")
# fig, ax = plt.subplots()
# ax.set_xlabel(r"$(k_{f} a)^{2}$")
# ax.set_ylabel(r"Deviation to general solution in \%")
# ax.set_title(r"Bubble Approximation")
# self.t.bubble_change_parameters()
# self.t.wave_type = "standing"
# self.t.assign_parameters()
# numbers = np.linspace(1, 100, 100)
# radi = self.t.compute_xlambda() / self.t.f
# radius = [n * radi for n in numbers]
# sol_general = []
# sol_bubble = []
# ka_squared = []
# for r in radius:
# self.t.R_0 = r
# self.t.assign_parameters()
# ka_squared.append((self.t.R_0 * self.t.compute_k_f()) ** 2)
# sol_general.append(self.t.cls_general.acoustic_radiation_force())
# sol_bubble.append((self.t.cls_bubble.acoustic_radiation_force()))
# sol_bubble_normalized = [
# abs((sol_bubble[i] - sol_general[i])
# / sol_general[i]) for i in range(len(sol_bubble))
# ]
# ax.plot(ka_squared,
# sol_bubble_normalized,
# label="bubbles approximation - normalized",
# color="b")
# # ax.set_xlim(0)
# ax.relim()
# plt.legend()
# plt.show()
# print(self.t.compute_xlambda())
#
# def test_frequency_sweep(self) -> None:
# """
# Recreates Fig. 2 from the Yosioka paper
# """
# plt.style.use("ggplot")
# fig, ax = plt.subplots()
# ax.set_xlabel(r"$\frac{k^{*} a}{\sqrt{3 \lambda}}$")
# ax.set_ylabel(r"Amplitude of the ARF")
# ax.set_title("Bubble Approximation")
# self.t.bubble_change_parameters()
# self.t.wave_type = "traveling"
# self.t.assign_parameters()
#
# frequency = np.linspace(1e3, 2e5, int(1e2))
# sol_general = []
# sol_bubble = []
# x_data = []
# for f in frequency:
# self.t.f = f
# self.t.assign_parameters()
# x_data.append(
# (self.t.R_0 * self.t.compute_k_s())
# / (np.sqrt(3 * self.t.compute_xlambda())))
# sol_general.append(self.t.cls_general.acoustic_radiation_force())
# sol_bubble.append(self.t.cls_bubble.acoustic_radiation_force())
# ax.semilogy(
# x_data,
# sol_bubble,
# label="bubble approximation",
# color="b",
# linestyle="-.")
# ax.semilogy(
# x_data,
# sol_general,
# label="general solution",
# color="r",
# linestyle=":")
# plt.legend()
# plt.show()
#
# def test_arf_traveling(self) -> None:
# self.t.sphere_change_parameters()
# self.t.assign_parameters()
# plt.style.use("ggplot")
# fig, ax = plt.subplots()
# ax.set_xlabel(r"Position")
# ax.set_ylabel(r"Amplitude of the ARF (N)")
# ax.set_title(r"ARF on different locations")
# pos = np.linspace(-1e-2, 1e-2, int(1e3))
# legend = []
# for i, key in enumerate(self.t.cls_dict):
# try:
# self.t.cls_dict[key].wave_type = "traveling"
# if key == "bubble" or key == "king" or key == "special":
# raise NotImplementedError
# arf = []
# for p in pos:
# self.t.cls_dict[key].position = p
# arf.append(
# self.t.cls_dict[key].acoustic_radiation_force())
# ax.plot(pos, arf, linestyle=self.line_palette[i])
# legend.append(key)
# except NotImplementedError:
# pass
# ax.legend(legend)
# plt.show()
#
# def test_arf_standing(self) -> None:
# self.t.sphere_change_parameters()
# self.t.assign_parameters()
# plt.style.use("ggplot")
# fig, ax = plt.subplots()
# ax.set_xlabel(r"Position (m)")
# ax.set_ylabel(r"Amplitude of the ARF (N)")
# ax.set_title(r"ARF on different locations")
# pos = np.linspace(-1e-2, 1e-2, int(1e3))
# legend = []
# for i, key in enumerate(self.t.cls_dict):
# try:
# if key == "bubble" or key == "king":
# raise NotImplementedError
# self.t.cls_dict[key].wave_type = "standing"
# arf = []
# for p in pos:
# self.t.cls_dict[key].position = p
# arf.append(
# (self.t.cls_dict[key].acoustic_radiation_force()))
# ax.plot(pos, arf, linestyle=self.line_palette[i])
# legend.append(key)
# except NotImplementedError:
# pass
# ax.legend(legend)
# plt.show()
#
# # ----------------------------------------------------------------------
# # Scattering field
# # ----------------------------------------------------------------------
#
# def test_potentials(self) -> None:
# self.t.cls_general.wave_type = 'traveling'
# self.t.cls_general.n_max = 3
# acc = 30
# theta = np.linspace(0, 2 * pi, acc)
# t = np.linspace(0, 5e-6, acc)
# phi = np.zeros((len(theta), len(t)))
# for ix, dx in enumerate(theta):
# for it, dt in enumerate(t):
# phi[ix][it] = self.t.cls_general.Phi_1(1e-6, dx, dt).real
# theta, t = np.meshgrid(theta, t)
# fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
# ax.plot_surface(theta, t, phi, antialiased=True)
# plt.show()
#
# def test_velocities(self) -> None:
# self.t.cls_general.wave_type = 'traveling'
# self.t.cls_general.n_max = 3
# acc = 30
# fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
# ax.set_xlabel("radius")
# ax.set_ylabel("theta")
# ax.set_zlabel("Velocity")
# plt.ion()
# plt.show()
# t = np.linspace(5e-7, 5e-5, acc)
# for dt in t:
# vel = np.zeros([acc, acc])
# theta = np.linspace(0, 2 * pi, acc)
# r = np.linspace(1e-9, 1e-6, acc)
# for i_t, val_t in enumerate(theta):
# for i_r, val_r in enumerate(r):
# a = self.t.cls_general
# vel[i_r][i_t] = a.radial_particle_velocity(
# r=val_r, theta=val_t, t=dt)
# angle, radius = np.meshgrid(theta, r)
#
# ax.plot_surface(angle, radius, vel)
# plt.pause(0.00000001)
# ax.clear()
#
#
# if __name__ == '__main__':
# unittest.main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment