Skip to content

Commit f2e523b

Browse files
committed
Export hierarchy(sys) to print subsystem hierarchy
1 parent 699fa62 commit f2e523b

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/ModelingToolkit.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ export Equation, ConstrainedEquation
243243
export Term, Sym
244244
export SymScope, LocalScope, ParentScope, DelayParentScope, GlobalScope
245245
export independent_variable, equations, controls, observed, full_equations
246-
export initialization_equations, guesses, defaults, parameter_dependencies
246+
export initialization_equations, guesses, defaults, parameter_dependencies, hierarchy
247247
export structural_simplify, expand_connections, linearize, linearization_function
248248

249249
export calculate_jacobian, generate_jacobian, generate_function, generate_custom_function

src/systems/abstractsystem.jl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,7 @@ function Base.show(io::IO, mime::MIME"text/plain", sys::AbstractSystem; bold = t
19121912
end
19131913
end
19141914
limited = nrows < nsubs
1915-
limited && print(io, "\n\n see ModelingToolkit.get_systems(sys) for all") # too many variables to print # TODO: should export e.g. systems(sys) for consistency
1915+
limited && print(io, "\n\n see hierarchy(sys) for all") # too many variables to print # TODO: should export e.g. systems(sys) for consistency
19161916

19171917
# Print equations
19181918
eqs = equations(sys)
@@ -2901,12 +2901,22 @@ function Base.showerror(io::IO, e::HybridSystemNotSupportedException)
29012901
print(io, "HybridSystemNotSupportedException: ", e.msg)
29022902
end
29032903

2904-
function AbstractTrees.children(sys::ModelingToolkit.AbstractSystem)
2904+
function AbstractTrees.children(sys::AbstractSystem)
29052905
ModelingToolkit.get_systems(sys)
29062906
end
2907-
function AbstractTrees.printnode(io::IO, sys::ModelingToolkit.AbstractSystem)
2908-
print(io, nameof(sys))
2907+
function AbstractTrees.printnode(io::IO, sys::AbstractSystem; describe = false, bold = false)
2908+
printstyled(io, nameof(sys); bold)
2909+
describe && !isempty(get_description(sys)) && print(io, ": ", get_description(sys))
29092910
end
2911+
"""
2912+
hierarchy(sys::AbstractSystem; describe = false, bold = describe, kwargs...)
2913+
2914+
Print a tree of a system's hierarchy of subsystems.
2915+
"""
2916+
function hierarchy(sys::AbstractSystem; describe = false, bold = describe, kwargs...)
2917+
print_tree(sys; printnode_kw = (describe = describe, bold = bold), kwargs...)
2918+
end
2919+
29102920
function Base.IteratorEltype(::Type{<:TreeIterator{ModelingToolkit.AbstractSystem}})
29112921
Base.HasEltype()
29122922
end

0 commit comments

Comments
 (0)