Skip to content

Commit f6dfcaa

Browse files
committed
handle analysis points in addition to symbols
1 parent 23739c4 commit f6dfcaa

File tree

1 file changed

+34
-39
lines changed

1 file changed

+34
-39
lines changed

src/ode_system.jl

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using ModelingToolkit: AnalysisPoint
2+
const AP = Union{Symbol, AnalysisPoint}
13
import ModelingToolkitStandardLibrary.Blocks as Blocks
24
conn = ModelingToolkit.connect
35
t = Blocks.t
@@ -168,40 +170,36 @@ function RobustAndOptimalControl.named_ss(
168170
kwargs...,
169171
)
170172

171-
if isa(inputs, Symbol)
172-
nu = 1
173-
else
174-
inputs = map(inputs) do inp
175-
if inp isa ODESystem
176-
@variables u(t)
177-
if u Set(unknowns(inp))
178-
inp.u
179-
else
180-
error("Input $(inp.name) is an ODESystem and not a variable")
181-
end
173+
inputs = vcat(inputs)
174+
outputs = vcat(outputs)
175+
176+
inputs = map(inputs) do inp
177+
if inp isa ODESystem
178+
@variables u(t)
179+
if u Set(unknowns(inp))
180+
inp.u
182181
else
183-
inp
182+
error("Input $(inp.name) is an ODESystem and not a variable")
184183
end
184+
else
185+
inp
185186
end
186-
nu = length(inputs)
187187
end
188-
if isa(outputs, Symbol)
189-
ny = 1
190-
else
191-
outputs = map(outputs) do out
192-
if out isa ODESystem
193-
@variables u(t)
194-
if u Set(unknowns(out))
195-
out.u
196-
else
197-
error("Outut $(out.name) is an ODESystem and not a variable")
198-
end
188+
nu = length(inputs)
189+
190+
outputs = map(outputs) do out
191+
if out isa ODESystem
192+
@variables u(t)
193+
if u Set(unknowns(out))
194+
out.u
199195
else
200-
out
196+
error("Outut $(out.name) is an ODESystem and not a variable")
201197
end
198+
else
199+
out
202200
end
203-
ny = length(outputs)
204201
end
202+
ny = length(outputs)
205203
matrices, ssys = ModelingToolkit.linearize(sys, inputs, outputs; kwargs...)
206204
symstr(x) = Symbol(string(x))
207205
unames = symstr.(inputs)
@@ -276,23 +274,20 @@ function named_sensitivity_function(
276274
kwargs...,
277275
)
278276

279-
if isa(inputs, Symbol)
280-
nu = 1
281-
else
282-
inputs = map(inputs) do inp
283-
if inp isa ODESystem
284-
@variables u(t)
285-
if u Set(unknowns(inp))
286-
inp.u
287-
else
288-
error("Input $(inp.name) is an ODESystem and not a variable")
289-
end
277+
inputs = vcat(inputs)
278+
inputs = map(inputs) do inp
279+
if inp isa ODESystem
280+
@variables u(t)
281+
if u Set(unknowns(inp))
282+
inp.u
290283
else
291-
inp
284+
error("Input $(inp.name) is an ODESystem and not a variable")
292285
end
286+
else
287+
inp
293288
end
294-
nu = length(inputs)
295289
end
290+
nu = length(inputs)
296291
matrices, ssys = fun(sys, inputs, args...; kwargs...)
297292
symstr(x) = Symbol(string(x))
298293
unames = symstr.(inputs)

0 commit comments

Comments
 (0)