Skip to content

Commit a418591

Browse files
authored
Merge pull request #2441 from SciML/myb/state_machine
Add StateMachineOperators
2 parents 4b2ef38 + 64d9d43 commit a418591

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/ModelingToolkit.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ using PrecompileTools, Reexport
5555
using Symbolics: _parse_vars, value, @derivatives, get_variables,
5656
exprs_occur_in, solve_for, build_expr, unwrap, wrap,
5757
VariableSource, getname, variable, Connection, connect,
58-
NAMESPACE_SEPARATOR, set_scalar_metadata, setdefaultval
58+
NAMESPACE_SEPARATOR, set_scalar_metadata, setdefaultval,
59+
initial_state, transition, activeState, entry,
60+
ticksInState, timeInState
5961
import Symbolics: rename, get_variables!, _solve, hessian_sparsity,
6062
jacobian_sparsity, isaffine, islinear, _iszero, _isone,
6163
tosymbol, lower_varname, diff2term, var_from_nested_derivative,
@@ -219,6 +221,7 @@ export JumpProblem
219221
export NonlinearSystem, OptimizationSystem, ConstraintsSystem
220222
export alias_elimination, flatten
221223
export connect, domain_connect, @connector, Connection, Flow, Stream, instream
224+
export initial_state, transition, activeState, entry, ticksInState, timeInState
222225
export @component, @mtkmodel, @mtkbuild
223226
export isinput, isoutput, getbounds, hasbounds, getguess, hasguess, isdisturbance,
224227
istunable, getdist, hasdist,

src/systems/connectors.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using Symbolics: StateMachineOperator
2+
isconnection(_) = false
3+
isconnection(_::Connection) = true
14
"""
25
domain_connect(sys1, sys2, syss...)
36
@@ -327,17 +330,17 @@ function generate_connection_set!(connectionsets, domain_csets,
327330
end
328331
neweq isa AbstractArray ? append!(eqs, neweq) : push!(eqs, neweq)
329332
else
330-
if lhs isa Number || lhs isa Symbolic || eltype(lhs) <: Symbolic
333+
if lhs isa Connection && get_systems(lhs) === :domain
334+
connection2set!(domain_csets, namespace, get_systems(rhs), isouter)
335+
elseif isconnection(rhs)
336+
push!(cts, get_systems(rhs))
337+
else
331338
# split connections and equations
332339
if eq.lhs isa AbstractArray || eq.rhs isa AbstractArray
333340
append!(eqs, Symbolics.scalarize(eq))
334341
else
335342
push!(eqs, eq)
336343
end
337-
elseif lhs isa Connection && get_systems(lhs) === :domain
338-
connection2set!(domain_csets, namespace, get_systems(rhs), isouter)
339-
else
340-
push!(cts, get_systems(rhs))
341344
end
342345
end
343346
end

0 commit comments

Comments
 (0)