|
1 | 1 | using ModelingToolkit, Test, Setfield, OrdinaryDiffEq, DiffEqCallbacks |
2 | 2 | using ModelingToolkit: ContinuousClock |
3 | 3 | using ModelingToolkit: t_nounits as t, D_nounits as D |
| 4 | +using Symbolics, SymbolicUtils |
4 | 5 |
|
5 | 6 | function infer_clocks(sys) |
6 | 7 | ts = TearingState(sys) |
@@ -146,6 +147,29 @@ eqs = [yd ~ Sample(dt)(y) |
146 | 147 | @test varmap[z] == clk |
147 | 148 | end |
148 | 149 |
|
| 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 | + |
149 | 173 | @test_skip begin |
150 | 174 | Tf = 1.0 |
151 | 175 | prob = ODEProblem( |
|
0 commit comments