Permanent magnet's magnetic field calculation

  • Thread starter fluidistic
  • Start date
  • #1
fluidistic
Gold Member
3,790
152
Hello people, in a near future I'd like to calculate (numerically, with finite elements) the magnetic field of several permanent magnets of various shapes. I am wondering which equation(s) I should solve, exactly.
It's been a long time I dived into an EM textbook and I don't have one in hand right now (though I do have internet!).
I think I will have to solve Maxwell equations with the following specifications.
##\vec E=\vec 0## (I consider there is no electric charge anywhere, no electric current either). Futhermore, nothing depends on time (steady state condition, as I won't move the magnets).

This leads to the consideration of ##\nabla \cdot \vec B=0## and ##\nabla \times B = \vec 0##. Now, I do not remember why, but as I remember, it is easier to solve for ##\vec A## the magnetic vector potential given by ##\vec B = \nabla \times \vec A##, to then retrieve ##\vec B##.
However I do not know which kind of boundary conditions I should apply for ##\vec A##. How would I specify that the medium is magnetized?
 
Last edited:

Answers and Replies

  • #2
Dale
Mentor
Insights Author
2020 Award
31,964
8,876
For permanent magnets you will want to use the macroscopic version of Maxwell’s equations. Then you will specify the magnetization and polarization of your magnet and solve those equations.
 
  • Like
Likes etotheipi and vanhees71
  • #3
fluidistic
Gold Member
3,790
152
I forgot to mention that I would like to solve for the magnetic field outside the magnets, if I can solve for the B field inside them, it's a plus.
For permanent magnets you will want to use the macroscopic version of Maxwell’s equations. Then you will specify the magnetization and polarization of your magnet and solve those equations.
May I know why? Here is an example of a calculation of a B field for an electromagnet: https://fenicsproject.org/pub/tutorial/html/._ftut1015.html.
They assume some symmetry which reduces the problem to a 2D one (something I will not do), they focus on tackling the potential vector first and then they get B afterwards.

I can sort of adapt their code to my case. In my case I don't have a current density (as far as I know), so ##\vec J = \vec 0##. They picked the Coulomb gauge for ##\vec A##, which I will replicate as well. They get a Poisson equation of the z-component of the vector potential, while in my case it would be a Laplace equation if I understand well (no source, i.e. no current density). But then, what kind of boundary conditions should I specify over the surface of the magnet? Certainly, these boundary conditions will be different than in their case. In their case I think they set ##A_z =0## on the boundaries (for large x and y as well as over the wires in the domain, if I understand well, but I am not 100% sure).

If I stick to the B field and the macroscopic description, I do not see how this would simply things.

Edit: I think I may be missing that there might be surface currents, so I may have to deal with a Poisson equation rather than Laplace. I need to figure this out.

Edit 2: I think that's the key. There is a surface current of magnitude proportional to the magnetization strength at the surface. And the jump of the magnetic potential vector might be proportional to this current density. I'm not quite sure yet.
 
Last edited:
  • #4
Vanadium 50
Staff Emeritus
Science Advisor
Education Advisor
27,594
11,791
I forgot to mention that I would like to solve for the magnetic field outside the magnets

That's kind of important.

May I know why?

You can't forget something that major and then complain that the answers you got are not exactly what you want.

By far the easiest (and most likely to be correct) way to go about this is to design the equivalent electromagnet and determine that field - i.e. use currents rather than magnetization as the source. Pretty much all the FEA programs are set up to do it this way and they've been extensively vetted.
 
  • #5
fluidistic
Gold Member
3,790
152
That's kind of important.
Is it because it would be a terrible mess to compute the magnetic field inside the material because usually permanent magnets are made of ferro/ferrimagnetic materials whose magnetization is not linear with the applied magnetic field? But in my case there would be no applied field, and we could assume right away that the material has a non zero given magnetization. Or is it for some other reason(s)?



Vanadium 50 said:
You can't forget something that major and then complain that the answers you got are not exactly what you want.

