Skip to content

Commit 53c4725

Browse files
Fix bug in Dirichlet BC for non-conservative equations (#2441)
* Fixed bug in Dirichlet BC for non-conservative equations * Updated reference values of 2D MHD tests that use initial_condition_convergence_test (new initial/exact solution depends on time) * Minor adjustment of reference values for MHD onion tests * adapt 1d * Update src/equations/ideal_glm_mhd_1d.jl --------- Co-authored-by: Daniel Doehring <[email protected]>
1 parent 53145ad commit 53c4725

File tree

9 files changed

+286
-117
lines changed

9 files changed

+286
-117
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using OrdinaryDiffEqLowStorageRK
2+
using Trixi
3+
4+
###############################################################################
5+
# semidiscretization of the compressible ideal GLM-MHD equations
6+
gamma = 5 / 3
7+
equations = IdealGlmMhdEquations2D(gamma)
8+
9+
initial_condition = initial_condition_convergence_test
10+
11+
volume_flux = (flux_central, flux_nonconservative_powell_local_symmetric)
12+
solver = DGSEM(polydeg = 3,
13+
surface_flux = (flux_lax_friedrichs,
14+
flux_nonconservative_powell_local_symmetric),
15+
volume_integral = VolumeIntegralFluxDifferencing(volume_flux))
16+
17+
coordinates_min = (0.0, 0.0)
18+
coordinates_max = (sqrt(2.0), sqrt(2.0))
19+
mesh = TreeMesh(coordinates_min, coordinates_max,
20+
initial_refinement_level = 4,
21+
n_cells_max = 10_000,
22+
periodicity = false)
23+
24+
boundary_conditions = (;
25+
x_neg = BoundaryConditionDirichlet(initial_condition_convergence_test),
26+
x_pos = BoundaryConditionDirichlet(initial_condition_convergence_test),
27+
y_neg = BoundaryConditionDirichlet(initial_condition_convergence_test),
28+
y_pos = BoundaryConditionDirichlet(initial_condition_convergence_test))
29+
30+
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
31+
boundary_conditions = boundary_conditions)
32+
33+
###############################################################################
34+
# ODE solvers, callbacks etc.
35+
36+
tspan = (0.0, 2.0)
37+
ode = semidiscretize(semi, tspan)
38+
39+
summary_callback = SummaryCallback()
40+
41+
analysis_interval = 100
42+
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
43+
save_analysis = true,
44+
extra_analysis_integrals = (entropy, energy_total,
45+
energy_kinetic,
46+
energy_internal,
47+
energy_magnetic,
48+
cross_helicity))
49+
50+
alive_callback = AliveCallback(analysis_interval = analysis_interval)
51+
52+
save_solution = SaveSolutionCallback(interval = 10,
53+
save_initial_solution = true,
54+
save_final_solution = true,
55+
solution_variables = cons2prim)
56+
57+
cfl = 1.5
58+
stepsize_callback = StepsizeCallback(cfl = cfl)
59+
60+
glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)
61+
62+
callbacks = CallbackSet(summary_callback,
63+
analysis_callback,
64+
alive_callback,
65+
save_solution,
66+
stepsize_callback,
67+
glm_speed_callback)
68+
69+
###############################################################################
70+
# run the simulation
71+
72+
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
73+
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
74+
ode_default_options()..., callback = callbacks);

