Skip to content

Commit

Permalink
update 2D convergence test
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickersing committed Apr 26, 2024
1 parent 5145e7e commit 7f00ff7
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using TrixiShallowWater
###############################################################################
# Semidiscretization of the multilayer shallow water equations with three layers

equations = ShallowWaterMultiLayerEquations2D(gravity_constant = 10.0,
equations = ShallowWaterMultiLayerEquations2D(gravity_constant = 1.1,
rhos = (0.9, 1.0, 1.1))

initial_condition = initial_condition_convergence_test
Expand All @@ -25,8 +25,8 @@ solver = DGSEM(polydeg = 3,
coordinates_min = (0.0, 0.0)
coordinates_max = (sqrt(2.0), sqrt(2.0))
mesh = TreeMesh(coordinates_min, coordinates_max,
initial_refinement_level = 4,
n_cells_max = 10_000,
initial_refinement_level = 2,
n_cells_max = 100_000,
periodicity = true)

# create the semi discretization object
Expand All @@ -50,12 +50,16 @@ save_solution = SaveSolutionCallback(interval = 500,
save_initial_solution = true,
save_final_solution = true)

callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback, save_solution)
stepsize_callback = StepsizeCallback(cfl = 1.0)

callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback, save_solution,
stepsize_callback)

###############################################################################
# run the simulation

# use a Runge-Kutta method with automatic (error based) time step size control
sol = solve(ode, RDPK3SpFSAL49(), abstol = 1.0e-8, reltol = 1.0e-8,
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using TrixiShallowWater
# Semidiscretization of the multilayer shallow water equations with a periodic
# bottom topography function (set in the initial conditions)

equations = ShallowWaterMultiLayerEquations2D(gravity_constant = 10.0,
equations = ShallowWaterMultiLayerEquations2D(gravity_constant = 1.1,
rhos = (0.9, 1.0, 1.1))

initial_condition = initial_condition_convergence_test
Expand Down Expand Up @@ -50,13 +50,16 @@ save_solution = SaveSolutionCallback(interval = 500,
save_initial_solution = true,
save_final_solution = true)

callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback, save_solution)
stepsize_callback = StepsizeCallback(cfl = 0.9)

callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback, save_solution, stepsize_callback)

###############################################################################
# run the simulation

# use a Runge-Kutta method with automatic (error based) time step size control
sol = solve(ode, RDPK3SpFSAL49(), abstol = 1.0e-8, reltol = 1.0e-8,
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);

summary_callback() # print the timer summary
61 changes: 35 additions & 26 deletions src/equations/shallow_water_multilayer_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function Trixi.initial_condition_convergence_test(x, t,
end

# Some constants are chosen such that the function is periodic on the domain [0,sqrt(2)]
ω = 2.0 * pi * sqrt(2.0)
ω = pi * sqrt(2.0)

H3 = 1.5 + 0.1 * cos* x[1] + t) + 0.1 * cos* x[2] + t)
H2 = 2.0 + 0.1 * sin* x[1] + t) + 0.1 * sin* x[2] + t)
Expand All @@ -166,7 +166,8 @@ in non-periodic domains).
equations::ShallowWaterMultiLayerEquations2D)
# Same settings as in `initial_condition_convergence_test`. Some derivative simplify because
# this manufactured solution velocity is taken to be constant
ω = 2 * pi * sqrt(2.0)
ω = pi * sqrt(2.0)
g = equations.gravity

du1 = (-0.1 * cos(t + x[2] * ω) - 0.1 * sin(t + x[1] * ω) -
0.1 * sin(t + x[2] * ω) -
Expand All @@ -189,10 +190,12 @@ in non-periodic domains).
0.1 * cos(t + x[1] * ω)) +
0.8 * (-0.1 * cos(t + x[2] * ω) * ω - 0.1 * sin(t + x[2] * ω) * ω) +
0.8^2 * (-0.1 * sin(t + x[1] * ω) * ω - 0.1 * cos(t + x[1] * ω) * ω) +
10.0 *
g *
(2.0 + 0.1 * cos(t + x[2] * ω) - 0.1 * sin(t + x[1] * ω) -
0.1 * sin(t + x[2] * ω) + 0.1 * cos(t + x[1] * ω)) *
0.1 * sin(t + x[2] * ω) +
0.1 * cos(t + x[1] * ω)) *
(-0.1 * sin(t + x[1] * ω) * ω - 0.1 * cos(t + x[1] * ω) * ω) +
0.1 * g *
(2.0 + 0.1 * cos(t + x[2] * ω) - 0.1 * sin(t + x[1] * ω) -
0.1 * sin(t + x[2] * ω) +
0.1 * cos(t + x[1] * ω)) * cos(t + x[1] * ω) * ω)
Expand All @@ -202,24 +205,26 @@ in non-periodic domains).
0.1 * cos(t + x[1] * ω)) +
0.8 * (0.1 * cos(t + x[2] * ω) * ω + 0.1 * sin(t + x[2] * ω) * ω) +
0.8^2 * (0.1 * sin(t + x[1] * ω) * ω + 0.1 * cos(t + x[1] * ω) * ω) +
10.0 *
g *
(0.5 - 0.1 * cos(t + x[2] * ω) + 0.1 * sin(t + x[1] * ω) +
0.1 * sin(t + x[2] * ω) - 0.1 * cos(t + x[1] * ω)) *
(0.1 * sin(t + x[1] * ω) * ω + 0.1 * cos(t + x[1] * ω) * ω) +
10.0 *
(0.5 - 0.1 * cos(t + x[2] * ω) + 0.1 * sin(t + x[1] * ω) +
0.1 * sin(t + x[2] * ω) - 0.1 * cos(t + x[1] * ω)) *
0.1 * sin(t + x[2] * ω) -
0.1 * cos(t + x[1] * ω)) *
(-0.1 * sin(t + x[1] * ω) * ω +
0.9 * (-0.1 * sin(t + x[1] * ω) * ω - 0.1 * cos(t + x[1] * ω) * ω)))
0.9 * (-0.1 * sin(t + x[1] * ω) * ω - 0.1 * cos(t + x[1] * ω) * ω)) +
g *
(0.5 - 0.1 * cos(t + x[2] * ω) + 0.1 * sin(t + x[1] * ω) +
0.1 * sin(t + x[2] * ω) -
0.1 * cos(t + x[1] * ω)) *
(0.1 * sin(t + x[1] * ω) * ω + 0.1 * cos(t + x[1] * ω) * ω))

