0% found this document useful (0 votes)
9 views8 pages

Annexure A1

Uploaded by

indrak
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)
9 views8 pages

Annexure A1

Uploaded by

indrak
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/ 8

ANNEXURE A1

import math
import matplotlib.pyplot as plt
import statistics
import numpy as np

def calculate_deoxygenation_rate(dL_dt, K1):


rate_of_deoxygenation = -dL_dt
rate_of_deoxygenation *= K1
return rate_of_deoxygenation

def solve_for_X1(L_prime, K1, t):


K = 0.4343 * K1
X1 = L_prime * (1 - math.pow(10, -K * t))
return X1

def calculate_deoxygenation_time(dL_dt, L_prime, L, X1, K):


ratio = L_prime / L
log_ratio = math.log(ratio)
time = log_ratio / (K * (L_prime - X1))
return time

title = input("Enter the title of the project: ")


NTR = int(input("Enter the number of transects: "))
QEFL = float(input("Enter the flow rate of the effluent in m3/s: "))
FMET = float(input("Enter the conversion factor FMET: "))
F1 = float(input("Enter the conversion factor F1: "))
F2 = float(input("Enter the conversion factor F2: "))
if(FMET<0):
FMET=1.0
if (F1 < 0):
F1=1.0
if (F2 < 0):
F2 = 0.67

QEFL = QEFL*FMET**3
OUTBNK = input("Enter the side of the bank of the effluent: ")

REFLD = []
for i in range(1, NTR+1):
REFLD.append(input("Enter the reference field for transect %d: "
% i))

