Skip to content

Commit f13291a

Browse files
committed
generate connection_namemap and is_stochastic if not given to PartitionedGraphSystem
1 parent 6d6be99 commit f13291a

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "GraphDynamics"
22
uuid = "bcd5d0fe-e6b7-4ef1-9848-780c183c7f4c"
3-
version = "0.4.6"
3+
version = "0.4.7"
44

55
[workspace]
66
projects = ["test", "scrap"]

src/graph_system.jl

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,18 @@ function system_wiring_rule!(g, src, dst; kwargs...)
7777
end
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 = (;)
9393
end
9494

@@ -266,3 +266,29 @@ function check_no_double_connections(g, conn_key)
266266
end
267267
end
268268
end
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

Comments
 (0)