Skip to content

Commit 17be238

Browse files
committed
Fix everything
1 parent 8521f85 commit 17be238

File tree

3 files changed

+7
-18
lines changed

3 files changed

+7
-18
lines changed

src/systems/clock_inference.jl

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@ function ClockInference(ts::TearingState)
99
@unpack fullvars, structure = ts
1010
@unpack graph = structure
1111
eq_domain = TimeDomain[Continuous() for _ in 1:nsrcs(graph)]
12-
var_domain = Vector{TimeDomain}(undef, ndsts(graph))
12+
var_domain = TimeDomain[Continuous() for _ in 1:ndsts(graph)]
1313
inferred = BitSet()
1414
for (i, v) in enumerate(fullvars)
1515
d = get_time_domain(v)
1616
if d isa Union{AbstractClock, Continuous}
1717
push!(inferred, i)
1818
dd = d
19-
else
20-
dd = Inferred()
19+
var_domain[i] = dd
2120
end
22-
var_domain[i] = dd
2321
end
2422
ClockInference(ts, eq_domain, var_domain, inferred)
2523
end
@@ -28,11 +26,7 @@ function infer_clocks!(ci::ClockInference)
2826
@unpack ts, eq_domain, var_domain, inferred = ci
2927
@unpack fullvars = ts
3028
@unpack graph = ts.structure
31-
if isempty(inferred)
32-
fill!(var_domain, Continuous())
33-
fill!(eq_domain, Continuous())
34-
return ci
35-
end
29+
isempty(inferred) && return ci
3630
# TODO: add a graph type to do this lazily
3731
var_graph = SimpleGraph(ndsts(graph))
3832
for eq in 𝑠vertices(graph)
@@ -48,12 +42,7 @@ function infer_clocks!(ci::ClockInference)
4842
for c′ in cc
4943
c = BitSet(c′)
5044
idxs = intersect(c, inferred)
51-
if isempty(idxs)
52-
for v in c′
53-
var_domain[v] = Continuous()
54-
end
55-
continue
56-
end
45+
isempty(idxs) && continue
5746
if !allequal(var_domain[i] for i in idxs)
5847
display(fullvars[c′])
5948
throw(ClockInferenceException("Clocks are not consistent in connected component $(fullvars[c′])"))
@@ -125,7 +114,6 @@ function split_system(ci::ClockInference)
125114
@assert cid!==0 "Internal error! Variable $(fullvars[i]) doesn't have a inferred time domain."
126115
var_to_cid[i] = cid
127116
v = fullvars[i]
128-
#TODO: remove Inferred*
129117
if istree(v) && (o = operation(v)) isa Operator &&
130118
input_timedomain(o) != output_timedomain(o)
131119
push!(input_idxs[cid], i)

src/systems/systemstructure.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import ..ModelingToolkit: isdiffeq, var_from_nested_derivative, vars!, flatten,
99
value, InvalidSystemException, isdifferential, _iszero,
1010
isparameter, isconstant,
1111
independent_variables, SparseMatrixCLIL, AbstractSystem,
12-
equations, isirreducible
12+
equations, isirreducible, input_timedomain, TimeDomain
1313
using ..BipartiteGraphs
1414
import ..BipartiteGraphs: invview, complete
1515
using Graphs
@@ -285,7 +285,7 @@ function TearingState(sys; quick_cancel = false, check = true)
285285
!isdifferential(var) && (it = input_timedomain(var)) !== nothing
286286
set_incidence = false
287287
var = only(arguments(var))
288-
var = setmetadata(var, ModelingToolkit.TimeDomain, it)
288+
var = setmetadata(var, TimeDomain, it)
289289
@goto ANOTHER_VAR
290290
end
291291
end

test/clock.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using ModelingToolkit, Test, Setfield, OrdinaryDiffEq, DiffEqCallbacks
2+
using ModelingToolkit: Continuous
23

34
function infer_clocks(sys)
45
ts = TearingState(sys)

0 commit comments

Comments
 (0)