Skip to content

Commit b73ef27

Browse files
fix: remove usages of ODAEProblem, fix solution indexing, use unknowns
1 parent b36b890 commit b73ef27

File tree

5 files changed

+20
-23
lines changed

5 files changed

+20
-23
lines changed

docs/src/tutorials/rc_circuit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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[], (0, 10.0))
32+
prob = ODEProblem(sys, Pair[], (0, 10.0))
3333
sol = solve(prob, Tsit5())
3434
plot(sol, idxs = [capacitor.v, resistor.i],
3535
title = "RC Circuit Demonstration",

test/Blocks/test_analysis_points.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ sys = ODESystem(eqs, t, systems = [P, C], name = :hej)
1919
ssys = structural_simplify(sys)
2020
prob = ODEProblem(ssys, [P.x => 1], (0, 10))
2121
sol = solve(prob, Rodas5())
22-
@test norm(sol[1]) >= 1
23-
@test norm(sol[end]) < 1e-6 # This fails without the feedback through C
22+
@test norm(sol.u[1]) >= 1
23+
@test norm(sol.u[end]) < 1e-6 # This fails without the feedback through C
2424
# plot(sol)
2525

2626
matrices, _ = get_sensitivity(sys, ap)
@@ -107,7 +107,6 @@ matrices2, _ = linearize(sys, :plant_input, [P.output.u])
107107
@named P = FirstOrder(k = 1, T = 1)
108108
@named C = Gain(; k = 1)
109109
@named add = Blocks.Add(k2 = -1)
110-
t = ModelingToolkit.get_iv(P)
111110

112111
eqs = [connect(P.output, :plant_output, add.input2)
113112
connect(add.output, C.input)
@@ -230,7 +229,6 @@ Si = ss(matrices...)
230229
@test tf(So) tf(Si)
231230

232231
## A simple multi-level system with loop openings
233-
@parameters t
234232
@named P_inner = FirstOrder(k = 1, T = 1)
235233
@named feedback = Feedback()
236234
@named ref = Step()
@@ -310,7 +308,6 @@ G = CS.feedback(Pss, Kss, pos_feedback = true)
310308
@named P = FirstOrder(k = 1, T = 1)
311309
@named C = Gain(; k = 1)
312310
@named add = Blocks.Add(k2 = -1)
313-
t = ModelingToolkit.get_iv(P)
314311

315312
eqs = [connect(P.output, :plant_output, add.input2)
316313
connect(add.output, C.input)

test/Electrical/analog.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ using OrdinaryDiffEq: ReturnCode.Success
4242
power_sensor
4343
])
4444
sys = structural_simplify(model)
45-
prob = ODAEProblem(sys, [], (0.0, 10.0))
45+
prob = ODEProblem(sys, [], (0.0, 10.0))
4646
sol = solve(prob, Tsit5())
4747

4848
# Plots.plot(sol; vars=[capacitor.v, voltage_sensor.v])
@@ -99,7 +99,7 @@ end
9999
@named model = ODESystem(connections, t;
100100
systems = [resistor, capacitor, source, voltage, ground])
101101
sys = structural_simplify(model)
102-
prob = ODAEProblem(sys, Pair[], (0.0, 10.0))
102+
prob = ODEProblem(sys, Pair[], (0.0, 10.0))
103103
sol = solve(prob, Tsit5())
104104

105105
# Plots.plot(sol; vars=[source.v, capacitor.v])
@@ -123,7 +123,7 @@ end
123123
@named model = ODESystem(connections, t;
124124
systems = [resistor, inductor, source, voltage, ground])
125125
sys = structural_simplify(model)
126-
prob = ODAEProblem(sys, Pair[], (0.0, 10.0))
126+
prob = ODEProblem(sys, Pair[], (0.0, 10.0))
127127
sol = solve(prob, Tsit5())
128128

129129
# Plots.plot(sol; vars=[inductor.i, inductor.i])
@@ -158,7 +158,7 @@ end
158158
@named model = ODESystem(connections, t;
159159
systems = [resistor, capacitor, source, ground, voltage])
160160
sys = structural_simplify(model)
161-
prob = ODAEProblem(sys, Pair[], (0.0, 10.0))
161+
prob = ODEProblem(sys, Pair[], (0.0, 10.0))
162162
sol = solve(prob, Tsit5())
163163
@test sol.retcode == Success
164164
sol = solve(prob, Rodas4())
@@ -185,7 +185,7 @@ end
185185
@named model = ODESystem(connections, t;
186186
systems = [ground, resistor, current, capacitor, source])
187187
sys = structural_simplify(model)
188-
prob = ODAEProblem(sys, Pair[], (0.0, 10.0))
188+
prob = ODEProblem(sys, Pair[], (0.0, 10.0))
189189
sol = solve(prob, Tsit5())
190190
y(x, st) = (x .> st) .* abs.(collect(x) .- st)
191191
@test sol.retcode == Success
@@ -295,7 +295,7 @@ _damped_sine_wave(x, f, A, st, ϕ, d) = exp((st - x) * d) * A * sin(2 * π * f *
295295

296296
u0 = [cap.v => 0.0]
297297

298-
prob = ODAEProblem(vsys, u0, (0, 10.0))
298+
prob = ODEProblem(vsys, u0, (0, 10.0))
299299
sol = solve(prob, dt = 0.1, Tsit5())
300300

301301
@test sol.retcode == Success
@@ -361,7 +361,7 @@ end
361361

362362
u0 = [cap.v => 0.0]
363363

364-
prob = ODAEProblem(isys, u0, (0, 10.0))
364+
prob = ODEProblem(isys, u0, (0, 10.0))
365365
sol = solve(prob, dt = 0.1, Tsit5())
366366

367367
@test sol.retcode == Success

test/Mechanical/rotational.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ using OrdinaryDiffEq: ReturnCode.Success
2626
sol1 = solve(prob, Rodas4())
2727
@test SciMLBase.successful_retcode(sol1)
2828

29-
prob = ODAEProblem(sys, Pair[], (0, 10.0))
29+
prob = ODEProblem(sys, Pair[], (0, 10.0))
3030
sol = solve(prob, Rodas4())
3131
@test SciMLBase.successful_retcode(sol)
3232

33-
prob = DAEProblem(sys, D.(states(sys)) .=> 0.0, Pair[], (0, 10.0))
33+
prob = DAEProblem(sys, D.(unknowns(sys)) .=> 0.0, Pair[], (0, 10.0))
3434
sol = solve(prob, DFBDF())
3535
@test SciMLBase.successful_retcode(sol)
3636
@test all(sol[inertia1.w] .== 0)
@@ -84,12 +84,12 @@ end
8484
sine
8585
])
8686
sys = structural_simplify(model)
87-
prob = DAEProblem(sys, D.(states(sys)) .=> 0.0,
88-
[D(D(inertia2.phi)) => 1.0; D.(states(model)) .=> 0.0], (0, 10.0))
87+
prob = DAEProblem(sys, D.(unknowns(sys)) .=> 0.0,
88+
[D(D(inertia2.phi)) => 1.0; D.(unknowns(model)) .=> 0.0], (0, 10.0))
8989
sol = solve(prob, DFBDF())
9090
@test SciMLBase.successful_retcode(sol)
9191

