MHD冲击波

时间:2018-06-21 12:42:26

标签: python-2.7 scipy physics

我需要使用scipy.fsolve求解MHD冲击波情况的这六个方程(https://en.wikipedia.org/wiki/Shocks_and_discontinuities_(magnetohydrodynamics))。有6个未知变量,其值需要存储在数组z中。虽然在某些情况下我得到正确的答案,但在大多数情况下,这些值是错误的。它们根据初始猜测而有所不同,什么才是正确的初始猜测,以便它适用于所有情况。 注意-z [0]和z [1]表示压力和密度,不能为负。因此,正确的答案将给出正值。

from scipy.optimize import fsolve, root
from scipy.constants import mu_0 as w

print("Assume the shock propogates in the x direction")
p1=float(input("Upstream pressure-"))
rho1=float(input("Upstream density-"))
vx1=float(input("Upstream velocity along x axis-"))
vy1=float(input("Upstream velocity along y axis-"))
bx1=float(input("Upstream magnetic field along x axis-"))
by1=float(input("Upstream magnetic field along y axis-"))


def eqn(x):                                 #jump conditions

    f1=(x[1]*x[2])-(rho1*vx1)
    f2=x[0]+(x[1]*x[2]*x[2])+(x[5]*x[5]*0.5/w)-p1-(rho1*vx1*vx1)-by1*by1*0.5/w
    f3=(x[1]*x[2]*x[3]-x[4]*x[5]/w)-rho1*vx1*vy1+bx1*by1/w
    f4= x[4]-bx1
    f5=x[2]*x[5]-x[4]*x[3]-vx1*by1+vy1*bx1
    f6=x[1]*x[2]*(0.5*(x[2]**2+x[3]**2) +2.5*x[0]/x[1]) +x[2]*(x[5]**2)/w -x[4]*x[5]*x[3]/w - rho1*vx1*(0.5*(vx1**2+vy1**2) +2.5*p1/rho1) -(vx1*by1**2)/w + bx1*by1*vy1/w

    return(f1,f2,f3,f4,f5,f6)

y=[2*p1,4*rho1,0.5,0.5,bx1*2,by1*2]                     #initial guess value

z=fsolve(eqn,y)


print '\n','Upstream Pressure- ',p1,'\t'*3,'Downstream Pressure- ',z[0]
print 'Upstream Density- ',rho1,'\t'*4,'Downstream Density- ',z[1] 
print 'Upstream velocity along x axis- ',vx1,'\t'*2,'Downstream velocity along x axis- ',z[2]
print 'Upstream velocity along y axis- ',vy1,'\t'*2,'Downstream velocity along y axis- ',z[3]
print 'Upstream magnetic field along x axis- ',bx1,'\t','Downstream magnetic field along x axis- ',z[4]
print 'Upstream magnetic field along y axis- ',by1,'\t','Downstream magnetic field along y axis- ',z[5]

0 个答案:

没有答案