Skip to content

Commit

Permalink
Update show method
Browse files Browse the repository at this point in the history
Have different methods for REPL and interpolation;
make it compatible with planned improvement of show method
for VoronoiFVM.System
  • Loading branch information
j-fu committed Nov 16, 2024
1 parent 021d230 commit a0346df
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
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

0 comments on commit a0346df

Please sign in to comment.