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

Make StructuredMesh fully type-general #2136

Merged
Merged
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
14 changes: 9 additions & 5 deletions src/meshes/structured_mesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ mutable struct StructuredMesh{NDIMS, RealT <: Real} <: AbstractMesh{NDIMS}
end

"""
StructuredMesh(cells_per_dimension, mapping; RealT=Float64, unsaved_changes=true, mapping_as_string=mapping2string(mapping, length(cells_per_dimension)))
StructuredMesh(cells_per_dimension, mapping;
RealT=Float64,
unsaved_changes=true,
mapping_as_string=mapping2string(mapping, length(cells_per_dimension), RealT=RealT))
Create a StructuredMesh of the given size and shape that uses `RealT` as coordinate type.
Expand All @@ -46,7 +49,8 @@ Create a StructuredMesh of the given size and shape that uses `RealT` as coordin
function StructuredMesh(cells_per_dimension, mapping; RealT = Float64,
periodicity = true, unsaved_changes = true,
mapping_as_string = mapping2string(mapping,
length(cells_per_dimension)))
length(cells_per_dimension),
RealT))
NDIMS = length(cells_per_dimension)

# Convert periodicity to a Tuple of a Bool for every dimension
Expand Down Expand Up @@ -95,7 +99,7 @@ function StructuredMesh(cells_per_dimension, faces::Tuple; RealT = Float64,
mapping = transfinite_mapping(faces)

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

faces_definition = faces .|> face2substring .|> string |> join_newline
Expand Down Expand Up @@ -141,8 +145,8 @@ function StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max;
end

# Extract a string of the code that defines the mapping function
function mapping2string(mapping, ndims)
string(code_string(mapping, ntuple(_ -> Float64, ndims)))
function mapping2string(mapping, ndims, RealT = Float64)
string(code_string(mapping, ntuple(_ -> RealT, ndims)))
end

# An internal function wrapping `CodeTracking.code_string` with additional
Expand Down
Loading