By far the easiest (and most likely to be correct) way to go about this is to design the equivalent electromagnet and determine that field - i.e. use currents rather than magnetization as the source. Pretty much all the FEA programs are set up to do it this way and they've been extensively vetted.
I certainly can forget important things :redface:. Regarding the answer I "do not like" is not that I do not like it (I am willing to go through and use it), but I do not see any advantage whatsoever so stick with the macroscopic versions of Maxwell equations. And since I already have a worked out example of an implementation of finite elements to compute a B field from a given source (in that case electric currents), I thought of using that way, which did not seem too complicated. Using the macroscopic Maxwell equations I think I could bypass the need to deal with the vector potential, provided I find a way to get the current density distribution that generates a B field equivalent to that of the permanent magnet. Is that the reason why it is simpler than to use the differential Maxwell equations? Or is there again something I am missing?

Thanks.
 
  • #6
vanhees71
Science Advisor
Insights Author
Gold Member
18,839
9,711
A permanent magnet can be described by a fixed magnetization density ##M(\vec{x})## in the interior of the hard ferromagnetic material.

The most simple way to solve for the field is to use a scalar potential for ##\vec{H}##,
$$\vec{H}=-\vec{\nabla} \phi_{\text{m}}.$$
That's possible because in this case there's no free current density, i.e.,
$$\vec{\nabla} \times \vec{H}=0$$
and (using SI units)
$$\vec{B}=\mu_0 (\vec{H}+\vec{M}).$$
Now
$$\vec{\nabla} \cdot \vec{B}=0$$
or
$$\vec{\nabla} \cdot \vec{H}=-\vec{\nabla} \cdot \vec{M}=-\Delta \phi_{\text{m}}.$$
So you get
$$\phi_{\text{m}}(\vec{x})=-\int_{\mathbb{R}} \frac{\vec{\nabla} \cdot \vec{M}(\vec{y}}{4 \pi|\vec{x}-\vec{y}|}.$$
Integrating by parts gives
$$\phi_{\text{m}}(\vec{x})=+ \int_{\mathbb{R}^3} \mathrm{d}^3 y \vec{M} \cdot \vec{\nabla}_y \frac{1}{4 \pi|\vec{x}-\vec{y}|} = -\vec{\nabla}_x \cdot \int_{\mathbb{R}^3} \mathrm{d}^3 y \frac{\vec{M}(\vec{y})}{4 \pi |\vec{x}-\vec{y}|}.$$
Take as an example a homogeneously magnetized sphere of radius ##a## with
$$\vec{M}(\vec{x})=M \vec{e}_3 \Theta(a-|\vec{r}|).$$
Then you have
$$\phi_{\text{m}}=-M \frac{\partial}{\partial x_3} \int_{K_a} \mathrm{d}^3 y \frac{1}{4 \pi |\vec{x}-\vec{y}|}.$$
The integral is formally the potential of a homogeneously charged sphere, i.e.,
$$f(\vec{x})=\mathrm{d}^3 y \frac{1}{4 \pi |\vec{x}-\vec{y}|} = \begin{cases} (3 a^2-r^2)/6 & \text{for} \quad r<a, \\
a^3/(3r) & \text{for} \quad r>a \end{cases} \quad \text{with} \quad r=|\vec{x}|.$$
The magnetic potential thus is
$$\phi_{\text{m}}(\vec{x})=-M \partial_3 f(\vec{x})=\begin{cases} M x_3/3 & \text{for} \quad r<a \\ M a^3 x_3/(3 r^3) & \text{for} \quad r>a. \end{cases}$$
From this you get
$$\vec{H}=-\vec{\nabla} \phi_{\text{m}} = \begin{cases}-M \vec{e}_3/3 & \text{for} \quad r<a \\ M a^3 (3 x_3 \vec{r}-r^2 \vec{e}_3)/(3r^5) &\text{for} \quad r>a. \end{cases}$$
The magnetic field finally is
$$\vec{B}=\mu_0 (\vec{H}+\vec{M})=\begin{cases}2 \mu_0M \vec{e}_3/3 & \text{for} \quad r<a \\ \mu_0 M a^3(3 x_3 \vec{r}-r^2 \vec{e}_3)/(3r^5) &\text{for} \quad r>a. \end{cases}$$
For ##r>a## you get a magnetic dipole field with the total magnetic dipole of the sphere,
$$\vec{\mu} = \frac{4 \pi}{3} a^3 \vec{M}.$$
 
  • #7
Vanadium 50
Staff Emeritus
Science Advisor
Education Advisor
27,594
11,791
Or is there again something I am missing?

Yes. It's that you jumped on Dale because you didn't provide a crucial piece of information. That's not his fault.

You seem also to not like my suggestion. Fair enough. My point is that there is a lot of code and experience out there to answer the question "I know the current and materials, what is the field?" If you can adapt that, you're done. If you don't want to, no skin off my teeth.
 
  • #8
fluidistic
Gold Member
3,790
152
Yes. It's that you jumped on Dale because you didn't provide a crucial piece of information. That's not his fault.
I don't feel I have jumped on him, I was (and still am) geniunely curious as to why the macroscopic version of Maxwell equations is what I should look for. Even if it's just for the interior of the magnet region (which is not what I intend to solve).

Vanadium 50 said:
You seem also to not like my suggestion. Fair enough. My point is that there is a lot of code and experience out there to answer the question "I know the current and materials, what is the field?" If you can adapt that, you're done. If you don't want to, no skin off my teeth.
As far as I understand it, your suggestion is to find the equivalent electromagnet of a given permanent magnet (whose shape can lack any symmetry). I would be interested to see which method I should google or investigate. I don't find the problem trivial enough to go that way, but since I am really willing to get the job done, I will take it.

On my side, I have adapted the example code I linked above for a spherical magnet. Here's what I get for the B field (it's a slice of 3D space. The arrows show the field's direction).
magnet_PF.png

Something is obviously wrong. I have tried several different things, like considering a current density (kind of guessing the electromagnet, which should be a dipole if the sphere is uniformly magnetized), considering no current density and solving for Laplace equation for each of the components of the potential vector, and then retrieve the B field by taking the curl of it (it is not expensive computationally, at least for this steady state configuration). I have tried different boundary conditions for the potential vector, either on the sphere itself, the faces of the box (almost equivalent to imposing conditions at infinity), etc. But I could not reproduce the magnetic field I expect, which should be very similar to the Earth's one.

Edit: I just found a discussion about macroscopic vs differential forms of Maxwell equations to solve for the B field: https://www.machinedesign.com/archive/article/21829509/the-best-way-to-model-magnetic-fields.
 
Last edited:
  • #9
vanhees71
Science Advisor
Insights Author
Gold Member
18,839
9,711
Have you seen my posting #6? There the spherical magnet is calculated till the very end. The analogous electromagnet is given by the equivalent current density
$$\vec{j}_{\text{m}}=\vec{\nabla} \times \vec{M}$$
and surface-current density
$$\vec{k}_{\text{m}}=\vec{M} \times \vec{n}$$
where ##\vec{n}## is the surface-normal vector pointing out of the material.

For my example, where I assumed a homogeneous magnetization ##\vec{M}=\text{const}## inside the sphere you have only the surface-current density of course. This you can also get from using the formula for the current density reading it in terms of a generalized function (distribution):
$$\vec{j}_{\text{m}}=\vec{\nabla} \times \vec{M} \Theta(a-r)=-\vec{M} \times \vec{\nabla} \Theta(a-r)=+\vec{M} \delta(a-r) \vec{\nabla r}=\vec{M} \times \vec{n} \delta(a-r).$$
This is equivalent to the said surface-current density,
 
  • #10
hutchphd
Science Advisor
Homework Helper
3,574
2,751
Or is there again something I am missing?
What @vanhees71 says is formally correct and describes the explicit calculation if the magnetization is uniform in magnitude and direction. Unfortunately I do not think that is likely true, particularly for complicated shapes. While most magnets are probably magnetized to ~saturation magnitude, the direction will likely depend upon surface geometry and the exact method of production. These will be tougher to model: you will need to know the magnetization process and model it as well. What is the purpose of this endeavor?
 
  • #11
vanhees71
Science Advisor
Insights Author
Gold Member
18,839
9,711
Sure, that's a very much simplified model. There are also other ansätze in the literature, e.g., in Sommerfeld, Lectures on Theoretical Physics, vol. 3. I'm not aware of more sophisticated models which really attempt to calculate the magnetization of a ferromagnetic material, but I'm sure they exist.
 
  • #12
fluidistic
Gold Member
3,790
152
Have you seen my posting #6? There the spherical magnet is calculated till the very end. The analogous electromagnet is given by the equivalent current density
$$\vec{j}_{\text{m}}=\vec{\nabla} \times \vec{M}$$
and surface-current density
$$\vec{k}_{\text{m}}=\vec{M} \times \vec{n}$$
where ##\vec{n}## is the surface-normal vector pointing out of the material.

For my example, where I assumed a homogeneous magnetization ##\vec{M}=\text{const}## inside the sphere you have only the surface-current density of course. This you can also get from using the formula for the current density reading it in terms of a generalized function (distribution):
$$\vec{j}_{\text{m}}=\vec{\nabla} \times \vec{M} \Theta(a-r)=-\vec{M} \times \vec{\nabla} \Theta(a-r)=+\vec{M} \delta(a-r) \vec{\nabla r}=\vec{M} \times \vec{n} \delta(a-r).$$
This is equivalent to the said surface-current density,
Yes, I had seen it, sorry. I did not react because although it is useful to get these expressions analytically (they can serve as guide in my particular case!), my goal was to get it numerically for more complicated shapes. The case of a uniformly magnetized sphere is nice because the math simplifies as you point out.
Thanks for showing me the equation to get the equivalent current density, so in the end I should provide the magnetization as "input".

hutchphd said:
What @vanhees71 says is formally correct and describes the explicit calculation if the magnetization is uniform in magnitude and direction. Unfortunately I do not think that is likely true, particularly for complicated shapes. While most magnets are probably magnetized to ~saturation magnitude, the direction will likely depend upon surface geometry and the exact method of production. These will be tougher to model: you will need to know the magnetization process and model it as well. What is the purpose of this endeavor?
My goal is just to compute the magnetic field outside of typical magnets, such as neodynium (just for fun), bar magnets and any other shape I can think of. Then I can think of solving some complicated equations where the (non magnetic) material properties's dependence on the magnetic field is taken into account, because there are some effects that may appear when a magnetic field is present.
So, I guess, to keep things simple I think I can assume uniform magnetization even though the shapes are complicated (say I consider a broken small chunk of ferrite).
So I would put a magnet near a material and assume its magnetic permeability is very close to vacuum, and then numerically solve complicated equations in the material with finite elements. What matters at this point, to me, is to get the field around the magnet.
 
  • #13
fluidistic
Gold Member
3,790
152
This problem has drained my energy today. I must be solving the wrong equation(s) or messing the boundary conditions somehow.
What I do, in my code, is solve 3 independent PDE's, one for each component of the potential vector. Namely, I solve ##\nabla \cdot (1/\mu_0 \nabla A_z) = 0## (because ##J_z=0##) and similarly for ##A_x## and ##A_y##. The only difference between these equations is the boundary conditions, which I take as ##A_z## being some non zero constant over the sphere (magnet's surface) and ##A_y## and ##A_x## as zero over the sphere (I also tried several variants, such as taking Dirichlet boundary conditions for ##A_i## at the wall's surface which corresponds to the limits at infinity.) Then the ##\vec B## field is simply the curl of ##\vec A##.
I couldn't get anything close to what it should, yet.
Is there something blatantly wrong with my approach? Of course I might have messed up in the code itself, but if the physics of the problem is wrong, then I am doomed from start.
 
  • #14
