Skip to content

Commit

Permalink
Restrict TreeMesh to hypercube domains (#2117)
Browse files Browse the repository at this point in the history
* add check for different domain lengths

* apply formatter

* adjust coordinates
  • Loading branch information
patrickersing authored Oct 16, 2024
1 parent f3e8878 commit cd6f796
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
6 changes: 2 additions & 4 deletions examples/tree_2d_dgsem/elixir_euler_warm_bubble.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,9 @@ volume_integral = VolumeIntegralFluxDifferencing(volume_flux)

solver = DGSEM(basis, surface_flux, volume_integral)

coordinates_min = (0.0, 0.0)
coordinates_max = (20_000.0, 10_000.0)
coordinates_min = (0.0, -5000.0)
coordinates_max = (20_000.0, 15_000.0)

# Same coordinates as in examples/structured_2d_dgsem/elixir_euler_warm_bubble.jl
# However TreeMesh will generate a 20_000 x 20_000 square domain instead
mesh = TreeMesh(coordinates_min, coordinates_max,
initial_refinement_level = 6,
n_cells_max = 10_000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ equations_parabolic = LaplaceDiffusion3D(diffusivity(), equations)
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)

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

# Create a uniformly refined mesh with periodic boundaries
mesh = TreeMesh(coordinates_min, coordinates_max,
Expand Down
7 changes: 5 additions & 2 deletions src/meshes/tree_mesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,12 @@ function TreeMesh(coordinates_min::NTuple{NDIMS, Real},
throw(ArgumentError("`initial_refinement_level` must be a non-negative integer (provided `initial_refinement_level = $initial_refinement_level`)"))
end

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

# TODO: MPI, create nice interface for a parallel tree/mesh
if mpi_isparallel()
Expand Down
10 changes: 10 additions & 0 deletions test/test_unit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ end
@timed_testset "TreeMesh" begin
@testset "constructors" begin
@test TreeMesh{1, Trixi.SerialTree{1}}(1, 5.0, 2.0) isa TreeMesh

# Invalid domain length check (TreeMesh expects a hypercube)
# 2D
@test_throws ArgumentError TreeMesh((-0.5, 0.0), (1.0, 2.0),
initial_refinement_level = 2,
n_cells_max = 10_000)
# 3D
@test_throws ArgumentError TreeMesh((-0.5, 0.0, -0.2), (1.0, 2.0, 1.5),
initial_refinement_level = 2,
n_cells_max = 10_000)
end
end

Expand Down

0 comments on commit cd6f796

Please sign in to comment.