Skip to content

Commit

Permalink
Export hierarchy(sys) to print subsystem hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
hersle committed Oct 20, 2024
1 parent db9348c commit d473a73
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/ModelingToolkit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export Equation, ConstrainedEquation
export Term, Sym
export SymScope, LocalScope, ParentScope, DelayParentScope, GlobalScope
export independent_variable, equations, controls, observed, full_equations
export initialization_equations, guesses, defaults, parameter_dependencies
export initialization_equations, guesses, defaults, parameter_dependencies, hierarchy
export structural_simplify, expand_connections, linearize, linearization_function

export calculate_jacobian, generate_jacobian, generate_function, generate_custom_function
Expand Down
18 changes: 14 additions & 4 deletions src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1898,7 +1898,7 @@ function Base.show(io::IO, mime::MIME"text/plain", sys::AbstractSystem; hint = t
nsubs = length(subs)
nrows = min(nsubs, limit ? rows : nsubs)
nrows > 0 && printstyled(io, "\nSubsystems ($(nsubs)):"; bold)
nrows > 0 && hint && print(io, " see ModelingToolkit.get_systems(sys)")
nrows > 0 && hint && print(io, " see hierarchy(sys)")
for i in 1:nrows
sub = subs[i]
name = String(nameof(sub))
Expand Down Expand Up @@ -2902,12 +2902,22 @@ function Base.showerror(io::IO, e::HybridSystemNotSupportedException)
print(io, "HybridSystemNotSupportedException: ", e.msg)
end

function AbstractTrees.children(sys::ModelingToolkit.AbstractSystem)
function AbstractTrees.children(sys::AbstractSystem)
ModelingToolkit.get_systems(sys)
end
function AbstractTrees.printnode(io::IO, sys::ModelingToolkit.AbstractSystem)
print(io, nameof(sys))
function AbstractTrees.printnode(io::IO, sys::AbstractSystem; describe = false, bold = false)
printstyled(io, nameof(sys); bold)
describe && !isempty(get_description(sys)) && print(io, ": ", get_description(sys))
end
"""
hierarchy(sys::AbstractSystem; describe = false, bold = describe, kwargs...)
Print a tree of a system's hierarchy of subsystems.
"""
function hierarchy(sys::AbstractSystem; describe = false, bold = describe, kwargs...)
print_tree(sys; printnode_kw = (describe = describe, bold = bold), kwargs...)
end

function Base.IteratorEltype(::Type{<:TreeIterator{ModelingToolkit.AbstractSystem}})
Base.HasEltype()
end
Expand Down

0 comments on commit d473a73

Please sign in to comment.