Skip to content

Commit 823a413

Browse files
committed
Add system tag
1 parent b72a0ed commit 823a413

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/systems/abstractsystem.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const SYSTEM_COUNT = Threads.Atomic{UInt}(0)
2+
13
"""
24
```julia
35
calculate_tgrad(sys::AbstractTimeDependentSystem)
@@ -175,6 +177,7 @@ function complete(sys::AbstractSystem)
175177
end
176178

177179
for prop in [:eqs
180+
:tag
178181
:noiseeqs
179182
:iv
180183
:states
@@ -911,7 +914,12 @@ macro named(expr)
911914
if Meta.isexpr(name, :ref)
912915
name, idxs = name.args
913916
check_name(name)
914-
esc(_named_idxs(name, idxs, :($(gensym()) -> $call)))
917+
var = gensym(name)
918+
ex = quote
919+
$var = $(_named(name, call))
920+
$name = map(i->$rename($var, Symbol($(Meta.quot(name)), :_, i)), $idxs)
921+
end
922+
esc(ex)
915923
else
916924
check_name(name)
917925
esc(:($name = $(_named(name, call))))

src/systems/diffeqs/odesystem.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ eqs = [D(x) ~ σ*(y-x),
2323
```
2424
"""
2525
struct ODESystem <: AbstractODESystem
26+
"""
27+
tag: a tag for the system. If two system have the same tag, then they are
28+
structurally identical.
29+
"""
30+
tag::UInt
2631
"""The ODEs defining the system."""
2732
eqs::Vector{Equation}
2833
"""Independent variable."""
@@ -120,7 +125,7 @@ struct ODESystem <: AbstractODESystem
120125
"""
121126
complete::Bool
122127

123-
function ODESystem(deqs, iv, dvs, ps, var_to_name, ctrls, observed, tgrad,
128+
function ODESystem(tag, deqs, iv, dvs, ps, var_to_name, ctrls, observed, tgrad,
124129
jac, ctrl_jac, Wfact, Wfact_t, name, systems, defaults,
125130
torn_matching, connector_type, preface, cevents,
126131
devents, metadata = nothing, tearing_state = nothing,
@@ -135,7 +140,7 @@ struct ODESystem <: AbstractODESystem
135140
if checks == true || (checks & CheckUnits) > 0
136141
all_dimensionless([dvs; ps; iv]) || check_units(deqs)
137142
end
138-
new(deqs, iv, dvs, ps, var_to_name, ctrls, observed, tgrad, jac,
143+
new(tag, deqs, iv, dvs, ps, var_to_name, ctrls, observed, tgrad, jac,
139144
ctrl_jac, Wfact, Wfact_t, name, systems, defaults, torn_matching,
140145
connector_type, preface, cevents, devents, metadata, tearing_state,
141146
substitutions, complete)
@@ -189,7 +194,8 @@ function ODESystem(deqs::AbstractVector{<:Equation}, iv, dvs, ps;
189194
end
190195
cont_callbacks = SymbolicContinuousCallbacks(continuous_events)
191196
disc_callbacks = SymbolicDiscreteCallbacks(discrete_events)
192-
ODESystem(deqs, iv′, dvs′, ps′, var_to_name, ctrl′, observed, tgrad, jac,
197+
ODESystem(Threads.atomic_add!(SYSTEM_COUNT, UInt(1)),
198+
deqs, iv′, dvs′, ps′, var_to_name, ctrl′, observed, tgrad, jac,
193199
ctrl_jac, Wfact, Wfact_t, name, systems, defaults, nothing,
194200
connector_type, preface, cont_callbacks, disc_callbacks,
195201
metadata, checks = checks)

0 commit comments

Comments
 (0)