Skip to content

Commit 7891e28

Browse files
Fix StructuredMesh1D nonuniform meshes (#2620)
* Start fix `StructuredMesh1D` non-uniform * Fix `StructuredMesh1D` nonuniform * bb * comms * test & fmt * fix test vals
1 parent 206ce52 commit 7891e28

File tree

6 files changed

+138
-4
lines changed

6 files changed

+138
-4
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using OrdinaryDiffEqLowStorageRK
2+
using Trixi
3+
4+
###############################################################################
5+
# semidiscretization of the linear advection equation
6+
7+
advection_velocity = 1.0
8+
equations = LinearScalarAdvectionEquation1D(advection_velocity)
9+
10+
solver = DGSEM(polydeg = 3, surface_flux = flux_godunov)
11+
12+
cells_per_dimension = (24,)
13+
14+
# This mapping converts [-1, 1] to [1, 9] with a non-uniform distribution of cells
15+
mapping(xi) = (xi + 2)^2
16+
17+
mesh = StructuredMesh(cells_per_dimension, mapping)
18+
19+
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,
20+
solver)
21+
22+
###############################################################################
23+
# ODE solvers, callbacks etc.
24+
25+
ode = semidiscretize(semi, (0.0, 0.5))
26+
27+
summary_callback = SummaryCallback()
28+
29+
analysis_callback = AnalysisCallback(semi, interval = 100)
30+
31+
stepsize_callback = StepsizeCallback(cfl = 1.6)
32+
33+
callbacks = CallbackSet(summary_callback, analysis_callback,
34+
stepsize_callback)
35+
36+
###############################################################################
37+
# run the simulation
38+
39+
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
40+
dt = 1.0,
41+
ode_default_options()..., callback = callbacks);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using OrdinaryDiffEqLowStorageRK
2+
using Trixi
3+
4+
###############################################################################
5+
# semidiscretization of the compressible Euler equations
6+
7+
equations = CompressibleEulerEquations1D(1.4)
8+
9+
initial_condition = initial_condition_convergence_test
10+
11+
volume_integral = VolumeIntegralFluxDifferencing(flux_ranocha)
12+
solver = DGSEM(polydeg = 3, surface_flux = flux_hllc,
13+
volume_integral = volume_integral)
14+
15+
cells_per_dimension = (8,)
16+
17+
# This mapping converts [-1, 1] to [0, 2] with a non-uniform distribution of cells
18+
mapping(xi) = ((xi + 2)^2 - 1) / 4
19+
20+
mesh = StructuredMesh(cells_per_dimension, mapping)
21+
22+
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
23+
source_terms = source_terms_convergence_test)
24+
25+
###############################################################################
26+
# ODE solvers, callbacks etc.
27+
28+
tspan = (0.0, 2.0)
29+
ode = semidiscretize(semi, tspan)
30+
31+
summary_callback = SummaryCallback()
32+
33+
analysis_interval = 100
34+
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
35+
36+
alive_callback = AliveCallback(analysis_interval = analysis_interval)
37+
38+
stepsize_callback = StepsizeCallback(cfl = 0.8)
39+
40+
callbacks = CallbackSet(summary_callback,
41+
analysis_callback, alive_callback,
42+
stepsize_callback)
43+
44+
###############################################################################
45+
# run the simulation
46+
47+
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
48+
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
49+
ode_default_options()..., callback = callbacks);

