Skip to content

Commit 20efc75

Browse files
feat: add clock phase
Co-authored-by: Fredrik Bagge Carlson <[email protected]>
1 parent 8af217d commit 20efc75

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/clock.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ using Expronicon.ADT: @adt, @match
88
Continuous
99
struct PeriodicClock
1010
dt::Union{Nothing, Float64, Rational{Int}}
11+
phase::Float64 = 0.0
1112
end
1213
SolverStepClock
1314
end
@@ -25,9 +26,9 @@ using .Clocks
2526
The default periodic clock with tick interval `dt`. If `dt` is left unspecified, it will
2627
be inferred (if possible).
2728
"""
28-
Clock(dt::Union{<:Rational, Float64}) = PeriodicClock(dt)
29-
Clock(dt) = PeriodicClock(convert(Float64, dt))
30-
Clock() = PeriodicClock(nothing)
29+
Clock(dt::Union{<:Rational, Float64}; phase = 0.0) = PeriodicClock(dt, phase)
30+
Clock(dt; phase = 0.0) = PeriodicClock(convert(Float64, dt), phase)
31+
Clock(; phase = 0.0) = PeriodicClock(nothing, phase)
3132

3233
@doc """
3334
SolverStepClock
@@ -44,7 +45,7 @@ filters.
4445
""" SolverStepClock
4546

4647
isclock(c) = @match c begin
47-
PeriodicClock(_) => true
48+
PeriodicClock(_...) => true
4849
_ => false
4950
end
5051

@@ -62,7 +63,7 @@ is_discrete_time_domain(c) = !iscontinuous(c)
6263

6364
function first_clock_tick_time(c, t0)
6465
@match c begin
65-
PeriodicClock(dt) => ceil(t0 / dt) * dt
66+
PeriodicClock(dt, _...) => ceil(t0 / dt) * dt
6667
&SolverStepClock => t0
6768
&Continuous => error("Continuous is not a discrete clock")
6869
end
@@ -79,7 +80,7 @@ function canonicalize_indexed_clock(ic::IndexedClock, sol::AbstractTimeseriesSol
7980
c = ic.clock
8081

8182
return @match c begin
82-
PeriodicClock(dt) => ceil(sol.prob.tspan[1] / dt) * dt .+ (ic.idx .- 1) .* dt
83+
PeriodicClock(dt, _...) => ceil(sol.prob.tspan[1] / dt) * dt .+ (ic.idx .- 1) .* dt
8384
&SolverStepClock => begin
8485
ssc_idx = findfirst(eachindex(sol.discretes)) do i
8586
!isa(sol.discretes[i].t, AbstractRange)

0 commit comments

Comments
 (0)