hutchphd
Science Advisor
Homework Helper
3,574
2,751
Sure, that's a very much simplified model. There are also other ansätze in the literature, e.g., in Sommerfeld, Lectures on Theoretical Physics, vol. 3. I'm not aware of more sophisticated models which really attempt to calculate the magnetization of a ferromagnetic material, but I'm sure they exist.
I guess if you magnetize your sample by driving with a very large external uniform field the (saturation) magnetization would not be much affected by the surfaces and therefore ~uniform. I don't know how it is done.
For the OP there are lots of free 2D programs to calculate fields. I designed some magnets a decade (maybe two) ago and used freeware called "visimag" I think. Maybe still extant. Playing with it was very educational and I recommend the activity.
 
  • #15
vanhees71
Science Advisor
Insights Author
Gold Member
18,839
9,711
I've browsed the literature a bit within google scholar. There also pretty often the simplifying assumption that ##\vec{M}=\text{const}## within a hard ferromagnetic material is made. Of course that's an idealization, valid most probably within the material but only approximately at its boundaries. It seems nevertheless to be a good enough model for at least semiquantitative approximations.

Now to the equations which have to be solved. For a hard ferromagnet you can consider the magnetization to be given (e.g., by the just discussed idealized model).

The local equations to be solved then are
$$\vec{\nabla} \times \vec{H}=0 \qquad (1)$$
and
$$\vec{\nabla} \cdot \vec{B}=0 \qquad(2)$$
with the constitutive equation
$$\vec{B}=\mu_0 (\vec{H}+\vec{M}). \qquad (3)$$
From the first two equations it's clear that there are two possibilities. The more simple one is to use (1) to deduce that there is a "magnetic potential". I've given the derivation, how to solve the problem in this way in #6. I guess that's also the most simple way to solve it numerically.

