2
2
Title: Bernoulli's Principle
3
3
4
4
Description:
5
- This algorithm implements Bernoulli's Principle to calculate the unknown pressure
6
- at a second point in a fluid system using the Bernoulli equation. Bernoulli's equation
7
- states that for an incompressible, frictionless fluid, the total mechanical energy
5
+ This algorithm implements Bernoulli's Principle to calculate the unknown pressure
6
+ at a second point in a fluid system using the Bernoulli equation. Bernoulli's equation
7
+ states that for an incompressible, frictionless fluid, the total mechanical energy
8
8
(remains constant) as the fluid flows.
9
9
10
10
The equation used:
24
24
100732.64
25
25
"""
26
26
27
- def bernoullis_principle (velocity1 : float , pressure1 : float , height1 : float ,
28
- velocity2 : float , height2 : float , density : float = 1.225 ) -> float :
27
+
28
+ def bernoullis_principle (
29
+ velocity1 : float ,
30
+ pressure1 : float ,
31
+ height1 : float ,
32
+ velocity2 : float ,
33
+ height2 : float ,
34
+ density : float = 1.225 ,
35
+ ) -> float :
29
36
"""
30
37
Calculate the unknown pressure at a second point in a fluid system using Bernoulli's equation.
31
38
@@ -39,7 +46,7 @@ def bernoullis_principle(velocity1: float, pressure1: float, height1: float,
39
46
40
47
Returns:
41
48
float: Pressure at point 2 in Pascals
42
-
49
+
43
50
Example:
44
51
>>> bernoullis_principle(density=1000, velocity=5, height=10, pressure=101325)
45
52
144413.5
@@ -51,8 +58,13 @@ def bernoullis_principle(velocity1: float, pressure1: float, height1: float,
51
58
g = 9.81 # gravitational constant in m/s^2
52
59
53
60
# Bernoulli's equation to solve for pressure at point 2
54
- pressure2 = (pressure1 + 0.5 * density * (velocity1 ** 2 ) + density * g * height1
55
- - 0.5 * density * (velocity2 ** 2 ) - density * g * height2 )
61
+ pressure2 = (
62
+ pressure1
63
+ + 0.5 * density * (velocity1 ** 2 )
64
+ + density * g * height1
65
+ - 0.5 * density * (velocity2 ** 2 )
66
+ - density * g * height2
67
+ )
56
68
57
69
return round (pressure2 , 2 )
58
70
@@ -61,6 +73,7 @@ def bernoullis_principle(velocity1: float, pressure1: float, height1: float,
61
73
if __name__ == "__main__" :
62
74
# Example doctest
63
75
import doctest
76
+
64
77
doctest .testmod ()
65
78
66
79
# Manual test
0 commit comments