Skip to content

Commit ea431a1

Browse files
committed
test handling of operating point in linearization
1 parent e1f0ffd commit ea431a1

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/systems/abstractsystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ function linearization_function(sys::AbstractSystem, inputs, outputs; simplify =
10401040
else
10411041
length(sts) == 0 ||
10421042
error("Number of state variables does not match the number of input states")
1043-
fg_xz = zeros(0,0)
1043+
fg_xz = zeros(0, 0)
10441044
h_xz = fg_u = zeros(0, length(inputs))
10451045
end
10461046
h_u = ForwardDiff.jacobian(p -> h(u, p, t), p)[:, input_idxs]

test/linearize.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,29 @@ lsys = ModelingToolkit.reorder_states(lsys, states(ssys), reverse(desired_order)
107107
## Test operating points
108108

109109
# The saturation has no dynamics
110-
function saturation(; y_max, y_min=y_max > 0 ? -y_max : -Inf, name)
110+
function saturation(; y_max, y_min = y_max > 0 ? -y_max : -Inf, name)
111111
@variables u(t)=0 y(t)=0
112112
@parameters y_max=y_max y_min=y_min
113113
ie = ModelingToolkit.IfElse.ifelse
114114
eqs = [
115115
# The equation below is equivalent to y ~ clamp(u, y_min, y_max)
116-
y ~ ie(u > y_max, y_max, ie( (y_min < u) & (u < y_max), u, y_min))
116+
y ~ ie(u > y_max, y_max, ie((y_min < u) & (u < y_max), u, y_min)),
117117
]
118-
ODESystem(eqs, t, name=name)
118+
ODESystem(eqs, t, name = name)
119119
end
120120

121-
@named sat = saturation(; y_max=1)
121+
@named sat = saturation(; y_max = 1)
122122
# inside the linear region, the function is identity
123-
@unpack u,y = sat
123+
@unpack u, y = sat
124124
lsys, ssys = linearize(sat, [u], [y])
125125
@test isempty(lsys.A) # there are no differential variables in this system
126126
@test isempty(lsys.B)
127127
@test isempty(lsys.C)
128128
@test lsys.D[] == 1
129+
130+
# outside the linear region the derivative is 0
131+
lsys, ssys = linearize(sat, [u], [y]; op = Dict(u => 2))
132+
@test isempty(lsys.A) # there are no differential variables in this system
133+
@test isempty(lsys.B)
134+
@test isempty(lsys.C)
135+
@test lsys.D[] == 0

0 commit comments

Comments
 (0)