Of course equivalently you can also use (2) to introduce the usual vector potential
$$\vec{B}=\vec{\nabla} \times \vec{B},$$
which is determined a priory only up to a gradient field (gauge invariance) and thus you can impose one gauge-fixing condition. As usual in statics it's most convenient to choose the Coulomb condition
$$\vec{\nabla} \cdot \vec{A}=0.$$
Then you get
$$\vec{\nabla} \times \vec{H}=\frac{1}{\mu_0} \vec{\nabla} \times (\vec{B}-\mu_0 \vec{M})=0$$
or
$$\vec{\nabla} \times \vec{B}=-\Delta \vec{A}=\mu_0 \vec{\nabla} \times \vec{M}=\mu_0 \vec{j}_{\text{m}}.$$
In our case
$$\vec{j}_{\text{m}}=M \vec{e}_3 \times \vec{e}_r \delta(r-a)=M \vec{e}_{\varphi} \delta(r-a).$$
Here I've introduced the usual spherical coordinates.

The obvious ansatz for ##\vec{A}## is
$$\vec{A}=\vec{e}_{\varphi} A_{\varphi}(r,\vartheta).$$
This fulfills automatically the Coulomb-gauge condition.

The rest of the calculation is quite lengthy. You find it in

https://itp.uni-frankfurt.de/~hees/publ/theo2-l3.pdf

