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,16 +43,17 @@ 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"""
@@ -65,14 +65,14 @@ Constant permeance.
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
72+ end
73+ @equations begin
74+ Phi ~ G_m * V_m
75+ end
7676end
7777
7878"""
@@ -84,18 +84,18 @@ Constant reluctance.
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
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 = 0.0)
9999
100100Ideal electromagnetic energy conversion.
101101
@@ -108,28 +108,38 @@ N * dΦ/dt = -v
108108 - `N`: Number of turns
109109 - `Phi_start`: [Wb] Initial magnetic flux flowing into the port_p
110110"""
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
111+ @mtkmodel ElectroMagneticConverter begin
112+ @components begin
113+ port_p = PositiveMagneticPort ()
114+ port_n = NegativeMagneticPort ()
115+ p = Pin ()
116+ n = Pin ()
117+ end
118+
119+ @variables begin
120+ v (t)
121+ i (t)
122+ V_m (t)
123+ Phi (t) = 0.0
124+ end
125+ @parameters begin
126+ N
127+ end
128+ @equations begin
129+ v ~ p. v - n. v
120130 0 ~ p. i + n. i
121131 i ~ p. i
122132 V_m ~ port_p. V_m - port_n. V_m
123133 0 ~ port_p. Phi + port_n. Phi
124134 Phi ~ port_p. Phi
125135 # converter equations:
126136 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)
137+ D (Phi) ~ - v / N
138+ end
129139end
130140
131141"""
132- EddyCurrent(;name, rho= 0.098e-6, l= 1, A= 1, Phi_start= 0.0)
142+ EddyCurrent(;name, rho = 0.098e-6, l = 1, A = 1, Phi = 0.0)
133143
134144For modelling of eddy current in a conductive magnetic flux tube.
135145
@@ -138,14 +148,18 @@ For modelling of eddy current in a conductive magnetic flux tube.
138148 - `rho`: [ohm * m] Resistivity of flux tube material (default: Iron at 20degC)
139149 - `l`: [m] Average length of eddy current path
140150 - `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)
151+ - `Phi`: [Wb] Initial magnetic flux flowing into the port_p
152+ """
153+ @mtkmodel EddyCurrent begin
154+ @extend (V_m, Phi) = two_port = TwoPort (; Phi = 0.0 )
155+ @parameters begin
156+ rho = 0.098e-6
157+ l = 1
158+ A = 1
159+ R = rho * l / A # Electrical resistance of eddy current path
160+ end
161+ @equations begin
162+ D (Phi) ~ V_m * R
163+ end
151164end
165+ EddyCurrent. f (; Phi, name, kwargs... ) = EddyCurrent. f (; two_port__Phi = Phi, name, kwargs... )
0 commit comments