-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathideal_components.jl
More file actions
315 lines (245 loc) · 5.96 KB
/
Copy pathideal_components.jl
File metadata and controls
315 lines (245 loc) · 5.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
"""
Ground(; name)
Ground node with the potential of zero and connector `g`. Every circuit must have one ground
node.
# Connectors:
- `g`
"""
@mtkmodel Ground begin
@components begin
g = Pin()
end
@equations begin
g.v ~ 0
end
end
"""
Resistor(; name, R)
Creates an ideal Resistor following Ohm's Law.
# States:
See [OnePort](@ref)
# Connectors:
- `p` Positive pin
- `n` Negative pin
# Parameters:
- `R`: [`Ohm`] Resistance
"""
@mtkmodel Resistor begin
@extend v, i = oneport = OnePort()
@parameters begin
R, [description = "Resistance"]
end
@equations begin
v ~ i * R
end
end
"""
Conductor(; name, G)
Creates an ideal conductor.
# States:
See [OnePort](@ref)
# Connectors:
- `p` Positive pin
- `n` Negative pin
# Parameters:
- `G`: [`S`] Conductance
"""
@mtkmodel Conductor begin
@extend v, i = oneport = OnePort()
@parameters begin
G, [description = "Conductance"]
end
@equations begin
i ~ v * G
end
end
"""
Capacitor(; name, C, v)
Creates an ideal capacitor.
Initial voltage of capacitor can be set with `v` ([`V`])
# States:
See [OnePort](@ref)
# Connectors:
- `p` Positive pin
- `n` Negative pin
# Parameters:
- `C`: [`F`] Capacitance
"""
@mtkmodel Capacitor begin
@parameters begin
C, [description = "Capacitance"]
end
@variables begin
v
end
@extend v, i = oneport = OnePort(; v = v)
@equations begin
D(v) ~ i / C
end
end
"""
Inductor(; name, L, i)
Creates an ideal Inductor.
Initial current through inductor can be set with `i` ([`A`]).
# States:
See [OnePort](@ref)
# Connectors:
- `p` Positive pin
- `n` Negative pin
# Parameters:
- `L`: [`H`] Inductance
"""
@mtkmodel Inductor begin
@parameters begin
L, [description = "Inductance"]
end
@variables begin
i
end
@extend v, i = oneport = OnePort(; i = i)
@equations begin
D(i) ~ 1 / L * v
end
end
"""
IdealOpAmp(; name)
Ideal operational amplifier (norator-nullator pair).
The ideal OpAmp is a two-port. The left port is fixed to `v1 = 0` and `i1 = 0` (nullator).
At the right port both any voltage `v2` and any current `i2` are possible (norator).
# States:
See [TwoPort](@ref)
# Connectors:
- `p1` Positive pin (left port)
- `p2` Positive pin (right port)
- `n1` Negative pin (left port)
- `n2` Negative pin (right port)
"""
@mtkmodel IdealOpAmp begin
@extend v1, v2, i1, i2 = twoport = TwoPort()
@equations begin
v1 ~ 0
i1 ~ 0
end
end
"""
Short(; name)
Short is a simple short cut branch. That means the voltage drop between both pins is zero.
# States:
See [OnePort](@ref)
# Connectors:
- `p` Positive pin
- `n` Negative pin
"""
@mtkmodel Short begin
@extend v, i = oneport = OnePort()
@equations begin
v ~ 0
end
end
"""
HeatingResistor(; name, R_ref = 1.0, T_ref = 300.15, alpha = 0)
Temperature dependent electrical resistor
# States
- See [OnePort](@ref)
- `R(t)`: [`Ohm`] Temperature dependent resistance `R ~ R_ref*(1 + alpha*(heat_port.T(t) - T_ref))`
# Connectors
- `p` Positive pin
- `n` Negative pin
# Parameters:
- `R_ref`: [`Ω`] Reference resistance
- `T_ref`: [K] Reference temperature
- `alpha`: [K⁻¹] Temperature coefficient of resistance
"""
@mtkmodel HeatingResistor begin
@extend v, i = oneport = OnePort()
@components begin
heat_port = HeatPort()
end
@parameters begin
R_ref = 1.0, [description = "Reference resistance"]
T_ref = 300.15, [description = "Reference temperature"]
alpha = 0, [description = "Temperature coefficient of resistance"]
end
@variables begin
R(t) = R_ref
end
@equations begin
R ~ R_ref * (1 + alpha * (heat_port.T - T_ref))
heat_port.Q_flow ~ -v * i # -LossPower
v ~ i * R
end
end
"""
EMF(; name, k)
Electromotoric force (electric/mechanic transformer)
# States
- `v(t)`: [`V`] The voltage across component `p.v - n.v`
- `i(t)`: [`A`] The current passing through positive pin
- `phi`: [`rad`] Rotation angle (=flange.phi - support.phi)
- `w`: [`rad/s`] Angular velocity (= der(phi))
# Connectors
- `p` [Pin](@ref) Positive pin
- `n` [Pin](@ref) Negative pin
- `flange` [Flange](@ref) Shaft of EMF shaft
- `support` [Support](@ref) Support/housing of emf shaft
# Parameters:
- `k`: [`N⋅m/A`] Transformation coefficient
"""
@mtkmodel EMF begin
@components begin
p = Pin()
n = Pin()
flange = Flange()
support = Support()
end
@parameters begin
k, [description = "Transformation coefficient"]
end
@variables begin
v(t) = 0.0
i(t) = 0.0
phi(t) = 0.0
w(t) = 0.0
end
@equations begin
v ~ p.v - n.v
0 ~ p.i + n.i
i ~ p.i
phi ~ flange.phi - support.phi
D(phi) ~ w
k * w ~ v
flange.tau ~ -k * i
end
end
"""
ChuaDiode(; name, Ga, Gb, Ve)
Chua's Diode
# States
See [OnePort](@ref)
# Connectors:
- `p` Positive pin
- `n` Negative pin
# Parameters:
- `Ga` : [`Ohm`] Negative of the slope of the V-I curve when v < -Ve and v > V
- `Gb` : [`Ohm`] Negative of the slope of the V-I curve when -Ve < v < Ve
- `Ve` : [`V`] Absolute value of voltage where the behaviour of the diode changes
"""
@mtkmodel ChuaDiode begin
@extend v, i = oneport = OnePort()
@parameters begin
Ga = 1.0,
[description = "Negative of the slope of the V-I curve when v < -Ve and v > Ve"]
Gb = 1.0, [description = "Negative of the slope of the V-I curve when -Ve < v < Ve"]
Ve = 1.0,
[
description = "Absolute value of voltage where the behaviour of the diode changes",
]
end
@equations begin
i ~ ifelse(v < -Ve,
Gb * (v + Ve) - Ga * Ve,
ifelse(v > Ve,
Gb * (v - Ve) + Ga * Ve,
Ga * v))
end
end