du6 = (0.8 * (-0.1 * sin(t + x[1] * ω) - 0.1 * sin(t + x[2] * ω)) +
0.8 * (0.1 * sin(x[2] * ω) * ω - 0.1 * sin(t + x[2] * ω) * ω) +
0.8^2 * (0.1 * sin(x[1] * ω) * ω - 0.1 * sin(t + x[1] * ω) * ω) +
10.0 *
g *
(0.5 - 0.1 * cos(x[1] * ω) + 0.1 * cos(t + x[2] * ω) - 0.1 * cos(x[2] * ω) +
0.1 * cos(t + x[1] * ω)) *
(0.1 * sin(x[1] * ω) * ω - 0.1 * sin(t + x[1] * ω) * ω) +
10.0 *
g *
(0.5 - 0.1 * cos(x[1] * ω) + 0.1 * cos(t + x[2] * ω) - 0.1 * cos(x[2] * ω) +
0.1 * cos(t + x[1] * ω)) *
(-0.1 * sin(x[1] * ω) * ω +
Expand All @@ -231,39 +236,43 @@ in non-periodic domains).
0.1 * cos(t + x[1] * ω) - 0.1 * cos(t + x[2] * ω) * ω +
0.8 * (-0.1 * sin(t + x[1] * ω) * ω - 0.1 * cos(t + x[1] * ω) * ω) -
0.1 * sin(t + x[2] * ω) * ω +
10.0 *
0.1 * g *
(2.0 + 0.1 * cos(t + x[2] * ω) - 0.1 * sin(t + x[1] * ω) -
0.1 * sin(t + x[2] * ω) + 0.1 * cos(t + x[1] * ω)) *
(-0.1 * cos(t + x[2] * ω) * ω - 0.1 * sin(t + x[2] * ω) * ω) +
0.1 * sin(t + x[2] * ω) +
0.1 * cos(t + x[1] * ω)) * cos(t + x[2] * ω) * ω +
g *
(2.0 + 0.1 * cos(t + x[2] * ω) - 0.1 * sin(t + x[1] * ω) -
0.1 * sin(t + x[2] * ω) +
0.1 * cos(t + x[1] * ω)) * cos(t + x[2] * ω) * ω)
0.1 * cos(t + x[1] * ω)) *
(-0.1 * cos(t + x[2] * ω) * ω - 0.1 * sin(t + x[2] * ω) * ω))

du8 = (0.1 * cos(t + x[2] * ω) + 0.1 * sin(t + x[1] * ω) + 0.1 * sin(t + x[2] * ω) +
0.1 * cos(t + x[1] * ω) + 0.1 * cos(t + x[2] * ω) * ω +
0.8 * (0.1 * sin(t + x[1] * ω) * ω + 0.1 * cos(t + x[1] * ω) * ω) +
0.1 * sin(t + x[2] * ω) * ω +
10.0 *
g *
(0.5 - 0.1 * cos(t + x[2] * ω) + 0.1 * sin(t + x[1] * ω) +
0.1 * sin(t + x[2] * ω) - 0.1 * cos(t + x[1] * ω)) *
(0.9 * (-0.1 * cos(t + x[2] * ω) * ω - 0.1 * sin(t + x[2] * ω) * ω) -
0.1 * sin(t + x[2] * ω) * ω) +
10.0 *
0.1 * sin(t + x[2] * ω) -
0.1 * cos(t + x[1] * ω)) *
(0.1 * cos(t + x[2] * ω) * ω + 0.1 * sin(t + x[2] * ω) * ω) +
g *
(0.5 - 0.1 * cos(t + x[2] * ω) + 0.1 * sin(t + x[1] * ω) +
0.1 * sin(t + x[2] * ω) - 0.1 * cos(t + x[1] * ω)) *
(0.1 * cos(t + x[2] * ω) * ω + 0.1 * sin(t + x[2] * ω) * ω))
0.1 * sin(t + x[2] * ω) -
0.1 * cos(t + x[1] * ω)) *
(0.9 * (-0.1 * cos(t + x[2] * ω) * ω - 0.1 * sin(t + x[2] * ω) * ω) -
0.1 * sin(t + x[2] * ω) * ω))

