Skip to content

Add StateMachineOperators #2441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ModelingToolkit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ using PrecompileTools, Reexport
using Symbolics: _parse_vars, value, @derivatives, get_variables,
exprs_occur_in, solve_for, build_expr, unwrap, wrap,
VariableSource, getname, variable, Connection, connect,
NAMESPACE_SEPARATOR, set_scalar_metadata, setdefaultval
NAMESPACE_SEPARATOR, set_scalar_metadata, setdefaultval,
initial_state, transition, activeState, entry,
ticksInState, timeInState
import Symbolics: rename, get_variables!, _solve, hessian_sparsity,
jacobian_sparsity, isaffine, islinear, _iszero, _isone,
tosymbol, lower_varname, diff2term, var_from_nested_derivative,
Expand Down Expand Up @@ -219,6 +221,7 @@ export JumpProblem
export NonlinearSystem, OptimizationSystem, ConstraintsSystem
export alias_elimination, flatten
export connect, domain_connect, @connector, Connection, Flow, Stream, instream
export initial_state, transition, activeState, entry, ticksInState, timeInState
export @component, @mtkmodel, @mtkbuild
export isinput, isoutput, getbounds, hasbounds, getguess, hasguess, isdisturbance,
istunable, getdist, hasdist,
Expand Down
13 changes: 8 additions & 5 deletions src/systems/connectors.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using Symbolics: StateMachineOperator
isconnection(_) = false
isconnection(_::Connection) = true
"""
domain_connect(sys1, sys2, syss...)

Expand Down Expand Up @@ -327,17 +330,17 @@ function generate_connection_set!(connectionsets, domain_csets,
end
neweq isa AbstractArray ? append!(eqs, neweq) : push!(eqs, neweq)
else
if lhs isa Number || lhs isa Symbolic || eltype(lhs) <: Symbolic
if lhs isa Connection && get_systems(lhs) === :domain
connection2set!(domain_csets, namespace, get_systems(rhs), isouter)
elseif isconnection(rhs)
push!(cts, get_systems(rhs))
else
# split connections and equations
if eq.lhs isa AbstractArray || eq.rhs isa AbstractArray
append!(eqs, Symbolics.scalarize(eq))
else
push!(eqs, eq)
end
elseif lhs isa Connection && get_systems(lhs) === :domain
connection2set!(domain_csets, namespace, get_systems(rhs), isouter)
else
push!(cts, get_systems(rhs))
end
end
end
Expand Down