Skip to content

Commit 37831a9

Browse files
committed
debug: use linmodel.buffer in linearize!
1 parent ffc3bda commit 37831a9

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/model/linearization.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,15 @@ function linearize!(
160160
linmodel::LinModel{NT}, model::SimModel;
161161
x=(model.buffer.x.=model.x0.+model.xop), u=model.uop, d=model.dop
162162
) where NT<:Real
163-
nonlinmodel = model
164-
buffer = nonlinmodel.buffer
163+
# using linmodel.buffer since default arguments already use model.buffer:
164+
nonlinmodel, buffer = model, linmodel.buffer
165+
# --- compute the Jacobians at linearization points ---
166+
linearize_core!(linmodel, nonlinmodel, x, u, d) # no deviation vectors in model.linfunc!
165167
# --- remove the operating points of the nonlinear model (typically zeros) ---
166168
x0, u0, d0, k0 = buffer.x, buffer.u, buffer.d, buffer.k
167169
x0 .= x .- nonlinmodel.xop
168170
u0 .= u .- nonlinmodel.uop
169171
d0 .= d .- nonlinmodel.dop
170-
# --- compute the Jacobians at linearization points ---
171-
linearize_core!(linmodel, nonlinmodel, x0, u0, d0)
172172
# --- compute the nonlinear model output at operating points ---
173173
x0next, y0 = linmodel.buffer.x, linmodel.buffer.y
174174
h!(y0, nonlinmodel, x0, d0, model.p)
@@ -177,7 +177,7 @@ function linearize!(
177177
# --- compute the nonlinear model next state at operating points ---
178178
f!(x0next, k0, nonlinmodel, x0, u0, d0, model.p)
179179
xnext = x0next
180-
xnext .= x0next .+ nonlinmodel.fop .- nonlinmodel.xop
180+
xnext .= x0next .+ nonlinmodel.xop
181181
# --- modify the linear model operating points ---
182182
linmodel.uop .= u
183183
linmodel.yop .= y
@@ -190,14 +190,14 @@ function linearize!(
190190
end
191191

192192
"Call `linfunc!` function to compute the Jacobians of `model` at the linearization point."
193-
function linearize_core!(linmodel::LinModel, model::SimModel, x0, u0, d0)
194-
x0next, y0 = linmodel.buffer.x, linmodel.buffer.y
193+
function linearize_core!(linmodel::LinModel, model::SimModel, x, u, d)
194+
xnext, y = linmodel.buffer.x, linmodel.buffer.y
195195
A, Bu, C, Bd, Dd = linmodel.A, linmodel.Bu, linmodel.C, linmodel.Bd, linmodel.Dd
196-
cst_x = Constant(x0)
197-
cst_u = Constant(u0)
198-
cst_d = Constant(d0)
196+
cst_x = Constant(x)
197+
cst_u = Constant(u)
198+
cst_d = Constant(d)
199199
backend = model.jacobian
200-
model.linfunc!(x0next, y0, A, Bu, C, Bd, Dd, backend, x0, u0, d0, cst_x, cst_u, cst_d)
200+
model.linfunc!(xnext, y, A, Bu, C, Bd, Dd, backend, x, u, d, cst_x, cst_u, cst_d)
201201
return nothing
202202
end
203203

0 commit comments

Comments
 (0)