Problem calculating the magnetic energy of two coils

Numerical methods and mathematical models of Elmer
lazyTom
Posts: 33
Joined: 05 Jun 2013, 01:32
Antispam: Yes

Problem calculating the magnetic energy of two coils

Hi all and happy new year!! I'm working on the following problem:

I have a system which is represented by two adjacent coils (the surface they enclose lay on the same plane and the coils don't touch each other, see picture below) in free space. adjacent_coils.jpg (128.54 KiB) Viewed 1306 times

Each coil carries a known constant current and the currents in the coils are not equal.

I need to calculate the total magnetic energy of the system.

To do so I have used in the following strategy:

I have created two stat current solvers (one for each coil, each solver impose the desired current). The current so calculated is then fed to the magdyn and magdycalc solver via body force.

The sif file can be seen below. In theory this should work (at least in my mind ), however, when I run ElmerSolver (both on Elmer 8.3 and 8.4) the simulation fails miserably (see attached file).

The mesh file can be found here

https://www.dropbox.com/s/rz82f4brzbum ... .zip?dl=0

Can anyone help me find out what am I doing wrong?

Many thanks,

Marco

Code: Select all

!!------ Skeleton for body section -----
!Body 1 = air
!Body 2 = trace 1
!Body 3 = trace 2

!------ Skeleton for boundary section -----
!BC1 = Current in coil 1
!BC2 = Current out coil 1
!BC3 = Current in coil 2
!BC4 = Current out coil 2
!BC5 = Air_BC (external air, where vector potential is assumed to be 0)

! All coils excited

Check Keywords "Warn"

Mesh DB "." "adjacent_open_coil_V01"

Include Path ""
Results Directory ""
End

Simulation
Coordinate System = Cartesian
Coordinate Mapping(3) = 1 2 3
! Coordinate Scaling=0.001
Simulation Type = Steady
Steady State Max Iterations = 1
End

Constants
Gravity(4) = 0 -1 0 9.82
Stefan Boltzmann = 5.67e-08
Permittivity of Vacuum = 8.8542e-12
Boltzmann Constant = 1.3807e-23
Unit Charge = 1.602e-19
End

Body 1
Target Bodies(1) = 1
Name = "Air"
Equation = 1
Material = 1
End

Body 2
Target Bodies(1) = 2
Name = "Coil 1"
Equation = 2
Material = 2
Body Force = 1
End

Body 3
Target Bodies(1) = 3
Name = "Coil 2"
Equation = 3
Material = 2
Body Force = 2
End

Material 1
Name = "Air (room temperature)"
Viscosity = 1.983e-5
Heat expansion Coefficient = 3.43e-3
Heat Conductivity = 0.0257
Sound speed = 343.0
Density = 1.205
Heat Capacity = 1005.0

Relative Permittivity = Real 1
Relative Permeability = Real 1
Electric Conductivity = Real 0
End

Material 2
Name = "Copper (generic)"
Heat expansion Coefficient = 16.5e-6
Heat Conductivity = 401.0
Sound speed = 3810.0
Heat Capacity = 385.0
Density = 8960.0
Mesh Poisson ratio = 0.34
Poisson ratio = 0.34
Youngs modulus = 115.0e9

Relative Permittivity = Real 1
Relative Permeability = Real 1
Electric Conductivity = Real 5.96e7
End

Equation 1
Name = "Equation for air"
Active Solvers(2) = 3 4
End

Equation 2
Name = "Equation for coil 1"
Active Solvers(3) = 1 3 4
End

Equation 2
Name = "Equation for coil 2"
Active Solvers(3) = 2 3 4
End

Solver 1
!  Exec Solver = before all !Always
Equation = solving coil 1
Calculate Volume Current = True
Procedure = "StatCurrentSolve" "StatCurrentSolver"

Current Control = 40
Variable = Potential_1

Stabilize = True
Bubbles = False
Lumped Mass Matrix = False
Optimize Bandwidth = True
Steady State Convergence Tolerance = 1.0e-5
Nonlinear System Convergence Tolerance = 1.0e-7
Nonlinear System Max Iterations = 1
Nonlinear System Newton After Iterations = 3
Nonlinear System Newton After Tolerance = 1.0e-3
Nonlinear System Relaxation Factor = 1

Linear System Solver = Iterative

!  Linear System Iterative Method = TFQMR
Linear System Iterative Method = GC
!  Linear System Iterative Method = GCR
!  Linear System Iterative Method = BiCGStab
!  Linear System Iterative Method = BiCGStab2
!  Linear System Iterative Method = BiCGStabl
!  BicGStabL Polynomial Degree = 4

Linear System Max Iterations = 15000
Linear System Convergence Tolerance = 1.0e-10

!  Linear System Preconditioning = Diagonal
!  Linear System ILUT Tolerance = 1.0e-3

Linear System Abort Not Converged = False
!  Linear System Residual Output = 1
!  Linear System Precondition Recompute = 1
End

Solver 2
!  Exec Solver = before all !Always
Equation = solving coil 2
Calculate Volume Current = True
Procedure = "StatCurrentSolve" "StatCurrentSolver"

Current Control = 10
Variable = Potential_2

Stabilize = True
Bubbles = False
Lumped Mass Matrix = False
Optimize Bandwidth = True
Steady State Convergence Tolerance = 1.0e-5
Nonlinear System Convergence Tolerance = 1.0e-7
Nonlinear System Max Iterations = 1
Nonlinear System Newton After Iterations = 3
Nonlinear System Newton After Tolerance = 1.0e-3
Nonlinear System Relaxation Factor = 1

Linear System Solver = Iterative

!  Linear System Iterative Method = TFQMR
Linear System Iterative Method = GC
!  Linear System Iterative Method = GCR
!  Linear System Iterative Method = BiCGStab
!  Linear System Iterative Method = BiCGStab2
!  Linear System Iterative Method = BiCGStabl
!  BicGStabL Polynomial Degree = 4

Linear System Max Iterations = 15000
Linear System Convergence Tolerance = 1.0e-10

!  Linear System Preconditioning = Diagonal
!  Linear System ILUT Tolerance = 1.0e-3

Linear System Abort Not Converged = False
!  Linear System Residual Output = 1
!  Linear System Precondition Recompute = 1
End

!===============================================
!=========== MAGNETIC FIELD SOLVER =============
Solver 3
!  Exec Solver = Never
Equation = "MGDynamics"
Variable = P
Procedure = "MagnetoDynamics" "WhitneyAVSolver"
Fix Input Current Density = Logical True

!  Linear System Symmetric = True
!  Optimize Bandwidth = True

Steady State Convergence Tolerance = 1e-09
Nonlinear System Convergence Tolerance = 1.0e-8
Nonlinear System Max Iterations = 1
Nonlinear System Newton After Iterations = 3
Nonlinear System Newton After Tolerance = 1.0e-3
Nonlinear System Relaxation Factor = 1

Linear System Solver = "Iterative"

!  Linear System Iterative Method = TFQMR
!  Linear System Iterative Method = GC
!  Linear System Iterative Method = GCR
!  Linear System Iterative Method = BiCGStab
!  Linear System Iterative Method = BiCGStab2
!  Linear System Iterative Method = BiCGStabl
!  BicGStabL Polynomial Degree = 4

!  Linear System Preconditioning = none
!  Linear System Preconditioning = ILU2
!  Linear System ILUT Tolerance = 1.0e-3

!  Linear System Precondition Recompute = 1
!  Linear System Residual Output = 20
!  Linear System Residual Output = 1

Linear System Max Iterations = 1400 !5000
Linear System Convergence Tolerance = 1.0e-8

Linear System Abort Not Converged = False

!  Edge Basis = Logical True
!  Apply Mortar BCs = Logical True
!  Mortar BCs additive = True

End

Solver 4
!  Exec Solver = Never
Equation = "MGDynamicsCalc"
Procedure = "MagnetoDynamics" "MagnetoDynamicsCalcFields"

Potential Variable = P

Calculate Current Density = Logical True
!  Calculate Electric Field  = Logical True
!  Calculate Magnetic Field Strength = Logical True
Calculate Magnetic Field Density = Logical True

Steady State Convergence Tolerance = 1e-09
Linear System Solver = "Iterative"
!  Linear System Iterative Method = CG
Linear System Iterative Method = BiCGStab

Linear System Max Iterations = 5000
Linear System Convergence Tolerance = 1.0e-8
End

Solver 5
!  Equation = Result Output
!  Exec Solver = Never
Procedure = "ResultOutputSolve" "ResultOutputSolver"
Binary Output = True
Output Format = vtu
Output File Name = results
End

Solver 6
!  Equation = "scalars"
!  Exec Solver = Never
procedure = "SaveData" "SaveScalars"
Filename = "data_scalars.dat"
End

Boundary Condition 1
Target Boundaries(1) = 5
Name = "Outer space"
P {e}= real 0
End

Boundary Condition 2
Target Boundaries(1) = 1
Name = "Coil 1 current in"
Potential_1 = real 0.05
End

Boundary Condition 3
Target Boundaries(1) = 2
Name = "Coil 1 current out"
Potential_1 = real 0
End

Boundary Condition 4
Target Boundaries(1) = 3
Name = "Coil 1 current in"
Potential_2 = real 0.05
End

Boundary Condition 5
Target Boundaries(1) = 4
Name = "Coil 2 current out"
Potential_2 = real 0
End

Body Force 1
Name = "Coil 1 Current Density"
Current Density 1 = Equals Volume current 1
Current Density 2 = Equals Volume current 2
Current Density 3 = Equals Volume current 3
End

Body Force 2
Name = "Coil 2 Current Density"
Current Density 1 = Equals Volume current 1
Current Density 2 = Equals Volume current 2
Current Density 3 = Equals Volume current 3
End

Attachments

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

Re: Problem calculating the magnetic energy of two coils

Hi Marco

Some comments on the sif.
• I would not use Varname_1 and Varname_2 but rather VarnameA and VarnameB. Number may be assumed to be component and avoid special characters in any workflow.
• The outputted current would like to have same name existing in different domains. Cannot do this. So unless you edit the solvers you cannot use current density.
• You could use probably "external potential = Equals PotentialA" as you can also feed the system by potential.
All this being said the CoilSolver is a solver intended to get this type of current sources. It can hopefully deal with closed coils and even set the coils up automatically just by some assumptions on the geometry. I once created a case that randomly generated coils in space and it seemed to work (convergence of the magnetic solver was another issue).

-Peter

lazyTom
Posts: 33
Joined: 05 Jun 2013, 01:32
Antispam: Yes

Re: Problem calculating the magnetic energy of two coils

Hi Peter,

Varname_1, Varnale_2... uh... I didn't see that coming. I'll correct the names as recommended.

About coilSolver, though I'd like to use it, the solver is not capable of handling complex structures which is what I'm planning to use once I validate (hopefully...) the solution of this simple system.

I already tested coilSolver, with no luck, here:
http://www.elmerfem.org/forum/viewtopi ... er#p19738

The possibility to use the potential is nice, let me edit the solver and see how it goes.

BTW, I've tried to grep for "external potential" in the tests directory and "Elmer Models Manual" and found no reference. Did you mean "electric potential = Equals PotentialA"?

Marco

lazyTom
Posts: 33
Joined: 05 Jun 2013, 01:32
Antispam: Yes

Re: Problem calculating the magnetic energy of two coils

Ok, so I've implemented the sif with potential as body force.

Since this is the fist time that I use the electric potential as body force I have simplified the problem using only one coil (the second coil is treated as air).

The sif is as follows:

Code: Select all

!!------ Skeleton for body section -----
!Body 1 = air
!Body 2 = trace 1
!Body 3 = trace 2

!------ Skeleton for boundary section -----
!BC1 = Current in coil 1
!BC2 = Current out coil 1
!BC3 = Current in coil 2
!BC4 = Current out coil 2
!BC5 = Air_BC (external air, where vector potential is assumed to be 0)

! SINGLE coil excited
! coilSolver Potential name changed to PotentialA
! Using potential distribution as bodyforce
! Calculate Volume Current changed from True to False
! Reintroduced magnetic solver in all bodies, including current coil volumes

Check Keywords "Warn"

Mesh DB "." "adjacent_open_coil_V01"

Include Path ""
Results Directory ""
End

Simulation
Coordinate System = Cartesian
Coordinate Mapping(3) = 1 2 3
! Coordinate Scaling=0.001
Simulation Type = Steady
Steady State Max Iterations = 1
End

Constants
Gravity(4) = 0 -1 0 9.82
Stefan Boltzmann = 5.67e-08
Permittivity of Vacuum = 8.8542e-12
Boltzmann Constant = 1.3807e-23
Unit Charge = 1.602e-19
End

Body 1
Target Bodies(1) = 2
Name = "Coil 1"
Equation = 1
Material = 2
Body Force = 1
End

Body 2
Target Bodies(2) = 1 3
Name = "Air"
Equation = 2
Material = 1
End

Equation 1
Name = "Equation for coil 1"
!  Active Solvers(1) = 1
Active Solvers(3) = 1 2 3
End

Equation 2
Name = "Equation for air"
Active Solvers(2) = 2 3
End

Material 1
Name = "Air (room temperature)"
Viscosity = 1.983e-5
Heat expansion Coefficient = 3.43e-3
Heat Conductivity = 0.0257
Sound speed = 343.0
Density = 1.205
Heat Capacity = 1005.0

Relative Permittivity = Real 1
Relative Permeability = Real 1
Electric Conductivity = Real 0
End

Material 2
Name = "Copper (generic)"
Heat expansion Coefficient = 16.5e-6
Heat Conductivity = 401.0
Sound speed = 3810.0
Heat Capacity = 385.0
Density = 8960.0
Mesh Poisson ratio = 0.34
Poisson ratio = 0.34
Youngs modulus = 115.0e9

Relative Permittivity = Real 1
Relative Permeability = Real 1
Electric Conductivity = Real 5.96e7
End

Solver 1
!  Exec Solver = before all !Always
Equation = solving coil 1
!  Calculate Volume Current = True
Calculate Volume Current = False
Procedure = "StatCurrentSolve" "StatCurrentSolver"

Current Control = 40
Variable = PotentialA

Stabilize = True
Bubbles = False
Lumped Mass Matrix = False
Optimize Bandwidth = True
Steady State Convergence Tolerance = 1.0e-5
Nonlinear System Convergence Tolerance = 1.0e-7
Nonlinear System Max Iterations = 1
Nonlinear System Newton After Iterations = 3
Nonlinear System Newton After Tolerance = 1.0e-3
Nonlinear System Relaxation Factor = 1

Linear System Solver = Iterative

!  Linear System Iterative Method = TFQMR
!  Linear System Iterative Method = GC
!  Linear System Iterative Method = GCR
!  Linear System Iterative Method = BiCGStab
Linear System Iterative Method = BiCGStab2
!  Linear System Iterative Method = BiCGStabl
!  BicGStabL Polynomial Degree = 4

Linear System Max Iterations = 15000
Linear System Convergence Tolerance = 1.0e-10

!  Linear System Preconditioning = Diagonal
!  Linear System ILUT Tolerance = 1.0e-3

Linear System Abort Not Converged = False
!  Linear System Residual Output = 1
!  Linear System Precondition Recompute = 1
End

!===============================================
!=========== MAGNETIC FIELD SOLVER =============
Solver 2
!  Exec Solver = Never
Equation = "MGDynamics"
Variable = P
Procedure = "MagnetoDynamics" "WhitneyAVSolver"
Fix Input Current Density = Logical True

!  Linear System Symmetric = True
!  Optimize Bandwidth = True

Steady State Convergence Tolerance = 1e-09
Nonlinear System Convergence Tolerance = 1.0e-8
Nonlinear System Max Iterations = 1
Nonlinear System Newton After Iterations = 3
Nonlinear System Newton After Tolerance = 1.0e-3
Nonlinear System Relaxation Factor = 1

Linear System Solver = "Iterative"

!  Linear System Iterative Method = TFQMR
!  Linear System Iterative Method = GC
!  Linear System Iterative Method = GCR
!  Linear System Iterative Method = BiCGStab
!  Linear System Iterative Method = BiCGStab2
!  Linear System Iterative Method = BiCGStabl
!  BicGStabL Polynomial Degree = 4

!  Linear System Preconditioning = none
!  Linear System Preconditioning = ILU0
!  Linear System Preconditioning = ILU2
!  Linear System ILUT Tolerance = 1.0e-3

!  Linear System Precondition Recompute = 1
!  Linear System Residual Output = 20
!  Linear System Residual Output = 1

Linear System Max Iterations = 1400 !5000
Linear System Convergence Tolerance = 1.0e-8

Linear System Abort Not Converged = False

!  Edge Basis = Logical True
!  Apply Mortar BCs = Logical True
!  Mortar BCs additive = True

End

Solver 3
!  Exec Solver = Never
Equation = "MGDynamicsCalc"
Procedure = "MagnetoDynamics" "MagnetoDynamicsCalcFields"

Potential Variable = P

Calculate Current Density = Logical True
Calculate Magnetic Field Density = Logical True

Steady State Convergence Tolerance = 1e-09
Linear System Solver = "Iterative"
!  Linear System Solver = "Direct"

!  Linear System Iterative Method = TFQMR
!  Linear System Iterative Method = GC
!  Linear System Iterative Method = GCR
!  Linear System Iterative Method = BiCGStab
Linear System Iterative Method = BiCGStab2
!  Linear System Iterative Method = BiCGStabl
!  BicGStabL Polynomial Degree = 4

Linear System Max Iterations = 15000
Linear System Convergence Tolerance = 1.0e-8

End

Solver 4
!  Equation = Result Output
!  Exec Solver = After all !Never
Procedure = "ResultOutputSolve" "ResultOutputSolver"
Binary Output = True
Output Format = vtu
Output File Name = results
End

Solver 5
!  Equation = "scalars"
!  Exec Solver = After all !Never
procedure = "SaveData" "SaveScalars"
Filename = "data_scalars.dat"
End

Boundary Condition 1
Target Boundaries(1) = 5
Name = "Outer space"
P {e}= real 0
End

Boundary Condition 2
Target Boundaries(1) = 1
Name = "Coil 1 current in"
PotentialA = real 0.05
End

Boundary Condition 3
Target Boundaries(1) = 2
Name = "Coil 1 current out"
PotentialA = real 0
End

Body Force 1
Name = "Coil 1 Potential distribution"
Electric Potential = Equals PotentialA
End

The result that I obtained is that the statCurrSolver works ok. While the magnetic solver diverges. Also, I get a suspicious "SolveSystem: Solution trivially zero!" in ElmerSolver output (see line 401 in the attached file).

Any dea of what might have gone wrong?

Regards

Marco
Attachments
output_single_coil_potential.txt

lazyTom
Posts: 33
Joined: 05 Jun 2013, 01:32
Antispam: Yes

Re: Problem calculating the magnetic energy of two coils

Hi! ,

any news?

From my side I have gone on with further simulations. The impression is that something is not right with how the potential calculated with currStatSolver is passed to the WhitneyAVSolver.

Is this keyword correct?

Code: Select all

electric potential = Equals PotentialA
I'm saying this based on the attached example where I have used exactly the same mesh and same sif file (just changed the the source type from Current to Potential) and even though both solutions share the same electric potential, the Current fed solution converge while the one fed with Potential does not.

I've tried 9 different iterative solvers but none worked (I also tried the preconditioning option).

Btw, for those who are interested in the contributed case using WhitneyAVSolver to analyze the mag field generated by a simple coil in free air (see: viewtopic.php?f=18&t=1856 ) this example is inspired by it (see picture below). The difference is in the fact that in my sif the current is not injected from outside the domain. Yes, it does not look very physical but at least it converges  one_coil_noExt.png (42.72 KiB) Viewed 1149 times

NB: Just you are aware I haven't yet checked the results of the simulation against a commercial solution

Any comment is more than welcome

Regards,

Marco
Attachments
one_coil_noExt.zip
Last edited by lazyTom on 19 Jan 2019, 01:12, edited 1 time in total.

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

Re: Problem calculating the magnetic energy of two coils

Hi

Had a quick look. The attached sif file could work for the original two-coil case. Probably requires rather fresh version. I was working with one that was updated to git just minutes ago.

Now the two-solver strategy could also work but I did not pursue it. Probably it would requite that the way how Jfix is computed should be altered. And in this case it is detrimental that the Jfix is computed since there magnetostatics case cannot have a solution unless the field is enforced to be divergence free. In this case the problems are at the ends of the coil where definiately current appears from nothing and goes to nothing.

The mesh could have a finer grading. Now the elements become small too quickly. There should be freedom to add dofs as this simulation takes just <20 s on a standard laptop.

-Peter
Attachments
log.txt
my log
case.sif
sif file

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

Re: Problem calculating the magnetic energy of two coils

Hi,

This is a follow-up to this thread that utilizes the CoilSolver to set currents in closed coils. Does not work always, but some observations are still valid also for this case.

viewtopic.php?f=3&t=6553

-Peter

lazyTom
Posts: 33
Joined: 05 Jun 2013, 01:32
Antispam: Yes

Re: Problem calculating the magnetic energy of two coils

Hi Peter,

Thanks a lot this is very useful information! The feature of having a single body force shared with all bodies that carry current is very nice.

I think it would be a good idea to put at least a link of your five coils example in the "Contributed Cases" section.

Going back to your previous post (the one with the updated sif file for the double coil problem), I have updated my Elmer version to the latest release and results matches with yours ^^

I will now go on and make some further tests with standard theory problems and then move to complex structures.

If everything goes well I should be able to provide some results soon There is one thing though that is causing me confusion, it's about the names of the keywords used in the boundary conditions on current (always talking about the two coils problem).

Can you please confirm the following?

Keyword “Current Density” is actually a current (measured in A)

Keyword "Current Density Normalize by Area" (= Logical True) converts "Current Density" from A to A/(m^2).

Regards,

Marco

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

Re: Problem calculating the magnetic energy of two coils

Hi Marco,

I don't blame you for the confusion - it is actually the other way around.

Usually source terms and body forces and boundary conditions in Elmer are distributed. I.e. the unit of "Current Density" is A/m^2. The idea is that we should not need any geometric information to interpret a keyword.

However, there is a library functionality that enables to scale any keyword, say "myparam", with the area a priori by adding a flag "myparam normalize by area = Logical True". This will divide the value of the keyword when used by the total area of the boundary. The normalization is only computed once at the start of the simulation so it is relatively inexpensive.

So the combination of

Code: Select all

Current Density = 10.0
Current Density Normalize by Area = Logical True
means that the "current density" actually now is expected to be the total current through the boundary, in this case 10 A.

-Peter

lazyTom
Posts: 33
Joined: 05 Jun 2013, 01:32
Antispam: Yes

Re: Problem calculating the magnetic energy of two coils

Hi Peter,

thanks for clarifying

Regards,

Marco