如何将另一个对象添加到此3D python SIM中?

时间:2019-04-24 09:11:48

标签: python python-3.x jupyter-notebook

我或多或少是编程新手,正在编写托卡马克反应堆磁场的模拟(融合),我必须添加更多回路(例如,当前回路上方1个回路和下方1个回路) 。另外,我需要一种将它们的磁场编程并加在一起的方法,以便最终图像显示结果场,该结果场是各个场的组合场。我正在使用Jupyter Notebook。任何帮助表示赞赏!

from mpl_toolkits.mplot3d import axes3d
import matplotlib
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-10,10,10)
y = np.linspace(-10,10,10)
z = np.linspace(-10,10,10)

x,y,z = np.meshgrid(x,y,z)

fig = plt.figure()
ax = fig.gca(projection='3d')

mi = 4*np.pi*10e-7                   
N = 1                                 
I = 20                                
phi = np.arctan2(y,x) 
fi = np.linspace(0,2*np.pi,100)
theta = np.linspace (0,np.pi,10)
r= np.sqrt((x)**2+(y)**2)  

def B(x,y):                                                                                      
    mag = ((mi*I)/((2*np.pi)*r**2))                     
    bx = (mag * (np.cos(theta)))*np.cos(phi)                    
    by = (mag * (-np.sin(theta)))*np.sin(phi) 
    bz = mag * (np.sin(theta))
    return bx,by,bz

def ring(r):
    x = r*np.cos(fi)
    y = r*np.sin(fi)
    return x,y,0

matplotlib.rcParams['figure.figsize'] = (10, 8)
matplotlib.rcParams['figure.dpi'] = 100

rx,ry,rz = ring(10)

bx,by,bz = B(x,y)   

ax.quiver(x,y,z,bx,by,bz,color='b',length=2,normalize=True)

for i in np.linspace(-10,10,800):                     
    ax.plot(rx,ry,rz,i,label='Plasma ring',color='r')

#for angle in range(0, 360):
#ax.view_init(270, 360)

ax.set_xlabel('X os')
ax.set_ylabel('Y os')
ax.set_zlabel('Z os')

#plt.savefig("biot-savart_2_3D.png")
plt.show()

结果应该是带有循环的环形场。我设法使它的领域成为一个循环。 Image of the field

0 个答案:

没有答案