Hello,
As a new user of NGSolve, I’m playing with a 2D magnetostatics tutorial (alternative link: JupyterLite version) by @tcherrie which runs fine, but I’d like to get extra visualizations of the result.
In particular, I’d like to plot the field lines of the B magnetic field. I’ve adapted from the last part of the Coil tutorial which gives me this code and the following result:
from ngsolve.webgui import FieldLines
fieldlines = FieldLines(B, mesh.Materials(".*"), length=1, num_lines=20)
Draw(B, mesh, objects=[fieldlines],
min=0, max=1e-4,
settings={"Objects": {"Surface": False}}
);
which looks somehow what I’d like, but this could be improved. In particular:
- aspect: have 2D lines rather than 3D tubes
- get control over color (here I understand that the red color comes from the cropped colormap with
max=1e-4while most of the B field is above this level) - random placement: better have an “isodensity” placement (not sure what the proper term is)
- closing the field lines requires using an “large” value for the
lengthparameter
Or said simpler, I’d like to get the field line plot of FEMM:
.For this, I kind of understand that the trick is not to plot the field lines of B but instead the equipotential lines of the magnetic potential A, Correct? However, I didn’t find in the doc an information on how to draw equipotentials (I understand that in 3D they are surfaces but in 2D they are lines, correct?).
An alternative would be to make the plot with another tool like Matplotlib’s contour plot function. For this, I’d need to export the A field value over a an x-y grid (which I have not yet searched how to do).
What option seems better: webgui or external tool?


