Skip to content

Commit 0153147

Browse files
committed
simplify implementation of named_sensitivity_function
1 parent 14cd42b commit 0153147

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

docs/src/batch_linearization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ We will explore these options below, starting with the first option, breaking th
175175
```@example BATCHLIN
176176
kwargs = (; adaptive=false, legend=false)
177177
plants, _ = trajectory_ss(closed_loop, closed_loop.u, closed_loop.y, sol; t=timepoints, verbose=true, loop_openings=[closed_loop.u]);
178-
controllersy, ssy = trajectory_ss(closed_loop, closed_loop.r, closed_loop.u, sol; t=timepoints, verbose=true, loop_openings=[closed_loop.y]);
178+
controllersy, ssy, ops3, resolved_ops3 = trajectory_ss(closed_loop, closed_loop.r, closed_loop.u, sol; t=timepoints, verbose=true, loop_openings=[closed_loop.y]);
179179
180180
closed_loopsy = feedback.(plants .* controllersy)
181181
bodeplot(closed_loopsy, w; title="Loop open at y", kwargs...)

src/ode_system.jl

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,13 @@ function named_sensitivity_function(
197197
fun,
198198
sys::ModelingToolkit.AbstractSystem,
199199
inputs, args...;
200+
descriptor = true,
200201
kwargs...,
201202
)
202203

203204
inputs = vcat(inputs)
204205
inputs = map(inputs) do inp
205-
if inp isa System
206+
if inp isa System
206207
@variables u(t)
207208
if u Set(unknowns(inp))
208209
inp.u
@@ -219,23 +220,10 @@ function named_sensitivity_function(
219220
unames = symstr.(inputs)
220221
fm(x) = convert(Matrix{Float64}, x)
221222
if nu > 0 && size(matrices.B, 2) == 2nu
222-
nx = size(matrices.A, 1)
223-
# This indicates that input derivatives are present
224-
duinds = findall(any(!iszero, eachcol(matrices.B[:, nu+1:end])))
225-
= matrices.B[:, duinds .+ nu]
226-
ndu = length(duinds)
227-
B = matrices.B[:, 1:nu]
228-
Iu = duinds .== (1:nu)'
229-
E = [I(nx) -B̄; zeros(ndu, nx+ndu)]
230-
231-
Ae = cat(matrices.A, -I(ndu), dims=(1,2))
232-
Be = [B; Iu]
233-
Ce = [fm(matrices.C) zeros(ny, ndu)]
234-
De = fm(matrices.D[:, 1:nu])
235-
dsys = dss(Ae, E, Be, Ce, De)
236-
lsys = ss(RobustAndOptimalControl.DescriptorSystems.dss2ss(dsys)[1])
237-
# unames = [unames; Symbol.("der_" .* string.(unames))]
238-
# sys = ss(matrices...)
223+
# This indicates that input derivatives are present
224+
duinds = findall(any(!iszero, eachcol(matrices.B[:, nu+1:end]))) .+ nu
225+
u2du = (1:nu) .=> duinds # This maps inputs to their derivatives
226+
lsys = causal_simplification(matrices, u2du; descriptor)
239227
else
240228
lsys = ss(matrices...)
241229
end

0 commit comments

Comments
 (0)