我有两个问题:
如果你的 str() 或 list() 对象最终可能是空的:astr = '' 或 alist = [],那么你可能想要使用 alist[-1:] 而不是 alist[-1]对于对象“相同”。
some_list = [1, 2, 3]
some_list[-1] = 5 # Set the last element
some_list[-2] = 3 # Set the second to last element
some_list
a_list = ['zero', 'one', 'two', 'three']
a_list[-1]
'three'
答案 0 :(得分:1)
看,你基本上已经做对了,但只是为了记录,这里是工作代码:
import numpy as np
from scipy.optimize import root
def viscosity(Tair_inlet):
mu=(1.458*(10**-6)*(Tair_inlet+ 273.15)**1.5)/((Tair_inlet+ 273.15)+110.4)
return mu
def per_circ(D_1):
p_c = np.pi*(D_1)
return p_c
def Tair_outlet(Ts_int,Tair_inlet, hint, p_c, v_air, rho_air, cp_air, L ):
k = hint/(p_c*v_air*rho_air*cp_air)
Tair_outlet = Ts_int + (Tair_inlet-Ts_int)*np.exp(-k*L)
return Tair_outlet
def simplified_friction_method(V_dot, rho_air , L, mu, delta_P, v_air, epsilon ):
m_dot = V_dot * rho_air
print('m_dot',m_dot, '[kgs^-1]')
D_0 = (4*m_dot/(np.pi*rho_air*v_air))**(1/2)
D_1 = D_0
print('D_0',D_0, '[m]')
Re = (v_air * D_0 * rho_air) / mu
print('Re', Re )
f_0= 0*D_0
f_0 = (-2*np.log((epsilon/D_0)/3.7065))**-2
print('f_0', f_0,)
delta_P_tot = delta_P*L
f_1 = f_0
f_2 = 0
e =np.ones(D_0.size)
print("e",e)
while e.any() > 0.0001:
D_1 = ((f_1 * L)/delta_P_tot )* rho_air *(v_air)**2
print('D_1', D_1, '[m]')
Re = (v_air * D_1 * rho_air) / mu
f_2=(-2*abs(np.log((epsilon/D_1)/3.7065 + 2.5226/(Re*np.sqrt(f_1)))))**-2
e = abs(f_1-f_2)
print('e', e, )
f_1 = f_2
return('D_1', D_1,'Re', Re,'f', f_2,'e', e )
class Duct:
def __init__(
self, Tair_inlet, Ts_int, hint, cp_air, rho_air, Rstar, epsilon
):
self.Tair_inlet = Tair_inlet
self.Ts_int = Ts_int
self.hint = hint
self.cp_air = cp_air
self.rho_air = rho_air
self.Rstar = Rstar
self.epsilon = epsilon
duct_ret = Duct(18, 19.5, 3, 1010, 1.2, 8324.68/29, 0.2/1000)
duct_circ = Duct(18, 19.5, 3, 1010, 1.2, 8324.68/29, 0.2/1000)
duct_ret.L = 8
duct_circ.L = np.array([[10, 8, 10, 8]])
duct_circ.V_dot = np.array([[3, 1, 2, 1]])
duct_circ.v_air = np.array([[5, 3, 5, 3]])
duct_circ.deltaP = 1
duct_circ.mu = viscosity(duct_circ.Tair_inlet)
print(duct_circ.mu)
duct_circ.D_1 = simplified_friction_method(
duct_circ.rho_air, duct_circ.V_dot, duct_circ.L, duct_circ.mu,
duct_circ.deltaP, duct_circ.v_air, duct_circ.epsilon
)
print(duct_circ.D_1)
请注意,由于我没有两个文件,因此我没有导入 EN
,因此删除了函数调用前面的 EN.
。我还将 epsilon
参数添加到您的版本中缺少的 Duct
类并将其传递给 simplified_friction_method
函数。有很多方法可以改进代码,但就目前而言,我认为它的工作原理和您理解它更为重要。您显然并不真正了解类的工作原理,因此我建议您look into that。
答案 1 :(得分:0)
最小工作示例如上编写