我正在编写一个热交换模拟程序。应该生成的值是T_hot_out = 65,T_cold_out = 35,A = 22.26。
下面是我一直在使用的代码。它打印T_hot_out = 36.9和T_cold_out = 64.32。没有引发错误,所以我对计算错误来自哪里以及如何修复它感到困惑。
#problem 4
import numpy as np
# from text (original design assumptions)
T_cold_out0 =35
T_hot_out0 = 65
# from Table 1
T_hot_in = 160.0
T_cold_in = 20.0
Cp_hot = 5.2
Cp_cold = 2.6
w_hot = 1.0
k = 0.05
l = 0.002
# from problem 2
w_cold = 5.555555
A_design = 22.26
def integrate(f, x0, x1, N):
h = (x1 - x0) / (N-1)
xvalues = np.linspace(x0,x1,N)
yvalues = f(xvalues)
F = np.zeros(N)
for i in range (1,N):
F[i] = h/2 * (yvalues[i-1]+yvalues[i])+F[i-1]
return xvalues,F
def bisection(f, y, x0, x1, eps, max_iter=1000):
x1_n = x1
x0_n = x0
T = (x1+x0) / 2.0
f_T = f(T)
for i in range(max_iter):
T_n = (x0_n+x1_n)/2
f_T_n = f(T_n)
error = f_T_n - y
if abs(error) <= eps:
break
elif error > 0:
x0_n = T_n
x1_n = x1_n
elif error < 0:
x0_n = x0_n
x1_n = T_n
return T_n, error, (abs(error)<=eps)
def h_hot(T_n):
return 0.9*(1+0.015*(T_n-70))
def h_cold(T_n):
return 3.0*(1+0.02*(T_n-40))
def h_overall(T_cold, T_hot):
return 1/((h_hot(T_hot))**-1 + (h_cold(T_cold))**-1 +(k/l)**-1)
# equation (2) using h_hot() and h_cold()
def T_hot(T_cold, T_hot_out):
return T_hot_out + ((Cp_cold*w_cold)/(Cp_hot*w_hot))*(T_cold - T_cold_in) # from problem 3
def T_cold_out(T_hot_out):
return T_cold_in + (Cp_hot*w_hot)/(Cp_cold*w_cold)*(T_hot_in-T_hot_out) # similar to T_hot()
def A(T_hot_out):
def f2(T_cold):
return ((Cp_cold*w_cold)/h_overall(T_cold, T_hot(T_cold, T_hot_out)))*(1/(T_hot(T_cold, T_hot_out)-T_cold)) # from equation (9)
T_cold, area = integrate(f2,T_cold_in,T_cold_out(T_hot_out), 1000)
return area[-1]
T_hot_out, err, success = bisection(A, A_design, T_cold_in, T_hot_in, 0.001, max_iter=1000)
if not success:
print("Bisection has failed!")
print("T_hot_out = {:.2f} (instead of {:.2f})".format(T_hot_out, T_hot_out0))
print("T_cold_out = {:.2f} (instead of {:.2f})".format(T_cold_out(T_hot_out), T_cold_out0))
print("A = {:.2f} (error = {:.4e})".format(A(T_hot_out), A(T_hot_out) - A_design))
1条答案
按热度按时间mgdq6dx11#
看起来你的T_hot_out和T_cold_out值在某个时候被切换了,而且看起来你在某个地方有一个舍入误差。