Skip to content

Commit

Permalink
Base.show fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoArtiano committed Jan 13, 2025
1 parent b7d1501 commit f647f72
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/meshes/structured_mesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,13 @@ function StructuredMesh(cells_per_dimension, faces::Tuple;

# Collect definitions of face functions in one string (separated by semicolons)
face2substring(face) = code_string(face, ntuple(_ -> RealT, NDIMS - 1))
join_newline(strings) = join(strings, "\n")
join_newline(strings) = join(strings, ";")

faces_definition = faces .|> face2substring .|> string |> join_newline

# Include faces definition in `mapping_as_string` to allow for evaluation
# without knowing the face functions
mapping_as_string = """
$faces_definition
faces = $(string(faces))
mapping = transfinite_mapping(faces)
"""
mapping_as_string = """$faces_definition;faces = $(string(faces));mapping = transfinite_mapping(faces)"""

return StructuredMesh(cells_per_dimension, mapping; RealT = RealT,
periodicity = periodicity,
Expand All @@ -141,8 +137,10 @@ function StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max;
RealT = promote_type(eltype(coordinates_min), eltype(coordinates_max))

mapping = coordinates2mapping(coordinates_min, coordinates_max)
mapping_as_string = """
coordinates_min = $coordinates_min;coordinates_max = $coordinates_max;mapping = coordinates2mapping(coordinates_min, coordinates_max)"""
ndims = length(cells_per_dimension)
mapping_as_string = join(["[$(coordinates_min[i]),$(coordinates_max[i])]"
for i in 1:ndims], "x") *
""";mapping = coordinates2mapping(coordinates_min, coordinates_max)"""
return StructuredMesh(cells_per_dimension, mapping; RealT = RealT,
periodicity = periodicity,
mapping_as_string = mapping_as_string)
Expand Down Expand Up @@ -358,12 +356,18 @@ function Base.show(io::IO, ::MIME"text/plain", mesh::StructuredMesh)
"StructuredMesh{" * string(ndims(mesh)) * ", " *
string(real(mesh)) * "}")
summary_line(io, "size", size(mesh))

summary_line(io, "mapping", "")
# Print code lines of mapping_as_string
mapping_lines = split(mesh.mapping_as_string, ";")
for i in eachindex(mapping_lines)
summary_line(increment_indent(io), "line $i", strip(mapping_lines[i]))

if occursin("coordinates", mesh.mapping_as_string)
summary_line(io, "mapping", "linear")

summary_line(increment_indent(io), "domain", strip(mapping_lines[1]))
else
summary_line(io, "mapping", "")
for i in eachindex(mapping_lines)
summary_line(increment_indent(io), "line $i", strip(mapping_lines[i]))
end
end
summary_footer(io)
end
Expand Down

0 comments on commit f647f72

Please sign in to comment.