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 003e381d authored by Christoph Goering's avatar Christoph Goering
Browse files

Merge branch 'patch/update_backgroundfield' into 'developer'

Patch/update backgroundfield

Added acoustic energy and acoustic intesity to  the backgroundfield.

See merge request !74
parents 21aa15aa 4bb42f67
Pipeline #91199 passed with stages
in 5 minutes and 7 seconds
......@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.2.8] - 2021-04-13
### Added - Cyrill Mast
- Acoustic Energy
- Acoustic Intensity
## [0.2.7] - 2021-03-29
### Changed - Cyrill Mast
......
......@@ -46,7 +46,10 @@ class BackgroundField:
"velocity potential amplitude A")
self._A_in = ActiveVariable(self._reset_A_in,
"velocity potential amplitude A_n")
self._E = ActiveVariable(self._compute_E,
"acoustic energy density E")
self._I = ActiveVariable(self._compute_I,
"acoustic intensity I")
# Dependencies
self._A.is_computed_by(self.fluid.frequency._omega,
self.fluid._rho_f,
......@@ -58,6 +61,17 @@ class BackgroundField:
self._A,
self._wave_type)
self._E.is_computed_by(
self._A,
self.fluid._rho_f,
self.fluid._k_f)
self._I.is_computed_by(
self._A,
self.fluid._rho_f,
self.fluid._k_f,
self.fluid._c_f)
# -------------------------------------------------------------------------
# Setters and Getters for Independent Variables
# -------------------------------------------------------------------------
......@@ -111,6 +125,7 @@ class BackgroundField:
@position.setter
def position(self, value: float) -> None:
self._position.value = value
# -------------------------------------------------------------------------
# Getters for Dependent Variables
# -------------------------------------------------------------------------
......@@ -123,6 +138,22 @@ class BackgroundField:
"""
return self._A.value
@property
def acoustic_energy_density(self) -> float:
"""Acoustic energy density [J/m^3]
:rtype: float
"""
return self._E.value
@property
def acoustic_intensity(self) -> float:
"""Acoustic Intensity [W/m^2]
:rtype: float
"""
return self._I.value
# -------------------------------------------------------------------------
# Method for Dependent Variables
# -------------------------------------------------------------------------
......@@ -203,6 +234,15 @@ class BackgroundField:
self._compute_A_in(n)
return self._A_in.value[n]
def _compute_E(self) -> float:
return abs(self.A) * self.rho_f * self.k_f ** 2
def _compute_I(self) -> float:
out = abs(self.A)
out *= self.rho_f * self.fluid.c_f
out *= (self.fluid.k_f ** 2) / 2
return out
if __name__ == '__main__':
pass
......@@ -87,6 +87,15 @@ class TestViscousBackgroundField(BaseTestComposite):
* (exp(1j * position * k_f)
+ (-1) ** n * exp(-1j * position * k_f)))
def compute_E(self):
return abs(self.compute_A()) * self.rho_f * self.compute_k_f() ** 2
def compute_I(self):
out = abs(self.compute_A())
out *= self.rho_f * self.c_f
out *= (self.compute_k_f() ** 2) / 2
return out
def test_k_v(self):
self.assertEqual(self.fluid_cls.k_v, self.cls.k_v)
......@@ -111,6 +120,24 @@ class TestViscousBackgroundField(BaseTestComposite):
self.cls.wave_type = 'None'
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())
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())
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