## Simulation of the force between two magnets

Numerical methods and mathematical models of Elmer
kevinarden
Posts: 641
Joined: 25 Jan 2019, 01:28
Antispam: Yes

### Re: Simulation of the force between two magnets

With the two_bodies geometry and the case.sif provided, modified to center the 0,0 between the bodies the force reported for different mesh sizes is

Element Size Force
0.0009 472
0.00045 870
0.0001 1212

raback
Posts: 3697
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

### Re: Simulation of the force between two magnets

Hi All,

Thank you for everybody who has been studying the case!

It seems that the nodal forces had not been used in 2D cylindrically symmetric cases before. So the postprocessing code was missing the weight multiplication by the radius. I have just committed a fix to the devel branch.

Now the fact that there was a missing multiplier meant that the results seemed more accurate when R was in range of 1. And unfortunately in my own test case, this was exactly the value I used.

Attached is the case in somewhat modified form. The same case is now done both in 2D and 3D, and we even obtain same results. I compared to an analytic formula but it is accurate only when x>>R. In this case we have x=2R. Already with x=4R the relative error is reduced to about one third. Maybe you will find better references.

I hope this helps people dealing with permanent magnets.

-Peter
Attachments
MagneticForceCylindricalBodies.tar.gz
Reference case in 2D and 3D

kevinarden
Posts: 641
Joined: 25 Jan 2019, 01:28
Antispam: Yes

### Re: Simulation of the force between two magnets

kevinarden
Posts: 641
Joined: 25 Jan 2019, 01:28
Antispam: Yes

### Re: Simulation of the force between two magnets

Phlix
Posts: 11
Joined: 31 Aug 2018, 13:51
Antispam: Yes

### Re: Simulation of the force between two magnets

Hi Peter,

thank you very much for providing MagneticForceCylindricalBodies.tar.gz
I tried to run it with the described steps in the readme-file but get the following error below.
I run elmer on windows 10.

Does anybody know where I have to start to fix this problem?

Thank you in advance for any hint!

Best regards

Phlix

ELMER SOLVER (v 8.4) STARTED AT: 2020/03/31 15:00:05
ParCommInit: Initialize #PEs: 1
MAIN:
MAIN: =============================================================
MAIN: ElmerSolver finite element software, Welcome!
MAIN: This program is free software licensed under (L)GPL
MAIN: Copyright 1st April 1995 - , CSC - IT Center for Science Ltd.
MAIN: Version: 8.4 (Rev: Release, Compiled: 2020-03-26)
MAIN: Running one task without MPI parallelization.
MAIN: =============================================================
MAIN:
MAIN:
MAIN: -------------------------------------
Model Input: Unlisted keyword: [vtu: discontinuous bodies] in section: [simulation]
Model Input: Unlisted keyword: [expression 1] in section: [solver 3]
LoadInputFile: Number of Body Forces: 0
LoadInputFile: Number of Initial Conditions: 0
WARNING:: ListFind:
WARNING:: ListFind:
WARNING:: ListFind:
WARNING:: ListFind:
WARNING:: ListFind:
WARNING:: ListFind:
ERROR:: MagnetoDynamicsCalcFields_Init0: Could not determine target variable type (real or complex)
STOP 1

Phlix
Posts: 11
Joined: 31 Aug 2018, 13:51
Antispam: Yes

### Re: Simulation of the force between two magnets

HI all,

I think found my mistake.
Here the solution if any other newbie runs into the same pitfall:

When i installed the newest version from here:

http://www.nic.funet.fi/pub/sci/physics ... dows-test/

I forgot to add elmer to the system path during the setup (see yellow highlights in screenshot).

I did it as depicted, when I reinstalled elmer. Now, everything seems to work

Best regards!
Attachments
Elmerinstall.PNG (19.15 KiB) Viewed 533 times

JanHoek
Posts: 15
Joined: 13 Jan 2020, 14:06
Antispam: Yes

### Re: Simulation of the force between two magnets

raback wrote:
30 Jan 2020, 15:43
Hi All,

Thank you for everybody who has been studying the case!

It seems that the nodal forces had not been used in 2D cylindrically symmetric cases before. So the postprocessing code was missing the weight multiplication by the radius. I have just committed a fix to the devel branch.

Now the fact that there was a missing multiplier meant that the results seemed more accurate when R was in range of 1. And unfortunately in my own test case, this was exactly the value I used.

Attached is the case in somewhat modified form. The same case is now done both in 2D and 3D, and we even obtain same results. I compared to an analytic formula but it is accurate only when x>>R. In this case we have x=2R. Already with x=4R the relative error is reduced to about one third. Maybe you will find better references.

I hope this helps people dealing with permanent magnets.

-Peter
Hi everyone,

I am currently trying to expand on this study by simulating multiple cases for two permanent magnets. Here, I am comparing the results from the 2D and 3D cases to the analytical solution. The results are shown below:
Results_simulations.png (21.82 KiB) Viewed 484 times
The results from Elmer 2D and the analytical solution seem to match, however I have some problems with getting the correct results for Elmer 3D. I noticed that the results from Elmer 3D were about a factor 2 too low. Multiplication by 2 gives the Elmer 3D correction line, which seems to be the correct answer. However, I cannot explain this factor and I cannot find any reason why this difference would be there. Here are the files from the 3D case I used:
3D_20.grd
case.sif
The files from the 2D case are in the next post.
Last edited by JanHoek on 23 Apr 2020, 17:22, edited 1 time in total.

JanHoek
Posts: 15
Joined: 13 Jan 2020, 14:06
Antispam: Yes

### Re: Simulation of the force between two magnets

Below are the files I used for the 2D case:
d20.grd
case.sif
The analytical solution is valid for x>>R, given by:
Analytical_Solution.png (97.13 KiB) Viewed 483 times
Does anyone have any idea why the solutions from the 2D and 3D case are different? Any help would be greatly appreciated.

Kind regards,
Jan

kevinarden
Posts: 641
Joined: 25 Jan 2019, 01:28
Antispam: Yes

### Re: Simulation of the force between two magnets

Yes, the 2D case has a finer mesh by a factor of a 1000. Mesh density affects the answer. increase the mesh density of the 3D problem and it will start converging to the 2D problem.

JanHoek
Posts: 15
Joined: 13 Jan 2020, 14:06
Antispam: Yes

### Re: Simulation of the force between two magnets

I tried to refine the mesh a couple of times for the case where the distance between the magnets is 1mm. I also tried multiple local mesh refinements, however the solution seems to converge to half the value of the analytical solution and 2D axisymmetric case result every time. Here are the files I use:
3D_1.grd