@@ -28,13 +28,13 @@ using ModelingToolkit, Plots, DifferentialEquations
28
28
ODESystem(Equation[], t, sts, []; name = name)
29
29
end
30
30
31
- function Ground(; name)
31
+ @component function Ground(; name)
32
32
@named g = Pin()
33
33
eqs = [g.v ~ 0]
34
34
compose(ODESystem(eqs, t, [], []; name = name), g)
35
35
end
36
36
37
- function OnePort(; name)
37
+ @component function OnePort(; name)
38
38
@named p = Pin()
39
39
@named n = Pin()
40
40
sts = @variables v(t)=1.0 i(t)=1.0
@@ -44,7 +44,7 @@ function OnePort(; name)
44
44
compose(ODESystem(eqs, t, sts, []; name = name), p, n)
45
45
end
46
46
47
- function Resistor(; name, R = 1.0)
47
+ @component function Resistor(; name, R = 1.0)
48
48
@named oneport = OnePort()
49
49
@unpack v, i = oneport
50
50
ps = @parameters R = R
@@ -54,7 +54,7 @@ function Resistor(; name, R = 1.0)
54
54
extend(ODESystem(eqs, t, [], ps; name = name), oneport)
55
55
end
56
56
57
- function Capacitor(; name, C = 1.0)
57
+ @component function Capacitor(; name, C = 1.0)
58
58
@named oneport = OnePort()
59
59
@unpack v, i = oneport
60
60
ps = @parameters C = C
@@ -65,7 +65,7 @@ function Capacitor(; name, C = 1.0)
65
65
extend(ODESystem(eqs, t, [], ps; name = name), oneport)
66
66
end
67
67
68
- function ConstantVoltage(; name, V = 1.0)
68
+ @component function ConstantVoltage(; name, V = 1.0)
69
69
@named oneport = OnePort()
70
70
@unpack v = oneport
71
71
ps = @parameters V = V
@@ -149,7 +149,7 @@ this component, we generate an `ODESystem` with a `Pin` subcomponent and specify
149
149
that the voltage in such a ` Pin ` is equal to zero. This gives:
150
150
151
151
``` @example acausal
152
- function Ground(; name)
152
+ @component function Ground(; name)
153
153
@named g = Pin()
154
154
eqs = [g.v ~ 0]
155
155
compose(ODESystem(eqs, t, [], []; name = name), g)
@@ -163,7 +163,7 @@ zero, and the current of the component equals to the current of the positive
163
163
pin.
164
164
165
165
``` @example acausal
166
- function OnePort(; name)
166
+ @component function OnePort(; name)
167
167
@named p = Pin()
168
168
@named n = Pin()
169
169
sts = @variables v(t)=1.0 i(t)=1.0
@@ -182,7 +182,7 @@ of charge we know that the current in must equal the current out, which means
182
182
zero. This leads to our resistor equations:
183
183
184
184
``` @example acausal
185
- function Resistor(; name, R = 1.0)
185
+ @component function Resistor(; name, R = 1.0)
186
186
@named oneport = OnePort()
187
187
@unpack v, i = oneport
188
188
ps = @parameters R = R
@@ -205,7 +205,7 @@ we can use `@unpack` to avoid the namespacing.
205
205
Using our knowledge of circuits, we similarly construct the ` Capacitor ` :
206
206
207
207
``` @example acausal
208
- function Capacitor(; name, C = 1.0)
208
+ @component function Capacitor(; name, C = 1.0)
209
209
@named oneport = OnePort()
210
210
@unpack v, i = oneport
211
211
ps = @parameters C = C
@@ -223,7 +223,7 @@ constant voltage, essentially generating the electric current. We would then
223
223
model this as:
224
224
225
225
``` @example acausal
226
- function ConstantVoltage(; name, V = 1.0)
226
+ @component function ConstantVoltage(; name, V = 1.0)
227
227
@named oneport = OnePort()
228
228
@unpack v = oneport
229
229
ps = @parameters V = V
0 commit comments