Skip to content

Commit d473a73

Browse files
committed
Export hierarchy(sys) to print subsystem hierarchy
1 parent db9348c commit d473a73

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
@@ -1898,7 +1898,7 @@ function Base.show(io::IO, mime::MIME"text/plain", sys::AbstractSystem; hint = t
18981898
nsubs = length(subs)
18991899
nrows = min(nsubs, limit ? rows : nsubs)
19001900
nrows > 0 && printstyled(io, "\nSubsystems ($(nsubs)):"; bold)
1901-
nrows > 0 && hint && print(io, " see ModelingToolkit.get_systems(sys)")
1901+
nrows > 0 && hint && print(io, " see hierarchy(sys)")
19021902
for i in 1:nrows
19031903
sub = subs[i]
19041904
name = String(nameof(sub))
@@ -2902,12 +2902,22 @@ function Base.showerror(io::IO, e::HybridSystemNotSupportedException)
29022902
print(io, "HybridSystemNotSupportedException: ", e.msg)
29032903
end
29042904

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

0 commit comments

Comments
 (0)