X = []
for i in range(1, NTR+1):
X.append(float(input("Enter the distance from outfall for
transect %d: " % i)))

Q = []
for i in range(1, NTR+1):
Q.append(float(input("Enter the flow for transect %d: " % i)))

MVEL = []
for i in range(1, NTR + 1):
Q.append(float(input("Enter the mean velocity for transect %d: "
% i)))

NYZ = [0] * 1000


YZ = [0.0] * 1000
U = [0.0] * 100
Ka = [0.0] * 100
KaO = [0.0] * 100
suma = [[0.0] * 100 for _ in range(100)]
sumf = [[0.0] * 100 for _ in range(100)]
sumq = [[0.0] * 100 for _ in range(100)]
ZAV = [0.0] * 100
CAVG = [0.0] * 100
CATRN = [0.0] * 100
YL = [[0.0] * 100 for _ in range(100)]
ZL = [[0.0] * 100 for _ in range(100)]
CPARM = [[0.0] * 100 for _ in range(100)]
VEL = [[0.0] * 100 for _ in range(100)]
DVEL = [[0.0] * 100 for _ in range(100)]
DELQ = [[0.0] * 100 for _ in range(100)]
DELA = [[0.0] * 100 for _ in range(100)]
DCONC = [[0.0] * 100 for _ in range(100)]
DCY = [[0.0] * 100 for _ in range(100)]
ARCY = [[0.0] * 100 for _ in range(100)]
FLUX = [[0.0] * 100 for _ in range(100)]
SUMF = [[0.0] * 100 for _ in range(100)]
UNIF = [[0.0] * 100 for _ in range(100)]
RYB = [[0.0] * 100 for _ in range(100)]
RQ = [[0.0] * 100 for _ in range(100)]
RC = [[0.0] * 100 for _ in range(100)]
RCTRN = [[0.0] * 100 for _ in range(100)]

for i in range(1, NTR + 1):


NYZ[i] = int(input("Enter the number of vertical strips for
transect {}: ".format(i)))
for j in range(1, NYZ[i] + 1):
YL[i][j] = float(input("Enter the distance of vertical strip
{} from the bank: ".format(j)))
for k in range(1, NYZ[i] + 1):
ZL[i][k] = float(input("Enter the depth of vertical strip {}:
".format(k)))
for l in range(1, NYZ[i] + 1):
CPARM[i][l] = float(input("Enter the conductivity at vertical
strip {}: ".format(l)))
for m in range(1, NYZ[i] + 1):
VEL[i][m] = float(input("Enter the velocity at vertical strip
{}: ".format(m)))

CBKG = float(input("Enter the background concentration in mg/l: "))


CEFL = float(input("Enter the concentration in the effluent in mg/l:
"))

CONC = [[0 for _ in range(100)] for _ in range(100)]


CONC_row = []
for i in range(1, NTR+1):
for l in range(1, NYZ[i] + 1):
CONC[i][l]= CPARM[i][l]-CBKG
if (CONC[i][l] < 0):
CONC[i][l] = 0.00
CONC_row.append(statistics.variance(CONC[i]))

squared_Q = [i ** 2 for i in Q]

Dh = []
for index in range(len(CONC_row)):
Dh.append(CONC_row[index] / squared_Q[index])
BKFX = [0]*NTR
TFLX = [0]*NTR
for i in range(NTR):
BKFX[i] = CBKG*(Q[i]-QEFL)
EFLX = CEFL*QEFL
TFLX[i] = BKFX[i]+EFLX

for i in range(1, NTR + 1):


for j in range(1, NYZ[i]+1):
DELA[i][j] = 0.5 * ((YL[i][j + 1]) - (YL[i][j])) * ((ZL[i][j
+ 1]) + (ZL[i][j]))
suma[i][j+1] = suma[i][j] + DELA[i][j]
DVEL[i][j] = 0.5 * ((VEL[i][j + 1]) + (VEL[i][j]))
DELQ[i][j] = DELA[i][j] * DVEL[i][j]
sumq[i][j+1] = sumq[i][j] + DELQ[i][j]
ZAV[i] = suma[i][NYZ[i]] / YL[i][NYZ[i]]
if (MVEL != 99):
U[i] = Q[i] / suma[i][NYZ[i]]

An = []
for i in range(1, NTR + 1):
An.append(ZAV[i-1]/X[i-1])

# To find slope(Beta)
slope = np.polyfit(An, Dh, 1)[0]
beta = round(slope/2, 2)

for i in range(1, NTR + 1):


for j in range(1, NYZ[i]+1):
DCONC[i][j] = 0.5 * ((CONC[i][j+1]) + (CONC[i][j]))
DCY[i][j] = DCONC[i][j] * ((YL[i][j+1]) - (YL[i][j]))
ARCY[i][j] = ARCY[i][j]+DCY[i][j]
FLUX[i][j] = DCONC[i][j] * DELQ[i][j]
sumf[i][j+1] = sumf[i][j] + FLUX[i][j]
UNIF[i][j] = FLUX[i][j] / ((YL[i][j+1]) - (YL[i][j]))
CAVG[i] = CEFL * QEFL / Q[i-1]
CATRN[i] = sumf[i][NYZ[i]] / sumq[i][NYZ[i]]

import math
def calculate_deoxygenation_rate(dL_dt, K1):
rate_of_deoxygenation = -dL_dt
rate_of_deoxygenation *= K1
return rate_of_deoxygenation

def solve_for_X1(L_prime, K1, t):


K = 0.4343 * K1
X1 = L_prime * (1 - math.pow(10, -K * t))
return X1

def calculate_deoxygenation_time(dL_dt, L_prime, L, X1, K):


ratio = L_prime / L
log_ratio = math.log(ratio)
time = log_ratio / (K * (L_prime - X1))
return time

L_prime = float(input("Enter the value of oxygen absorbed during


first stage:"))
L = float(input("Enter the value of oxygen requirement of the sample
at the time:"))
K1 = float(input("Enter the value of deoxygenation constant:"))
t = float(input("Enter the time:"))

# Calculate the derivative dL/dt


dL_dt = (L_prime * K1) / (0.4343 * (L_prime - L))

rate_of_deoxygenation = calculate_deoxygenation_rate(dL_dt, K1)


print("Rate of deoxygenation:", rate_of_deoxygenation)

X1 = solve_for_X1(L_prime, K1, t)
print("Value of X:", X1)

deoxygenation_time = calculate_deoxygenation_time(dL_dt, L_prime, L,


X1, K1)
print("Deoxygenation time:", deoxygenation_time)

#REAERATION CONSTANT

for i in range(1, NTR + 1):


#O CONNOR AND DOBBINS
Ka[i] = 3.93*((U[i]**0.5)/(ZAV[i]**1.5))
#OWENS
KaO[i] = 5.32*((U[i]**0.67)/(ZAV[i]**1.85))

import math
import matplotlib.pyplot as plt

def calculate_derivative(t, D, k_prime, S, H):


# Calculate the derivative dD/dt
dD_dt = -k_prime * D + (S / H)
return dD_dt

k_prime = float(input("Enter the Decay constant per unit time:")) #


Decay constant in per time unit
S = float(input("Enter the Sediment oxygen Demand:")) # Source term
H = float(input("Enter the Depth of the river:")) # Scaling factor

# Initial condition
D_initial = int()

# Time span
t_start = 0.0
t_end = 10.0
t_points = 100
dt = (t_end - t_start) / t_points

# Lists to store time and solution values


t_values = []
D_values = []

# Solve the differential equation using Euler's method


t = t_start
D = D_initial
for _ in range(t_points + 1):
t_values.append(t)
D_values.append(D)
dD_dt = calculate_derivative(t, D, k_prime, S, H)
D += dt * dD_dt
t += dt
# Plot the solution
plt.plot(t_values, D_values)
plt.xlabel('Time')
plt.ylabel('D')
plt.title('D vs. Time')
plt.show()

# Open the output file for writing


output_file = open("mixandat_output.txt", "w")

# Write the output to the file


output_file.write(title + "\n")
for i in range(1, NTR + 1):
output_file.write("TRANSECT %d:\n" % i)
output_file.write("%f meters from outfall\n" % X[i - 1])
output_file.write("QRIVER = %f\n" % Q[i - 1])
output_file.write("QEFL = %f\n" % QEFL)
output_file.write("BACKGROUND CONC. = %f\n" % CBKG)
output_file.write("EFFLUENT CONC. = %f\n" % CEFL)
output_file.write("UPSTREAM FLUX = %f\n" % BKFX[i - 1])
output_file.write("EFFLUENT FLUX = %f\n" % EFLX)
output_file.write("TOTAL FLUX = %f\n" % TFLX[i - 1])
column_names = ['Y', 'Z', 'VEL', 'CONC', 'SUMA', 'SUMQ', 'SUMF']
formatted_column_names = [str(col) for col in column_names]
column_names_str = '\t\t\t\t'.join(formatted_column_names)
output_file.write(column_names_str + "\n")
for j in range(1, NYZ[i] + 1):
row_values = [YL[i][j], ZL[i][j], VEL[i][j], CONC[i][j],
suma[i][j], sumq[i][j], sumf[i][j]]
formatted_row_values = [f"{value:.4f}" for value in
row_values]
row_values_str = "\t\t\t".join(formatted_row_values)
output_file.write(row_values_str + "\n")
output_file.write("AVG. CONC. JUST BELOW OUTFALL, CAVG = %f\n" %
CAVG[i])
output_file.write("AVG. CONC. AT THE TRANSECT, CATRN = %f\n" %
CATRN[i])
output_file.write("MEAN DEPTH = %f\n" % ZAV[i])
output_file.write("MEAN VELOCITY = %f\n" % U[i])
output_file.write("REAERATION CONSTANT FROM O CONNOR AND DOBBINS
EQUATION = %f\n" % Ka[i])
output_file.write("REAERATION CONSTANT FROM OWENS EQUATION = %f\
n" % KaO[i])
output_file.write("Rate of deoxygenation= %f\n" %
rate_of_deoxygenation)
output_file.write("Value of X= %f\n" % X1)
output_file.write("Deoxygenation time= %f\n" % deoxygenation_time)
output_file.write("BETA= %f\n" % beta)
plt.savefig('plot.png')
output_file.write("T H A N K Y O U")
output_file.write("\n")

# Close the output file


output_file.close()

# Print a message indicating the completion of the program


print("Output written to 'mixandat_output.txt'.")

You might also like