Skip to content

Commit cd6f796

Browse files
Restrict TreeMesh to hypercube domains (#2117)
* add check for different domain lengths * apply formatter * adjust coordinates
1 parent f3e8878 commit cd6f796

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

examples/tree_2d_dgsem/elixir_euler_warm_bubble.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,9 @@ volume_integral = VolumeIntegralFluxDifferencing(volume_flux)
9696

9797
solver = DGSEM(basis, surface_flux, volume_integral)
9898

99-
coordinates_min = (0.0, 0.0)
100-
coordinates_max = (20_000.0, 10_000.0)
99+
coordinates_min = (0.0, -5000.0)
100+
coordinates_max = (20_000.0, 15_000.0)
101101

102-
# Same coordinates as in examples/structured_2d_dgsem/elixir_euler_warm_bubble.jl
103-
# However TreeMesh will generate a 20_000 x 20_000 square domain instead
104102
mesh = TreeMesh(coordinates_min, coordinates_max,
105103
initial_refinement_level = 6,
106104
n_cells_max = 10_000,

examples/tree_3d_dgsem/elixir_advection_diffusion_nonperiodic.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ equations_parabolic = LaplaceDiffusion3D(diffusivity(), equations)
1212
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
1313
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
1414

15-
coordinates_min = (-1.0, -0.5, -0.25) # minimum coordinates (min(x), min(y), min(z))
16-
coordinates_max = (0.0, 0.5, 0.25) # maximum coordinates (max(x), max(y), max(z))
15+
coordinates_min = (-1.0, -0.5, -0.5) # minimum coordinates (min(x), min(y), min(z))
16+
coordinates_max = (0.0, 0.5, 0.5) # maximum coordinates (max(x), max(y), max(z))
1717

1818
# Create a uniformly refined mesh with periodic boundaries
1919
mesh = TreeMesh(coordinates_min, coordinates_max,

src/meshes/tree_mesh.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,12 @@ function TreeMesh(coordinates_min::NTuple{NDIMS, Real},
119119
throw(ArgumentError("`initial_refinement_level` must be a non-negative integer (provided `initial_refinement_level = $initial_refinement_level`)"))
120120
end
121121

122-
# Domain length is calculated as the maximum length in any axis direction
122+
# TreeMesh requires equal domain lengths in all dimensions
123123
domain_center = @. (coordinates_min + coordinates_max) / 2
124-
domain_length = maximum(coordinates_max .- coordinates_min)
124+
domain_length = coordinates_max[1] - coordinates_min[1]
125+
if !all(coordinates_max[i] - coordinates_min[i] domain_length for i in 2:NDIMS)
126+
throw(ArgumentError("The TreeMesh domain must be a hypercube (provided `coordinates_max` .- `coordinates_min` = $(coordinates_max .- coordinates_min))"))
127+
end
125128

126129
# TODO: MPI, create nice interface for a parallel tree/mesh
127130
if mpi_isparallel()

test/test_unit.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ end
6565
@timed_testset "TreeMesh" begin
6666
@testset "constructors" begin
6767
@test TreeMesh{1, Trixi.SerialTree{1}}(1, 5.0, 2.0) isa TreeMesh
68+
69+
# Invalid domain length check (TreeMesh expects a hypercube)
70+
# 2D
71+
@test_throws ArgumentError TreeMesh((-0.5, 0.0), (1.0, 2.0),
72+
initial_refinement_level = 2,
73+
n_cells_max = 10_000)
74+
# 3D
75+
@test_throws ArgumentError TreeMesh((-0.5, 0.0, -0.2), (1.0, 2.0, 1.5),
76+
initial_refinement_level = 2,
77+
n_cells_max = 10_000)
6878
end
6979
end
7080

0 commit comments

Comments
 (0)