From 5058450d1981dfb36e531f6beb0fa50de5f452b8 Mon Sep 17 00:00:00 2001 From: pluto-tofu Date: Fri, 6 Oct 2023 17:51:41 +0530 Subject: [PATCH 1/3] added the algorithm to compute Reynolds number --- physics/reynolds_number | 57 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 physics/reynolds_number diff --git a/physics/reynolds_number b/physics/reynolds_number new file mode 100644 index 000000000000..8d14c21853ad --- /dev/null +++ b/physics/reynolds_number @@ -0,0 +1,57 @@ +""" +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 + >>> 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") + return (density * abs(velocity) * diameter)/viscosity + +if __name__ == "__main__": + import doctest + + doctest.testmod() \ No newline at end of file From d18e5a653049c23498b1d5d4eee8fc1ef72af7af Mon Sep 17 00:00:00 2001 From: pluto-tofu Date: Fri, 6 Oct 2023 17:56:09 +0530 Subject: [PATCH 2/3] fixed file name issue --- physics/{reynolds_number => reynolds_number.py} | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) rename physics/{reynolds_number => reynolds_number.py} (83%) diff --git a/physics/reynolds_number b/physics/reynolds_number.py similarity index 83% rename from physics/reynolds_number rename to physics/reynolds_number.py index 8d14c21853ad..7f0331015cf5 100644 --- a/physics/reynolds_number +++ b/physics/reynolds_number.py @@ -29,7 +29,10 @@ Reference : https://byjus.com/physics/reynolds-number/ """ -def reynolds_number(density:float, velocity:float, diameter:float, viscosity:float) -> float : + +def reynolds_number( + density: float, velocity: float, diameter: float, viscosity: float +) -> float: """ >>> reynolds_number(900,2.5,0.05,0.4) 281.25 @@ -47,11 +50,14 @@ def reynolds_number(density:float, velocity:float, diameter:float, viscosity:flo 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") - return (density * abs(velocity) * diameter)/viscosity + if density <= 0 or diameter <= 0 or viscosity <= 0: + raise ValueError( + "please ensure that density, diameter and viscosity are non negative" + ) + return (density * abs(velocity) * diameter) / viscosity + if __name__ == "__main__": import doctest - doctest.testmod() \ No newline at end of file + doctest.testmod() From ef67be4a4ee9066217ccfa3a5f144fb0c8981e2e Mon Sep 17 00:00:00 2001 From: Tianyi Zheng Date: Tue, 10 Oct 2023 01:20:33 -0400 Subject: [PATCH 3/3] Apply suggestions from code review --- physics/reynolds_number.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/physics/reynolds_number.py b/physics/reynolds_number.py index 7f0331015cf5..dffe690f8822 100644 --- a/physics/reynolds_number.py +++ b/physics/reynolds_number.py @@ -24,7 +24,7 @@ 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. +irregular path with lots of mixing. Reference : https://byjus.com/physics/reynolds-number/ """ @@ -34,25 +34,25 @@ def reynolds_number( density: float, velocity: float, diameter: float, viscosity: float ) -> float: """ - >>> reynolds_number(900,2.5,0.05,0.4) + >>> reynolds_number(900, 2.5, 0.05, 0.4) 281.25 - >>> reynolds_number(450,3.86,0.078,0.23) + >>> reynolds_number(450, 3.86, 0.078, 0.23) 589.0695652173912 - >>> reynolds_number(234,-4.5,0.3,0.44) + >>> reynolds_number(234, -4.5, 0.3, 0.44) 717.9545454545454 - >>> reynolds_number(-90,2,0.045,1) + >>> 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) + ValueError: please ensure that density, diameter and viscosity are positive + >>> reynolds_number(0, 2, -0.4, -2) Traceback (most recent call last): ... - ValueError: please ensure that density, diameter and viscosity are non negative + ValueError: please ensure that density, diameter and viscosity are positive """ if density <= 0 or diameter <= 0 or viscosity <= 0: raise ValueError( - "please ensure that density, diameter and viscosity are non negative" + "please ensure that density, diameter and viscosity are positive" ) return (density * abs(velocity) * diameter) / viscosity