From 37f5771699501d954277bd337c5ed6e2c6860105 Mon Sep 17 00:00:00 2001 From: ShivaDahal99 <130563462+ShivaDahal99@users.noreply.github.com> Date: Mon, 22 May 2023 19:19:07 +0200 Subject: [PATCH 1/8] Create TestShiva --- TestShiva | 1 + 1 file changed, 1 insertion(+) create mode 100644 TestShiva diff --git a/TestShiva b/TestShiva new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/TestShiva @@ -0,0 +1 @@ + From baf8d49b81cb576cad1821e05ad11240110958e0 Mon Sep 17 00:00:00 2001 From: ShivaDahal99 <130563462+ShivaDahal99@users.noreply.github.com> Date: Mon, 22 May 2023 19:19:40 +0200 Subject: [PATCH 2/8] Delete TestShiva --- TestShiva | 1 - 1 file changed, 1 deletion(-) delete mode 100644 TestShiva diff --git a/TestShiva b/TestShiva deleted file mode 100644 index 8b137891791f..000000000000 --- a/TestShiva +++ /dev/null @@ -1 +0,0 @@ - From ccc60ccab7a8363c9037e5a9e72b7d5dc7b782e6 Mon Sep 17 00:00:00 2001 From: ShivaDahal99 Date: Wed, 7 Jun 2023 19:48:03 +0200 Subject: [PATCH 3/8] Add speed of sound --- physics/speed_of_sound.py | 56 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 physics/speed_of_sound.py diff --git a/physics/speed_of_sound.py b/physics/speed_of_sound.py new file mode 100644 index 000000000000..2f31c41f8d8d --- /dev/null +++ b/physics/speed_of_sound.py @@ -0,0 +1,56 @@ +""" +Title : Calculating the speed of sound + +Description : + The speed of sound (c) is the speed that a sound wave travels + per unit time (m/s). During propagation, the sound wave propagates + through an elastic medium. Its SI unit is meter per second (m/s). + + Only longitudinal waves can propagate in liquids and gas other then + solid where they also travel in transverse wave. The following Algo- + rithem calculates the speed of sound in fluid depanding on the bulk + module and the density of the fluid. + + Equation for calculating speed od sound in fluid: + c_fluid = (K_s*p)**0.5 + + c_fluid: speed of sound in fluid + K_s: isentropic bulk modulus + p: density of fluid + + + +Source : https://en.wikipedia.org/wiki/Speed_of_sound +""" + + +class SpeedOfSound: + @staticmethod + def fluid(fluid_density: float, bulk_modulus: float) -> float: + """ + This method calculates the speed of sound in fluid - + This is calculated from the other two provided values + Examples: + Example 1 --> Water 20°C: bulk_moduls= 2.15MPa, fluid_density=998kg/m³ + Example 2 --> Murcery 20°: bulk_moduls= 28.5MPa, fluid_density=13600kg/m³ + + >>> SpeedOfSound.fluid(bulk_modulus=2.15*10**9, fluid_density=998) + 1467.7563207952705 + >>> SpeedOfSound.fluid(bulk_modulus=28.5*10**9, fluid_density=13600) + 1447.614670861731 + """ + + if fluid_density <= 0: + raise ValueError("Impossible fluid density") + if bulk_modulus <= 0: + raise ValueError("Impossible bulk modulus") + + speed_of_sound = (bulk_modulus / fluid_density) ** 0.5 + + return speed_of_sound + + +if __name__ == "__main__": + import doctest + + doctest.testmod() From c351b34a2f9ceb820d8a2f3c9fa9ae8e2d0c3082 Mon Sep 17 00:00:00 2001 From: ShivaDahal99 <130563462+ShivaDahal99@users.noreply.github.com> Date: Wed, 7 Jun 2023 21:04:27 +0200 Subject: [PATCH 4/8] Update physics/speed_of_sound.py Co-authored-by: Christian Clauss --- physics/speed_of_sound.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/physics/speed_of_sound.py b/physics/speed_of_sound.py index 2f31c41f8d8d..4c6b18b188e4 100644 --- a/physics/speed_of_sound.py +++ b/physics/speed_of_sound.py @@ -45,9 +45,7 @@ def fluid(fluid_density: float, bulk_modulus: float) -> float: if bulk_modulus <= 0: raise ValueError("Impossible bulk modulus") - speed_of_sound = (bulk_modulus / fluid_density) ** 0.5 - - return speed_of_sound + return (bulk_modulus / fluid_density) ** 0.5 if __name__ == "__main__": From e092d00481164a7b28244a574c6847e0d6ac838e Mon Sep 17 00:00:00 2001 From: ShivaDahal99 <130563462+ShivaDahal99@users.noreply.github.com> Date: Wed, 7 Jun 2023 21:09:41 +0200 Subject: [PATCH 5/8] Update physics/speed_of_sound.py Co-authored-by: Christian Clauss --- physics/speed_of_sound.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/physics/speed_of_sound.py b/physics/speed_of_sound.py index 4c6b18b188e4..f5b59ddfc232 100644 --- a/physics/speed_of_sound.py +++ b/physics/speed_of_sound.py @@ -24,9 +24,7 @@ """ -class SpeedOfSound: - @staticmethod - def fluid(fluid_density: float, bulk_modulus: float) -> float: +def speed_of_sound_in_a_fluid(density: float, bulk_modulus: float) -> float: """ This method calculates the speed of sound in fluid - This is calculated from the other two provided values From a1f3d5a1bc9959b0babc77ac8cdc1d6ec4581c4d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 7 Jun 2023 19:10:38 +0000 Subject: [PATCH 6/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/speed_of_sound.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/physics/speed_of_sound.py b/physics/speed_of_sound.py index f5b59ddfc232..4d673bbd34cc 100644 --- a/physics/speed_of_sound.py +++ b/physics/speed_of_sound.py @@ -25,25 +25,25 @@ def speed_of_sound_in_a_fluid(density: float, bulk_modulus: float) -> float: - """ - This method calculates the speed of sound in fluid - - This is calculated from the other two provided values - Examples: - Example 1 --> Water 20°C: bulk_moduls= 2.15MPa, fluid_density=998kg/m³ - Example 2 --> Murcery 20°: bulk_moduls= 28.5MPa, fluid_density=13600kg/m³ - - >>> SpeedOfSound.fluid(bulk_modulus=2.15*10**9, fluid_density=998) - 1467.7563207952705 - >>> SpeedOfSound.fluid(bulk_modulus=28.5*10**9, fluid_density=13600) - 1447.614670861731 - """ - - if fluid_density <= 0: - raise ValueError("Impossible fluid density") - if bulk_modulus <= 0: - raise ValueError("Impossible bulk modulus") - - return (bulk_modulus / fluid_density) ** 0.5 + """ + This method calculates the speed of sound in fluid - + This is calculated from the other two provided values + Examples: + Example 1 --> Water 20°C: bulk_moduls= 2.15MPa, fluid_density=998kg/m³ + Example 2 --> Murcery 20°: bulk_moduls= 28.5MPa, fluid_density=13600kg/m³ + + >>> SpeedOfSound.fluid(bulk_modulus=2.15*10**9, fluid_density=998) + 1467.7563207952705 + >>> SpeedOfSound.fluid(bulk_modulus=28.5*10**9, fluid_density=13600) + 1447.614670861731 + """ + + if fluid_density <= 0: + raise ValueError("Impossible fluid density") + if bulk_modulus <= 0: + raise ValueError("Impossible bulk modulus") + + return (bulk_modulus / fluid_density) ** 0.5 if __name__ == "__main__": From aa2495212b4f59b0330cf6d93b1c17dfe51beb3a Mon Sep 17 00:00:00 2001 From: ShivaDahal99 <130563462+ShivaDahal99@users.noreply.github.com> Date: Wed, 7 Jun 2023 21:24:38 +0200 Subject: [PATCH 7/8] Update speed_of_sound.py --- physics/speed_of_sound.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/physics/speed_of_sound.py b/physics/speed_of_sound.py index 4d673bbd34cc..67a7e469bc55 100644 --- a/physics/speed_of_sound.py +++ b/physics/speed_of_sound.py @@ -29,12 +29,12 @@ def speed_of_sound_in_a_fluid(density: float, bulk_modulus: float) -> float: This method calculates the speed of sound in fluid - This is calculated from the other two provided values Examples: - Example 1 --> Water 20°C: bulk_moduls= 2.15MPa, fluid_density=998kg/m³ - Example 2 --> Murcery 20°: bulk_moduls= 28.5MPa, fluid_density=13600kg/m³ + Example 1 --> Water 20°C: bulk_moduls= 2.15MPa, density=998kg/m³ + Example 2 --> Murcery 20°: bulk_moduls= 28.5MPa, density=13600kg/m³ - >>> SpeedOfSound.fluid(bulk_modulus=2.15*10**9, fluid_density=998) + >>> speed_of_sound_in_a_fluid(bulk_modulus=2.15*10**9, density=998) 1467.7563207952705 - >>> SpeedOfSound.fluid(bulk_modulus=28.5*10**9, fluid_density=13600) + >>> speed_of_sound_in_a_fluid(bulk_modulus=28.5*10**9, density=13600) 1447.614670861731 """ @@ -43,7 +43,7 @@ def speed_of_sound_in_a_fluid(density: float, bulk_modulus: float) -> float: if bulk_modulus <= 0: raise ValueError("Impossible bulk modulus") - return (bulk_modulus / fluid_density) ** 0.5 + return (bulk_modulus / density) ** 0.5 if __name__ == "__main__": From 11677d1116bbf9c04c28c0bd5c8a7837a429df00 Mon Sep 17 00:00:00 2001 From: ShivaDahal99 <130563462+ShivaDahal99@users.noreply.github.com> Date: Wed, 7 Jun 2023 21:29:02 +0200 Subject: [PATCH 8/8] Update speed_of_sound.py --- physics/speed_of_sound.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/physics/speed_of_sound.py b/physics/speed_of_sound.py index 67a7e469bc55..a4658366a36c 100644 --- a/physics/speed_of_sound.py +++ b/physics/speed_of_sound.py @@ -38,7 +38,7 @@ def speed_of_sound_in_a_fluid(density: float, bulk_modulus: float) -> float: 1447.614670861731 """ - if fluid_density <= 0: + if density <= 0: raise ValueError("Impossible fluid density") if bulk_modulus <= 0: raise ValueError("Impossible bulk modulus")