Matrix Creation for Circuit Calculations

Numerical methods and mathematical models of Elmer
Post Reply
FabianH
Posts: 19
Joined: 13 Nov 2020, 01:08
Antispam: Yes

Matrix Creation for Circuit Calculations

Post by FabianH »

Meanwhile I'm confused how to set up equations for the matrix to calculate the coil values via CircuitsAndDynamics. Afters some tests by hand and the CircuitBuilder, I still have a deviation of the matrix B and open questions.

Simple Example:
https://github.com/ElmerCSC/elmer-elmag ... ent_source
Image

Equations from CircuitBuilder:
1. -Is + Icoil = 0
2. +Us - phi2 = 0
3. -Ucoil + phi2 = 0
4. Is = Is(t)

As I understood, i have to create the network equations for Kirchhoff 1/2 and the component equations. My try was:

Kirchoff 1 (KCL):
1. Is - Icoil = 0

Kirchoff 2 (KVL):
2. -Us + Ucoil = 0

Component (or Potential):
3. -phi2 + Us = 0
4. -phi2 + Ucoil = 0
5. Is = Is(t)

With that way more complex circuits are correct with CircuitBuilder. But in this case i have an additional equation.

In addition, the question for the 2D case: If I have several coils, each with a positive / negative side, then I have combined all the positive coil sides for e.g. phase 1 in one body (analogously for the negative side). Is it also possible to go this way for the circuit simulation or is it smarter to look at each coil individually in the circuit (2 coils (bodies) each with a positive and negative side are then 4 components (bodies) with the circuit solver)?
FabianH
Posts: 19
Joined: 13 Nov 2020, 01:08
Antispam: Yes

Re: Matrix Creation for Circuit Calculations

Post by FabianH »

Hello everyone,

maybe someone can check my sif file. I've been trying to convert my simulations with the circuit solver for a long time now, but I keep getting error messages and I'm a bit lost now.

The circuit file is created with CircuitBuilder. Mesh with gmsh. The same case without the circuit defintions runs fine.


Best regards
Fabian
Attachments
init_model_simple_circuit.7z
(239.26 KiB) Downloaded 32 times
hielau
Posts: 11
Joined: 26 Sep 2017, 19:18
Antispam: Yes

Re: Matrix Creation for Circuit Calculations

Post by hielau »

Hi,

Simulation section could use "Circuit Model Depth = Real $ length" to define length for circuits solver.

I think you don't need to add all solvers to equation 1. Solvers(3) = 1 2 3 should be enough.

Solver mgdyn2d: MUMPS seems a little heavy direct solver for this kind of small 2D case. I am using:

Code: Select all

  Linear System Solver = Direct
  Linear System Direct Method = umfpack
You don't need these since it is direct solver

Code: Select all

  Linear System Max Iterations = 5000
  Linear System Preconditioning = ILU2
  Linear System Convergence Tolerance = 1e-8
  Linear System Residual Output = 50
If you add BH-curve then you need to add nonlinear stuff. Something like this:

Code: Select all

  Nonlinear System Compute Change in Scaled System = Logical True
  Nonlinear System Convergence Tolerance = 1e-5
  Nonlinear System Convergence Measure = Residual
  Nonlinear System Max Iterations = 20
  Nonlinear System Min Iterations = 1
  Nonlinear System Relaxation Factor = 1.0
  Nonlinear System Newton After Iterations = 3
Each coil need its own component. Stranded example

Code: Select all

Component 1
  Name = String Uplus
  Body = Integer 6
  Coil Type = String Stranded
  Number of Turns = Real $ Nph
  Resistance = Real $ Rs/2
End
 
Component 2
  Name = String Uminus
  Body = Integer 9
  Coil Type = String Stranded
  Number of Turns = Real $ Nph
  Resistance = Real $ Rs/2
End
I am using voltage source and additional precomputed end winding inductance L_ew. 3 phase winding have been divided in to 3 separate one phase windings. (The other 2 winding would be very similar)

Code: Select all

