@@ -77,18 +77,18 @@ function system_wiring_rule!(g, src, dst; kwargs...)
7777end
7878
7979@kwdef struct PartitionedGraphSystem{CM <: ConnectionMatrices , S, P, EVT, Ns, CONM, SNM, PNM, CNM, EP}
80- is_stochastic:: Bool
81- graph:: GraphSystem = GraphSystem ()
82- flat_graph:: GraphSystem = GraphSystem ()
80+ graph:: Union{Nothing, GraphSystem} = nothing
81+ flat_graph:: Union{Nothing, GraphSystem} = nothing
8382 connection_matrices:: CM
8483 states_partitioned:: S
8584 params_partitioned:: P
8685 tstops:: EVT = Float64[]
8786 names_partitioned:: Ns
88- connection_namemap:: CONM
87+ connection_namemap:: CONM = make_connection_namemape (names_partitioned, connection_matrices)
8988 state_namemap:: SNM = make_state_namemap (names_partitioned, states_partitioned)
9089 param_namemap:: PNM = make_param_namemap (names_partitioned, params_partitioned)
9190 compu_namemap:: CNM = make_compu_namemap (names_partitioned, states_partitioned, params_partitioned)
91+ is_stochastic:: Bool = any (v -> any (isstochastic, v), states_partitioned)
9292 extra_params:: EP = (;)
9393end
9494
@@ -266,3 +266,29 @@ function check_no_double_connections(g, conn_key)
266266 end
267267 end
268268end
269+
270+ @generated function make_connection_namemape (names_partitioned:: NTuple{Len, Any} ,
271+ connection_matrices:: ConnectionMatrices{NConn} ) where {Len, NConn}
272+ quote
273+ connection_namemap = OrderedDict {Symbol, ConnectionIndex} ()
274+ @nexprs $ Len k -> begin
275+ @nexprs $ Len i -> begin
276+ @nexprs $ NConn nc -> begin
277+ M = connection_matrices[nc]. data[k][i]
278+ if ! (M isa NotConnected)
279+ for j ∈ eachindex (names_partitioned)
280+ for (l, conn) ∈ maybe_sparse_enumerate_col (M, j)
281+ name_kl = names_partitioned[k][l]
282+ name_ij = names_partitioned[i][j]
283+ for (prop, name) ∈ pairs (connection_property_namemap (conn, name_kl, name_ij))
284+ connection_namemap[name] = ConnectionIndex (nc, k, i, l, j, prop)
285+ end
286+ end
287+ end
288+ end
289+ end
290+ end
291+ end
292+ connection_namemap
293+ end
294+ end
0 commit comments