Skip to content

Commit 07c65c8

Browse files
refactor: use unknowns, fix some tests
1 parent 0ced536 commit 07c65c8

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/Blocks/analysis_points.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function ap_var(sys)
2323
# collect to turn symbolic arrays into arrays of symbols
2424
return length(sys.u) == 1 ? sys.u : collect(sys.u)
2525
end
26-
x = states(sys)
26+
x = unknowns(sys)
2727
length(x) == 1 && return x[1]
2828
error("Could not determine the analysis-point variable in system $(nameof(sys)). To use an analysis point, apply it to a connection between two causal blocks containing connectors of type `RealInput/RealOutput` from ModelingToolkitStandardLibrary.Blocks.")
2929
end

test/Blocks/test_analysis_points.jl

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

2828
matrices, _ = get_sensitivity(sys, ap)

test/Mechanical/multibody.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ eqs = [connect(link1.TX1, cart.flange) #, force.flange)
2222
@named model = ODESystem(eqs, t, [], []; systems = [link1, link2, cart, fixed])
2323

2424
sys = structural_simplify(model)
25-
@test length(states(sys)) == 6
25+
@test length(unknowns(sys)) == 6
2626

2727
# The below code does work...
2828
#=

test/Mechanical/rotational.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ using OrdinaryDiffEq: ReturnCode.Success
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,8 +84,8 @@ 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

@@ -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)

0 commit comments

Comments
 (0)