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

Developer

parent 04073723
...@@ -140,20 +140,28 @@ class BackgroundField: ...@@ -140,20 +140,28 @@ class BackgroundField:
return self._A.value return self._A.value
@property @property
def acoustic_energy_density(self) -> float: def E_ac(self) -> float:
"""Acoustic energy density [J/m^3] """Mean acoustic energy density [J/m^3]
:rtype: float :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 @property
def acoustic_intensity(self) -> float: def I_ac(self) -> float:
"""Acoustic Intensity [W/m^2] """Acoustic intensity / energy flux density [W/m^2]
:rtype: float :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 # Method for Dependent Variables
...@@ -236,10 +244,10 @@ class BackgroundField: ...@@ -236,10 +244,10 @@ class BackgroundField:
return self._A_in.value[n] return self._A_in.value[n]
def _compute_E(self) -> float: 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: def _compute_I(self) -> float:
out = abs(self.A) out = abs(self.A) ** 2
out *= self.rho_f * self.fluid.c_f out *= self.rho_f * self.fluid.c_f
out *= (self.fluid.k_f ** 2) / 2 out *= (self.fluid.k_f ** 2) / 2
return out return out
......
...@@ -88,10 +88,11 @@ class TestViscousBackgroundField(BaseTestComposite): ...@@ -88,10 +88,11 @@ class TestViscousBackgroundField(BaseTestComposite):
+ (-1) ** n * exp(-1j * position * k_f))) + (-1) ** n * exp(-1j * position * k_f)))
def compute_E(self): 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): def compute_I(self):
out = abs(self.compute_A()) out = abs(self.compute_A() ** 2)
out *= self.rho_f * self.c_f out *= self.rho_f * self.c_f
out *= (self.compute_k_f() ** 2) / 2 out *= (self.compute_k_f() ** 2) / 2
return out return out
...@@ -104,14 +105,13 @@ class TestViscousBackgroundField(BaseTestComposite): ...@@ -104,14 +105,13 @@ class TestViscousBackgroundField(BaseTestComposite):
self.fluid_cls, self.p_0, 'standing') self.fluid_cls, self.p_0, 'standing')
def test_A(self): 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()) 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: 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)) self.assertEqual(self.cls.A_in(n), self.compute_A_in(n))
for _ in self.range_runs: for _ in self.range_runs:
self.change_and_assign() self.change_and_assign()
...@@ -121,22 +121,26 @@ class TestViscousBackgroundField(BaseTestComposite): ...@@ -121,22 +121,26 @@ class TestViscousBackgroundField(BaseTestComposite):
self.assertRaises(ValueError, self.cls.A_in, 20) self.assertRaises(ValueError, self.cls.A_in, 20)
def test_E(self) -> None: def test_E(self) -> None:
for n in range(3): self.assertEqual(self.cls.E_ac, self.compute_E())
self.assertEqual( for _ in self.range_runs:
self.cls.acoustic_energy_density, self.compute_E()) self.change_and_assign()
for _ in self.range_runs: if self.wave_type == 'standing':
self.change_and_assign() self.assertEqual(self.cls.E_ac, self.compute_E())
self.assertEqual( else:
self.cls.acoustic_energy_density, self.compute_E()) with self.assertRaises(NotImplementedError):
self.cls.E_ac
def test_I(self) -> None: def test_I(self) -> None:
for n in range(3): self.wave_type = 'travelling'
self.assertEqual( self.cls.wave_type = self.wave_type
self.cls.acoustic_intensity, self.compute_I()) self.assertEqual(self.cls.I_ac, self.compute_I())
for _ in self.range_runs: for _ in self.range_runs:
self.change_and_assign() self.change_and_assign()
self.assertEqual( if self.wave_type == 'travelling':
self.cls.acoustic_intensity, self.compute_I()) self.assertEqual(self.cls.I_ac, self.compute_I())
else:
with self.assertRaises(NotImplementedError):
self.cls.I_ac
if __name__ == '__main__': 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