Skip to content

Commit 7a5c20a

Browse files
committed
refactor: @model -> @mtkmodel
1 parent d99fdcd commit 7a5c20a

File tree

12 files changed

+31
-65
lines changed

12 files changed

+31
-65
lines changed

docs/src/tutorials/rc_circuit.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ C = 1.0
1616
V = 1.0
1717
@variables t
1818
@named resistor = Resistor(R = R)
19-
@named capacitor = Capacitor(C = C)
19+
@named capacitor = Capacitor(C = C, v = 0.0)
2020
@named source = Voltage()
2121
@named constant = Constant(k = V)
2222
@named ground = Ground()
@@ -29,7 +29,7 @@ rc_eqs = [connect(constant.output, source.V)
2929
@named rc_model = ODESystem(rc_eqs, t,
3030
systems = [resistor, capacitor, constant, source, ground])
3131
sys = structural_simplify(rc_model)
32-
prob = ODAEProblem(sys, Pair[capacitor.v_start => 1], (0, 10.0))
32+
prob = ODAEProblem(sys, Pair[], (0, 10.0))
3333
sol = solve(prob, Tsit5())
3434
plot(sol, vars = [capacitor.v, resistor.i],
3535
title = "RC Circuit Demonstration",

src/Blocks/math.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Output the product of a gain value with the input signal.
1212
- `input`
1313
- `output`
1414
"""
15-
@model Gain begin
15+
@mtkmodel Gain begin
1616
@extend u, y = siso = SISO()
1717
@parameters begin
1818
k, [description = "Gain function"]
@@ -79,7 +79,7 @@ Output difference between reference input (input1) and feedback input (input2).
7979
- `input2`
8080
- `output`
8181
"""
82-
@model Feedback begin
82+
@mtkmodel Feedback begin
8383
@components begin
8484
input1 = RealInput()
8585
input2 = RealInput()

src/Blocks/sources.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Generate constant signal.
6969
7070
- `output`
7171
"""
72-
@model Constant begin
72+
@mtkmodel Constant begin
7373
@components begin
7474
output = RealOutput()
7575
end

src/Electrical/Analog/ideal_components.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ node.
88
99
- `g`
1010
"""
11-
@model Ground begin
11+
@mtkmodel Ground begin
1212
@components begin
1313
g = Pin()
1414
end
@@ -35,7 +35,7 @@ See [OnePort](@ref)
3535
3636
- `R`: [`Ohm`] Resistance
3737
"""
38-
@model Resistor begin
38+
@mtkmodel Resistor begin
3939
@extend v, i = oneport = OnePort()
4040
@parameters begin
4141
R
@@ -63,7 +63,7 @@ See [OnePort](@ref)
6363
6464
- `G`: [`S`] Conductance
6565
"""
66-
@model Conductor begin
66+
@mtkmodel Conductor begin
6767
@extend v, i = oneport = OnePort()
6868
@parameters begin
6969
G
@@ -92,7 +92,7 @@ Creates an ideal capacitor.
9292
- `C`: [`F`] Capacitance
9393
- `v`: [`V`] Initial voltage of capacitor
9494
"""
95-
@model Capacitor begin
95+
@mtkmodel Capacitor begin
9696
@parameters begin
9797
C
9898
end
@@ -124,7 +124,7 @@ See [OnePort](@ref)
124124
- `L`: [`H`] Inductance
125125
- `i`: [`A`] Initial current through inductor
126126
"""
127-
@model Inductor begin # name, L, i_start = 0.0)
127+
@mtkmodel Inductor begin # name, L, i_start = 0.0)
128128
@parameters begin
129129
L
130130
end
@@ -244,7 +244,7 @@ Electromotoric force (electric/mechanic transformer)
244244
245245
- `k`: [`N⋅m/A`] Transformation coefficient
246246
"""
247-
@model EMF begin
247+
@mtkmodel EMF begin
248248
@components begin
249249
p = Pin()
250250
n = Pin()

src/Electrical/Analog/sources.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See [OnePort](@ref)
1313
- `n` Negative pin
1414
- `V` [RealInput](@ref) Input for the voltage control signal, i.e. `V ~ p.v - n.v`
1515
"""
16-
@model Voltage begin
16+
@mtkmodel Voltage begin
1717
@extend v, i = oneport = OnePort()
1818
@components begin
1919
V = RealInput()
@@ -38,7 +38,7 @@ See [OnePort](@ref)
3838
- `n` Negative pin
3939
- `I` [RealInput](@ref) Input for the current control signal, i.e. `I ~ p.i
4040
"""
41-
@model Current begin
41+
@mtkmodel Current begin
4242
@extend v, i = oneport = OnePort()
4343
@components begin
4444
I = RealInput()

src/Electrical/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Component with two electrical pins `p` and `n` and current `i` flows from `p` to
3232
- `p` Positive pin
3333
- `n` Negative pin
3434
"""
35-
@model OnePort begin
35+
@mtkmodel OnePort begin
3636
@components begin
3737
p = Pin()
3838
n = Pin()

src/Mechanical/Rotational/components.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Flange fixed in housing at a given angle.
1111
1212
- `phi0`: [`rad`] Fixed offset angle of housing
1313
"""
14-
@model Fixed begin
14+
@mtkmodel Fixed begin
1515
@components begin
1616
flange = Flange()
1717
end
@@ -115,7 +115,7 @@ Linear 1D rotational damper
115115
116116
- `d`: [`N.m.s/rad`] Damping constant
117117
"""
118-
@model Damper begin
118+
@mtkmodel Damper begin
119119
@extend w_rel, tau = partial_comp = PartialCompliantWithRelativeStates()
120120
begin
121121
@symcheck d > 0 || throw(ArgumentError("Expected `d` to be positive"))

src/Mechanical/Rotational/sensors.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Ideal sensor to measure the absolute flange angular velocity
2626
- `flange`: [Flange](@ref) Flange of shaft from which sensor information shall be measured
2727
- `w`: [RealOutput](@ref) Absolute angular velocity of flange
2828
"""
29-
@model SpeedSensor begin
29+
@mtkmodel SpeedSensor begin
3030
@components begin
3131
flange = Flange()
3232
w = RealOutput()

test/Electrical/analog.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ using OrdinaryDiffEq: ReturnCode.Success
1313
@named source = Sine(offset = 1, amplitude = 10, frequency = 5)
1414
@named voltage = Voltage()
1515
@named resistor = Resistor(R = 1)
16-
@named capacitor = Capacitor(C = 1)
16+
@named capacitor = Capacitor(C = 1, v = 0.0)
1717
@named ground = Ground()
1818

1919
@named voltage_sensor = VoltageSensor()
@@ -43,7 +43,7 @@ using OrdinaryDiffEq: ReturnCode.Success
4343
power_sensor,
4444
])
4545
sys = structural_simplify(model)
46-
prob = ODAEProblem(sys, Pair[capacitor.v => 0.0], (0.0, 10.0))
46+
prob = ODAEProblem(sys, [], (0.0, 10.0))
4747
sol = solve(prob, Tsit5())
4848

4949
# Plots.plot(sol; vars=[capacitor.v, voltage_sensor.v])
@@ -89,7 +89,7 @@ end
8989
@named source = Constant(k = 10)
9090
@named voltage = Voltage()
9191
@named resistor = Resistor(R = 1)
92-
@named capacitor = Capacitor(C = 1)
92+
@named capacitor = Capacitor(C = 1, v = 0.0)
9393
@named ground = Ground()
9494

9595
connections = [connect(source.output, voltage.V)
@@ -100,7 +100,7 @@ end
100100
@named model = ODESystem(connections, t;
101101
systems = [resistor, capacitor, source, voltage, ground])
102102
sys = structural_simplify(model)
103-
prob = ODAEProblem(sys, [capacitor.v => 0.0], (0.0, 10.0))
103+
prob = ODAEProblem(sys, Pair[], (0.0, 10.0))
104104
sol = solve(prob, Tsit5())
105105

106106
# Plots.plot(sol; vars=[source.v, capacitor.v])
@@ -113,7 +113,7 @@ end
113113
@named source = Constant(k = 10)
114114
@named voltage = Voltage()
115115
@named resistor = Resistor(R = 1)
116-
@named inductor = Inductor(L = 1.0)
116+
@named inductor = Inductor(L = 1.0, i = 0.0)
117117
@named ground = Ground()
118118

119119
connections = [connect(source.output, voltage.V)
@@ -124,7 +124,7 @@ end
124124
@named model = ODESystem(connections, t;
125125
systems = [resistor, inductor, source, voltage, ground])
126126
sys = structural_simplify(model)
127-
prob = ODAEProblem(sys, [inductor.i => 0.0], (0.0, 10.0))
127+
prob = ODAEProblem(sys, Pair[], (0.0, 10.0))
128128
sol = solve(prob, Tsit5())
129129

130130
# Plots.plot(sol; vars=[inductor.i, inductor.i])
@@ -147,7 +147,7 @@ end
147147
sources = [source_const, source_sin, source_step, source_tri, source_dsin, source_ramp]
148148

149149
@named resistor = Resistor(; R)
150-
@named capacitor = Capacitor(; C)
150+
@named capacitor = Capacitor(; C, v = 0.0)
151151
@named ground = Ground()
152152

153153
for source in sources
@@ -159,7 +159,7 @@ end
159159
@named model = ODESystem(connections, t;
160160
systems = [resistor, capacitor, source, ground, voltage])
161161
sys = structural_simplify(model)
162-
prob = ODAEProblem(sys, [capacitor.v => 0.0], (0.0, 10.0))
162+
prob = ODAEProblem(sys, Pair[], (0.0, 10.0))
163163
sol = solve(prob, Tsit5())
164164
@test sol.retcode == Success
165165
sol = solve(prob, Rodas4())
@@ -175,7 +175,7 @@ end
175175
@named current = Current()
176176
@named source = Step(start_time = 2)
177177
@named resistor = Resistor(R = 1)
178-
@named capacitor = Capacitor(C = 1)
178+
@named capacitor = Capacitor(C = 1, v = 0.0)
179179
@named ground = Ground()
180180

181181
connections = [connect(source.output, current.I)
@@ -186,7 +186,7 @@ end
186186
@named model = ODESystem(connections, t;
187187
systems = [ground, resistor, current, capacitor, source])
188188
sys = structural_simplify(model)
189-
prob = ODAEProblem(sys, [capacitor.v => 0.0], (0.0, 10.0))
189+
prob = ODAEProblem(sys, Pair[], (0.0, 10.0))
190190
sol = solve(prob, Tsit5())
191191
y(x, st) = (x .> st) .* abs.(collect(x) .- st)
192192
@test sol.retcode == Success
@@ -200,7 +200,7 @@ end
200200
@named ground = Ground()
201201
@named R1 = Resistor(R = R)
202202
@named R2 = Resistor(R = 100 * R)
203-
@named C1 = Capacitor(C = 1 / (2 * pi * f * R))
203+
@named C1 = Capacitor(C = 1 / (2 * pi * f * R), v = 0.0)
204204
@named opamp = IdealOpAmp()
205205
@named square_source = Square(amplitude = Vin)
206206
@named voltage = Voltage()
@@ -247,7 +247,7 @@ _damped_sine_wave(x, f, A, st, ϕ, d) = exp((st - x) * d) * A * sin(2 * π * f *
247247
st, o, h, f, A, et, ϕ, d, δ = 0.7, 1.25, 3, 2, 2.5, 2, π / 4, 0.1, 0.0001
248248

249249
@named res = Resistor(R = 1)
250-
@named cap = Capacitor(C = 1)
250+
@named cap = Capacitor(C = 1, v = 0.0)
251251
@named ground = Ground()
252252
@named voltage = Voltage()
253253
@named voltage_sensor = VoltageSensor()
@@ -311,7 +311,7 @@ end
311311

312312
@named ground = Ground()
313313
@named res = Resistor(R = 1.0)
314-
@named cap = Capacitor(C = 1)
314+
@named cap = Capacitor(C = 1, v = 0.0)
315315
@named current_sensor = CurrentSensor()
316316
@named current = Current()
317317
@named step = Step(start_time = st, offset = o, height = h)

test/demo.jl

Lines changed: 0 additions & 30 deletions
This file was deleted.

test/multi_domain.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ D = Differential(t)
5757
])
5858
sys = structural_simplify(model)
5959

60-
prob = ODEProblem(sys, [], (0, 6.0))
60+
prob = ODEProblem(sys, Pair[], (0, 6.0))
6161
sol = solve(prob, Rodas4())
6262
@test sol.retcode == Success
6363
# EMF equations

test/runtests.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ end
3131
@safetestset "Digital Circuits" begin
3232
include("Electrical/digital.jl")
3333
end
34-
@safetestset "RC Circuit Demo" begin
35-
include("demo.jl")
36-
end
3734
@safetestset "Chua Circuit Demo" begin
3835
include("chua_circuit.jl")
3936
end
@@ -66,4 +63,3 @@ end
6663
@safetestset "Hydraulic IsothermalCompressible" begin
6764
include("Hydraulic/isothermal_compressible.jl")
6865
end
69-

0 commit comments

Comments
 (0)