Skip to content

Commit be1ab34

Browse files
committed
Pretty printing
1 parent 755ebdf commit be1ab34

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/extra_functions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ function LinearAlgebra.det(A::AbstractMatrix{<:Num}; laplace=true)
7474
end
7575
return det(lu(A; check = false))
7676
end
77-
end
77+
end

src/systems/abstractsystem.jl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,53 @@ function (f::AbstractSysToExpr)(O)
316316
end
317317
return build_expr(:call, Any[operation(O); f.(arguments(O))])
318318
end
319+
320+
function Base.show(io::IO, sys::AbstractSystem)
321+
eqs = equations(sys)
322+
Base.printstyled(io, "Equations ($(length(eqs))):\n"; bold=true)
323+
Base.print_matrix(io, eqs)
324+
println(io)
325+
326+
rows = first(displaysize(io)) ÷ 3
327+
limit = get(io, :limit, false)
328+
329+
vars = states(sys); nvars = length(vars)
330+
Base.printstyled(io, "States ($nvars):"; bold=true)
331+
nrows = min(nvars, limit ? rows : nvars)
332+
limited = nrows < length(vars)
333+
d_u0 = default_u0(sys)
334+
for i in 1:nrows
335+
s = vars[i]
336+
print(io, "\n ", s)
337+
338+
val = get(d_u0, s, nothing)
339+
if val !== nothing
340+
print(io, " [defaults to $val]")
341+
end
342+
end
343+
limited && print(io, "\n")
344+
println(io)
345+
346+
vars = parameters(sys); nvars = length(vars)
347+
Base.printstyled(io, "Parameters ($nvars):"; bold=true)
348+
nrows = min(nvars, limit ? rows : nvars)
349+
limited = nrows < length(vars)
350+
d_p = default_p(sys)
351+
for i in 1:nrows
352+
s = vars[i]
353+
print(io, "\n ", s)
354+
355+
val = get(d_p, s, nothing)
356+
if val !== nothing
357+
print(io, " [defaults to $val]")
358+
end
359+
end
360+
limited && print(io, "\n")
361+
362+
s = get_structure(sys)
363+
if s !== nothing
364+
Base.printstyled(io, "\nIncidence matrix:"; color=:magenta)
365+
show(io, incidence_matrix(s.graph, Num(Sym{Real}(:×))))
366+
end
367+
return nothing
368+
end

0 commit comments

Comments
 (0)