2017-08-08 86 views
1

我正在使用Spark燃烧引擎模型,并且因为我使用python来模拟燃烧的一些原因。我试图使用ODE的解算器,但收益完全超出了现实。我发现圆柱体积的集成是错误的。我已经尝试过使用“odeint”和“ode”解算器,但结果是一样的。 该代码显示了Volume与theta的导数并整合以查找音量。我把分析方程进行比较。Python中的ODE求解器错误

OBS:我有一个类似的问题,使用Matlab,但是当我尝试在三角函数中使用度。当我改变弧度时,问题解决了。 代码如下:

from scipy.integrate import odeint 
from scipy.integrate import ode 
from scipy import integrate 
import math 
import sympy 
from sympy import sqrt, sin, cos, tan, atan 
from pylab import * 
from RatesComp import * 
V_real=np.zeros((100)) 

def Volume(V,theta): 
    V_sol = V[0] 
    dVdtheta = Vtdc*(r-1)/2 *(sin(theta) + eps/2*sin(2*theta)/sqrt(1-(eps**2)*sin(theta)**2)) 
    return [dVdtheta] 

#Geometry 
eps = 0.25;  # half stroke to rod ratio, s/2l 
r = 10;   # compression ratio 
Vtdc = 6.9813e-05 # volume at TDC 

# Initial Conditions 
theta0 = - pi 
V_init = 0.0006283 
theta = linspace(-pi,pi,100) 
solve = odeint(Volume, V_init, theta) 

# Analytical Result 
Size = len(theta) 

for i in range(0, Size,1): 
    V_real[i] = Vtdc*(1+(r-1)/2*(1-cos(theta[i])+ 1/eps*(1-(1-(eps**2)*sin(theta[i])**2)**0.5))) 

figure(1) 
plot(theta, solve[:,0],label="Comput") 
plot(theta, V_real[0:Size],label="Real") 
ylabel('Volume [m^3]') 
xlabel('CA [Rad]') 
legend() 
grid(True) 
show() 

我展示的是圆柱体的体积的图。结果实和计算

https://i.stack.imgur.com/MIoEV.png

能有人为什么这个问题发生的信息帮助吗?

+0

如果增加矢量theta的大小,你会得到相同的行为吗? – jmoon

回答

2

显然你使用python2。 r=10的声明给出rinteger这种类型导致在'真正'解决方案中的(r-1)/2中出现不需要的整数除法。在派生函数中,浮点值为Vtdc作为产品中的第一个因子,之后整个产品评估处于浮动状态。

因此更改为r=10.0或使用(r-1.0)/20.5*(r-1)


而且你还要设置V_init = r*Vtdc为是V_real(-pi)值。

+0

谢谢您的帮助。代码现在运行。 –