2
2
Title: Bernoulli's Principle Implementation
3
3
4
4
Description:
5
- This Python script implements Bernoulli's Principle, which describes the behavior of
5
+ This Python script implements Bernoulli's Principle, which describes the behavior of
6
6
a fluid under varying conditions of pressure, velocity, and height. Bernoulli's equation
7
- is applied to an incompressible, frictionless fluid to calculate the unknown variable
7
+ is applied to an incompressible, frictionless fluid to calculate the unknown variable
8
8
(pressure, velocity, or height) when the others are known.
9
9
10
10
Bernoulli's Equation:
20
20
The function `bernoullis_principle` calculates one unknown variable based on inputs and returns the result.
21
21
"""
22
22
23
+
23
24
def bernoullis_principle (P1 , v1 , h1 , P2 = None , v2 = None , h2 = None , density = 1000 , g = 9.81 ):
24
25
"""
25
26
Apply Bernoulli's Principle to calculate unknown variables.
26
-
27
+
27
28
Parameters:
28
29
P1 : float -> Pressure at point 1 (in Pascals)
29
30
v1 : float -> Velocity at point 1 (in m/s)
@@ -33,18 +34,18 @@ def bernoullis_principle(P1, v1, h1, P2=None, v2=None, h2=None, density=1000, g=
33
34
h2 : float -> Height at point 2 (in meters) (optional)
34
35
density : float -> Fluid density (in kg/m^3) (default is 1000 for water)
35
36
g : float -> Acceleration due to gravity (default is 9.81 m/s²)
36
-
37
+
37
38
Returns:
38
39
- If one unknown is provided (P2, v2, or h2), the function calculates the missing value.
39
40
"""
40
-
41
+
41
42
if P2 is None :
42
43
# Calculate Pressure at point 2 (P2)
43
44
P2 = P1 + 0.5 * density * (v1 ** 2 - v2 ** 2 ) + density * g * (h1 - h2 )
44
45
return P2
45
46
elif v2 is None :
46
47
# Calculate Velocity at point 2 (v2)
47
- v2 = ((2 * (P1 - P2 + density * g * (h1 - h2 ))) / density + v1 ** 2 )** 0.5
48
+ v2 = ((2 * (P1 - P2 + density * g * (h1 - h2 ))) / density + v1 ** 2 ) ** 0.5
48
49
return v2
49
50
elif h2 is None :
50
51
# Calculate Height at point 2 (h2)
@@ -57,10 +58,10 @@ def bernoullis_principle(P1, v1, h1, P2=None, v2=None, h2=None, density=1000, g=
57
58
# Example Usage
58
59
# Given: P1 = 101325 Pa, v1 = 5 m/s, h1 = 10 m, v2 = 10 m/s, h2 = 5 m
59
60
P1 = 101325 # Pressure at point 1 in Pascals
60
- v1 = 5 # Velocity at point 1 in m/s
61
- h1 = 10 # Height at point 1 in meters
62
- v2 = 10 # Velocity at point 2 in m/s
63
- h2 = 5 # Height at point 2 in meters
61
+ v1 = 5 # Velocity at point 1 in m/s
62
+ h1 = 10 # Height at point 1 in meters
63
+ v2 = 10 # Velocity at point 2 in m/s
64
+ h2 = 5 # Height at point 2 in meters
64
65
65
66
# Calculate pressure at point 2 (P2)
66
67
P2 = bernoullis_principle (P1 , v1 , h1 , v2 = v2 , h2 = h2 )
0 commit comments