Skip to content

Commit 8c54b15

Browse files
committed
init fixes
1 parent 0937cc6 commit 8c54b15

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

docs/src/batch_linearization.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ This example will demonstrate how to linearize a nonlinear ModelingToolkit model
88
The model will be a simple Duffing oscillator:
99
```@example BATCHLIN
1010
using ControlSystemsMTK, ModelingToolkit, MonteCarloMeasurements, ModelingToolkitStandardLibrary.Blocks
11-
using ModelingToolkit: getdefault
1211
unsafe_comparisons(true)
1312
1413
# Create a model
@@ -26,15 +25,15 @@ eqs = [D(x) ~ v
2625
y.u ~ x]
2726
2827
29-
@named duffing = ODESystem(eqs, t, systems=[y, u], defaults=[u.u => 0])
28+
@named duffing = ODESystem(eqs, t, systems=[y, u])
3029
```
3130

3231
## Batch linearization
3332
To perform batch linearization, we create a vector of operating points, and then linearize the model around each of these points. The function [`batch_ss`](@ref) does this for us, and returns a vector of `StateSpace` models, one for each operating point. An operating point is a `Dict` that maps variables in the MTK model to numerical values. In the example below, we simply sample the variables uniformly within their bounds specified when we created the variables (normally, we might want to linearize on stationary points)
3433
```@example BATCHLIN
3534
N = 16 # Number of samples
3635
xs = range(getbounds(x)[1], getbounds(x)[2], length=N)
37-
ops = Dict.(x .=> xs)
36+
ops = Dict.(u.u => 0, x .=> xs)
3837
```
3938

4039
Just like [`ModelingToolkit.linearize`](@ref), [`batch_ss`](@ref) takes the set of inputs and the set of outputs to linearize between.
@@ -155,7 +154,7 @@ The generated code starts by defining the interpolation vector `xs`, this variab
155154
We can linearize around a trajectory obtained from `solve` using the function [`trajectory_ss`](@ref). We provide it with a vector of time points along the trajectory at which to linearize, and in this case we specify the inputs and outputs to linearize between as analysis points `r` and `y`.
156155
```@example BATCHLIN
157156
timepoints = 0:0.01:8
158-
Ps2, ssys = trajectory_ss(closed_loop, closed_loop.r, closed_loop.y, sol; t=timepoints)
157+
Ps2, ssys = trajectory_ss(closed_loop, closed_loop.r, closed_loop.y, sol; t=timepoints, initialize=true, verbose=true)
159158
bodeplot(Ps2, w, legend=false)
160159
```
161160

src/ode_system.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,9 @@ function trajectory_ss(sys, inputs, outputs, sol; t = _max_100(sol.t), allow_inp
525525
minimum(t) < minimum(sol.t) && @warn("The minimum time in `t`: $(minimum(t)), is smaller than the minimum time in `sol.t`: $(minimum(sol.t)).")
526526

527527
# NOTE: we call linearization_funciton twice :( The first call is to get x=unknowns(ssys), the second call provides the operating points.
528-
lin_fun, ssys = linearization_function(sys, inputs, outputs; kwargs...)
528+
# lin_fun, ssys = linearization_function(sys, inputs, outputs; warn_initialize_determined = false, kwargs...)
529+
lin_fun, ssys = linearization_function(sys, inputs, outputs; warn_initialize_determined = false, kwargs...)
530+
529531
x = unknowns(ssys)
530532
defs = ModelingToolkit.defaults(sys)
531533
ops = map(t) do ti
@@ -538,7 +540,7 @@ function trajectory_ss(sys, inputs, outputs, sol; t = _max_100(sol.t), allow_inp
538540
ops = reduce(vcat, opsv)
539541
t = repeat(t, inner = length(ops) ÷ length(t))
540542
end
541-
lin_fun, ssys = linearization_function(sys, inputs, outputs; op=ops[1], kwargs...)
543+
# lin_fun, ssys = linearization_function(sys, inputs, outputs; op=ops[1], initialize, kwargs...)
542544
lins = map(zip(ops, t)) do (op, t)
543545
linearize(ssys, lin_fun; op, t, allow_input_derivatives)
544546
# linearize(sys, inputs, outputs; op, t, allow_input_derivatives, initialize=false)[1]
@@ -676,7 +678,7 @@ function GainScheduledStateSpace(systems, vt; interpolator, x = zeros(systems[1]
676678
@variables x(t)[1:nx]=x [
677679
description = "State variables of gain-scheduled statespace system $name",
678680
]
679-
@variables v(t) = 0 [
681+
@variables v(t) [
680682
description = "Scheduling variable of gain-scheduled statespace system $name",
681683
]
682684

0 commit comments

Comments
 (0)