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 0066a5ff authored by Jonas Fankhauser's avatar Jonas Fankhauser
Browse files

Passive variable for small particle limit and bubble added, further...

Passive variable for small particle limit and bubble  added, further cosmetics, useless tests commented out
parent 6db170a7
Pipeline #98061 failed with stages
in 2 minutes and 7 seconds
......@@ -27,7 +27,7 @@ class ARF(ScatteringField, BaseARF):
rho_s: float, c_s: float, rho_f: float, c_f: float,
p_0: float, position: Optional[float],
wave_type: str = "traveling", N_max: int = 10,
small_particle: str = False, bubble: str = False) -> None:
small_particle: bool = False, bubble: bool = False) -> None:
"""
Initializes the class and sets all parameter needed for the
computation.
......@@ -56,10 +56,10 @@ class ARF(ScatteringField, BaseARF):
wave_type=wave_type,
N_max=N_max)
self.small_particle = PassiveVariable(small_particle,
"Small Particle Limit")
self.bubble_solution = PassiveVariable(small_particle,
"Bubble solution Limit")
self._small_particle = PassiveVariable(small_particle,
"Small Particle Limit")
self._bubble_solution = PassiveVariable(bubble,
"Bubble solution Limit")
self._F = ActiveVariable(self._compute_F,
"density-compressibility factor")
......@@ -98,6 +98,8 @@ class ARF(ScatteringField, BaseARF):
Computes the ARF, based on the general solution (Eq. 44), or the
approximation for either small particles (Eq. 59, 62) or small bubbles
(Eq. 68, 73), if the respective options are selected.
:return: ARF [N]
"""
if self.small_particle and self.bubble_solution:
......@@ -110,6 +112,42 @@ class ARF(ScatteringField, BaseARF):
else:
return self._compute_general_arf()
# -------------------------------------------------------------------------
# Setters and Getters for Independent Variables
# -------------------------------------------------------------------------
@property
def small_particle(self) -> bool:
"""Small particle limit option.
:getter: returns the setting for the small particle limit
:rtype: bool
:setter: automatically invokes
:func:`gorkov.core.variable.BaseVariable.notify`
:type: bool
"""
return self._small_particle.value
@small_particle.setter
def small_particle(self, value: bool) -> None:
self._small_particle.value = value
@property
def bubble_solution(self) -> bool:
"""Bubble solution option.
:getter: returns the setting for the bubble solution
:rtype: bool
:setter: automatically invokes
:func:`gorkov.core.variable.BaseVariable.notify`
:type: bool
"""
return self._bubble_solution.value
@bubble_solution.setter
def bubble_solution(self, value: bool) -> None:
self._bubble_solution.value = value
# -------------------------------------------------------------------------
# General Solution
# -------------------------------------------------------------------------
......@@ -121,7 +159,7 @@ class ARF(ScatteringField, BaseARF):
(Eq. 44)
"""
out = 4 * [0]
out = 5 * [0]
if self.N_max is None:
N_max = 10
......@@ -269,28 +307,24 @@ class ARF(ScatteringField, BaseARF):
@property
def F(self) -> float:
"""
Density-compressibility factor F [-]
Density-compressibility factor :math:`F` [-]
(Eq. 60, 63, 75)
Acoustic contrast factor for small particle solutions.
:return: contrast factor [-]
"""
return self._F.value
def _compute_F(self) -> float:
"""
Compute density-compressibility factor F
According to Eq. (60), (63), (75)
"""
# (60)
if self.wave_type == "standing":
if self.bubble_solution:
# (63)
out = self.lambda_rho + (2 * (self.lambda_rho - 1) / 3)
out /= 1 + 2 * self.lambda_rho
out -= 1 / (3 * self.lambda_rho * self.sigma ** 2)
else:
if self.bubble_solution:
# (75)
resonance_term = (3 * self.lambda_rho
- (self.k_s * self.R_0) ** 2)
......@@ -298,8 +332,15 @@ class ARF(ScatteringField, BaseARF):
out /= (self.sigma ** 2 * (self.k_s * self.R_0) ** 6
+ resonance_term ** 2)
else:
# (63)
out = self.lambda_rho + (2 * (self.lambda_rho - 1) / 3)
out /= 1 + 2 * self.lambda_rho
out -= 1 / (3 * self.lambda_rho * self.sigma ** 2)
elif (self.wave_type == 'travelling'
or self.wave_type == 'traveling'):
if self.bubble_solution:
raise ValueError("Factor F is not defined for traveling wave"
"and bubble solution. "
......
......@@ -53,7 +53,7 @@ class BaseYosioka(BaseSphereFrequencyComposite):
self._R_0 = PassiveVariable(radius, "Particle-Radius")
# Dependent variables
self._labmda_rho = ActiveVariable(self._compute_xlambda,
self._labmda_rho = ActiveVariable(self._compute_lambda_rho,
"ratio of densities")
self._sigma = ActiveVariable(self._compute_sigma,
"ratio of speed of sounds")
......@@ -318,7 +318,7 @@ class BaseYosioka(BaseSphereFrequencyComposite):
"""
return self.c_s / self.c_f
def _compute_xlambda(self) -> float:
def _compute_lambda_rho(self) -> float:
"""
Compute lambda (ratio of densities)
......
......@@ -49,6 +49,7 @@ class ScatteringField(BaseYosioka, BaseScattering):
log.info('Create ScatteringField')
# Dependent Variables
self._A_n = ActiveVariable(self._reset_coeff,
"Coefficient A_n"
" for scattered potential")
......@@ -56,10 +57,7 @@ class ScatteringField(BaseYosioka, BaseScattering):
"Coefficient B_n"
" for potential inside particle")
# -------------------------------------------------------------------------
# Dependencies
# -------------------------------------------------------------------------
self._A_n.is_computed_by(
self._labmda_rho, self.fluid._k_f,
self.particle._k_f, self._R_0, self.field._A_in
......
......@@ -18,11 +18,11 @@ class TestYosioka(BaseTest):
self.R_0 = 50e-6
# Frequency
self.f = 1e5
self.f = 5e3
# Solid parameters
self.rho_s = 1.05e3
self.c_s = 1.5e3
self.rho_s = 1
self.c_s = 3e2
# Fluid parameters
self.rho_f = 1e3
......@@ -32,7 +32,7 @@ class TestYosioka(BaseTest):
self.p0 = 10e3
self.wave_type = 'traveling'
self.pos = 1e-4
n_max = 10
self.N_max = 10
self.cls_general = Yosioka1955.ARF(frequency=self.f,
radius=self.R_0,
......@@ -41,7 +41,7 @@ class TestYosioka(BaseTest):
p_0=self.p0,
position=self.pos,
wave_type=self.wave_type,
N_max=n_max)
N_max=self.N_max)
self.cls_bubble = Yosioka1955.ARF(frequency=self.f,
radius=self.R_0,
......@@ -52,7 +52,7 @@ class TestYosioka(BaseTest):
wave_type=self.wave_type,
small_particle=True,
bubble=True,
N_max=n_max)
N_max=self.N_max)
self.cls_sphere = Yosioka1955.ARF(frequency=self.f,
radius=self.R_0,
rho_s=self.rho_s, c_s=self.c_s,
......@@ -60,7 +60,8 @@ class TestYosioka(BaseTest):
p_0=self.p0,
position=self.pos,
wave_type=self.wave_type,
small_particle=True, N_max=n_max)
small_particle=True,
N_max=self.N_max)
# for comparison
self.cls_king = King1934.ARF(self.f,
self.R_0, self.rho_s,
......@@ -85,12 +86,6 @@ class TestYosioka(BaseTest):
def compute_sigma(self) -> float:
return self.c_s / self.c_f
def compute_k_f(self) -> float:
return 2 * pi * self.f / self.c_f
def compute_k_s(self) -> float:
return 2 * pi * self.f / self.c_s
def randomly_change_parameters(self) -> None:
self.f = self.randomly_change_number(self.f)
self.c_f = self.randomly_change_number(self.c_f)
......@@ -168,7 +163,7 @@ class TestYosioka(BaseTest):
Tests for coefficients
"""
def test_xlambda(self) -> None:
def test_lambda_rho(self) -> None:
for _ in range(10):
self.change_and_assign()
for key in self.cls_dict:
......@@ -188,6 +183,8 @@ class TestYosioka(BaseTest):
except AttributeError:
pass
# TODO: Remove this... Or figure out what it tests.
# def test_F(self) -> None:
# for w in self.wave_types:
# self.wave_type = w
......@@ -276,12 +273,14 @@ class TestYosioka(BaseTest):
Tests for the acoustic radiation force
"""
# TODO: Remove this... Or figure out what it tests.
def test_arf(self) -> None:
for n in range(2):
for n in range(1):
print("traveling wave field")
print("====================")
self.bubble_change_parameters()
# self.bubble_change_parameters()
sol = []
for key in self.cls_dict:
self.cls_dict[key].wave_type = "traveling"
......@@ -306,83 +305,91 @@ class TestYosioka(BaseTest):
print("")
# self.assertAlmostEqual(sol[0], -sol[4], 1e-2)
def test_small_spheres(self) -> None:
self.sphere_change_parameters()
self.wave_type = "traveling"
self.assign_parameters()
radius = np.linspace(4e-3, 1e-9, int(1e2))
sol_general = []
sol_sphere = []
ka_squared = []
for r in radius:
self.R_0 = r
self.assign_parameters()
ka_squared.append((self.R_0 * self.compute_k_f()) ** 2)
sol_general.append(self.cls_general.acoustic_radiation_force())
sol_sphere.append((self.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))
]
print(sol_sphere_normalized)
def test_bubbles(self) -> None:
self.bubble_change_parameters()
self.wave_type = "standing"
self.assign_parameters()
numbers = np.linspace(1, 100, 100)
radi = self.compute_xlambda() / self.f
radius = [n * radi for n in numbers]
sol_general = []
sol_bubble = []
ka_squared = []
for r in radius:
self.R_0 = r
self.assign_parameters()
ka_squared.append((self.R_0 * self.compute_k_f()) ** 2)
sol_general.append(self.cls_general.acoustic_radiation_force())
sol_bubble.append((self.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))
]
print(sol_bubble_normalized)
def test_arf_traveling(self) -> None:
self.sphere_change_parameters()
pos = np.linspace(-1e-2, 1e-2, int(1e3))
for i, key in enumerate(self.cls_dict):
try:
self.cls_dict[key].wave_type = "traveling"
if key == "bubble" or key == "king" or key == "special":
raise NotImplementedError
arf = []
for p in pos:
self.cls_dict[key].position = p
arf.append(
self.cls_dict[key].acoustic_radiation_force())
print(arf)
except NotImplementedError:
pass
def test_arf_standing(self) -> None:
self.sphere_change_parameters()
pos = np.linspace(-1e-2, 1e-2, int(1e3))
for i, key in enumerate(self.cls_dict):
try:
if key == "bubble" or key == "king":
raise NotImplementedError
self.cls_dict[key].wave_type = "standing"
arf = []
for p in pos:
self.cls_dict[key].position = p
arf.append(
(self.cls_dict[key].acoustic_radiation_force()))
print(arf)
except NotImplementedError:
pass
# TODO: Remove this... Or figure out what it tests.
# def test_small_spheres(self) -> None:
# self.sphere_change_parameters()
# self.wave_type = "traveling"
# self.assign_parameters()
#
# radius = np.linspace(4e-3, 1e-9, int(1e2))
# sol_general = []
# sol_sphere = []
# ka_squared = []
# for r in radius:
# self.R_0 = r
# self.assign_parameters()
# ka_squared.append((self.R_0 * self.compute_k_f()) ** 2)
# sol_general.append(self.cls_general.acoustic_radiation_force())
# sol_sphere.append((self.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))
# ]
# print(sol_sphere_normalized)
# TODO: Remove this... Or figure out what it tests.
# def test_bubbles(self) -> None:
# self.bubble_change_parameters()
# self.wave_type = "standing"
# self.assign_parameters()
# numbers = np.linspace(1, 100, 100)
# radi = self.compute_xlambda() / self.f
# radius = [n * radi for n in numbers]
# sol_general = []
# sol_bubble = []
# ka_squared = []
# for r in radius:
# self.R_0 = r
# self.assign_parameters()
# ka_squared.append((self.R_0 * self.compute_k_f()) ** 2)
# sol_general.append(self.cls_general.acoustic_radiation_force())
# sol_bubble.append((self.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))
# ]
# print(sol_bubble_normalized)
# TODO: Remove this... Or figure out what it tests.
# def test_arf_traveling(self) -> None:
# self.sphere_change_parameters()
# pos = np.linspace(-1e-2, 1e-2, int(1e3))
# for i, key in enumerate(self.cls_dict):
# try:
# self.cls_dict[key].wave_type = "traveling"
# if key == "bubble" or key == "king" or key == "special":
# raise NotImplementedError
# arf = []
# for p in pos:
# self.cls_dict[key].position = p
# arf.append(
# self.cls_dict[key].acoustic_radiation_force())
# print(arf)
# except NotImplementedError:
# pass
# TODO: Remove this... Or figure out what it tests.
# def test_arf_standing(self) -> None:
# self.sphere_change_parameters()
#
# pos = np.linspace(-1e-2, 1e-2, int(1e3))
# for i, key in enumerate(self.cls_dict):
# try:
# if key == "bubble" or key == "king":
# raise NotImplementedError
# self.cls_dict[key].wave_type = "standing"
# arf = []
# for p in pos:
# self.cls_dict[key].position = p
# arf.append(
# (self.cls_dict[key].acoustic_radiation_force()))
# print(arf)
# except NotImplementedError:
# pass
"""
Tests for errors:
......@@ -404,11 +411,15 @@ class TestYosioka(BaseTest):
Tests for str & repr
"""
def test_str(self) -> None:
print(self.cls_general.__str__())
# TODO: Remove this... Or figure out what it tests.
#
# def test_str(self) -> None:
# print(self.cls_general.__str__())
# TODO: Remove this... Or figure out what it tests.
def test_repr(self) -> None:
print(self.cls_general.__repr__())
# def test_repr(self) -> None:
# print(self.cls_general.__repr__())
if __name__ == '__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