src/equations/equations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ end
203203
else # u_boundary is "left" of boundary, u_inner is "right" of boundary
204204
flux = surface_flux_function(u_boundary, u_inner, orientation_or_normal,
205205
equations)
206-
noncons_flux = nonconservative_flux_function(u_boundary, u_inner,
206+
noncons_flux = nonconservative_flux_function(u_inner, u_boundary,
207207
orientation_or_normal,
208208
equations)
209209
end

src/equations/ideal_glm_mhd_1d.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function initial_condition_convergence_test(x, t, equations::IdealGlmMhdEquation
6969
RealT = eltype(x)
7070
rho = 1
7171
v1 = 0
72-
si, co = sincospi(2 * x[1])
72+
si, co = sincospi(2 * (x[1] + t)) # Adding `t` makes non-integer time valid
7373
v2 = convert(RealT, 0.1) * si
7474
v3 = convert(RealT, 0.1) * co
7575
p = convert(RealT, 0.1)

src/equations/ideal_glm_mhd_2d.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ function initial_condition_convergence_test(x, t, equations::IdealGlmMhdEquation
8383
RealT = eltype(x)
8484
alpha = 0.25f0 * convert(RealT, pi)
8585
x_perp = x[1] * cos(alpha) + x[2] * sin(alpha)
86-
B_perp = convert(RealT, 0.1) * sinpi(2 * x_perp)
86+
B_perp = convert(RealT, 0.1) * sinpi(2 * (x_perp + t))
8787
rho = 1
8888
v1 = -B_perp * sin(alpha)
8989
v2 = B_perp * cos(alpha)
90-
v3 = convert(RealT, 0.1) * cospi(2 * x_perp)
90+
v3 = convert(RealT, 0.1) * cospi(2 * (x_perp + t))
9191
p = convert(RealT, 0.1)
9292
B1 = cos(alpha) + v1
9393
B2 = sin(alpha) + v2

test/test_mpi_p4est_2d.jl

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -215,24 +215,28 @@ const EXAMPLES_DIR = pkgdir(Trixi, "examples", "p4est_2d_dgsem")
215215
@trixi_testset "elixir_mhd_alfven_wave_nonconforming.jl" begin
216216
@test_trixi_include(joinpath(EXAMPLES_DIR,
217217
"elixir_mhd_alfven_wave_nonconforming.jl"),
218-
l2=[0.032257043714485005,
219-
0.0698809831015213,
220-
0.07024507293378073,
221-
0.09318700512682686,
222-
0.04075287377819964,
223-
0.06598033890138222,
224-
0.06584394125943109,
225-
0.09317325194007701,
226-
0.001603893541181234],
227-
linf=[0.17598491051066556,
228-
0.13831592490115455,
229-
0.14124330399841845,
230-
0.17293937185553027,
231-
0.1332948089388849,
232-
0.16128651157312346,
233-
0.15572969249532598,
234-
0.1810247231315753,
235-
0.01967917976620706],
218+
l2=[
219+
0.0322570437144848,
220+
0.03598284801272945,
221+
0.03562228071357411,
222+
0.05288641880143085,
223+
0.040752873778199326,
224+
0.04207276835260492,
225+
0.04171391252403866,
226+
0.05289242879893149,
227+
0.0016038935411812223
228+
],
229+
linf=[
230+
0.175984910510666,
231+
0.13999726708245439,
232+
0.13336032728399658,
233+
0.21248359539637798,
234+
0.133294808938885,
235+
0.17934684696413217,
236+
0.1831567822932948,
237+
0.21575881133569155,
238+
0.01967917976620703
239+
],
236240
tspan=(0.0, 0.25),)
237241
# Ensure that we do not have excessive memory allocations
238242
# (e.g., from type instabilities)
@@ -249,26 +253,26 @@ const EXAMPLES_DIR = pkgdir(Trixi, "examples", "p4est_2d_dgsem")
249253
@test_trixi_include(joinpath(EXAMPLES_DIR,
250254
"elixir_mhd_alfven_wave_nonconforming.jl"),
251255
l2=[
252-
0.02918489280986602,
253-
0.06894247101538993,
254-
0.06934211084749892,
255-
0.09143968257530088,
256-
0.038237912462171675,
257-
0.06509909515945271,
258-
0.06502196369480336,
259-
0.0915205366320386,
260-
0.0023325491966802855
256+
0.02918489280986591,
257+
0.03430197485998593,
258+
0.033958258414233555,
259+
0.05015261058202805,
260+
0.03823791246217151,
261+
0.04013747495809935,
262+
0.039752335789428925,
263+
0.05021821589628951,
264+
0.002332549196680272
261265
],
262266
linf=[
263-
0.10312055320325908,
264-
0.13916440641975747,
265-
0.14191886090656713,
266-
0.16048337905766766,
267+
0.1031205532032593,
268+
0.1408724803980772,
269+
0.1377071548888711,
270+
0.24265946222482881,
267271
0.12403522681540824,
268-
0.14689365133406318,
269-
0.1568420189383094,
270-
0.16311092390521648,
271-
0.01959765683054841
272+
0.19380378175033763,
273+
0.19743139999820714,
274+
0.2453908414271658,
275+
0.019597656830548395
272276
],
273277
tspan=(0.0, 0.25), trees_per_dimension=(1, 1),)
274278
# Ensure that we do not have excessive memory allocations

test/test_p4est_2d.jl

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -644,24 +644,28 @@ end
644644
@trixi_testset "elixir_mhd_alfven_wave_nonconforming.jl" begin
645645
@test_trixi_include(joinpath(EXAMPLES_DIR,
646646
"elixir_mhd_alfven_wave_nonconforming.jl"),
647-
l2=[0.032257043714485005,
648-
0.0698809831015213,
649-
0.07024507293378073,
650-
0.09318700512682686,
651-
0.04075287377819964,
652-
0.06598033890138222,
653-
0.06584394125943109,
654-
0.09317325194007701,
655-
0.001603893541181234],
656-
linf=[0.17598491051066556,
657-
0.13831592490115455,
658-
0.14124330399841845,
659-
0.17293937185553027,
660-
0.1332948089388849,
661-
0.16128651157312346,
662-
0.15572969249532598,
663-
0.1810247231315753,
664-
0.01967917976620706],
647+
l2=[
648+
0.0322570437144848,
649+
0.03598284801272945,
650+
0.03562228071357411,
651+
0.05288641880143085,
652+
0.040752873778199326,
653+
0.04207276835260492,
654+
0.04171391252403866,
655+
0.05289242879893149,
656+
0.0016038935411812223
657+
],
658+
linf=[
659+
0.175984910510666,
660+
0.13999726708245439,
661+
0.13336032728399658,
662+
0.21248359539637798,
663+
0.133294808938885,
664+
0.17934684696413217,
665+
0.1831567822932948,
666+
0.21575881133569155,
667+
0.01967917976620703
668+
],
665669
tspan=(0.0, 0.25))
666670
# Ensure that we do not have excessive memory allocations
667671
# (e.g., from type instabilities)

test/test_structured_2d.jl

Lines changed: 80 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -996,15 +996,14 @@ end
996996

997997
@trixi_testset "elixir_mhd_onion.jl" begin
998998
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_mhd_onion.jl"),
999-
l2=[0.006145639992956197, 0.042989758089762846,
1000-
0.009442309049940338, 0.0,
1001-
0.02346607486955775, 0.003700847949592663,
1002-
0.006939946054722184, 0.0, 5.379622479061923e-7],
1003-
linf=[0.04033992113717777, 0.2507389500590965,
1004-
0.055979197375423013, 0.0,
1005-
0.14115256348718286, 0.01995761261479112,
1006-
0.038667260744994936, 0.0,
1007-
3.3767778019495598e-6])
999+
l2=[0.00614563999392665, 0.04298975803343982,
1000+
0.009442309044853874, 0.0,
1001+
0.023466074865980138, 0.0037008480771081663,
1002+
0.006939946049331198, 0.0, 5.379545284544848e-7],
1003+
linf=[0.04033992113717799, 0.2507389500590966,
1004+
0.05597919737542288, 0.0,
1005+
0.14115256348718308, 0.01995761261479123,
1006+
0.038667260744994714, 0.0, 3.376777801961409e-6])
10081007
# Ensure that we do not have excessive memory allocations
10091008
# (e.g., from type instabilities)
10101009
let
@@ -1042,45 +1041,87 @@ end
10421041
@trixi_testset "elixir_mhd_coupled.jl" begin
10431042
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_mhd_coupled.jl"),
10441043
l2=[
1045-
1.0743426980507015e-7, 0.030901698521864966,
1046-
0.030901698662039206, 0.04370160129981656,
1047-
8.259193827852516e-8, 0.03090169908364623,
1048-
0.030901699039770684, 0.04370160128147447,
1049-
8.735923402748945e-9, 1.0743426996067106e-7,
1050-
0.03090169852186498, 0.030901698662039206,
1051-
0.04370160129981657, 8.259193829690747e-8,
1052-
0.03090169908364624, 0.030901699039770726,
1053-
0.04370160128147445, 8.73592340076897e-9
1044+
1.0743426976677776e-7,
1045+
5.941703122781545e-8,
1046+
6.373264854058786e-8,
1047+
1.0327320202980158e-7,
1048+
8.259193826511926e-8,
1049+
8.377839796183567e-8,
1050+
7.469434303577898e-8,
1051+
1.0770585130793933e-7,
1052+
8.735923402823923e-9,
1053+
1.0743426990741475e-7,
1054+
5.941703121622708e-8,
1055+
6.373264853185012e-8,
1056+
1.0327320202884373e-7,
1057+
8.259193828324533e-8,
1058+
8.377839796046157e-8,
1059+
7.469434302767398e-8,
1060+
1.077058513088068e-7,
1061+
8.735923400740853e-9
10541062
],
10551063
linf=[
1056-
9.021023431587949e-7, 0.043701454182710486,
1057-
0.043701458294527366, 0.061803146322536154,
1058-
9.487023335807976e-7, 0.043701561010342616,
1059-
0.04370147392153734, 0.06180318786081025,
1060-
3.430673132525334e-8, 9.02102342825728e-7,
1061-
0.043701454182710764, 0.043701458294525895,
1062-
0.06180314632253597, 9.487023254761695e-7,
1063-
0.04370156101034084, 0.04370147392153745,
1064-
0.06180318786081015, 3.430672973680963e-8
1064+
9.021023420485719e-7,
1065+
5.540360292766167e-7,
1066+
8.97403747285308e-7,
1067+
9.962467816537757e-7,
1068+
9.48702334468976e-7,
1069+
1.4284730157632097e-6,
1070+
5.317911039304235e-7,
1071+
9.92786089865083e-7,
1072+
3.4306731372516224e-8,
1073+
9.021023412714158e-7,
1074+
5.540360226014007e-7,
1075+
8.974037428166604e-7,
1076+
9.962467838325884e-7,
1077+
9.487023256982141e-7,
1078+
1.4284730160962766e-6,
1079+
5.317911003777098e-7,
1080+
9.92786092363085e-7,
1081+
3.430672968714232e-8
10651082
],)
10661083

