11"""
2- Ground(;name)
2+ Ground(; name)
33
44Zero magnetic potential.
55"""
6- @component function Ground (; name)
7- @named port = PositiveMagneticPort ()
8- eqs = [port. V_m ~ 0 ]
9- ODESystem (eqs, t, [], [], systems = [port], name = name)
6+ @mtkmodel Ground begin
7+ @components begin
8+ port = PositiveMagneticPort ()
9+ end
10+ @equations begin
11+ port. V_m ~ 0
12+ end
1013end
1114
1215"""
1316 Idle(;name)
1417
1518Idle running branch.
1619"""
17- @component function Idle (; name)
18- @named two_port = TwoPort ()
19- @unpack Phi = two_port
20- eqs = [
21- Phi ~ 0 ,
22- ]
23- extend (ODESystem (eqs, t, [], [], systems = [], name = name), two_port)
20+ @mtkmodel Idle begin
21+ @extend (Phi,) = two_port = TwoPort ()
22+ @equations begin
23+ Phi ~ 0
24+ end
2425end
2526
2627"""
2728 Short(;name)
2829
2930Short cut branch.
3031"""
31- @component function Short (; name)
32- @named two_port = TwoPort ()
33- @unpack V_m = two_port
34- eqs = [
35- V_m ~ 0 ,
36- ]
37- extend (ODESystem (eqs, t, [], [], systems = [], name = name), two_port)
32+ @mtkmodel Short begin
33+ @extend (V_m,) = two_port = TwoPort ()
34+ @equations begin
35+ V_m ~ 0
36+ end
3837end
3938
4039"""
@@ -44,108 +43,120 @@ Crossing of two branches.
4443
4544This is a simple crossing of two branches. The ports port_p1 and port_p2 are connected, as well as port_n1 and port_n2.
4645"""
47- @component function Crossing (; name)
48- @named port_p1 = PositiveMagneticPort ()
49- @named port_p2 = PositiveMagneticPort ()
50- @named port_n1 = NegativeMagneticPort ()
51- @named port_n2 = NegativeMagneticPort ()
52- eqs = [
53- connect (port_p1, port_p2),
54- connect (port_n1, port_n2),
55- ]
56- ODESystem (eqs, t, [], [], systems = [port_p1, port_p2, port_n1, port_n2], name = name)
46+ @mtkmodel Crossing begin
47+ @components begin
48+ port_p1 = PositiveMagneticPort ()
49+ port_p2 = PositiveMagneticPort ()
50+ port_n1 = NegativeMagneticPort ()
51+ port_n2 = NegativeMagneticPort ()
52+ end
53+ @equations begin
54+ connect (port_p1, port_p2)
55+ connect (port_n1, port_n2)
56+ end
5757end
5858
5959"""
60- ConstantPermeance(;name, G_m= 1.0)
60+ ConstantPermeance(; name, G_m = 1.0)
6161
6262Constant permeance.
6363
6464# Parameters:
6565
6666 - `G_m`: [H] Magnetic permeance
6767"""
68- @component function ConstantPermeance (; name, G_m = 1.0 )
69- @named two_port = TwoPort ()
70- @unpack V_m, Phi = two_port
71- @parameters G_m = G_m
72- eqs = [
73- Phi ~ G_m * V_m,
74- ]
75- extend ( ODESystem (eqs, t, [], [G_m], name = name), two_port)
68+ @mtkmodel ConstantPermeance begin
69+ @extend V_m, Phi = two_port = TwoPort ()
70+ @parameters begin
71+ G_m = 1.0 , [description = " Magnetic permeance " ]
72+ end
73+ @equations begin
74+ Phi ~ G_m * V_m
75+ end
7676end
7777
7878"""
79- ConstantReluctance(;name, R_m= 1.0)
79+ ConstantReluctance(; name, R_m = 1.0)
8080
8181Constant reluctance.
8282
8383# Parameters:
8484
8585 - `R_m`: [H^-1] Magnetic reluctance
8686"""
87- @component function ConstantReluctance (; name, R_m = 1.0 )
88- @named two_port = TwoPort ()
89- @unpack V_m, Phi = two_port
90- @parameters R_m = R_m
91- eqs = [
92- V_m ~ Phi * R_m,
93- ]
94- extend ( ODESystem (eqs, t, [], [R_m], name = name), two_port)
87+ @mtkmodel ConstantReluctance begin
88+ @extend V_m, Phi = two_port = TwoPort (; Phi = 0.0 )
89+ @parameters begin
90+ R_m = 1.0 , [description = " Magnetic reluctance " ]
91+ end
92+ @equations begin
93+ V_m ~ Phi * R_m
94+ end
9595end
9696
9797"""
98- ElectroMagneticConverter(;name, N, Phi_start=0.0 )
98+ ElectroMagneticConverter(; name, N, Phi )
9999
100100Ideal electromagnetic energy conversion.
101101
102102The electromagnetic energy conversion is given by Ampere's law and Faraday's law respectively
103103V_m = N * i
104104N * dΦ/dt = -v
105105
106+ Initial magnetic flux flowing into the port_p can be set with `Phi` ([Wb])
107+
106108# Parameters:
107109
108110 - `N`: Number of turns
109- - `Phi_start`: [Wb] Initial magnetic flux flowing into the port_p
110111"""
111- @component function ElectroMagneticConverter (; name, N, Phi_start = 0.0 )
112- @named port_p = PositiveMagneticPort ()
113- @named port_n = NegativeMagneticPort ()
114- @named p = Pin ()
115- @named n = Pin ()
116-
117- sts = @variables v (t) i (t) V_m (t) Phi (t)= Phi_start
118- pars = @parameters N = N
119- eqs = [v ~ p. v - n. v
112+ @mtkmodel ElectroMagneticConverter begin
113+ @parameters begin
114+ N, [description = " Number of turns" ]
115+ end
116+ @variables begin
117+ v (t)
118+ i (t)
119+ Phi
120+ end
121+ @extend V_m, Phi = two_port = TwoPort (; Phi = Phi)
122+ @components begin
123+ p = Pin ()
124+ n = Pin ()
125+ end
126+ @equations begin
127+ v ~ p. v - n. v
120128 0 ~ p. i + n. i
121129 i ~ p. i
122- V_m ~ port_p. V_m - port_n. V_m
123- 0 ~ port_p. Phi + port_n. Phi
124- Phi ~ port_p. Phi
125- # converter equations:
130+ # converter equations:
126131 V_m ~ i * N # Ampere's law
127- D (Phi) ~ - v / N]
128- ODESystem (eqs, t, sts, pars, systems = [port_p, port_n, p, n], name = name)
132+ D (Phi) ~ - v / N
133+ end
129134end
130135
131136"""
132- EddyCurrent(;name, rho= 0.098e-6, l= 1, A=1, Phi_start=0.0 )
137+ EddyCurrent(;name, Phi, rho = 0.098e-6, l = 1, A = 1 )
133138
134139For modelling of eddy current in a conductive magnetic flux tube.
140+ Initial magnetic flux flowing into the port_p can be set with `Phi` ([`Wb`])
135141
136142# Parameters:
137143
138144 - `rho`: [ohm * m] Resistivity of flux tube material (default: Iron at 20degC)
139145 - `l`: [m] Average length of eddy current path
140146 - `A`: [m^2] Cross sectional area of eddy current path
141- - `Phi_start`: [Wb] Initial magnetic flux flowing into the port_p
142- """
143- @component function EddyCurrent (; name, rho = 0.098e-6 , l = 1 , A = 1 , Phi_start = 0.0 )
144- @named two_port = TwoPort (Phi_start = Phi_start)
145- @unpack V_m, Phi = two_port
146- @parameters R = rho * l / A # Electrical resistance of eddy current path
147- eqs = [
148- D (Phi) ~ V_m * R,
149- ]
150- extend (ODESystem (eqs, t, [], [R], name = name), two_port)
147+ """
148+ @mtkmodel EddyCurrent begin
149+ @variables begin
150+ Phi
151+ end
152+ @parameters begin
153+ rho = 0.098e-6 , [description = " Resistivity of flux tube material" ]
154+ l = 1 , [description = " Average length of eddy current path" ]
155+ A = 1 , [description = " Cross sectional area of eddy current path" ]
156+ R = rho * l / A # Electrical resistance of eddy current path
157+ end
158+ @extend (V_m, Phi) = two_port = TwoPort (; Phi = Phi)
159+ @equations begin
160+ D (Phi) ~ V_m * R
161+ end
151162end
0 commit comments