Initial+Visualization+of+Magnetic+Field+Lines

2009 June 29:

The basic idea with this attempt at visualization has to do with taking magnetic vector field information from the simulation tool (shown graphically on the right), and using that to generate magnetic field lines by tracing paths through the magnetic field. We extracted the magnetic vector field information and used MatLab to make a contour plot of the magnitudes of the field at each mesh point (shown on the left).

Loading and plotting of the magnitudes of the field vectors appeared to be a success, so we started to trace paths inside the magnetic field. We tried placing virtual particles at different locations in the magnetic field area, and calculated paths of different lengths going iterating one step at a time (both images below). The image on the right shows the paths, while the image on the left shows a circle at each iteration point along the path. Near the magnet, the particle moved a greater distance with each step, while, at the edge, the particle only moved a little bit at a time.

However, the paths did not make sense given the magnetic field given from the simulation tool. We went over our code to make sure that the instructions were correct as far as we could tell. We tried fixing some minor issues, but there was still a problem. The paths did not trace the field lines we expected given the vector field data. We were sure that our path code was correct, so we tried to understand exactly what MatLab was doing at each step from the loading of the data from file, to the creation of the matrix, to the plotting of the data using the contour function.

We found that MatLab was treating the dimentions differently at each step. In the image from the simulation tool, the x and y coordinates of mesh points increased in the x dimension from left to right, and increased in the y dimension from top to bottom. After loading the data from the simulation data file, the MatLab matrix stored the field information for each mesh point differently. The x dimension was stored increasingly from top to bottom, and the y dimention increased from left to right. The contour plot displayed the mesh point for the x dimension from bottom to top and for the y dimension from left to right. So, instead of transforming the data to make the magnet vertical, we just let MatLab do its thing. The result contour plot is below.

After figuring out how MatLab delt with the 2D spaces differently for each step, we again tried to make some more paths through the field. Again, we found that the line function was backwards as compared to the contour function. The contour function treated x as vertical and y as horizontal, but the line function treated x as horizontal and y as vertical. So we passed the x and y values of our paths into the line function backwards, and it worked! See the two images below.



The particle paths shown in the above two images are closer to what we expected after looking at the magnetic vector field from the simulation tool.

The next step is to do this systematically and automatically, based on the dimentions of the magnetic field area.