!----------------------------------------------------------
!Winding 1
!----------------------------------------------------------
!init matrices of Ax' + Bx = Source
$ C.1.variables = 8
$ C.1.perm = zeros(C.1.variables)
$ C.1.A = zeros(C.1.variables, C.1.variables)
$ C.1.B = zeros(C.1.variables, C.1.variables)
$ C.1.Mre = zeros(C.1.variables, C.1.variables)
$ C.1.Mim = zeros(C.1.variables, C.1.variables)

!define circuit variables
$ C.1.name.1 = "i_s"
$ C.1.name.2 = "v_s"
$ C.1.name.3 = "i_component(1)"
$ C.1.name.4 = "v_component(1)"
$ C.1.name.5 = "i_component(2)"
$ C.1.name.6 = "v_component(2)"
$ C.1.name.7 = "i_ew"
$ C.1.name.8 = "v_ew"

!Define sources:
!------------------
$ C.1.B(0,1) = 1
$ C.1.source.1 = "U"

!Circuit equations:
!-------------------------
!Kirchoff current law
$ C.1.B(2,0) = -1
$ C.1.B(2,2) = 1
$ C.1.B(4,0) = 1
$ C.1.B(4,4) = 1
$ C.1.B(6,0) = -1
$ C.1.B(6,6) = 1

!Kirchoff voltage law
$ C.1.B(1,1) = -1
$ C.1.B(1,3) = 1
$ C.1.B(1,5) = -1
$ C.1.B(1,7) = 1

!Elemental equations
$ C.1.A(7,6) = L_ew
$ C.1.B(7,7) = -1
My understanding is that source has to in body force 1. Here is all 3 voltage sources inside body force 1.

Code: Select all

Body Force 1
  Name = "Circuit"

  ! Y-connection
  !Phase U
  U_u = Variable time
    Real MATC "U*sqrt(2)/sqrt(3)/2*sin(tx(0)*2*pi*f)"


  !Phase V
  U_v = Variable time
    Real MATC "U*sqrt(2)/sqrt(3)/2*sin(tx(0)*2*pi*f-2*pi/3)"

  !Phase W
  U_w = Variable time
    Real MATC "U*sqrt(2)/sqrt(3)/2*sin(tx(0)*2*pi*f+2*pi/3)"
End
BR,
Lauri
Attachments
elmer_winding.png
elmer_winding.png (48.73 KiB) Viewed 455 times
FabianH
Posts: 19
Joined: 13 Nov 2020, 01:08
Antispam: Yes

Re: Matrix Creation for Circuit Calculations

Post by FabianH »

Hey Lauri,

thanks for your great repsonse! I simplified my example to match the test case https://github.com/ElmerCSC/elmer-elmag ... ent_source. I also edit your points into the example, but after quite a while of tests i'm sure that it's not because of that (exception: number of components, but simplified this also). The defintion file is nearly the same and the sif equivalent to the test case sif.

The test case runs without any problems. My example stops with an error message:

Code: Select all

MAIN: Reading Model: .\elmer_transient_2.sif
 Caught LUA error:...0-Release/share/elmersolver/lua-scripts/defaults.lua:58: r
LoadInputFile: Scanning input file: .\elmer_transient_2.sif
LoadInputFile: Scanning only size info
LoadInputFile: First time visiting
LoadInputFile: Reading base load of sif file
OpenIncludeFile: Trying to include file: example_2.definition
ERROR:: LoadInputFile:  Unknown input field in header section: component 1
STOP 1
Maybe you have a hint ;-)

Best regards
Fabian
Attachments
init_model_simple_circuit.7z
(238.73 KiB) Downloaded 26 times
kevinarden
Posts: 2221
Joined: 25 Jan 2019, 01:28
Antispam: Yes

Re: Matrix Creation for Circuit Calculations

Post by kevinarden »

It is saying that the component definition should not be in the header of the sif file. It is pulled in by the include statement. Move the component and body definition into the component section of the sif and remove it from the definition file.
Post Reply