92-
prob = ODAEProblem(sys, Pair[], (0, 1.0))
92+
prob = ODEProblem(sys, Pair[], (0, 1.0))
9393
sol = solve(prob, Rodas4())
9494
@test SciMLBase.successful_retcode(sol)
9595

@@ -164,7 +164,7 @@ end
164164
])
165165
@test_skip begin
166166
sys = structural_simplify(model) #key 7 not found
167-
prob = ODAEProblem(sys, Pair[], (0, 1.0))
167+
prob = ODEProblem(sys, Pair[], (0, 1.0))
168168
sol = solve(prob, Rodas4())
169169
@test SciMLBase.successful_retcode(sol)
170170
end
@@ -212,7 +212,7 @@ end
212212
angle_sensor
213213
])
214214
sys = structural_simplify(model)
215-
prob = DAEProblem(sys, D.(states(sys)) .=> 0.0, Pair[], (0, 10.0))
215+
prob = DAEProblem(sys, D.(unknowns(sys)) .=> 0.0, Pair[], (0, 10.0))
216216

217217
sol = solve(prob, DFBDF())
218218
@test SciMLBase.successful_retcode(sol)
@@ -259,7 +259,7 @@ end
259259
@test all(sol[rel_speed_sensor.w_rel.u] .== sol[speed_sensor.w.u])
260260
@test all(sol[torque_sensor.tau.u] .== -sol[inertia1.flange_b.tau])
261261

262-
prob = DAEProblem(sys, D.(states(sys)) .=> 0.0, Pair[], (0, 10.0))
262+
prob = DAEProblem(sys, D.(unknowns(sys)) .=> 0.0, Pair[], (0, 10.0))
263263
sol = solve(prob, DFBDF())
264264
@test SciMLBase.successful_retcode(sol)
265265
@test all(sol[inertia1.w] .== 0)

test/multi_domain.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ using OrdinaryDiffEq: ReturnCode.Success
7070
@test sol[inertia.w][idx_t](dc_gain * [V_step; -tau_L_step])[2] rtol=1e-3
7171
@test sol[emf.i][idx_t](dc_gain * [V_step; -tau_L_step])[1] rtol=1e-3
7272

73-
prob = DAEProblem(sys, D.(states(sys)) .=> 0.0, Pair[], (0, 6.0))
73+
prob = DAEProblem(sys, D.(unknowns(sys)) .=> 0.0, Pair[], (0, 6.0))
7474
sol = solve(prob, DFBDF())
7575
@test sol.retcode == Success
7676
# EMF equations
@@ -159,7 +159,7 @@ end
159159

160160
@test all(sol[inertia.w] .== sol[speed_sensor.w.u])
161161

162-
prob = DAEProblem(sys, D.(states(sys)) .=> 0.0, Pair[], (0, 6.0))
162+
prob = DAEProblem(sys, D.(unknowns(sys)) .=> 0.0, Pair[], (0, 6.0))
163163
sol = solve(prob, DFBDF())
164164

165165
@test sol.retcode == Success

0 commit comments

Comments
 (0)