Skip to content

Commit 68803aa

Browse files
feat: add EventClock
1 parent ca46a3d commit 68803aa

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/clock.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ abstract type AbstractClock end
77
phase::Float64 = 0.0
88
end
99
SolverStepClock
10+
struct EventClock
11+
id::Symbol
12+
end
1013
end
1114

1215
# for backwards compatibility
1316
const TimeDomain = Clocks.Type
14-
using .Clocks: ContinuousClock, PeriodicClock, SolverStepClock
17+
using .Clocks: ContinuousClock, PeriodicClock, SolverStepClock, EventClock
1518
const Continuous = ContinuousClock()
1619
(clock::TimeDomain)() = clock
1720

@@ -57,12 +60,18 @@ iscontinuous(c::TimeDomain) = @match c begin
5760
_ => false
5861
end
5962

63+
iseventclock(c::TimeDomain) = @match c begin
64+
EventClock() => true
65+
_ => false
66+
end
67+
6068
is_discrete_time_domain(c::TimeDomain) = !iscontinuous(c)
6169

6270
# workaround for https://github.com/Roger-luo/Moshi.jl/issues/43
6371
isclock(::Any) = false
6472
issolverstepclock(::Any) = false
6573
iscontinuous(::Any) = false
74+
iseventclock(::Any) = false
6675
is_discrete_time_domain(::Any) = false
6776

6877
# public
@@ -71,6 +80,8 @@ function first_clock_tick_time(c, t0)
7180
PeriodicClock(dt) => ceil(t0 / dt) * dt
7281
SolverStepClock() => t0
7382
ContinuousClock() => error("ContinuousClock() is not a discrete clock")
83+
EventClock() => error("Event clocks do not have a defined first tick time.")
84+
_ => error("Unimplemented for clock $c")
7485
end
7586
end
7687

0 commit comments

Comments
 (0)