Exporting Magnetic Field from FEMM
There is a whole subset of plasma problems that involve non-zero but constant magnetic fields. Ampere’s law tells us that current passing through some medium will induce a magnetic field. However, often these self-induced fields are small enough to be safely neglected. This is especially true if an external magnetic field is applied as is the came with many types of electric propulsion devices. For instance, Hall thrusters and some vacuum arc jets utilize permanent or electromagnets to create a region of relatively strong magnetic field. The strength of this field is several orders of magnitude higher than that of the self-induced fields. We can then assume that \(\partial B/\partial t = 0\), giving us a magnetostatics problem.
In order to simulate such a problem, we need to know the magnetic field profile. Some codes include a built-in magnetic solver but many others don’t. Such as is the case (at least for now!) with our Starfish code. Starfish requires the magnetic field to be loaded from an input file. Luckily, it is quite easy to model magnetic fields with the FEMM (Finite Element Method Magnetics) program written by David Meeker. FEMM includes a GUI that is used to define the problem geometry, assign material properties, and define boundaries. With a click of a button, the computational mesh is generated and the problem is solved. The code contains a built-in post-processor to view the results.
And here lies the problem with FEMM. While the entire simulation is easily driven from the GUI, the GUI lacks one significant capability: the ability to export 2D results in some standard format for post-processing in a different package! The GUI allows you to only define a line connecting control points and export the data along the line. Doing this for the entire domain would be rather tedious, but it is in fact what we used to do before.
However, some Googling led me to an example code that I have since modified that allows you to export the results automatically by utilizing the built-in Lua scripting language. The code is listed below.
--bf_output.lua-- x1=-0.04 x2=0.04 dx=0.001 y1=0.02 y2=0.06 dy=0.001 ni = (x2-x1)/dx+2 nj = (y2-y1)/dy+2 handle=openfile("B.dat","w") write(handle,"VARIABLES = x y B Bx Byn") write(handle,format("ZONE I=%d J=%dn",ni,nj)) for j=0,nj-1,1 do for i=0,ni-1,1 do x=x1+i*dx y=y1+j*dy A,B1,B2=mo_getpointvalues(x,y) write(handle,x," ",y," ",sqrt(B1*B1+B2*B2)," ",B1," ",B2,"n") end end closefile(handle)
You will want to modify the code based on your domain geometry and the desired output format. This particular incarnation outputs the data in a simple Tecplot format as a rectilinear mesh between (-0.04,0.02) and (0.04,0.06) with uniform mesh spacing of 0.001. To run the script, save the file in the folder with your FEMM input file. Then click the “Open a LUA script” button on top of the toolbar. See Figure 2 below. Select the file and click open. You will only see a message box if something went wrong. On the other hand, if you get no messages, the script ran fine, and you should have a file in your directory named B.dat containing the simulation results. Here we output only the magnetic field vectors and magnitude. You can get additional data from mo_getpointvalues. These are summarized in the reference manual.