From fa1e00467026c5dc439371b70a8b0829fdb7d0f0 Mon Sep 17 00:00:00 2001 From: Jesse Chan <1156048+jlchan@users.noreply.github.com> Date: Tue, 17 Sep 2024 13:55:39 -0500 Subject: [PATCH] add convenience constructor for MeshData (#184) --- src/MeshData.jl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/MeshData.jl b/src/MeshData.jl index a37097c6..7a6f002e 100644 --- a/src/MeshData.jl +++ b/src/MeshData.jl @@ -221,6 +221,26 @@ MeshData(mesh::Tuple{<:Tuple, Matrix{Int64}}, rd::RefElemData, other_args...; kw MeshData(VXYZ, EToV, rd::RefElemData, other_args...; kwargs...) = MeshData(VXYZ..., EToV, rd, other_args...; kwargs...) # splats VXYZ +""" + MeshData(cells_per_dimension, rd::RefElemData{NDIMS}; + coordinates_min = ntuple(_ -> -1.0, NDIMS), + coordinates_max = ntuple(_ -> 1.0, NDIMS), + is_periodic=ntuple(_ -> false, NDIMS)) where {NDIMS} + +Returns a `MeshData` initialized on a uniform mesh with `cells_per_dimension` elements per +dimension scaled to the following tensor product domain: +`[coordinates_min[1], coordinates_max[1]]x[coordinates_min[2], coordinates_max[2]], ...`. +""" +function MeshData(cells_per_dimension, rd::RefElemData{NDIMS}; + coordinates_min = ntuple(_ -> -1.0, NDIMS), + coordinates_max = ntuple(_ -> 1.0, NDIMS), + is_periodic=ntuple(_ -> false, NDIMS)) where {NDIMS} + VXYZ, EToV = uniform_mesh(rd.element_type, cells_per_dimension) + VXYZ = map((x, xmin, xmax) -> (@. 0.5 * (x + 1) * (xmax - xmin) + xmin), + VXYZ, coordinates_min, coordinates_max) + return MeshData(VXYZ, EToV, rd; is_periodic) +end + function MeshData(VX::AbstractVector, EToV, rd::RefElemData{1}; is_periodic=(false, )) # Construct global coordinates