我正在用python编写一个程序,该程序应该计算沿由一堆点组成的导电线圈的磁场,并且磁场是由其他导电线圈产生的,这些导电线圈是通过旋转组成的点而形成的原导电线圈。我曾尝试使用 Biot-Savart 定律(代码如下)来做到这一点,但每个线圈由 ~300 个点组成,总共有 10 个线圈,所以我的方法被称为 ~810,000 次,但我认为创建和减去 2向量然后在每次迭代中交叉它们会导致运行时间很长,所以我想知道是否有人知道一种更有效的方法来做 Biot-Savart,或者我是否应该尝试不同的方法。任何见解将不胜感激,谢谢!
我的 Biot-Savart 方法:
def biotsav(l,lprev,pointpos,cur,mu0=1e-7):
#l is the point along the wire generating the magnetic field
#lprev is the previous point along the wire that generated a magnetic field
#pointpos is the position where the magnetic field will be measured at
#cur is the current running through the wire
#if the point causing the magnetic field is the point where the magnetic field is being measured at, return 0 otherwise it would return infinity
if l[0] == pointpos[0] and l[1] == pointpos[1] and l[2] == pointpos[2]:
return np.array([0,0,0])
dl = np.subtract(l,lprev) #vector going from previous point along wire to current point
r = np.subtract(pointpos,l) #vector going from point causing magnetic field to point where magnetic field is being measured
rmag = np.sqrt(r[0]**2 + r[1]**2 + r[2]**2) #magnitude of r
return mu0*cur*np.cross(dl,r)/(rmag**3) #biot savart equation
调用该方法的循环:
#array that will hold magnetic field values along each point on the coil
Bfield = []
#Caclculates the magnetic field at a point on the TF caused by all points on all coils
for i in range(numpts): #this for loop runs through all points along original coil
Btemp = [0,0,0] #placeholder array for updating magnetic field measured at a point along original coil
for j in range(len(allxs)): #this for loop goes through all coils created through symmetry
for k in range(len(allxs[j])): #this for loop goes through all points along coils created by symmetry
currentpt = [allxs[j][k],allys[j][k],allzs[j][k]]
prevpt = [allxs[j][k-1],allys[j][k-1],allzs[j][k-1]]
coilpt = [xlist[i],ylist[i],zlist[i]]
Btemp = np.add(Btemp,biotsav(currentpt,prevpt,coilpt,cur)) #adds magnetic field contributions from all points in coils made by symmetry
Bfield.append(np.array([Btemp[0],Btemp[1],Btemp[2]])) #updates array with net magnetic field measured at point along original coil
**注意:allxs、allys 和 allzs 是包含对称创建的 9 个线圈的 x、y 和 z 坐标的数组。此外,所有线圈都有相等的电流流过它们