Skip to content

Commit db88bc5

Browse files
Check that coordinates_min[dim] < coordinates_max[dim] (#2257)
* Check coords * function * Check * Update src/meshes/abstract_tree.jl * Apply suggestions from code review Co-authored-by: Joshua Lampert <[email protected]> * comment + s --------- Co-authored-by: Joshua Lampert <[email protected]>
1 parent 6a733dd commit db88bc5

File tree

5 files changed

+18
-3
lines changed

5 files changed

+18
-3
lines changed

src/meshes/abstract_tree.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,13 +387,20 @@ function refine!(t::AbstractTree, cell_ids,
387387
return refined_original_cells
388388
end
389389

390+
@inline function coordinates_min_max_check(coordinates_min, coordinates_max)
391+
for dim in eachindex(coordinates_min)
392+
@assert coordinates_min[dim]<coordinates_max[dim] "coordinates_min[$dim] must be smaller than coordinates_max[$dim]!"
393+
end
394+
end
395+
# For the p4est and the t8code mesh we allow `coordinates_min` and `coordinates_max` to be `nothing`.
396+
# This corresponds to meshes constructed from analytic mapping functions.
397+
coordinates_min_max_check(::Nothing, ::Nothing) = nothing
398+
390399
# Refine all leaf cells with coordinates in a given rectangular box
391400
function refine_box!(t::AbstractTree{NDIMS},
392401
coordinates_min,
393402
coordinates_max) where {NDIMS}
394-
for dim in 1:NDIMS
395-
@assert coordinates_min[dim]<coordinates_max[dim] "Minimum coordinates are not minimum."
396-
end
403+
coordinates_min_max_check(coordinates_min, coordinates_max)
397404

398405
# Find all leaf cells within box
399406
cells = filter_leaf_cells(t) do cell_id

src/meshes/p4est_mesh.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ function P4estMesh(trees_per_dimension; polydeg,
191191
p4est_partition_allow_for_coarsening = true)
192192
@assert ((coordinates_min === nothing)===(coordinates_max === nothing)) "Either both or none of coordinates_min and coordinates_max must be specified"
193193

194+
coordinates_min_max_check(coordinates_min, coordinates_max)
195+
194196
@assert count(i -> i !== nothing,
195197
(mapping, faces, coordinates_min))==1 "Exactly one of mapping, faces and coordinates_min/max must be specified"
196198

src/meshes/structured_mesh.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ function StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max;
140140
periodicity = true)
141141
RealT = promote_type(eltype(coordinates_min), eltype(coordinates_max))
142142

143+
coordinates_min_max_check(coordinates_min, coordinates_max)
144+
143145
mapping = coordinates2mapping(coordinates_min, coordinates_max)
144146
mapping_as_string = """
145147
coordinates_min = $coordinates_min

src/meshes/t8code_mesh.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ function T8codeMesh(trees_per_dimension; polydeg = 1,
427427
periodicity = true)
428428
@assert ((coordinates_min === nothing)===(coordinates_max === nothing)) "Either both or none of coordinates_min and coordinates_max must be specified"
429429

430+
coordinates_min_max_check(coordinates_min, coordinates_max)
431+
430432
@assert count(i -> i !== nothing,
431433
(mapping, faces, coordinates_min))==1 "Exactly one of mapping, faces and coordinates_min/max must be specified"
432434

src/meshes/tree_mesh.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ function TreeMesh(coordinates_min::NTuple{NDIMS, Real},
134134
end
135135
end
136136

137+
coordinates_min_max_check(coordinates_min, coordinates_max)
138+
137139
# TreeMesh requires equal domain lengths in all dimensions
138140
domain_center = @. convert(RealT, (coordinates_min + coordinates_max) / 2)
139141
domain_length = convert(RealT, coordinates_max[1] - coordinates_min[1])

0 commit comments

Comments
 (0)