TypeError:函数名()缺少1个必需的位置参数:“v_air”

2024-09-30 08:16:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两个问题:

  1. 当我调用functiuon时,Python说我错过了函数的一个位置参数simplified_friction_method,但所有参数都写在上面

如果str()或list()对象可能最终为空,例如:asr=''或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'

Tags: the对象函数参数someelementsimplifiedmethod
2条回答

听着,你基本上已经做对了,但为了记录在案,这里是工作代码:

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

最小工作负载示例如上所述

相关问题 更多 >

    热门问题