Skip to content

Commit 1a96915

Browse files
YingboMabaggepinnen
andcommitted
Fix zero_dummy_der
Co-authored-by: Fredrik Bagge Carlson <baggepinnen@gmail.com>
1 parent a9c56b6 commit 1a96915

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/systems/abstractsystem.jl

+16-6
Original file line numberDiff line numberDiff line change
@@ -1277,9 +1277,18 @@ function linearization_function(sys::AbstractSystem, inputs,
12771277
initialize = true,
12781278
op = Dict(),
12791279
p = DiffEqBase.NullParameters(),
1280+
zero_dummy_der = false,
12801281
kwargs...)
1281-
sys, diff_idxs, alge_idxs, input_idxs = io_preprocessing(sys, inputs, outputs; simplify,
1282+
ssys, diff_idxs, alge_idxs, input_idxs = io_preprocessing(sys, inputs, outputs;
1283+
simplify,
12821284
kwargs...)
1285+
if zero_dummy_der
1286+
dummyder = setdiff(states(ssys), states(sys))
1287+
defs = Dict(x => 0.0 for x in dummyder)
1288+
@set! ssys.defaults = merge(defs, defaults(ssys))
1289+
op = merge(defs, op)
1290+
end
1291+
sys = ssys
12831292
x0 = merge(defaults(sys), op)
12841293
u0, p, _ = get_u0_p(sys, x0, p; use_union = false, tofloat = true)
12851294
p, split_idxs = split_parameters_by_type(p)
@@ -1612,11 +1621,12 @@ function linearize(sys, inputs, outputs; op = Dict(), t = 0.0,
16121621
allow_input_derivatives = false,
16131622
zero_dummy_der = false,
16141623
kwargs...)
1615-
if zero_dummy_der
1616-
dummyder = setdiff(states(ssys), states(sys))
1617-
op = merge(op, Dict(x => 0.0 for x in dummyder))
1618-
end
1619-
lin_fun, ssys = linearization_function(sys, inputs, outputs; op, kwargs...)
1624+
lin_fun, ssys = linearization_function(sys,
1625+
inputs,
1626+
outputs;
1627+
zero_dummy_der,
1628+
op,
1629+
kwargs...)
16201630
linearize(ssys, lin_fun; op, t, allow_input_derivatives), ssys
16211631
end
16221632

test/input_output_handling.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ using ModelingToolkitStandardLibrary.Mechanical.Rotational
124124
t = ModelingToolkitStandardLibrary.Mechanical.Rotational.t
125125
@named inertia1 = Inertia(; J = 1)
126126
@named inertia2 = Inertia(; J = 1)
127-
@named spring = Spring(; c = 10)
128-
@named damper = Damper(; d = 3)
127+
@named spring = Rotational.Spring(; c = 10)
128+
@named damper = Rotational.Damper(; d = 3)
129129
@named torque = Torque(; use_support = false)
130130
@variables y(t) = 0
131131
eqs = [connect(torque.flange, inertia1.flange_a)

0 commit comments

Comments
 (0)