Skip to content

Commit

Permalink
refactor: use unknowns, fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Feb 14, 2024
1 parent 2431138 commit fb03256
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Blocks/analysis_points.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function ap_var(sys)
# collect to turn symbolic arrays into arrays of symbols
return length(sys.u) == 1 ? sys.u : collect(sys.u)
end
x = states(sys)
x = unknowns(sys)
length(x) == 1 && return x[1]
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.")
end
Expand Down
4 changes: 2 additions & 2 deletions test/Blocks/test_analysis_points.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ sys = ODESystem(eqs, t, systems = [P, C], name = :hej)
ssys = structural_simplify(sys)
prob = ODEProblem(ssys, [P.x => 1], (0, 10))
sol = solve(prob, Rodas5())
@test norm(sol[1]) >= 1
@test norm(sol[end]) < 1e-6 # This fails without the feedback through C
@test norm(sol.u[1]) >= 1
@test norm(sol.u[end]) < 1e-6 # This fails without the feedback through C
# plot(sol)

matrices, _ = get_sensitivity(sys, ap)
Expand Down
2 changes: 1 addition & 1 deletion test/Mechanical/multibody.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ eqs = [connect(link1.TX1, cart.flange) #, force.flange)
@named model = ODESystem(eqs, t, [], []; systems = [link1, link2, cart, fixed])

sys = structural_simplify(model)
@test length(states(sys)) == 6
@test length(unknowns(sys)) == 6

# The below code does work...
#=
Expand Down
10 changes: 5 additions & 5 deletions test/Mechanical/rotational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ using OrdinaryDiffEq: ReturnCode.Success
sol = solve(prob, Rodas4())
@test SciMLBase.successful_retcode(sol)

prob = DAEProblem(sys, D.(states(sys)) .=> 0.0, Pair[], (0, 10.0))
prob = DAEProblem(sys, D.(unknowns(sys)) .=> 0.0, Pair[], (0, 10.0))
sol = solve(prob, DFBDF())
@test SciMLBase.successful_retcode(sol)
@test all(sol[inertia1.w] .== 0)
Expand Down Expand Up @@ -84,8 +84,8 @@ end
sine,
])
sys = structural_simplify(model)
prob = DAEProblem(sys, D.(states(sys)) .=> 0.0,
[D(D(inertia2.phi)) => 1.0; D.(states(model)) .=> 0.0], (0, 10.0))
prob = DAEProblem(sys, D.(unknowns(sys)) .=> 0.0,
[D(D(inertia2.phi)) => 1.0; D.(unknowns(model)) .=> 0.0], (0, 10.0))
sol = solve(prob, DFBDF())
@test SciMLBase.successful_retcode(sol)

Expand Down Expand Up @@ -212,7 +212,7 @@ end
angle_sensor,
])
sys = structural_simplify(model)
prob = DAEProblem(sys, D.(states(sys)) .=> 0.0, Pair[], (0, 10.0))
prob = DAEProblem(sys, D.(unknowns(sys)) .=> 0.0, Pair[], (0, 10.0))

sol = solve(prob, DFBDF())
@test SciMLBase.successful_retcode(sol)
Expand Down Expand Up @@ -259,7 +259,7 @@ end
@test all(sol[rel_speed_sensor.w_rel.u] .== sol[speed_sensor.w.u])
@test all(sol[torque_sensor.tau.u] .== -sol[inertia1.flange_b.tau])

prob = DAEProblem(sys, D.(states(sys)) .=> 0.0, Pair[], (0, 10.0))
prob = DAEProblem(sys, D.(unknowns(sys)) .=> 0.0, Pair[], (0, 10.0))
sol = solve(prob, DFBDF())
@test SciMLBase.successful_retcode(sol)
@test all(sol[inertia1.w] .== 0)
Expand Down
4 changes: 2 additions & 2 deletions test/multi_domain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ using OrdinaryDiffEq: ReturnCode.Success
@test sol[inertia.w][idx_t](dc_gain * [V_step; -tau_L_step])[2] rtol=1e-3
@test sol[emf.i][idx_t](dc_gain * [V_step; -tau_L_step])[1] rtol=1e-3

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

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

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

@test sol.retcode == Success
Expand Down

0 comments on commit fb03256

Please sign in to comment.