-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Speed of sound #8803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Speed of sound #8803
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
37f5771
Create TestShiva
ShivaDahal99 baf8d49
Delete TestShiva
ShivaDahal99 99013f8
Merge branch 'TheAlgorithms:master' into master
jlhuhn ccc60cc
Add speed of sound
ShivaDahal99 c351b34
Update physics/speed_of_sound.py
ShivaDahal99 e092d00
Update physics/speed_of_sound.py
ShivaDahal99 a1f3d5a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] aa24952
Update speed_of_sound.py
ShivaDahal99 11677d1
Update speed_of_sound.py
ShivaDahal99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
ShivaDahal99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
if __name__ == "__main__": | ||
import doctest | ||
|
||
doctest.testmod() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.