@@ -18,30 +18,57 @@ node.
18
18
end
19
19
20
20
"""
21
- Resistor(; name, R)
21
+ Resistor(; name, R = 1.0, T_ref = 300.15, alpha = 0, T_dep = false )
22
22
23
- Creates an ideal Resistor following Ohm's Law .
23
+ Generic resistor with optional temperature dependency .
24
24
25
25
# States:
26
26
27
- See [OnePort](@ref)
27
+ - See [OnePort](@ref)
28
+ - `R(t)`: [`Ω`] Resistance (temperature dependent if `T_dep = true`)
28
29
29
30
# Connectors:
30
31
31
32
- `p` Positive pin
32
33
- `n` Negative pin
34
+ - `heat_port` [HeatPort](@ref) (only if `T_dep = true`) Heat port to model the temperature dependency
33
35
34
36
# Parameters:
35
37
36
- - `R`: [`Ohm`] Resistance
38
+ - `R`: [`Ω`] Reference resistance
39
+ - `T_ref`: [K] Reference temperature
40
+ - `alpha`: [K⁻¹] Temperature coefficient of resistance
41
+ - `T_dep`: [bool] Temperature dependency
37
42
"""
38
43
@mtkmodel Resistor begin
39
44
@extend v, i = oneport = OnePort ()
45
+
46
+ @structural_parameters begin
47
+ T_dep = false
48
+ end
49
+
40
50
@parameters begin
41
- R, [description = " Resistance" ]
51
+ R = 1.0 , [description = " Reference resistance" ]
52
+ T_ref = 300.15 , [description = " Reference temperature" ]
53
+ alpha = 0.0 , [description = " Temperature coefficient of resistance" ]
42
54
end
43
- @equations begin
44
- v ~ i * R
55
+
56
+ if T_dep
57
+ @components begin
58
+ heat_port = HeatPort ()
59
+ end
60
+ @variables begin
61
+ R_T (t), [description = " Temperature-dependent resistance" ]
62
+ end
63
+ @equations begin
64
+ R_T ~ R * (1 + alpha * (heat_port. T - T_ref)) # Temperature-dependent resistance
65
+ heat_port. Q_flow ~ - v * i # -LossPower
66
+ v ~ i * R_T # Ohm's Law
67
+ end
68
+ else
69
+ @equations begin
70
+ v ~ i * R # Ohm's Law for constant resistance
71
+ end
45
72
end
46
73
end
47
74
@@ -178,47 +205,6 @@ See [OnePort](@ref)
178
205
end
179
206
end
180
207
181
- """
182
- HeatingResistor(; name, R_ref = 1.0, T_ref = 300.15, alpha = 0)
183
-
184
- Temperature dependent electrical resistor
185
-
186
- # States
187
-
188
- - See [OnePort](@ref)
189
- - `R(t)`: [`Ohm`] Temperature dependent resistance `R ~ R_ref*(1 + alpha*(heat_port.T(t) - T_ref))`
190
-
191
- # Connectors
192
-
193
- - `p` Positive pin
194
- - `n` Negative pin
195
-
196
- # Parameters:
197
-
198
- - `R_ref`: [`Ω`] Reference resistance
199
- - `T_ref`: [K] Reference temperature
200
- - `alpha`: [K⁻¹] Temperature coefficient of resistance
201
- """
202
- @mtkmodel HeatingResistor begin
203
- @extend v, i = oneport = OnePort ()
204
- @components begin
205
- heat_port = HeatPort ()
206
- end
207
- @parameters begin
208
- R_ref = 1.0 , [description = " Reference resistance" ]
209
- T_ref = 300.15 , [description = " Reference temperature" ]
210
- alpha = 0 , [description = " Temperature coefficient of resistance" ]
211
- end
212
- @variables begin
213
- R (t), [guess = R_ref]
214
- end
215
- @equations begin
216
- R ~ R_ref * (1 + alpha * (heat_port. T - T_ref))
217
- heat_port. Q_flow ~ - v * i # -LossPower
218
- v ~ i * R
219
- end
220
- end
221
-
222
208
"""
223
209
EMF(; name, k)
224
210
@@ -264,9 +250,9 @@ Electromotoric force (electric/mechanic transformer)
264
250
end
265
251
266
252
"""
267
- Diode(; name, Is = 1e-6, n = 1, T = 300.15)
253
+ Diode(; name, Is = 1e-6, n = 1, T = 300.15, T_dep = false )
268
254
269
- Ideal diode based on the Shockley diode equation .
255
+ Generic diode with optional temperature dependency .
270
256
271
257
# States
272
258
@@ -276,70 +262,48 @@ Ideal diode based on the Shockley diode equation.
276
262
277
263
- `p` Positive pin
278
264
- `n` Negative pin
265
+ - `port` [HeatPort](@ref) (only if `T_dep = true`) Heat port to model variable temperature dependency
279
266
280
- # Parameters
281
-
267
+ # Parameters:
268
+
282
269
- `Is`: [`A`] Saturation current
283
270
- `n`: Ideality factor
284
- - `T`: [K] Ambient temperature
271
+ - `T`: [K] Constant ambient temperature - only used if T_dep=false
272
+ - `T_dep`: [bool] Temperature dependency
285
273
"""
286
274
@mtkmodel Diode begin
287
275
@constants begin
288
276
k = 1.380649e-23 # Boltzmann constant (J/K)
289
277
q = 1.602176634e-19 # Elementary charge (C)
290
278
end
291
279
@extend v, i = oneport = OnePort (; v = 0.0 )
292
- @parameters begin
293
- Is = 1e-6 , [description = " Saturation current (A)" ]
294
- n = 1 , [description = " Ideality factor" ]
295
- T = 300.15 , [description = " Ambient temperature" ]
296
- end
297
- @equations begin
298
- i ~ Is * (exp (v * q / (n * k * T)) - 1 )
299
- end
300
- end
301
-
302
- """
303
- HeatingDiode(; name, Is = 1e-6, n = 1)
304
280
305
- Temperature dependent diode based on the Shockley diode equation.
306
-
307
- # States
308
-
309
- - See [OnePort](@ref)
310
-
311
- # Connectors
312
-
313
- - `p` Positive pin
314
- - `n` Negative pin
315
- - `port` [HeatPort](@ref) Heat port to model the temperature dependency
316
-
317
- # Parameters:
318
-
319
- - `Is`: [`A`] Saturation current
320
- - `n`: Ideality factor
321
- """
322
- @mtkmodel HeatingDiode begin
323
- begin
324
- k = 1.380649e-23 # Boltzmann constant (J/K)
325
- q = 1.602176634e-19 # Elementary charge (C)
281
+ @structural_parameters begin
282
+ T_dep = false
326
283
end
327
284
328
- @extend v, i = oneport = OnePort (; v = 0.0 )
329
- @components begin
330
- port = HeatPort ()
331
- end
332
285
@parameters begin
333
286
Is = 1e-6 , [description = " Saturation current (A)" ]
334
287
n = 1 , [description = " Ideality factor" ]
288
+ T = 300.15 , [description = " Ambient temperature" ]
335
289
end
336
- @variables begin
337
- Vt (t), [description = " Thermal voltage" ]
338
- end
339
- @equations begin
340
- Vt ~ k * port. T / q # Thermal voltage equation
341
- i ~ Is * (exp (v / (n * Vt)) - 1 ) # Shockley diode equation
342
- port. Q_flow ~ - v * i # -LossPower
290
+
291
+ if T_dep
292
+ @components begin
293
+ port = HeatPort ()
294
+ end
295
+ @variables begin
296
+ Vt (t), [description = " Thermal voltage" ]
297
+ end
298
+ @equations begin
299
+ Vt ~ k * port. T / q # Thermal voltage equation
300
+ i ~ Is * (exp (v / (n * Vt)) - 1 ) # Shockley diode equation with temperature dependence
301
+ port. Q_flow ~ - v * i # -LossPower
302
+ end
303
+ else
304
+ @equations begin
305
+ i ~ Is * (exp (v * q / (n * k * T)) - 1 ) # Shockley diode equation
306
+ end
343
307
end
344
308
end
345
309
0 commit comments