@@ -11,6 +11,7 @@ struct System{N,T}
1111 dfs_list:: SVector{N,Int64} # depth-first search list of nodes [last-found node, ..., first-found node]
1212 graph:: SimpleGraph{Int64} # the graph built from the adjacency matrix
1313 dfs_graph:: SimpleDiGraph{Int64} # the directed graph built from the depth-first search
14+ dims:: Vector{Int64} # Dimensions of the matrix entries
1415
1516 function System {T} (A, dims; force_static = false , symmetric = false ) where T
1617 N = length (dims)
@@ -79,7 +80,7 @@ struct System{N,T}
7980 cyclic_children = [unique (vcat (cycles[i]. .. )) for i= 1 : N]
8081 cyclic_children = [intersect (dfs_list, cyclic_children[i]) for i= 1 : N]
8182
82- new {N,S} (matrix_entries, vector_entries, diagonal_inverses, acyclic_children, cyclic_children, parents, dfs_list, full_graph, full_dfs_graph)
83+ new {N,S} (matrix_entries, vector_entries, diagonal_inverses, acyclic_children, cyclic_children, parents, dfs_list, full_graph, full_dfs_graph, dims )
8384 end
8485
8586 System (A, dims; force_static = false , symmetric = false ) = System {Float64} (A, dims; force_static, symmetric)
@@ -94,79 +95,3 @@ function Base.show(io::IO, mime::MIME{Symbol("text/plain")}, system::System{N,S}
9495 println (io, " System with " * string (N)* " nodes." )
9596 SparseArrays. _show_with_braille_patterns (io, system. matrix_entries)
9697end
97-
98-
99- @inline children (system:: System , v) = outneighbors (system. dfs_graph, v) # all direct children of v
100- @inline connections (system:: System , v) = neighbors (system. graph, v) # all connected nodes of v
101- @inline parents (system:: System , v) = inneighbors (system. dfs_graph, v) # same elements as system.parents[v], but potentially different order
102-
103- dimensions (system:: System{N} ) where N = [size (system. vector_entries[i]. value)[1 ] for i= 1 : N]
104- function ranges (system:: System{N} ) where N
105- dims = dimensions (system)
106- range_dict = Dict (1 => 1 : dims[1 ])
107- for i= 2 : N
108- range_dict[i] = last (range_dict[i- 1 ])+ 1 : sum (dims[1 : i])
109- end
110-
111- return range_dict
112- end
113-
114- # There probably exists a smarter way of getting the dense matrix from the spares one
115- function full_matrix (system:: System{N} ) where N
116- dims = dimensions (system)
117- range_dict = ranges (system)
118- A = zeros (sum (dims), sum (dims))
119-
120- for (i,row) in enumerate (system. matrix_entries. rowval)
121- col = findfirst (x -> i< x, system. matrix_entries. colptr)- 1
122- A[range_dict[row],range_dict[col]] = system. matrix_entries[row,col]. value
123- end
124- return A
125- end
126-
127- function full_matrix (system:: System{N,<:Symmetric} ) where N
128- dims = dimensions (system)
129- range_dict = ranges (system)
130- A = zeros (sum (dims),sum (dims))
131-
132- for (i,row) in enumerate (system. matrix_entries. rowval)
133- col = findfirst (x -> i< x, system. matrix_entries. colptr)- 1
134- A[range_dict[row],range_dict[col]] = system. matrix_entries[row,col]. value
135- if col != row
136- A[range_dict[col],range_dict[row]] = system. matrix_entries[row,col]. value'
137- end
138- end
139- return A
140- end
141-
142- full_vector (system:: System ) = vcat (getfield .(system. vector_entries,:value )... )
143-
144- function randomize! (system:: System , rand_function = randn)
145- for entry in system. matrix_entries. nzval
146- randomize! (entry, rand_function)
147- end
148- for entry in system. vector_entries
149- randomize! (entry, rand_function)
150- end
151- end
152-
153- function randomize! (system:: System{N,<:Symmetric} , rand_function = randn) where N
154- matrix_entries = system. matrix_entries
155-
156- for entry in matrix_entries. nzval
157- randomize! (entry, rand_function)
158- end
159- for i= 1 : N
160- matrix_entries[i,i]. value += matrix_entries[i,i]. value'
161- end
162-
163- for entry in system. vector_entries
164- randomize! (entry, rand_function)
165- end
166- end
167-
168- function reset_inverse_diagonals! (system:: System )
169- for entry in system. diagonal_inverses
170- entry. isinverted = false
171- end
172- end
0 commit comments