Skip to content

Commit e5257d6

Browse files
YingboMabaggepinnen
andcommitted
Consistently initialize before computing the linearization
Co-authored-by: Fredrik Bagge Carlson <[email protected]>
1 parent a69570a commit e5257d6

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
3131
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
3232
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
3333
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
34+
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
3435
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
3536
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
3637
RuntimeGeneratedFunctions = "7e49a35a-f44a-4d26-94aa-eba1b4ca6b47"
@@ -78,6 +79,7 @@ Latexify = "0.11, 0.12, 0.13, 0.14, 0.15, 0.16"
7879
MLStyle = "0.4.17"
7980
MacroTools = "0.5"
8081
NaNMath = "0.3, 1"
82+
OrdinaryDiffEq = "6"
8183
RecursiveArrayTools = "2.3"
8284
Reexport = "0.2, 1"
8385
RuntimeGeneratedFunctions = "0.5.9"
@@ -107,7 +109,6 @@ NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
107109
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
108110
OptimizationMOI = "fd9f6733-72f4-499f-8506-86b2bdd0dea1"
109111
OptimizationOptimJL = "36348300-93cb-4f02-beb5-3c3902f8871e"
110-
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
111112
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
112113
ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf"
113114
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"

src/systems/abstractsystem.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using OrdinaryDiffEq
12
const SYSTEM_COUNT = Threads.Atomic{UInt}(0)
23

34
get_component_type(x::AbstractSystem) = get_gui_metadata(x).type
@@ -1294,6 +1295,9 @@ function linearization_function(sys::AbstractSystem, inputs,
12941295
if u !== nothing # Handle systems without states
12951296
length(sts) == length(u) ||
12961297
error("Number of state variables ($(length(sts))) does not match the number of input states ($(length(u)))")
1298+
prob = ODEProblem(fun, u, (t, t + 1), p)
1299+
integ = init(prob, Rodas5P())
1300+
u = integ.u
12971301
uf = SciMLBase.UJacobianWrapper(fun, t, p)
12981302
fg_xz = ForwardDiff.jacobian(uf, u)
12991303
h_xz = ForwardDiff.jacobian(let p = p, t = t

0 commit comments

Comments
 (0)