on p. 93ff. It's in German, but the formula density should be high enough so that you can follow the calculation.

At least you have an analytic example to check your numerics against ;-).
 
  • Like
Likes fluidistic and hutchphd
  • #16
fluidistic
Gold Member
3,790
152
So, I am still dealing with this problem in my free time, and I have made only little progress. As in the post just above, Jackson gets the vector potential for a uniformly magnetized sphere, which is in the azimuthal direction only. For the region outside of the sphere (my region of interest), he gets ##\vec A= A_\varphi (\vec r)=C\sin(\theta)/r^2## where ##C## is a constant. Note that for ##r=a## the radius of the sphere, he gets a vector potential that is not constant over the surface of the sphere, but is something that depends on the azimuthal angle. Very strange.

In these lecture notes: https://www.famaf.unc.edu.ar/~reula/Docencia/Electromagnetismo/electrodynamics.pdf, p.168 right after the expression 11.43, one can see that the vector potential is constant inside the sphere, and constant but of different magnitude outside the sphere, the potential vector being discontinuous at the sphere' surface. There is no dependence on the azimuthal angle anymore...! What is this?!

Jackson's 3d ed. p 208 says that, at least for 2D magnetostatics problems, ##A_z## the potential vector is constant over the surface.

In some other places, I have seen that the condition on the potential vector is a Neuman's kind, that is that its derivative with respect to the normal of the surface is equal to something proportional to the surface current over the sphere.

So overall, I am left without understanding what's going on.
 
  • #17
caz
Gold Member
523
496
I know of a couple of books “Magnetic Materials and 3d Finite element modeling” and “The Finite Element Method in Magnetics.”

I found the first one useful for some of my magnetization questions and I moved on to different things before I got to the second.
 
  • #18
