我遇到错误
RuntimeWarning:除以零的幂次
和
RuntimeWarning:在double_scalars中遇到无效的值
连续执行for循环中两个值的计算之一。这两个值是Tu和n_u_com,但是哪个值导致错误并不一致。
我尝试打印计算中的所有值,以查看是否存在“ 0”或“ nan”并且什么也没发现。
import numpy as np
import matplotlib.pyplot as plt
import csv
#Constants specific to problem
del_e = 0.4
m_e = 9.10938356*10**-31 #[kg]
m_i = 3.34449439655*10**-27 #deutrium [kg]
ko_e = 2000 #stangeby page 394 [Electron conduction coefficient
ko_i = 58.9 #Ion conduction coefficient
k_b = 1.381e-23 #Boltzmans constant [J/K]
K_ev = 11604.525 #ev to kelvin conversion factor
e = 1.6e-19 #coulombs
def main():
Ti_Te_ratio = int(input("Select Ti/Te ratio: \n[1]-Ti/Te=1 \n[2]-Ti/Te=2 \n[3]-Ti/Te=3 \n[4]-Ti/Te=4 \n[5]-Ti/Te=5\n"))
y = int(input("1.Complex gamma \n2.gamma = 7\n"))
Te_t=np.zeros(26,dtype=float)
Ti_t=np.zeros(26,dtype=float)
n_t=np.zeros(26,dtype=float)
L=np.zeros(26,dtype=float)
gamma=np.zeros(26,dtype=float)
c_s=np.zeros(26,dtype=float)
Tu=np.zeros(26,dtype=float)
q_par=np.zeros(26,dtype=float)
n_u_simp=np.zeros(26,dtype=float)
n_u_com=np.zeros(26,dtype=float)
Te_u_div=np.zeros(26,dtype=float)
Ti_u_div=np.zeros(26,dtype=float)
n_u_div=np.zeros(26,dtype=float)
q_par_div=np.zeros(26,dtype=float)
Tu_div=np.zeros(26,dtype=float)
c_s_div=np.zeros(26,dtype=float)
test=np.zeros(10,dtype=float)
s=0
#factor={}
#print(Ti_Te_ratio)
i=0
#z=0
if (Ti_Te_ratio == 1):
data_file = open('Ti=Te.csv')
csv_f = csv.reader(data_file)
if (Ti_Te_ratio == 2):
data_file = open('Ti=2Te.csv')
csv_f = csv.reader(data_file)
if (Ti_Te_ratio == 3):
data_file = open('Ti=3Te.csv')
csv_f = csv.reader(data_file)
if (Ti_Te_ratio == 4):
data_file = open('Ti=4Te.csv')
csv_f = csv.reader(data_file)
if (Ti_Te_ratio == 5):
data_file = open('Ti=5Te.csv')
csv_f = csv.reader(data_file)
for row in csv_f:
if i == 26:
#print("end")
break
else:
#print(i)
Te_t[i] = float(row[3])
Ti_t[i] = float(row[4])
n_t[i] = float(row[5])
L[i] = float(row[10])
Te_u_div[i] = float(row[6])
Ti_u_div[i] = float(row[7])
n_u_div[i] = float(row[8])
q_par_div[i] = float(row[9])
Tu_div[i] = float(Te_u_div[i]+Ti_u_div[i])
c_s_div[i] = float(row[11])
#print(Ti_t[i])
i = i+1
f_cond=np.linspace(.1,.9,9)
f_pow=np.linspace(.1,.9,9)
f_mom=np.linspace(.1,.9,9)
for a in f_cond:
s=s+1
for b in f_pow:
for c in f_mom:
#factor[z]=[a,b,c]
#print(factor[z])
#z=z+1
if y ==1:
for x in range(0, len(Te_t)):
gamma[x] = 2.5*Ti_t[x]/Te_t[x]+2/(1-del_e)-0.5*np.log((2*np.pi*m_e/m_i)*(1+Ti_t[x]/Te_t[x])*(1-del_e)**-2)+.05 #[int] Sheath heat transmission coefficient Stangeby pg. 649
#print(gamma[x])
c_s[x] = np.power([k_b*(Ti_t[x]+Te_t[x])*K_ev/(m_e+m_i)] , 0.5)
#print(c_s[x])
q_par[x] = gamma[x]*n_t[x]*k_b*K_ev*(Ti_t[x]+Te_t[x])*c_s[x]*(1-b)
#print("x=",x,"Ti_t=",Ti_t[x],"Te_t=",Te_t[x],"f_cond=",a,"q_par=",q_par[x],"L=",L[x])
Tu[x] = np.power(np.power(Ti_t[x]+Te_t[x], (7/2))+(7/2)*a*q_par[x]*L[x]/ko_e , (2/7))
test[s]=Tu[0]
#print("a=",a,"b=",b,"c=",c)
#print("x=",x)
#print(Tu[x])
n_u_simp[x] = 2*n_t[x]*(Ti_t[x]+Te_t[x])/(c*Tu[x])
n_u_com[x] = np.power(m_i/(2*e*(Ti_t[x]+Te_t[x]))*4*np.power(q_par[x], 2)*np.power((7/2)*q_par[x]*L[x]/ko_e, (-4/7))/(np.power(gamma[x], 2)*e**2), 0.5)/c
下面是n_u_comp错误之一的副本。
a= 0.1 b= 0.1 c= 0.1
x= 19
10.326673193174681
a= 0.1 b= 0.1C:/.AA_UT Skewl/Plasma Work/Masters Thesis-Two Point Model/TPM with DIVIMP input wtih correction factors.py:120: RuntimeWarning: divide by zero encountered in power
n_u_com[x] = np.power(m_i/(2*e*(Ti_t[x]+Te_t[x]))*4*np.power(q_par[x], 2)*np.power((7/2)*q_par[x]*L[x]/ko_e, (-4/7))/(np.power(gamma[x], 2)*e**2), 0.5)/c
C:/.AA_UT Skewl/Plasma Work/Masters Thesis-Two Point Model/TPM with DIVIMP input wtih correction factors.py:120: RuntimeWarning: invalid value encountered in double_scalars
n_u_com[x] = np.power(m_i/(2*e*(Ti_t[x]+Te_t[x]))*4*np.power(q_par[x], 2)*np.power((7/2)*q_par[x]*L[x]/ko_e, (-4/7))/(np.power(gamma[x], 2)*e**2), 0.5)/c
c= 0.1
x= 20
12.535269603652413
a= 0.1 b= 0.1 c= 0.1
我打印出测试数组,该数组每次在a更改(b,b = 0.9和c = 0.9)(a,0.1、0.2、0.3等)时都存储Tu的所有值,并得到以下结果:[0. 70.930719 71.83187034 72.70561282 73.55386582 74.37834424 75.18058716 75.96198164 76.72378251 77.46712907]因此,Tu第一次为零对我来说没有意义