du9 = (-0.1 * sin(t + x[1] * ω) - 0.1 * sin(t + x[2] * ω) +
0.1 * sin(x[2] * ω) * ω +
0.8 * (0.1 * sin(x[1] * ω) * ω - 0.1 * sin(t + x[1] * ω) * ω) -
0.1 * sin(t + x[2] * ω) * ω +
10.0 *
g *
(0.5 - 0.1 * cos(x[1] * ω) + 0.1 * cos(t + x[2] * ω) - 0.1 * cos(x[2] * ω) +
0.1 * cos(t + x[1] * ω)) *
(0.9 / 1.1 * (-0.1 * cos(t + x[2] * ω) * ω - 0.1 * sin(t + x[2] * ω) * ω) +
1.0 / 1.1 * (0.1 * cos(t + x[2] * ω) * ω + 0.1 * sin(t + x[2] * ω) * ω) -
0.1 * sin(x[2] * ω) * ω) +
10.0 *
g *
(0.5 - 0.1 * cos(x[1] * ω) + 0.1 * cos(t + x[2] * ω) - 0.1 * cos(x[2] * ω) +
0.1 * cos(t + x[1] * ω)) *
(0.1 * sin(x[2] * ω) * ω - 0.1 * sin(t + x[2] * ω) * ω))
Expand Down
80 changes: 40 additions & 40 deletions test/test_tree_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -448,28 +448,28 @@ end # 2LSWE
@test_trixi_include(joinpath(EXAMPLES_DIR,
"elixir_shallowwater_multilayer_convergence.jl"),
l2=[
0.00013147471504344405,
0.00015514765626121514,
0.000189385179009786,
0.00011608534902216235,
0.00015078355278842716,
0.00014740625262810186,
0.00011588655436490155,
0.00018765407379989162,
0.00016853529382291021,
1.2548293535443184e-5,
0.001578480912165503,
0.0010725791806397446,
0.00036117546296274316,
0.0010107766709183063,
0.0009612673392275463,
0.00026390576962071974,
0.001140711809558893,
0.001197469124790338,
0.00031384421384170294,
0.00019675440964325044,
],
linf=[
0.0007914697417876759,
0.0006348222705068185,
0.001002926474891086,
0.0006466327311540621,
0.0009859041580843608,
0.0008083921716079412,
0.0006016100163761529,
0.0010877289257850142,
0.0010435037400048364,
3.639351911033373e-5,
0.006611273262461914,
0.0047987596637860674,
0.001476163166610922,
0.004378481797734368,
0.004059620398096986,
0.00107253722812789,
0.004650692998510841,
0.005014864957408438,
0.0013175223929244861,
0.0004374891172380657,
],
tspan=(0.0, 0.25))
# Ensure that we do not have excessive memory allocations
Expand All @@ -486,28 +486,28 @@ end # 2LSWE
@test_trixi_include(joinpath(EXAMPLES_DIR,
"elixir_shallowwater_multilayer_convergence.jl"),
l2=[
0.00015249970137499414,
9.061891979391998e-5,
9.396591776903845e-5,
0.00011273701474177127,
6.279405808220591e-5,
5.3495033579633576e-5,
0.00010797255635235481,
7.167327550380933e-5,
7.40293792497647e-5,
1.2548293535443157e-5,
0.0009657284251663235,
0.0007574316192008629,
0.00014884847789419973,
0.0008365221427534766,
0.0005829573732731771,
0.00013759996082561183,
0.0009795167874289885,
0.0007208939038902295,
0.00015863343571957187,
0.00019675440964325044,
],
linf=[
0.0007475490650712402,
0.00040410931043857734,
0.0004618601405063094,
0.0005819120302106295,
0.00033956825032638305,
0.00016617565116200383,
0.0005672335445119359,
0.0003107057954721548,
0.00038873185787224873,
3.639351911033373e-5,
0.005343578840408814,
0.005546044302341735,
0.0005110705217063471,
0.004897047461771331,
0.004047517471484768,
0.0005991894625433924,
0.006191481703377466,
0.005110806058533313,
0.000775668423696807,
0.0004374891172380657,
],
surface_flux=(flux_lax_friedrichs,
flux_nonconservative_ersing_etal),
Expand Down
Loading

0 comments on commit 7f00ff7

Please sign in to comment.