Replies: 2 comments 4 replies
-
hi @quenot, This is really nice!!! Vector field analysis ftw!!! I followed your references and try to reproduce the argument here in a compressed form for other readers. This shows that the contours of the stream function PSI correspond to the stream lines of a 2D field u if div(u)=0. If u is a magnetostatic field that is the result of homogeneously magnetized bodies (Magpylib case) then div(u)=0 holds everywhere except at the magnet boundaries, where the field will not be evaluated in any case. Then you compute the function PSI at all grid points by using Here is a slightly modified version of the core of your code:
which produces something like this: Some questions Since you are integrating from always the same start position I would expect the integration path to somehow cross the respective magnet boundaries where divB!=0, and possibly to produce faulty results thereon. I did not manage to create faulty results. The algorithm seems to be extraordinary stable. Do you know why? Have you considered what is the influence of discretization? I noticed that for similar contour levels, when increasing the mesh finesse, the results are quite different. The figure shows for a discretization of 40 (blue) 80(red) 160(green). Probably should not be surprised that the contour levels are moving....but then there is this puzzling left-right asymmetry. Any thoughts on this? Do you know what happens when you are not in a symmetry plane? @peter-leitner and @fslanovc : Please feel free to join the discussion! Any insights would be appreciated. Once all issues are understood, I would love to add this to the Magpylib examples!!! As you brought this up @quenot, would you like to add this by yourself, which would also automatically make you a Magpylib contributor. I'd create a documentation page template in a separate branch for you to work in. In case you don't know how, I'd be happy to guide you through the process. In case you don't want to, I would take care of it. Thanks for bringing this to our attention! BR Michael |
Beta Was this translation helpful? Give feedback.
-
@quenot has prepared a nice code for 2D field lines. You can find it at his repository. The code is based on the method proposed by @Alexboiboi in #678, which uses pyvista streamtubes in 2D. The major issue is the integration error so that stream tubes are not properly closing, but @quenot found a good way to compensate this error. |
Beta Was this translation helpful? Give feedback.
-
The Matplotlib Streamplot page of the documentation illustrates how to display streamlines using matplotlib's streamplot function. However, I wanted to display unbroken streamlines and I struggled to do it with streamplot because streamplot does not handle well closed streamlines. After asking for support from matplotlib developpers, it turned out that using streamplot is not the most practical way to do that. Instead, it is much easier to build a stream function from the field and to display its contours. I have provided an example derived from one of those provided on the Matplotlib Streamplot page and I think it might be useful for magpylib users: https://stackoverflow.com/a/77419388/13707125
Beta Was this translation helpful? Give feedback.
All reactions