Skip to content

Commit bea6a41

Browse files
BenChungAayushSabharwal
authored andcommitted
Better support for multi-adic operators
1 parent 8b7e1f7 commit bea6a41

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

src/clock.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ function is_discrete_domain(x)
101101
end
102102

103103
sampletime(c) = Moshi.Match.@match c begin
104+
x::SciMLBase.AbstractClock => nothing
104105
PeriodicClock(dt) => dt
105106
_ => nothing
106107
end

src/discretedomain.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,15 +363,25 @@ sampletime(op::ShiftIndex, _ = nothing) = sampletime(op.clock)
363363

364364
function output_timedomain(x)
365365
if isoperator(x, Operator)
366-
return output_timedomain(operation(x), arguments(x)[])
366+
args = arguments(x)
367+
return output_timedomain(operation(x), if length(args) == 1
368+
args[]
369+
else
370+
args
371+
end)
367372
else
368373
throw(ArgumentError("$x of type $(typeof(x)) is not an operator expression"))
369374
end
370375
end
371376

372377
function input_timedomain(x)
373378
if isoperator(x, Operator)
374-
return input_timedomain(operation(x), arguments(x)[])
379+
args = arguments(x)
380+
return input_timedomain(operation(x), if length(args) == 1
381+
args[]
382+
else
383+
args
384+
end)
375385
else
376386
throw(ArgumentError("$x of type $(typeof(x)) is not an operator expression"))
377387
end

src/systems/clock_inference.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,16 @@ function infer_clocks!(ci::ClockInference)
142142
# now we only care about synchronous operators
143143
iscall(var) || continue
144144
op = operation(var)
145-
is_synchronous_operator(op) || continue
145+
if (!is_synchronous_operator(op)) && !(op isa Differential)
146+
continue
147+
end
146148

147149
# arguments and corresponding time domains
148150
args = arguments(var)
149151
tdomains = input_timedomain(op)
152+
if !(tdomains isa AbstractArray || tdomains isa Tuple)
153+
tdomains = [tdomains]
154+
end
150155
nargs = length(args)
151156
ndoms = length(tdomains)
152157
if nargs != ndoms

src/systems/systemstructure.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,9 @@ function TearingState(sys; quick_cancel = false, check = true, sort_eqs = true)
470470
addvar!(v, VARIABLE)
471471
if iscall(v) && operation(v) isa Symbolics.Operator && !isdifferential(v) &&
472472
(it = input_timedomain(v)) !== nothing
473-
v′ = only(arguments(v))
474-
addvar!(setmetadata(v′, VariableTimeDomain, it), VARIABLE)
473+
for v′ in arguments(v)
474+
addvar!(setmetadata(v′, VariableTimeDomain, it), VARIABLE)
475+
end
475476
end
476477
end
477478

0 commit comments

Comments
 (0)