0% found this document useful (0 votes)
5 views3 pages

Pipe Network Code

code

Uploaded by

sonukumarjha150
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Pipe Network Code

code

Uploaded by

sonukumarjha150
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

# INPUT PARAMETERS

# Pipe Resistances: [AB, BD, DA, BC, CD]

R = [3,4,6,5,4,6,5,3,7,6,3,4,3,6,5,4,5,7]

# Initial Flow Guesses (L/s): [AB, BD, DA, BC, CD]

Q1 =[20,10,35,5,45,5,25,5,15,30,20,10,5,25,5,10,25,5]

# Loop Definitions (each row defines a loop with pipe indices and signs)

loops = [

[1, 2, -3], # Loop 1

[3,6,-5,-4], # Loop 2

[7,8,-9], # Loop 3

[9,-13,-10,-6], # Loop 4

[10,-12,-11], # Loop 5

[14,15,-16,13], # Loop 6

[16,-17,-18]] # Loop 7

# Convergence Parameters

tolerance = 1e-6

max_iterations = 100

# Store iteration results

iteration_results = []

for iteration in range(1, max_iterations + 1):

max_correction = 0

Q=Q1.copy()

# Iterate over each loop

for loop in loops:

sum_head_loss = 0

sum_RQ = 0
# Process each pipe in the loop

for pipe in loop:

pipe_idx = abs(pipe) - 1 # Adjust for zero-based indexing

direction = pipe/abs(pipe)

# Calculate head loss and accumulate sums

head_loss = R[pipe_idx] * (Q1[pipe_idx] ** 2)

sum_head_loss += direction * head_loss

sum_RQ += R[pipe_idx] * Q1[pipe_idx]

# Calculate correction for this loop

correction = -sum_head_loss / (2 * sum_RQ)

# Apply the correction to each pipe in the loop

for pipe in loop:

pipe_idx = abs(pipe) - 1

direction = pipe/abs(pipe)

Q[pipe_idx] += direction * correction

# Track the maximum correction

max_correction = max(max_correction, abs(correction))

Q1=Q.copy()

# Store the flow rates for this iteration

iteration_results.append(Q.copy())

# Display the current iteration results

print(f"Iteration {iteration}: Flow Rates (L/s) = {Q}")

# Check for convergence

if max_correction < tolerance:


print(f"Converged in {iteration} iterations.")

break

else:

print("Did not converge within the maximum number of iterations.")

# Display final flow rates

print("\nFinal Flow Rates (L/s):")

print(Q)

You might also like