Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Extraction of Transformer Parameters from FEMM Simulations

and Automated Creation of a Transformer SPICE Model Using


a Scripting Language
This paper was downloaded from TechRxiv (https://www.techrxiv.org).

LICENSE

CC BY 4.0

SUBMISSION DATE / POSTED DATE

13-03-2023 / 02-05-2023

CITATION

ZAIKIN, DENYS (2023): Extraction of Transformer Parameters from FEMM Simulations and Automated
Creation of a Transformer SPICE Model Using a Scripting Language. TechRxiv. Preprint.
https://doi.org/10.36227/techrxiv.22263358.v4

DOI

10.36227/techrxiv.22263358.v4
Extraction of Transformer Parameters from FEMM Simulations and Automated Creation of a
Transformer SPICE Model Using a Scripting Language

Denys I. Zaikin
Advent Technologies A/S
Lyngvej 8, Aalborg, 9000, Denmark
e-mail: denys.zaikin@advent.energy

This study presents a method for extracting transformer parameters using simulations in the Finite
Element Method Magnetics (FEMM) electromagnetic solver. The extracted parameters represent a full model
of a linear transformer and can be used in Simulation Program with Integrated Circuit Emphasis (SPICE)
simulations. A model of the two-winding transformer is presented in three variants, for which different
approaches were used in the transformer simulation in the SPICE program, all yielding the same simulation
results. A three-winding transformer T-model extraction is also developed in the study. A method for extracting
transformer parameters from FEMM is proposed, along with an automated tool based on a scripting language
built into the FEMM software.

Keywords−finite element method modeling, FEMM, SPICE, transformer parameters, leakage inductance, Lua
programming language

Introduction. Simulation tools based on the Simulation Program with Integrated Circuit Emphasis
(SPICE) software, such as LTspice [1] and Pspice [2], are particularly useful in power electronics development.
An important aspect of the realistic modeling of a power converter is a proper simulation model of the mag-
netics, i.e., the high frequency (HF) inductors and transformers. Using realistic transformer parameters in the
model is crucial for the different power converter topologies involved, e.g., resonance converters, in which the
ratio of the leakage inductances to the magnetizing inductances affects the entire converter operation and its
performance. In such a converter, the coupling coefficient can be much smaller than 1, and the values of the
leakage and magnetizing inductances can be of the same order. Therefore, it is critical to use a proper simula-
tion model of the transformer from the early stages of calculating and simulating the converter.
To estimate the parameters of a real transformer, simulation of the magnetics can be performed using
computational electrodynamics methods and tools. The Finite Element Method Magnetics (FEMM) software
[3] is a popular free software tool that enables users to simulate inductors and transformers in axisymmetric or
planar problem definitions. FEMM uses the finite element method in its simulation of various physics
problems.
This study describes a method for extracting the parameters of a transformer from a simulation in
FEMM. Another aspect of this study is the description of a script that enables automation of the generation of
a sub-model of the transformer in SPICE using results from a simulation in the FEMM program.

Two-winding transformer equivalent circuit. A two-winding transformer can be represented by a


developed equivalent circuit [4] [5] [6], e.g., a T-model equivalent circuit, a Cantilever model equivalent cir-
cuit, and the SPICE standard mutual inductance model, which uses a coupling coefficient between the induct-
ances. In this study, the T-model of a two-winding transformer was found to suitably match the features in its
FEMM simulation. All other equivalent circuits can easily be calculated using parameters from the T-model
and will be presented in subsequent sections. All transformer equivalent circuits yielded the same results in a
SPICE simulation. The T-model of the transformer considered in this study is presented in Fig. 1.
Fig. 1

An equation describing the circuit in Fig. 1 can be derived as follows:

𝑁𝑠𝑒𝑐
𝐿𝑙𝑒𝑎𝑘1 + 𝐿𝑚 𝐿𝑚
𝑁𝑝𝑟𝑖
𝑢1
|𝑢 | = || | 𝑑 |𝑖1 |   + |𝑖1 𝑅𝑝𝑟𝑖 |
2 |⋅
2 𝑁𝑠𝑒𝑐 𝑁𝑠𝑒𝑐 𝑑𝑡 𝑖2 𝑖2 𝑅𝑠𝑒𝑐
𝐿𝑚 𝐿𝑙𝑒𝑎𝑘2 + 𝐿𝑚 2
𝑁𝑝𝑟𝑖 𝑁𝑝𝑟𝑖
(1)

where Lleak1 and Lleak2 are leakage inductances on the primary and secondary sides of the transformer; Lm is the
magnetizing inductance referred to the primary side; and the related magnetic parameters: Lleak1, Lleak2, and Lm,
along with the ohmic resistances of the windings Rpri and Rsec, are unknown variables to be determined using
a FEMM simulation. It should be noted that the T-model in Fig. 1 uses the physical turn ratio Npri:Nsec in the
ideal transformer, such that Npri and Nsec are the actual number of turns in the primary and secondary windings,
respectively, and are therefore assumed to be known. For the first part of the right side of Equation (1), there
are only three unknown magnetic parameters: Lleak1, Lleak2, and Lm. Generally, it can be shown that for any two-
winding transformer equivalent circuit, only three magnetic parameters fully describe the circuit [4] [5] [6].
Thus, these five parameters: Rpri, Rsec, Lleak1, Lleak2, and Lm should be calculated using simulations in FEMM.

Transformer Parameter Extraction from FEMM Simulations. The proposed method for extracting
transformer parameters can be described as follows:
First Simulation. Both windings of the two-winding transformer in Fig. 1 are supplied with reference
currents i1 = Ipri and i2 = Isec = −Ipri*Npri/Nsec, where Ipri is some constant reference current. It can be
demonstrated that with such a windings supply, the current in the magnetizing inductance Lm is equal to zero,
i.e., im = 0. This means that the voltage across the magnetizing inductance Lm is also equal to zero. Thus, the
windings become decoupled from each other, and the stored magnetic energy will comprise only energy stored
in the leakage inductances Lleak1 and Lleak2. The leakage energy, Wleak, can be calculated using the FEMM post-
processing solver. Analytically, it can be expressed in terms of the unknown Lleak1 and Lleak2 as follows:

2
𝐼𝑝𝑟𝑖 𝑁𝑝𝑟𝑖 2
𝑊𝑙𝑒𝑎𝑘 = (𝐿𝑙𝑒𝑎𝑘1 + 𝐿𝑙𝑒𝑎𝑘2 ( ) )
2 𝑁𝑠𝑒𝑐
( 2)

The solver also returns voltages u1 and u2 across the windings. For the specific case in which i1 = Ipri, i2 = Isec
= −Ipri*Npri/Nsec and the magnetizing inductance is virtually shortened, the voltages across the windings are
equal to the corresponding voltage drops.

𝑢1 = 𝑖1 (𝑅𝑝𝑟𝑖 + 𝑗𝜔𝐿𝑙𝑒𝑎𝑘1 ) = 𝐼𝑝𝑟𝑖 (𝑅𝑝𝑟𝑖 + 𝑗𝜔𝐿𝑙𝑒𝑎𝑘1 )


𝑢2 = 𝑖2 (𝑅𝑠𝑒𝑐 + 𝑗𝜔𝐿𝑙𝑒𝑎𝑘2 ) = 𝐼𝑠𝑒𝑐 (𝑅𝑠𝑒𝑐 + 𝑗𝜔𝐿𝑙𝑒𝑎𝑘2 )
( 3)
The voltages u1 and u2 are returned by the FEMM solver and can be used to calculate ohmic resistances as
follows:
𝑅𝑝𝑟𝑖 = 𝐑𝐞(𝑢1 /𝑖1 ) = 𝐑𝐞(𝑢1 /𝐼𝑝𝑟𝑖 )
𝑅𝑠𝑒𝑐 = 𝐑𝐞(𝑢2 /𝑖1 ) = 𝐑𝐞(𝑢2 /𝐼𝑠𝑒𝑐 )
( 4)

At this moment, in the first simulation, the parameters Lleak1 and Lleak2 can be calculated using the
following equations:
Im(𝑢1 /𝑖1 )
𝐿𝑙𝑒𝑎𝑘1 =
2𝜋𝐹
Im(𝑢2 /𝑖2 )
𝐿𝑙𝑒𝑎𝑘2 =
2π𝐹
( 5)
This approach will work only at the AC winding supply. With DC, F = 0; hence, this method will not work.
However, calculating leakage inductances using stored energy is a universal approach that works for both AC
and DC excitations.
It should be noted that the first simulation setup, in which Isec = −Ipri*Npri/Nsec and no current flows
through the magnetizing inductance Lm, is very close to the real-world operation of the transformer because
the magnetizing current in an actual transformer is relatively small (except for fly-back converter
transformers). Therefore, skin and proximity effects on the leakage inductance values are also considered using
the proposed method employed in the first simulation.
Second Simulation. Only the primary winding is supplied with a reference current, such that i1 = Ipri.
The secondary winding is maintained as an open circuit, such that Isec = 0. In this case, all the energy is
stored in the primary winding, can be calculated using the solver, and can be expressed in terms of the
unknown Lleak1 and Lm as follows:

2
𝐼𝑝𝑟𝑖
𝑊𝑝𝑟𝑖 = (𝐿𝑙𝑒𝑎𝑘1 + 𝐿𝑚 )
2
( 6)

Third Simulation. Only the secondary winding is supplied with current i2 = −Ipri·Npri/Nsec. The primary
winding is maintained as an open circuit Ipri = 0. In this case, all the energy is stored in the secondary winding,
can be calculated using the solver, and can be expressed in terms of the unknown Lleak2 and Lm as follows:
2
𝐼𝑝𝑟𝑖 𝑁𝑝𝑟𝑖 2
𝑊𝑠𝑒𝑐 = (𝐿𝑙𝑒𝑎𝑘2 ( ) + 𝐿𝑚 )
2 𝑁𝑠𝑒𝑐
( 7)

At this point, there is a system of three linear equations: Equation ( 2), Equation ( 6), and Equation (
7) with three unknown variables Lleak1, Lleak2, and Lm. Solving these equations as part of the transformer T-
model can be achieved as follows:

𝑊𝑝𝑟𝑖 + 𝑊𝑙𝑒𝑎𝑘 − 𝑊𝑠𝑒𝑐


𝐿𝑙𝑒𝑎𝑘1 =
𝐼𝑝𝑟𝑖 2
( 8)
2
𝑁𝑠𝑒𝑐 𝑊𝑠𝑒𝑐 − 𝑊𝑝𝑟𝑖 + 𝑊𝑙𝑒𝑎𝑘
𝐿𝑙𝑒𝑎𝑘2 = ( )
𝑁𝑝𝑟𝑖 2 𝐼𝑝𝑟𝑖 2
( 9)
𝑊𝑠𝑒𝑐 + 𝑊𝑝𝑟𝑖 − 𝑊𝑙𝑒𝑎𝑘
𝐿𝑚 = 2 ,
𝐼𝑝𝑟𝑖
( 10)
where Wleak, Wpri, and Wsec are calculated stored energies from the FEMM simulations described earlier; Ipri is
the reference current used in the preceding simulations; and Nsec and Npri are the actual physical number of
turns in the simulated two-winding transformer.
The resistance of the windings is calculated in the first simulation, i.e., Equation ( 4).

FEMM Simulation. There are some features of magnetics problem simulation in FEMM that should
be mentioned:
• The windings of the transformer can only be driven by current sources and cannot be driven by voltage
sources or loaded with any external load. This means that the FEMM tool cannot calculate the steady state
of the transformer supplied by the voltage source on the primary side and loaded on the secondary side.
• The FEMM solver calculates complex voltages across windings.
• The FEMM solver calculates the time average stored magnetic energy.
• All calculations were performed using the peak magnitude values of the currents and voltages. This also
means that the only time average stored magnetic energy is calculated via a simulation. Taking this into
account, the stored magnetic energy calculated using FEMM for the peak values of the currents should be
multiplied by two if the primary and secondary supply currents have the same phase or if the phase
difference is 180º—similar to the current method employed in the first simulation.
• The best way to simulate linear transformer parameters is to use an axisymmetric simulation setup, which
matches most of the core geometries, e.g., PQ, PM, and ETD. Even if the cross section of the core is a
square, the axisymmetric simulation will still yield appropriate results. The planar setup is recommended
only for some specific cases in which the cross section of the core is rectangular, and a high aspect ratio is
used. A planar setup is also recommended for toroidal cores.
• All currents and voltages in the FEMM tool are represented as the peak magnitude values of complex
values, not the root mean square (RMS).
• Generated models are linear transformer models that do not include the effect of core non-linearity. The
setup of the transformer in the FEMM solver should include the linear core characteristic or be far away
from saturation at specific currents (i.e., Ipri and Isec).
• Since we measure energy stored in a full geometry area, proper boundary conditions should be specified
for the simulated area and some free space (air) should be presented around the calculated transformer to
reduce the error for the air-core transformer simulation.
• Skin and proximity effects can affect the calculation of inductances, although the effect is assumed to be
negligible.

Script Program for Automated Model Generation. Based on considerations from the preceding
sections, a Lua language script can be implemented for automated model generation. There are some instruc-
tions that should be considered to use the script correctly:
• The geometry of the transformer should be created in the FEMM tool before execution of the script, as the
proposed script does not implement the creation of the geometry or the simulation setup. The script
performs only the calculation of the parameters for an existing FEMM file. The only parameters modified
by the script during simulations are the currents Ipri and Isec for the windings supply, and the frequency F.
• Windings in the FEMM geometry should be implemented as circuits with the names “PRI” and “SEC.”
• The number of turns in each winding in the FEMM setup and in the script should be equal (the parameters
are “NPRI” and “NSEC” in the script file). The number of turns in the FEMM setup is set using block
parameters and should be a positive number. The direction of the current is controlled by the polarity of
the current in the script. A winding may have separations in its layers and sections; therefore, the total
number of series-connected turns should match the number of turns (NPRI or NSEC) in the script.
• In LTspice settings, the option "Always default inductors to Rser=0" should be checked for cor-
rect losses' calculation in high power magnetics.

An example of the setup and simulation in FEMM is illustrated in Fig. 2 and Fig. 3.
Fig. 2

Fig. 3

Other models for two-winding transformer. The complete script for a two-winding transformer,
written in Lua language that is built into the FEMM tool listing, is presented below in Appendix section. This
script and other simulation models can also be found in online resources [7]. The script also calculates the
parameters of two other transformer equivalent circuits: a Cantilever-model (Fig. 4) and a standard SPICE
model (Fig. 5). All these models, along with the described T-model, are generated separately as subcircuit
models that can be used directly in SPICE programs. These models yield the same simulation results in a
SPICE simulation and can be converted from one to the other to enhance convergence in the SPICE engine.
Fig. 4

Fig. 5

Three-winding transformer model extraction. The T-model equivalent circuit of a three-winding


transformer is shown in Fig. 6.

Fig. 6

Fig. 6 demonstrates the transformer model that is similar to the two-winding transformer from Fig. 1. But now
the number of magnetic parameters that should be extracted has been changed to six instead of three. Now the
turn ratios Nsec1/Npri and Nsec2/Npri become effective turn ratios and must also be calculated and extracted from
simulation in FEMM. These effective turn ratios can be significantly different from the real physical turn ratios
of the simulated transformer. Because of this, some of the calculated leakage inductances in the T-model may
have a negative value [4]. Therefore, additional simulation steps to calculate the effective turn ratios
n1=Nsec1/Npri and n2=Nsec2/Npri must be performed.
First Simulation. The primary winding is supplied with current i1=Ipri and the two other windings are
supplied with zero current, i2=0, i3=0. In this case, the turn ratio Nsec1/Nsec2 can be determined by measuring
voltages on windings with zero current:
𝑁𝑠𝑒𝑐2 𝑢3
𝑛32 = = .
𝑁𝑠𝑒𝑐1 𝑢2
( 11)
Second Simulation. The secondary winding 1 is supplied with some current i2=Isec2 and the two other
windings are supplied with zero current, i1=0, i3=0. In this case, the turn ratio Npri/Nsec2 can be determined by
measuring voltages on windings with zero current:

𝑁𝑠𝑒𝑐2 𝑢3
𝑛31 = = .
𝑁𝑝𝑟𝑖 𝑢1
( 12)
Now, the primary number of turns is assumed to be equal to 1, and the rest of the winding turns can
be determined as follows:
𝑁𝑝𝑟𝑖 = 1
𝑁𝑠𝑒𝑐2 = 𝑛31 ⋅ 𝑁𝑝𝑟𝑖 = 𝑛31
𝑁𝑠𝑒𝑐1 = 𝑛32 ⋅ 𝑁𝑠𝑒𝑐2 = 𝑛32 ⋅ n31 .
( 13)
Third Simulation. Having estimated the Npri, Nsec1, and Nsec2 model parameters, the following winding
excitation is performed in the third simulation. The primary winding of the three-winding transformer is sup-
plied with a reference current of i1 = Ipri. And the secondary windings are supplied with currents:

𝑖2 = −𝐼𝑝𝑟𝑖 ⋅ 𝑁𝑝𝑟𝑖 /𝑁𝑠𝑒𝑐1 ⋅ 𝑘1


𝑖3 = −𝐼𝑝𝑟𝑖 ⋅ 𝑁𝑝𝑟𝑖 /𝑁𝑠𝑒𝑐2 ⋅ 𝑘2 ,
( 14)
where 0<k1<1 and 0<k2<1 are some coefficients that must also satisfy the condition k1+k2=1. In this case, as
for the first simulation for two-winding transformer, the voltage across the magnetizing inductance Lm and its
current are equal to zero. The magnetic field energy is only stored in leakage inductances Lleak1, Lleak2 and Lleak3.
The following equation can be obtained:
2 2 2
𝐿𝑙𝑒𝑎𝑘1 𝐼𝑝𝑟𝑖 𝐿𝑙𝑒𝑎𝑘2 𝐼𝑠𝑒𝑐1 𝐿𝑙𝑒𝑎𝑘3 𝐼𝑠𝑒𝑐2
𝑊𝑙𝑒𝑎𝑘 = + +
2 2 2
( 15)
Forth Simulation. Only the primary winding is supplied with a reference current, such that i1 = Ipri.
Both secondary windings are maintained as an open circuit, such that Isec1=Isec2 = 0. In this case, all the
energy is stored in the primary winding, which can be calculated using the solver and expressed in terms of
the unknown Lleak1 and Lm as follows:

2
𝐼𝑝𝑟𝑖
𝑊𝑝𝑟𝑖 = (𝐿𝑙𝑒𝑎𝑘1 + 𝐿𝑚 )
2
( 16)
Fifth Simulation. Only the secondary winding 1 is supplied with current i2 = −Ipri·Npri/Nsec1. The
primary and secondary winding 2 are maintained as an open circuit Ipri = Isec2=0. In this case, all the energy is
stored in the secondary winding 1, which can be calculated using the solver and expressed in terms of the
unknown Lleak2 and Lm as follows:
2 2
𝐼𝑠𝑒𝑐1 𝑁𝑠𝑒𝑐1
𝑊𝑠𝑒𝑐1 = (𝐿𝑚 2 + 𝐿𝑙𝑒𝑎𝑘2 )
2 𝑁𝑝𝑟𝑖
( 17)
Sixth Simulation. Only the secondary winding 2 is supplied with current i3 = −Ipri·Npri/Nsec2. The
primary and secondary winding 1 are maintained as an open circuit Ipri = Isec1=0. In this case, all the energy is
stored in the secondary winding 2, which can be calculated using the solver and expressed in terms of the
unknown Lleak3 and Lm as follows:
2 2
𝐼𝑠𝑒𝑐2 𝑁𝑠𝑒𝑐2
𝑊𝑠𝑒𝑐2 = (𝐿𝑚 2 + 𝐿𝑙𝑒𝑎𝑘3 )
2 𝑁𝑝𝑟𝑖
( 18)
At this point, there is a system of linear equations: Equations ( 15)- ( 18), along with Equations ( 14)
with four unknown variables Lleak1, Lleak2, Lleak2 and Lm. Solving these equations will result in the full T-model
of a three-winding transformer. Winding resistances can be calculated similarly to the method described for a
two-winding transformer (Equation ( 4)).
The script and the models for three-winding transformers can be found in the Appendix and in [7].

Appendix.
Script Listing for two-winding transformer.
showconsole()
mydir="./"
open(mydir .. "trafo_EDT39_test_with_script.FEM")
mi_saveas(mydir .. "temp.fem")
mi_seteditmode("group")

clearconsole()

F=100000--transformer frequency
IPRI=1--primary current, should be !=0
NPRI=6--primary number of turns
NSEC=24--secondary number of turns
ISEC=-IPRI*NPRI/NSEC

--set problem parameters


mi_probdef(F)

--calculation leak stored energy, primary and secondary are driven with currents IPRI and ISEC

mi_modifycircprop("PRI",1,IPRI)
mi_modifycircprop("PRI",2,1)
mi_modifycircprop("SEC",1,ISEC)
mi_modifycircprop("SEC",2,1)

mi_analyze()
mi_loadsolution()
mo_groupselectblock()
wleak=mo_blockintegral(2)

--resistances calcultion (should be performed when both windings are excited with currents IPRI and ISEC)

I1,V1,Flux1=mo_getcircuitproperties("PRI")
I2,V2,Flux2=mo_getcircuitproperties("SEC")

Rpri=re(V1/I1)--works for AC and DC


Rsec=re(V2/I2)--works for AC and DC

if F>0 then
Lleak1_alt=im(V1/I1)/(2*pi*F)--alternative way to calculate inductances but works only on AC
Lleak2_alt=im(V2/I2)/(2*pi*F)--alternative way to calculate inductances but works only on AC
end
--calculation primary stored energy when secondary is open

mi_modifycircprop("PRI",1,IPRI)
mi_modifycircprop("PRI",2,1)
mi_modifycircprop("SEC",1,0)
mi_modifycircprop("SEC",2,1)

mi_analyze()
mi_loadsolution()
mo_groupselectblock()
wpri=mo_blockintegral(2)

--calculation secondary stored energy when primary is open

mi_modifycircprop("PRI",1,0)
mi_modifycircprop("PRI",2,1)
mi_modifycircprop("SEC",1,ISEC)
mi_modifycircprop("SEC",2,1)

mi_analyze()
mi_loadsolution()
mo_groupselectblock()
wsec=mo_blockintegral(2)

--parameters calculation
--energy correction (FEMM feature)

if F>0 then
wleak=2*wleak
wpri=2*wpri
wsec=2*wsec
else
wleak=wleak
wpri=wpri
wsec=wsec
end

--Inductance calculation for the T-model (Lleak1, Lleak2, Lm, N1:N2: with leakage inductances on primary
and secondary and actual physical turn ratio NPRI:NSEC)
Lleak1=-(wsec-wpri-wleak)/IPRI^2
Lleak2=NSEC^2*(wsec-wpri+wleak)/(IPRI^2*NPRI^2)
Lm=(wsec+wpri-wleak)/IPRI^2

--Resistances for all models


print('Resistances for all models')
print('Rpri=',Rpri)
print('Rsec=',Rsec)

print('Parameters for T-model:')


print('Lleak1=',Lleak1)
print('Lleak2=',Lleak2)
print('Lm=',Lm)
print('n=',NSEC/NPRI)

--Parameters calculation for the standard SPICE modeling (L1 L2 and mutual inductance M=k*sqrt(L1*L2))
L1=Lleak1+Lm
L2=Lleak2+Lm*(NSEC/NPRI)^2
M=Lm*NSEC/NPRI
k=M/sqrt(L1*L2)

print('Parameters for standard SPICE model:')


print('L1=',L1)
print('L2=',L2)
print('M=',M)
print('k=',k)

--Parameters calculation for the Cantilever model (Lleak Lpri at primary side and effective turn ratio 1:Ne)
Lleak=(Lleak1*Lm*NSEC^2+(Lleak2*Lm+Lleak1*Lleak2)*NPRI^2)/(Lm*NSEC^2+Lleak2*NPRI^2)
Lpri=(Lm^2*NSEC^2)/(Lm*NSEC^2+Lleak2*NPRI^2)
Ne=(Lm*NSEC^2+Lleak2*NPRI^2)/(Lm*NPRI*NSEC)

print('Parameters for Cantilever model:')


print('Lleak=',Lleak)
print('Lpri=',Lpri)
print('Ne=',Ne)

--model files writing


model1_file=openfile("transformer_from_femm_t_model.lib","w")
write(model1_file,'.subckt transformer_from_femm_t_model 1 2 3 4 \n')
write(model1_file,'.params Rpri=',Rpri," Rsec=",Rsec," Lleak1=",Lleak1," Lleak2=",Lleak2," Lm=",Lm,"
n=",NSEC/NPRI,"\n")
write(model1_file,'R1 9 1 {Rpri} \n')
write(model1_file,'L1 9 5 {Lleak1} \n')
write(model1_file,'R2 10 3 {Rsec} \n')
write(model1_file,'L2 10 7 {Lleak2}\n')
write(model1_file,'Gp 2 5 value={n*i(Es)}\n')
write(model1_file,'Es 7 4 value={n*V(5,2)}\n')
write(model1_file,'L3 5 2 {Lm}\n')
write(model1_file,'.end transformer_from_femm_t_model \n')
closefile(model1_file)

model2_file=openfile("transformer_from_femm_standard_SPICE.lib","w")
write(model2_file,'.subckt transformer_from_femm_standard_SPICE 1 2 3 4 \n')
write(model2_file,'.params Rpri=',Rpri," Rsec=",Rsec," L1=",L1," L2=",L2," k=",k,"\n")
write(model2_file,'L1 5 2 {L1}\n')
write(model2_file,'L2 6 4 {L2}\n')
write(model2_file,'R1 5 1 {Rpri}\n')
write(model2_file,'R2 3 6 {Rsec}\n')
write(model2_file,'K1 L1 L2 {k}\n')
write(model2_file,'.end transformer_from_femm_standard_SPICE \n')
closefile(model2_file)

model3_file=openfile("transformer_from_femm_cantilever_model.lib","w")
write(model3_file,'.subckt transformer_from_femm_pi_model 1 2 3 4 \n')
write(model3_file,'.params Rpri=',Rpri," Rsec=",Rsec," Lleak=",Lleak," Lpri=",Lpri," Ne=",Ne,"\n")
write(model3_file,'R1 9 1 {Rpri}\n')
write(model3_file,'L1 9 5 {Lleak}\n')
write(model3_file,'R2 7 3 {Rsec}\n')
write(model3_file,'Gp 2 5 value={Ne*i(Es)}\n')
write(model3_file,'Es 7 4 value={Ne*v(5,2)}\n')
write(model3_file,'L3 5 2 {Lpri}\n')
write(model3_file,'.end transformer_from_femm_cantilever_model \n')
closefile(model3_file)

--back to both currents excitation

mi_modifycircprop("PRI",1,IPRI)
mi_modifycircprop("PRI",2,1)
mi_modifycircprop("SEC",1,ISEC)
mi_modifycircprop("SEC",2,1)
mi_saveas(mydir .. "temp.fem")

mo_close()
mi_close()
print('done')

Script Listing for three-winding transformer.


showconsole()
mydir="./"
open(mydir .. "trafo_EDT39_three_windings_test_with_script.FEM")
mi_saveas(mydir .. "temp.fem")
mi_seteditmode("group")

clearconsole()

F=100000--transformer frequency
IPRI=1--primary current, should be !=0
NPRI=6--primary number of turns, initially here is physical (real)
NSEC1=24--secondary1 number of turns, initially here is physical (real)
NSEC2=1--secondary2 number of turns, initially here is physical (real)
K1=0.5
K2=0.5
ISEC1=-IPRI*NPRI/NSEC1*K1
ISEC2=-IPRI*NPRI/NSEC2*K2

--set problem parameters


mi_probdef(F)

--calculation of NSEC1:NSEC2 turn ratio

mi_modifycircprop("PRI",1,IPRI)
mi_modifycircprop("PRI",2,1)
mi_modifycircprop("SEC1",1,0)
mi_modifycircprop("SEC1",2,1)
mi_modifycircprop("SEC2",1,0)
mi_modifycircprop("SEC2",2,1)

mi_analyze()
mi_loadsolution()
mo_groupselectblock()
wleak=mo_blockintegral(2)

I2,V2,Flux2=mo_getcircuitproperties("SEC1")
I3,V3,Flux3=mo_getcircuitproperties("SEC2")
NSEC1_NSEC2=re(V2/V3)

--calculation of NPRI:NSEC2 turn ratio

mi_modifycircprop("PRI",1,0)
mi_modifycircprop("PRI",2,1)
mi_modifycircprop("SEC1",1,ISEC2)
mi_modifycircprop("SEC1",2,1)
mi_modifycircprop("SEC2",1,0)
mi_modifycircprop("SEC2",2,1)

mi_analyze()
mi_loadsolution()
mo_groupselectblock()
wleak=mo_blockintegral(2)

I1,V1,Flux2=mo_getcircuitproperties("PRI")
I3,V3,Flux3=mo_getcircuitproperties("SEC2")

NPRI_NSEC2=re(V1/V3)

--number of turns now can be calculated and reestimated- they are not physical turns ration anymore
NPRI=1
NSEC2=NPRI/NPRI_NSEC2
NSEC1=NSEC2*NSEC1_NSEC2
K1=0.5--shoudl be K1+K2=1
K2=0.5
ISEC1=-IPRI*NPRI/NSEC1*K1
ISEC2=-IPRI*NPRI/NSEC2*K2

--calculation leak stored energy, primary and secondary1 and secondary2 are driven with currenst IPRI and
ISEC1 and ISEC2

mi_modifycircprop("PRI",1,IPRI)
mi_modifycircprop("PRI",2,1)
mi_modifycircprop("SEC1",1,ISEC1)
mi_modifycircprop("SEC1",2,1)
mi_modifycircprop("SEC2",1,ISEC2)
mi_modifycircprop("SEC2",2,1)

mi_analyze()
mi_loadsolution()
mo_groupselectblock()
wleak=mo_blockintegral(2)

--resistances calcultion (should be performed when all windings are excited with currents IPRI and ISEC1 and
ISEC2, normal transformer (not a flyback!))

I1,V1,Flux1=mo_getcircuitproperties("PRI")
I2,V2,Flux2=mo_getcircuitproperties("SEC1")
I3,V3,Flux3=mo_getcircuitproperties("SEC2")
Rpri=re(V1/I1)
Rsec1=re(V2/I2)
Rsec2=re(V3/I3)
--calculation primary stored energy when secondary1 and secondary2 are open

mi_modifycircprop("PRI",1,IPRI)
mi_modifycircprop("PRI",2,1)
mi_modifycircprop("SEC1",1,0)
mi_modifycircprop("SEC1",2,1)
mi_modifycircprop("SEC2",1,0)
mi_modifycircprop("SEC2",2,1)

mi_analyze()
mi_loadsolution()
mo_groupselectblock()
wpri=mo_blockintegral(2)

--I1,V1,Flux1=mo_getcircuitproperties("PRI")--if a flyback transformer


--Rpri=re(V1/I1)--if a flyback transformer

--calculation secondary1 stored energy when primary and secondary2 are open

mi_modifycircprop("PRI",1,0)
mi_modifycircprop("PRI",2,1)
mi_modifycircprop("SEC1",1,ISEC1)
mi_modifycircprop("SEC1",2,1)
mi_modifycircprop("SEC2",1,0)
mi_modifycircprop("SEC2",2,1)

mi_analyze()
mi_loadsolution()
mo_groupselectblock()
wsec1=mo_blockintegral(2)

--I2,V2,Flux2=mo_getcircuitproperties("SEC1")--if a flyback transformer


--Rsec1=re(V2/I2)--if a flyback transformer

--calculation secondary2 stored energy when primary and secondary1 are open

mi_modifycircprop("PRI",1,0)
mi_modifycircprop("PRI",2,1)
mi_modifycircprop("SEC1",1,0)
mi_modifycircprop("SEC1",2,1)
mi_modifycircprop("SEC2",1,ISEC2)
mi_modifycircprop("SEC2",2,1)

mi_analyze()
mi_loadsolution()
mo_groupselectblock()
wsec2=mo_blockintegral(2)

--I3,V3,Flux3=mo_getcircuitproperties("SEC2")--if a flyback transformer


--Rsec2=re(V3/I3)--if a flyback transformer

--parameters calculation
--energy correction (FEMM feature)

if F>0 then
wleak=2*wleak
wpri=2*wpri
wsec1=2*wsec1
wsec2=2*wsec2
else
wleak=wleak
wpri=wpri
wsec1=wsec1
wsec2=wsec2
end

--Inductance calculation for the T-model (Lleak1, Lleak2, Lleak3,Lm, NPRI:NSEC1:NSEC2 with leakage
inductances on primary and secondaries and actual physical turn ratios)
Lleak1=-(2*wsec2+2*wsec1+(-2*K2^2-2*K1^2)*wpri-2*wleak)/(IPRI^2*K2^2+IPRI^2*K1^2+IPRI^2)
Lleak2=-(2*K1^2*NSEC1^2*wsec2+(-2*K2^2-2)*NSEC1^2*wsec1+2*K1^2*NSEC1^2*wpri-
2*K1^2*NSEC1^2*wleak)/((IPRI^2*K1^2*K2^2+IPRI^2*K1^4+IPRI^2*K1^2)*NPRI^2)
Lleak3=((2*K1^2+2)*NSEC2^2*wsec2-2*K2^2*NSEC2^2*wsec1-
2*K2^2*NSEC2^2*wpri+2*K2^2*NSEC2^2*wleak)/((IPRI^2*K2^4+(IPRI^2*K1^2+IPRI^2)*K2^2)*NPR
I^2)
Lm=(2*wsec2+2*wsec1+2*wpri-2*wleak)/(IPRI^2*K2^2+IPRI^2*K1^2+IPRI^2)

--Resistances for all models


print('Resistances for all models')
print('Rpri=',Rpri)
print('Rsec1=',Rsec1)
print('Rsec2=',Rsec2)

print('Parameters for T-model:')


print('Lleak1=',Lleak1)
print('Lleak2=',Lleak2)
print('Lleak3=',Lleak3)
print('Lm=',Lm)
print('n1=',NSEC1/NPRI)
print('n2=',NSEC2/NPRI)

--model file writing


model1_file=openfile("three_winding_transformer_from_femm_t_model.lib","w")
write(model1_file,'.subckt three_winding_transformer_from_femm_t_model 1 2 3 4 5 6\n')
write(model1_file,'.params Rpri=',Rpri," Rsec1=",Rsec1," Rsec2=",Rsec2," Lleak1=",Lleak1,"
Lleak2=",Lleak2," Lleak3=",Lleak3," Lm=",Lm," n1=",NSEC1/NPRI," n2=",NSEC2/NPRI,"\n")
write(model1_file,'R1 15 1 {Rpri} \n')
write(model1_file,'L1 15 7 {Lleak1} \n')
write(model1_file,'R2 11 3 {Rsec1} \n')
write(model1_file,'L2 11 9 {Lleak2} \n')
write(model1_file,'Gp1 2 7 value={n1*i(Es1)} \n')
write(model1_file,'Es1 9 4 value={n1*v(7,2)} \n')
write(model1_file,'L3 7 2 {Lm} \n')
write(model1_file,'R3 14 5 {Rsec2} \n')
write(model1_file,'L4 14 12 {Lleak3} \n')
write(model1_file,'Es2 12 6 value={n2*v(7,2)} \n')
write(model1_file,'Gp2 2 7 value={n2*i(Es2)} \n')
write(model1_file,'.end three_winding_transformer_from_femm_t_model \n')
closefile(model1_file)

--back to both currents excitation


mi_modifycircprop("PRI",1,IPRI)
mi_modifycircprop("PRI",2,1)
mi_modifycircprop("SEC1",1,ISEC1)
mi_modifycircprop("SEC1",2,1)
mi_modifycircprop("SEC2",1,ISEC2)
mi_modifycircprop("SEC2",2,1)
mi_saveas(mydir .. "temp.fem")

mo_close()
mi_close()
print('done')
References

1. "LTspice - SPICE simulator software," Analog Devices, Inc., [Online]. Available:


https://www.analog.com/en/design-center/design-tools-and-calculators/ltspice-simulator.html. [Accessed 04 03 2023].
2. "PSPICE - Circuit Simulation," Cadence Design Systems, Inc., [Online]. Available: www.pspice.com.
[Accessed 04 03 2023].
3. D. C. Meeker, "Finite Element Method Magnetics, Version 4.2 (28Feb2018 Build)," [Online]. Available:
https://www.femm.info. [Accessed 04 03 2023].
4. A. J. Hanson and D. J. Perreault, "Modeling the Magnetic Behavior of N-Winding Components:
Approaches for Unshackling Switching Superheroes," IEEE Power Electronics Magazine, vol. 7, no. 1, pp. 35-45,
2020.
5. C. P. Basso, Switch-Mode Power Supplies: SPICE Simulations and Practical Designs, McGraw Hill
Professional, 2008.
6. R. W. Erickson and D. Maksimovic, Fundamentals of power electronics, Springer Science & Business
Media, 2007.
7. D. I. ZAIKIN, "Supplementary materials for the article: Extraction of Transformer Parameters from Femm
Simulations and Automated Creation of a Transformer Spice Model Using a Scripting Language.," 13 04 2023.
[Online]. Available: https://doi.org/10.6084/m9.figshare.22263034. [Accessed 13 04 2023].

You might also like