Skip to content

Commit

Permalink
Make StructuredMesh fully type-general
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielDoehring committed Oct 29, 2024
1 parent df9013a commit eb3775d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/meshes/structured_mesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ 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=Float64))
Create a StructuredMesh of the given size and shape that uses `RealT` as coordinate type.
Expand All @@ -46,7 +47,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 +97,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 +143,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

0 comments on commit eb3775d

Please sign in to comment.