Skip to content

Commit 57fc261

Browse files
test: test zero-arg operators
1 parent 6d8a82a commit 57fc261

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/clock.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using ModelingToolkit, Test, Setfield, OrdinaryDiffEq, DiffEqCallbacks
22
using ModelingToolkit: ContinuousClock
33
using ModelingToolkit: t_nounits as t, D_nounits as D
4+
using Symbolics, SymbolicUtils
45

56
function infer_clocks(sys)
67
ts = TearingState(sys)
@@ -146,6 +147,29 @@ eqs = [yd ~ Sample(dt)(y)
146147
@test varmap[z] == clk
147148
end
148149

150+
struct ZeroArgOp <: Symbolics.Operator end
151+
(o::ZeroArgOp)() = Symbolics.Term{Bool}(o, Any[])
152+
SymbolicUtils.promote_symtype(::ZeroArgOp, T) = Union{Bool, T}
153+
SymbolicUtils.isbinop(::ZeroArgOp) = false
154+
Base.nameof(::ZeroArgOp) = :ZeroArgOp
155+
ModelingToolkit.input_timedomain(::ZeroArgOp, _ = nothing) = ()
156+
ModelingToolkit.output_timedomain(::ZeroArgOp, _ = nothing) = Clock(0.1)
157+
ModelingToolkit.validate_operator(::ZeroArgOp, args, iv; context = nothing) = nothing
158+
SciMLBase.is_discrete_time_domain(::ZeroArgOp) = true
159+
160+
@testset "Zero-argument clock operators" begin
161+
@variables x(t) y(t)
162+
clk = Clock(0.1)
163+
eqs = [D(x) ~ x
164+
y ~ ZeroArgOp()()]
165+
@named sys = System(eqs, t)
166+
@test issetequal(unknowns(sys), [x, y])
167+
ts = TearingState(sys)
168+
@test issetequal(ts.fullvars, [D(x), x, y, ZeroArgOp()()])
169+
ci, clkmap = infer_clocks(sys)
170+
@test clkmap[ZeroArgOp()()] == clk
171+
end
172+
149173
@test_skip begin
150174
Tf = 1.0
151175
prob = ODEProblem(

0 commit comments

Comments
 (0)