From d6ff72c9ec47988abc25d34176f53caa216c3639 Mon Sep 17 00:00:00 2001 From: patrickersing Date: Wed, 16 Oct 2024 11:18:49 +0200 Subject: [PATCH 1/3] add check for different domain lengths --- examples/tree_2d_dgsem/elixir_euler_warm_bubble.jl | 6 ++---- src/meshes/tree_mesh.jl | 7 +++++-- test/test_unit.jl | 10 ++++++++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/examples/tree_2d_dgsem/elixir_euler_warm_bubble.jl b/examples/tree_2d_dgsem/elixir_euler_warm_bubble.jl index f2e14273ae..2632e80db7 100644 --- a/examples/tree_2d_dgsem/elixir_euler_warm_bubble.jl +++ b/examples/tree_2d_dgsem/elixir_euler_warm_bubble.jl @@ -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, diff --git a/src/meshes/tree_mesh.jl b/src/meshes/tree_mesh.jl index 933bfa6272..458a43203d 100644 --- a/src/meshes/tree_mesh.jl +++ b/src/meshes/tree_mesh.jl @@ -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() diff --git a/test/test_unit.jl b/test/test_unit.jl index bccdcf8faa..3ad646c8f9 100644 --- a/test/test_unit.jl +++ b/test/test_unit.jl @@ -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 From 4d2b97df0fbc3598bb6c9445311fee330bdb7f3d Mon Sep 17 00:00:00 2001 From: patrickersing Date: Wed, 16 Oct 2024 11:37:19 +0200 Subject: [PATCH 2/3] apply formatter --- test/test_unit.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_unit.jl b/test/test_unit.jl index 3ad646c8f9..4e8945eab8 100644 --- a/test/test_unit.jl +++ b/test/test_unit.jl @@ -69,12 +69,12 @@ end # 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) + 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) + initial_refinement_level = 2, + n_cells_max = 10_000) end end From 6b3a48445d0274cb251c48d90c0752d221b04733 Mon Sep 17 00:00:00 2001 From: patrickersing Date: Wed, 16 Oct 2024 13:10:28 +0200 Subject: [PATCH 3/3] adjust coordinates --- .../tree_3d_dgsem/elixir_advection_diffusion_nonperiodic.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/tree_3d_dgsem/elixir_advection_diffusion_nonperiodic.jl b/examples/tree_3d_dgsem/elixir_advection_diffusion_nonperiodic.jl index 4c30406680..874b8845cb 100644 --- a/examples/tree_3d_dgsem/elixir_advection_diffusion_nonperiodic.jl +++ b/examples/tree_3d_dgsem/elixir_advection_diffusion_nonperiodic.jl @@ -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,