hutchphd
Science Advisor
Homework Helper
3,574
2,751
Then you get
$$\vec{\nabla} \times \vec{H}=\frac{1}{\mu_0} \vec{\nabla} \times (\vec{B}-\mu_0 \vec{M})=0$$
or
$$\vec{\nabla} \times \vec{B}=-\Delta \vec{A}=\mu_0 \vec{\nabla} \times \vec{M}=\mu_0 \vec{j}_{\text{m}}.$$


Isn't this exactly equivalent to the problem of a rotating uniform shell of charge? Griffiths treats this as an example of the use of the vector potential in section 5.4.1 of the 1981 edition. Its not too bad.

Perhaps I am oversimplifying, (but obviously i don't see it).



'
 
  • #19
vanhees71
Science Advisor
Insights Author
Gold Member
18,839
9,711
Of course these two problems are equivalent. The point is that a magnetization can be mapped to an equivalent (surface) current and this can be reinterpreted with an equivalent problem, where you have moving charges making up this current. At the end the equations to be solved are the same.
 
  • #20
fluidistic
Gold Member
3,790
152
Thanks a lot for everything. So, from one point of view, it looks like the vector potential is not constant over the surface of the magnetized sphere, but really depends on the azimuthal angle. When I use your (and Griffiths's) solution as Dirichlet boundary conditions for the vector potential, I do get the correct magnetic field, I think. But this isn't really helpful in that if I modify the shape to something more complicated, I am left in the dark regarding which boundary condition to impose for the vector potential. So it's like using a "cheat" that allows to get the correct B field only if the magnet(s) is spherical, which is already something, but not useful for customization.

In some paper dealing exclusively with the magnetic vector potential (if I remember well, it was https://cds.cern.ch/record/450637/files/p31.pdf, expressions 24a, and 26), there might lie the answer. I should investigate deeper.
 
  • #21
vanhees71
Science Advisor
Insights Author
Gold Member
18,839
9,711
I don't understand this question. Here you just solve for ##\vec{A}## given the surface-current density. The only boundary condition is that you make ##\vec{A} \rightarrow 0## at ##\vec{r} \rightarrow \infty##.
 
  • Informative
  • Like
Likes hutchphd and fluidistic
  • #22
Dale
Mentor
Insights Author
2020 Award
31,964
8,876
May I know why?
IMO it is easier. You specify how the magnet was arranged and then straightforward calculate the field. You can always switch to an equivalent current distribution (@Charles Link has an insights on that), but either way first you start with a good description of the magnet itself.
 
  • Like
Likes hutchphd, fluidistic and Charles Link
  • #23
fluidistic
Gold Member
3,790
152
I don't understand this question. Here you just solve for ##\vec{A}## given the surface-current density. The only boundary condition is that you make ##\vec{A} \rightarrow 0## at ##\vec{r} \rightarrow \infty##.
Thanks once more, I'll try your suggestion and get back to you as soon as possible afterwards. Might take me a few days to get the free time to do it.
 
  • #24
fluidistic
Gold Member
3,790
152
I don't understand this question. Here you just solve for ##\vec{A}## given the surface-current density. The only boundary condition is that you make ##\vec{A} \rightarrow 0## at ##\vec{r} \rightarrow \infty##.
I am currently back on this project for some minutes. I see, thanks a lot. Now that I am in front of my code, I don't think it is as easy to implement. Essentially the equation is the Laplace equation in the whole volume of interest except at the surface of the sphere where the (vector) Laplacian is worth the surface current. I'm not an expert with FEniCS, but I think I should find a way to get a boundary condition of ##\vec A## over the surface of the sphere (be it Dirichlet, Neumann, Robin or possibly of other kinds). There is one such approach described in https://comphysblog.wordpress.com/2018/09/06/tem-mode-analysis-with-fenics/. I might have to follow a similar path.
 

Related Threads on Permanent magnet's magnetic field calculation

Replies
1
Views
17K
  • Last Post
Replies
11
Views
11K
Replies
2
Views
2K
Replies
27
Views
2K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
8
Views
4K
Replies
1
Views
4K
Replies
4
Views
4K
  • Last Post
Replies
6
Views
16K
Top