-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Added the algorithm to compute Reynolds number in the physics section #9913
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
tianyizheng02
merged 3 commits into
TheAlgorithms:master
from
pluto-tofu:reynolds_number
Oct 10, 2023
Merged
Changes from 2 commits
Commits
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,63 @@ | ||
""" | ||
Title : computing the Reynolds number to find | ||
out the type of flow (laminar or turbulent) | ||
|
||
Reynolds number is a dimensionless quantity that is used to determine | ||
the type of flow pattern as laminar or turbulent while flowing through a | ||
pipe. Reynolds number is defined by the ratio of inertial forces to that of | ||
viscous forces. | ||
|
||
R = Inertial Forces / Viscous Forces | ||
R = (ρ * V * D)/μ | ||
|
||
where : | ||
ρ = Density of fluid (in Kg/m^3) | ||
D = Diameter of pipe through which fluid flows (in m) | ||
V = Velocity of flow of the fluid (in m/s) | ||
μ = Viscosity of the fluid (in Ns/m^2) | ||
|
||
If the Reynolds number calculated is high (greater than 2000), then the | ||
flow through the pipe is said to be turbulent. If Reynolds number is low | ||
(less than 2000), the flow is said to be laminar. Numerically, these are | ||
acceptable values, although in general the laminar and turbulent flows | ||
are classified according to a range. Laminar flow falls below Reynolds | ||
number of 1100 and turbulent falls in a range greater than 2200. | ||
Laminar flow is the type of flow in which the fluid travels smoothly in | ||
regular paths. Conversely, turbulent flow isn't smooth and follows an | ||
irregular math with lots of mixing. | ||
|
||
Reference : https://byjus.com/physics/reynolds-number/ | ||
""" | ||
|
||
|
||
def reynolds_number( | ||
density: float, velocity: float, diameter: float, viscosity: float | ||
) -> float: | ||
""" | ||
>>> reynolds_number(900,2.5,0.05,0.4) | ||
281.25 | ||
>>> reynolds_number(450,3.86,0.078,0.23) | ||
589.0695652173912 | ||
>>> reynolds_number(234,-4.5,0.3,0.44) | ||
717.9545454545454 | ||
tianyizheng02 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
>>> reynolds_number(-90,2,0.045,1) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: please ensure that density, diameter and viscosity are non negative | ||
>>> reynolds_number(0,2,-0.4,-2) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: please ensure that density, diameter and viscosity are non negative | ||
""" | ||
|
||
if density <= 0 or diameter <= 0 or viscosity <= 0: | ||
raise ValueError( | ||
"please ensure that density, diameter and viscosity are non negative" | ||
) | ||
tianyizheng02 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return (density * abs(velocity) * diameter) / viscosity | ||
|
||
|
||
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.