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 c5ac6b96 authored by mastc's avatar mastc 🎯
Browse files

Merge branch 'developer' into 'patch/yosioka'

Developer

See merge request !80
parents 04073723 67a8e20e
Pipeline #91248 passed with stages
in 6 minutes and 38 seconds
......@@ -140,20 +140,28 @@ class BackgroundField:
return self._A.value
@property
def acoustic_energy_density(self) -> float:
"""Acoustic energy density [J/m^3]
def E_ac(self) -> float:
"""Mean acoustic energy density [J/m^3]
:rtype: float
"""
return self._E.value
if self.wave_type == 'standing':
return self._E.value
else:
raise NotImplementedError('The acoustic energy density is only '
'defined for standing waves.')
@property
def acoustic_intensity(self) -> float:
"""Acoustic Intensity [W/m^2]
def I_ac(self) -> float:
"""Acoustic intensity / energy flux density [W/m^2]
:rtype: float
"""
return self._I.value
if self.wave_type == 'travelling' or self.wave_type == 'traveling':
return self._I.value
else:
raise NotImplementedError('The acoustic intensity is only defined'
'for travelling waves.')
# -------------------------------------------------------------------------
# Method for Dependent Variables
......@@ -236,10 +244,10 @@ class BackgroundField:
return self._A_in.value[n]
def _compute_E(self) -> float:
return abs(self.A) * self.rho_f * self.k_f ** 2
return 1 / 4 * abs(self.A) ** 2 * self.rho_f * self.k_f ** 2
def _compute_I(self) -> float:
out = abs(self.A)
out = abs(self.A) ** 2
out *= self.rho_f * self.fluid.c_f
out *= (self.fluid.k_f ** 2) / 2
return out
......
......@@ -88,10 +88,11 @@ class TestViscousBackgroundField(BaseTestComposite):
+ (-1) ** n * exp(-1j * position * k_f)))
def compute_E(self):
return abs(self.compute_A()) * self.rho_f * self.compute_k_f() ** 2
return 1 / 4 * (abs(self.compute_A() ** 2) * self.rho_f
* self.compute_k_f() ** 2)
def compute_I(self):
out = abs(self.compute_A())
out = abs(self.compute_A() ** 2)
out *= self.rho_f * self.c_f
out *= (self.compute_k_f() ** 2) / 2
return out
......@@ -104,14 +105,13 @@ class TestViscousBackgroundField(BaseTestComposite):
self.fluid_cls, self.p_0, 'standing')
def test_A(self):
for n in range(3):
self.assertEqual(self.cls.A, self.compute_A())
for _ in self.range_runs:
self.change_and_assign()
self.assertEqual(self.cls.A, self.compute_A())
for _ in self.range_runs:
self.change_and_assign()
self.assertEqual(self.cls.A, self.compute_A())
def test_A_in(self) -> None:
for n in [4, 3, 2, 1]:
for n in range(4, 0, -1):
self.assertEqual(self.cls.A_in(n), self.compute_A_in(n))
for _ in self.range_runs:
self.change_and_assign()
......@@ -121,22 +121,26 @@ class TestViscousBackgroundField(BaseTestComposite):
self.assertRaises(ValueError, self.cls.A_in, 20)
def test_E(self) -> None:
for n in range(3):
self.assertEqual(
self.cls.acoustic_energy_density, self.compute_E())
for _ in self.range_runs:
self.change_and_assign()
self.assertEqual(
self.cls.acoustic_energy_density, self.compute_E())
self.assertEqual(self.cls.E_ac, self.compute_E())
for _ in self.range_runs:
self.change_and_assign()
if self.wave_type == 'standing':
self.assertEqual(self.cls.E_ac, self.compute_E())
else:
with self.assertRaises(NotImplementedError):
self.cls.E_ac
def test_I(self) -> None:
for n in range(3):
self.assertEqual(
self.cls.acoustic_intensity, self.compute_I())
for _ in self.range_runs:
self.change_and_assign()
self.assertEqual(
self.cls.acoustic_intensity, self.compute_I())
self.wave_type = 'travelling'
self.cls.wave_type = self.wave_type
self.assertEqual(self.cls.I_ac, self.compute_I())
for _ in self.range_runs:
self.change_and_assign()
if self.wave_type == 'travelling':
self.assertEqual(self.cls.I_ac, self.compute_I())
else:
with self.assertRaises(NotImplementedError):
self.cls.I_ac
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