src/solvers/dgsem_structured/containers_2d.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function calc_jacobian_matrix!(jacobian_matrix, element,
102102
return jacobian_matrix
103103
end
104104

105-
# Calculate contravarant vectors, multiplied by the Jacobian determinant J of the transformation mapping.
105+
# Calculate contravariant vectors, multiplied by the Jacobian determinant J of the transformation mapping.
106106
# Those are called Ja^i in Kopriva's blue book.
107107
function calc_contravariant_vectors!(contravariant_vectors::AbstractArray{<:Any, 5},
108108
element, jacobian_matrix)

src/solvers/dgsem_structured/dg_1d.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function calc_interface_flux!(cache, u, mesh::StructuredMesh{1},
1212

1313
@threaded for element in eachelement(dg, cache)
1414
left_element = cache.elements.left_neighbors[1, element]
15+
# => `element` is the right element of the interface
1516

1617
if left_element > 0 # left_element = 0 at boundaries
1718
u_ll = get_node_vars(u, equations, dg, nnodes(dg), left_element)
@@ -67,4 +68,21 @@ function calc_boundary_flux!(cache, u, t, boundary_conditions::NamedTuple,
6768

6869
return nothing
6970
end
71+
72+
function apply_jacobian!(du, mesh::StructuredMesh{1},
73+
equations, dg::DG, cache)
74+
@unpack inverse_jacobian = cache.elements
75+
76+
@threaded for element in eachelement(dg, cache)
77+
for i in eachnode(dg)
78+
factor = -inverse_jacobian[i, element]
79+
80+
for v in eachvariable(equations)
81+
du[v, i, element] *= factor
82+
end
83+
end
84+
end
85+
86+
return nothing
87+
end
7088
end # @muladd

src/solvers/dgsem_tree/dg_1d.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ function calc_surface_integral!(du, u, mesh::Union{TreeMesh{1}, StructuredMesh{1
641641
return nothing
642642
end
643643

644-
function apply_jacobian!(du, mesh::Union{TreeMesh{1}, StructuredMesh{1}},
644+
function apply_jacobian!(du, mesh::TreeMesh{1},
645645
equations, dg::DG, cache)
646646
@unpack inverse_jacobian = cache.elements
647647

test/test_structured_1d.jl

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ end
3333
@test_allocations(Trixi.rhs!, semi, sol, 1000)
3434
end
3535

36+
@trixi_testset "elixir_advection_nonuniform.jl" begin
37+
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_nonuniform.jl"),
38+
l2=[0.0006665846145698006], linf=[0.00643334347367408])
39+
# Ensure that we do not have excessive memory allocations
40+
# (e.g., from type instabilities)
41+
@test_allocations(Trixi.rhs!, semi, sol, 1000)
42+
end
43+
3644
@trixi_testset "elixir_advection_shockcapturing.jl" begin
3745
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_shockcapturing.jl"),
3846
l2=[0.08015029105233593],
@@ -81,13 +89,31 @@ end
8189
save_solution=SaveSolutionCallback(dt = 0.1 + 1.0e-8), # Adding a small epsilon to avoid floating-point precision issues
8290
callbacks=CallbackSet(summary_callback, save_solution,
8391
analysis_callback, alive_callback),
84-
l2=[5.726144824784944e-7],
85-
linf=[3.43073006914274e-6])
92+
l2=[5.725028892495733e-7],
93+
linf=[3.4292579200734252e-6])
8694
# Ensure that we do not have excessive memory allocations
8795
# (e.g., from type instabilities)
8896
@test_allocations(Trixi.rhs!, semi, sol, 8000)
8997
end
9098

99+
@trixi_testset "elixir_euler_convergence_nonuniform.jl" begin
100+
@test_trixi_include(joinpath(EXAMPLES_DIR,
101+
"elixir_euler_convergence_nonuniform.jl"),
102+
l2=[
103+
6.0145954087568086e-5,
104+
4.865396929677369e-5,
105+
0.00012525608158029655
106+
],
107+
linf=[
108+
0.00014050847320445925,
109+
0.00038307746603916115,
110+
0.0006872324329503243
111+
])
112+
# Ensure that we do not have excessive memory allocations
113+
# (e.g., from type instabilities)
114+
@test_allocations(Trixi.rhs!, semi, sol, 1000)
115+
end
116+
91117
@trixi_testset "elixir_euler_sedov.jl" begin
92118
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_sedov.jl"),
93119
l2=[3.67478226e-01, 3.49491179e-01, 8.08910759e-01],

0 commit comments

Comments
 (0)