Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update show method #73

Merged
merged 1 commit into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ExtendableGrids"
uuid = "cfc395e8-590f-11e8-1f13-43a2532b2fa8"
authors = ["Juergen Fuhrmann <[email protected]>", "Christian Merdon <[email protected]>", "Johannes Taraz <[email protected]>", "Patrick Jaap <[email protected]>"]
version = "1.10.5"
version = "1.11"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
32 changes: 27 additions & 5 deletions src/extendablegrid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -541,16 +541,38 @@ function Base.map(f::Function, grid::ExtendableGrid{Tc, Ti}) where {Tc,Ti}
end
end

#
# Define two show methods, one extended for printing the repl, one
# compact for e.g. interpolating into a string
# See https://discourse.julialang.org/t/show-and-showcompact-on-custom-types/8493/6
#
function Base.show(io::IO, ::MIME"text/plain", grid::ExtendableGrid)
str = @sprintf("%s\n dim = %7d\n nnodes = %7d\n ncells = %7d\n nbfaces = %7d",
typeof(grid),
dim_space(grid), num_nodes(grid), num_cells(grid), num_bfaces(grid))
if num_edges(grid) > 0
str*=@sprintf("\n nedges = %7d", num_edges(grid))
end
if num_partitions(grid)>1
str*="\n npartitions/color = $(num_partitions_per_color(grid))"
end
print(io, str)
nothing
end

function Base.show(io::IO, grid::ExtendableGrid)
str = @sprintf("%s;\ndim: %d nodes: %d cells: %d bfaces: %d",
typeof(grid), dim_space(grid), num_nodes(grid), num_cells(grid), num_bfaces(grid))
str = @sprintf("%s(dim=%d, nnodes=%d, ncells=%d, nbfaces=%d",
typeof(grid),
dim_space(grid), num_nodes(grid), num_cells(grid), num_bfaces(grid))
if num_edges(grid) > 0
str*=@sprintf(", edges: %d", num_edges(grid))
str*=@sprintf(", nedges=%d", num_edges(grid))
end
if num_partitions(grid)>1
str*="\npartitions/color: $(num_partitions_per_color(grid))"
str*=", npart/color=$(num_partitions_per_color(grid))"
end
println(io, str)
str*=")"
print(io, str)
nothing
end

### Tests for the gmsh extension:
Expand Down