1- module Clocks
2-
3- export TimeDomain
4-
5- using Expronicon. ADT: variant_type, @adt , @match
6-
7- @adt TimeDomain begin
1+ @data Clocks begin
82 Continuous
93 struct PeriodicClock
104 dt:: Union{Nothing, Float64, Rational{Int}}
@@ -13,21 +7,10 @@ using Expronicon.ADT: variant_type, @adt, @match
137 SolverStepClock
148end
159
16- Base. Broadcast. broadcastable (d:: TimeDomain ) = Ref (d)
17-
18- const DiscriminatorType = typeof (variant_type (Continuous))
19-
20- function Base. write (io:: IO , x:: DiscriminatorType )
21- write (io, Base. reinterpret (UInt32, x))
22- end
23-
24- function Base. read (io:: IO , :: Type{DiscriminatorType} )
25- Base. reinterpret (DiscriminatorType, read (io, UInt32))
26- end
27-
28- end
10+ const TimeDomain = Clocks. Type
11+ using . Clocks: Continuous, PeriodicClock, SolverStepClock
2912
30- using . Clocks
13+ Base . Broadcast . broadcastable (d :: TimeDomain ) = Ref (d)
3114
3215"""
3316 Clock(dt)
@@ -55,27 +38,27 @@ filters.
5538""" SolverStepClock
5639
5740isclock (c) = @match c begin
58- PeriodicClock (_ ... ) => true
41+ PeriodicClock () => true
5942 _ => false
6043end
6144
6245issolverstepclock (c) = @match c begin
63- & SolverStepClock => true
46+ SolverStepClock () => true
6447 _ => false
6548end
6649
6750iscontinuous (c) = @match c begin
68- & Continuous => true
51+ Continuous () => true
6952 _ => false
7053end
7154
7255is_discrete_time_domain (c) = ! iscontinuous (c)
7356
7457function first_clock_tick_time (c, t0)
7558 @match c begin
76- PeriodicClock (dt, _ ... ) => ceil (t0 / dt) * dt
77- & SolverStepClock => t0
78- & Continuous => error (" Continuous is not a discrete clock" )
59+ PeriodicClock (dt) => ceil (t0 / dt) * dt
60+ SolverStepClock () => t0
61+ Continuous () => error (" Continuous is not a discrete clock" )
7962 end
8063end
8164
@@ -90,13 +73,13 @@ function canonicalize_indexed_clock(ic::IndexedClock, sol::AbstractTimeseriesSol
9073 c = ic. clock
9174
9275 return @match c begin
93- PeriodicClock (dt, _ ... ) => ceil (sol. prob. tspan[1 ] / dt) * dt .+ (ic. idx .- 1 ) .* dt
94- & SolverStepClock => begin
76+ PeriodicClock (dt) => ceil (sol. prob. tspan[1 ] / dt) * dt .+ (ic. idx .- 1 ) .* dt
77+ SolverStepClock () => begin
9578 ssc_idx = findfirst (eachindex (sol. discretes)) do i
9679 ! isa (sol. discretes[i]. t, AbstractRange)
9780 end
9881 sol. discretes[ssc_idx]. t[ic. idx]
9982 end
100- & Continuous => sol. t[ic. idx]
83+ Continuous () => sol. t[ic. idx]
10184 end
10285end
0 commit comments