Skip to content

Commit

Permalink
Fix zero_dummy_der
Browse files Browse the repository at this point in the history
Co-authored-by: Fredrik Bagge Carlson <[email protected]>
  • Loading branch information
YingboMa and baggepinnen committed Sep 26, 2023
1 parent a9c56b6 commit 1a96915
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
22 changes: 16 additions & 6 deletions src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1277,9 +1277,18 @@ function linearization_function(sys::AbstractSystem, inputs,
initialize = true,
op = Dict(),
p = DiffEqBase.NullParameters(),
zero_dummy_der = false,
kwargs...)
sys, diff_idxs, alge_idxs, input_idxs = io_preprocessing(sys, inputs, outputs; simplify,
ssys, diff_idxs, alge_idxs, input_idxs = io_preprocessing(sys, inputs, outputs;

Check warning on line 1282 in src/systems/abstractsystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/abstractsystem.jl#L1282

Added line #L1282 was not covered by tests
simplify,
kwargs...)
if zero_dummy_der
dummyder = setdiff(states(ssys), states(sys))
defs = Dict(x => 0.0 for x in dummyder)
@set! ssys.defaults = merge(defs, defaults(ssys))
op = merge(defs, op)

Check warning on line 1289 in src/systems/abstractsystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/abstractsystem.jl#L1285-L1289

Added lines #L1285 - L1289 were not covered by tests
end
sys = ssys
x0 = merge(defaults(sys), op)
u0, p, _ = get_u0_p(sys, x0, p; use_union = false, tofloat = true)
p, split_idxs = split_parameters_by_type(p)
Expand Down Expand Up @@ -1612,11 +1621,12 @@ function linearize(sys, inputs, outputs; op = Dict(), t = 0.0,
allow_input_derivatives = false,
zero_dummy_der = false,
kwargs...)
if zero_dummy_der
dummyder = setdiff(states(ssys), states(sys))
op = merge(op, Dict(x => 0.0 for x in dummyder))
end
lin_fun, ssys = linearization_function(sys, inputs, outputs; op, kwargs...)
lin_fun, ssys = linearization_function(sys,

Check warning on line 1624 in src/systems/abstractsystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/abstractsystem.jl#L1624

Added line #L1624 was not covered by tests
inputs,
outputs;
zero_dummy_der,
op,
kwargs...)
linearize(ssys, lin_fun; op, t, allow_input_derivatives), ssys
end

Expand Down
4 changes: 2 additions & 2 deletions test/input_output_handling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ using ModelingToolkitStandardLibrary.Mechanical.Rotational
t = ModelingToolkitStandardLibrary.Mechanical.Rotational.t
@named inertia1 = Inertia(; J = 1)
@named inertia2 = Inertia(; J = 1)
@named spring = Spring(; c = 10)
@named damper = Damper(; d = 3)
@named spring = Rotational.Spring(; c = 10)
@named damper = Rotational.Damper(; d = 3)
@named torque = Torque(; use_support = false)
@variables y(t) = 0
eqs = [connect(torque.flange, inertia1.flange_a)
Expand Down

0 comments on commit 1a96915

Please sign in to comment.