Skip to content

Commit ddd09dc

Browse files
committed
avoid creating full ODEProblem
1 parent fb8d58b commit ddd09dc

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/systems/abstractsystem.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,8 +1090,8 @@ function markio!(state, inputs, outputs)
10901090
end
10911091

10921092
"""
1093-
(; A, B, C, D), simplified_sys = linearize(sys, inputs, outputs; op = Dict(), allow_input_derivatives = false, kwargs...)
1094-
(; A, B, C, D) = linearize(simplified_sys, lin_fun; op = Dict(), allow_input_derivatives = false)
1093+
(; A, B, C, D), simplified_sys = linearize(sys, inputs, outputs; t=0.0, op = Dict(), allow_input_derivatives = false, kwargs...)
1094+
(; A, B, C, D) = linearize(simplified_sys, lin_fun; t=0.0, op = Dict(), allow_input_derivatives = false)
10951095
10961096
Return a NamedTuple with the matrices of a linear statespace representation
10971097
on the form
@@ -1179,10 +1179,12 @@ lsys = ModelingToolkit.reorder_states(lsys, states(ssys), desired_order)
11791179
@assert lsys.D[] == 0
11801180
```
11811181
"""
1182-
function linearize(sys, lin_fun; op = Dict(), allow_input_derivatives = false)
1182+
function linearize(sys, lin_fun; t = 0.0, op = Dict(), allow_input_derivatives = false,
1183+
p = DiffEqBase.NullParameters())
11831184
x0 = merge(defaults(sys), op)
1184-
prob = ODEProblem(sys, x0, (0.0, 1.0))
1185-
linres = lin_fun(prob.u0, prob.p, 0.0)
1185+
f, u0, p = process_DEProblem(ODEFunction{true}, sys, x0, p)
1186+
1187+
linres = lin_fun(u0, p, t)
11861188
f_x, f_z, g_x, g_z, f_u, g_u, h_x, h_z, h_u = linres
11871189

11881190
nx, nu = size(f_u)

test/linearize.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ lsys = ModelingToolkit.reorder_states(lsys, states(ssys), reverse(desired_order)
105105
@test lsys.D == [4400 -4400]
106106

107107
## Test that there is a warning when input is misspecified
108-
if VERSION >= v"1.7"
108+
if VERSION >= v"1.8"
109109
@test_throws "Some specified inputs were not found" linearize(pid,
110110
[
111111
pid.reference.u,

0 commit comments

Comments
 (0)