10671084
@testset "analysis_callback(sol) for AnalysisCallbackCoupled" begin
10681085
errors = analysis_callback(sol)
10691086
@test errors.l2[
1070-
1.0743426980507015e-7, 0.030901698521864966, 0.030901698662039206,
1071-
0.04370160129981656, 8.259193827852516e-8, 0.03090169908364623,
1072-
0.030901699039770684, 0.04370160128147447, 8.735923402748945e-9,
1073-
1.0743426996067106e-7, 0.03090169852186498, 0.030901698662039206,
1074-
0.04370160129981657, 8.259193829690747e-8, 0.03090169908364624,
1075-
0.030901699039770726, 0.04370160128147445, 8.73592340076897e-9
1087+
1.0743426976677776e-7,
1088+
5.941703122781545e-8,
1089+
6.373264854058786e-8,
1090+
1.0327320202980158e-7,
1091+
8.259193826511926e-8,
1092+
8.377839796183567e-8,
1093+
7.469434303577898e-8,
1094+
1.0770585130793933e-7,
1095+
8.735923402823923e-9,
1096+
1.0743426990741475e-7,
1097+
5.941703121622708e-8,
1098+
6.373264853185012e-8,
1099+
1.0327320202884373e-7,
1100+
8.259193828324533e-8,
1101+
8.377839796046157e-8,
1102+
7.469434302767398e-8,
1103+
1.077058513088068e-7,
1104+
8.735923400740853e-9
10761105
] rtol=1.0e-4
10771106
@test errors.linf[
1078-
9.021023431587949e-7, 0.043701454182710486, 0.043701458294527366,
1079-
0.061803146322536154, 9.487023335807976e-7, 0.043701561010342616,
1080-
0.04370147392153734, 0.06180318786081025, 3.430673132525334e-8,
1081-
9.02102342825728e-7, 0.043701454182710764, 0.043701458294525895,
1082-
0.06180314632253597, 9.487023254761695e-7, 0.04370156101034084,
1083-
0.04370147392153745, 0.06180318786081015, 3.430672973680963e-8
1107+
9.021023420485719e-7,
1108+
5.540360292766167e-7,
1109+
8.97403747285308e-7,
1110+
9.962467816537757e-7,
1111+
9.48702334468976e-7,
1112+
1.4284730157632097e-6,
1113+
5.317911039304235e-7,
1114+
9.92786089865083e-7,
1115+
3.4306731372516224e-8,
1116+
9.021023412714158e-7,
1117+
5.540360226014007e-7,
1118+
8.974037428166604e-7,
1119+
9.962467838325884e-7,
1120+
9.487023256982141e-7,
1121+
1.4284730160962766e-6,
1122+
5.317911003777098e-7,
1123+
9.92786092363085e-7,
1124+
3.430672968714232e-8
10841125
] rtol=1.0e-4
10851126
# Ensure that we do not have excessive memory allocations
10861127
# (e.g., from type instabilities)

0 commit comments

Comments
 (0)