diff --git a/examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_grass.jl b/examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_grass.jl new file mode 100644 index 0000000..9da9326 --- /dev/null +++ b/examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_grass.jl @@ -0,0 +1,109 @@ +using OrdinaryDiffEq +using Trixi +using TrixiShallowWater + +############################################################################### +# Semidiscretization of the SWE-Exner equations with source terms for convergence testing + +# Equations with Grass model +equations = ShallowWaterExnerEquations1D(gravity_constant = 10.0, rho_f = 0.5, + rho_s = 1.0, porosity = 0.5, + friction = ManningFriction(n = 0.0), + sediment_model = GrassModel(A_g = 0.01)) + +# Smooth initial condition to test convergence +@inline function Trixi.initial_condition_convergence_test(x, t, + equations::ShallowWaterExnerEquations1D) + ω = sqrt(2) * pi + + h = 2.0 + cos(ω * x[1]) * cos(ω * t) + v = 0.5 + h_b = 2.0 + sin(ω * x[1]) * cos(ω * t) + + return SVector(h, h * v, h_b) +end + +# Source terms used for convergence tests in combination with [`initial_condition_convergence_test`](@extref) +# when using the the [`GrassModel`](@ref) model. +# To use this source term the equations must be set to: +# +# equations = ShallowWaterExnerEquations1D(gravity_constant = 10.0, rho_f = 0.5, +# rho_s = 1.0, porosity = 0.5, +# friction = ManningFriction(n = 0.0), +# sediment_model = GrassModel(A_g = 0.01) +@inline function Trixi.source_terms_convergence_test(u, x, t, + equations::ShallowWaterExnerEquations1D{T, + S, + GrassModel{T}}) where { + T, + S + } + ω = sqrt(2.0) * pi + A_g = equations.sediment_model.A_g + + h = -cos(x[1] * ω) * sin(t * ω) * ω - 0.5 * sin(x[1] * ω) * cos(t * ω) * ω + hv = -0.5 * cos(x[1] * ω) * sin(t * ω) * ω - 0.25 * sin(x[1] * ω) * cos(t * ω) * ω + + 10.0 * A_g * + (cos(x[1] * ω) * cos(t * ω) * ω - 0.5 * sin(x[1] * ω) * cos(t * ω) * ω) + + 10.0 * (2.0 + cos(x[1] * ω) * cos(t * ω)) * + (cos(x[1] * ω) * cos(t * ω) * ω - sin(x[1] * ω) * cos(t * ω) * ω) + h_b = -sin(x[1] * ω) * sin(t * ω) * ω + return SVector(h, hv, h_b) +end + +initial_condition = initial_condition_convergence_test + +############################################################################### +# Get the DG approximation space + +volume_flux = (flux_ersing_etal, flux_nonconservative_ersing_etal) +surface_flux = (flux_ersing_etal, flux_nonconservative_ersing_etal) + +solver = DGSEM(polydeg = 4, + surface_flux = surface_flux, + volume_integral = VolumeIntegralFluxDifferencing(volume_flux)) + +############################################################################### +# Get the TreeMesh and setup a periodic mesh + +coordinates_min = 0.0 +coordinates_max = sqrt(2.0) +mesh = TreeMesh(coordinates_min, coordinates_max, + initial_refinement_level = 2, + n_cells_max = 10_000, + periodicity = true) + +# create the semi discretization object +semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver, + source_terms = source_terms_convergence_test) + +############################################################################### +# ODE solvers, callbacks etc. + +tspan = (0.0, 1.0) +ode = semidiscretize(semi, tspan) + +summary_callback = SummaryCallback() + +analysis_interval = 200 +analysis_callback = AnalysisCallback(semi, interval = analysis_interval) + +alive_callback = AliveCallback(analysis_interval = analysis_interval) + +stepsize_callback = StepsizeCallback(cfl = 1.0) + +save_solution = SaveSolutionCallback(interval = 200, + save_initial_solution = true, + save_final_solution = true) + +callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback, + stepsize_callback, save_solution) + +############################################################################### +# run the simulation + +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 diff --git a/examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms.jl b/examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_mpm.jl similarity index 73% rename from examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms.jl rename to examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_mpm.jl index eb3dcc5..32d7fa8 100644 --- a/examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms.jl +++ b/examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_mpm.jl @@ -5,11 +5,12 @@ using TrixiShallowWater ############################################################################### # Semidiscretization of the SWE-Exner equations with source terms for convergence testing -# Equations with Grass model +# Equations with Meyer-Peter-Mueller model equations = ShallowWaterExnerEquations1D(gravity_constant = 10.0, rho_f = 0.5, rho_s = 1.0, porosity = 0.5, - friction = ManningFriction(n = 0.0), - sediment_model = GrassModel(A_g = 0.01)) + friction = ManningFriction(n = 0.01), + sediment_model = MeyerPeterMueller(theta_c = 0.0, + d_s = 1e-3)) # Smooth initial condition to test convergence @inline function Trixi.initial_condition_convergence_test(x, t, @@ -64,34 +65,6 @@ end return SVector(h, hv, h_b) end -# Source terms used for convergence tests in combination with [`initial_condition_convergence_test`](@extref) -# when using the the [`GrassModel`](@ref) model. -# To use this source term the equations must be set to: -# -# equations = ShallowWaterExnerEquations1D(gravity_constant = 10.0, rho_f = 0.5, -# rho_s = 1.0, porosity = 0.5, -# friction = ManningFriction(n = 0.0), -# sediment_model = GrassModel(A_g = 0.01) -@inline function Trixi.source_terms_convergence_test(u, x, t, - equations::ShallowWaterExnerEquations1D{T, - S, - GrassModel{T}}) where { - T, - S - } - ω = sqrt(2.0) * pi - A_g = equations.sediment_model.A_g - - h = -cos(x[1] * ω) * sin(t * ω) * ω - 0.5 * sin(x[1] * ω) * cos(t * ω) * ω - hv = -0.5 * cos(x[1] * ω) * sin(t * ω) * ω - 0.25 * sin(x[1] * ω) * cos(t * ω) * ω + - 10.0 * A_g * - (cos(x[1] * ω) * cos(t * ω) * ω - 0.5 * sin(x[1] * ω) * cos(t * ω) * ω) + - 10.0 * (2.0 + cos(x[1] * ω) * cos(t * ω)) * - (cos(x[1] * ω) * cos(t * ω) * ω - sin(x[1] * ω) * cos(t * ω) * ω) - h_b = -sin(x[1] * ω) * sin(t * ω) * ω - return SVector(h, hv, h_b) -end - initial_condition = initial_condition_convergence_test ############################################################################### diff --git a/test/test_tree_1d.jl b/test/test_tree_1d.jl index d0b530b..f96df5c 100644 --- a/test/test_tree_1d.jl +++ b/test/test_tree_1d.jl @@ -825,9 +825,9 @@ end # 2LSWE end # MLSWE @testset "Shallow Water - Exner" begin - @trixi_testset "elixir_shallowwater_exner_source_terms.jl with EC fluxes/Grass" begin + @trixi_testset "elixir_shallowwater_exner_source_terms_grass.jl with EC fluxes" begin @test_trixi_include(joinpath(EXAMPLES_DIR, - "elixir_shallowwater_exner_source_terms.jl"), + "elixir_shallowwater_exner_source_terms_grass.jl"), l2=[ 0.0004102960441666415, 0.0024123111823754154, @@ -848,9 +848,9 @@ end # MLSWE end end - @trixi_testset "elixir_shallowwater_exner_source_terms.jl with Roe/MPM" begin + @trixi_testset "elixir_shallowwater_exner_source_terms_mpm.jl with Roe dissipation" begin @test_trixi_include(joinpath(EXAMPLES_DIR, - "elixir_shallowwater_exner_source_terms.jl"), + "elixir_shallowwater_exner_source_terms_mpm.jl"), l2=[ 8.314469574617161e-5, 0.00037371557342261787, @@ -863,10 +863,7 @@ end # MLSWE ], surface_flux=(FluxPlusDissipation(flux_ersing_etal, dissipation_roe), - flux_nonconservative_ersing_etal), - friction=ManningFriction(n = 0.01), - sediment_model=MeyerPeterMueller(theta_c = 0.0, - d_s = 1e-3)) + flux_nonconservative_ersing_etal)) # Ensure that we do not have excessive memory allocations # (e.g., from type instabilities) let @@ -877,9 +874,9 @@ end # MLSWE end end - @trixi_testset "elixir_shallowwater_exner_source_terms.jl with LLF/MPM" begin + @trixi_testset "elixir_shallowwater_exner_source_terms_mpm.jl with LLF dissipation" begin @test_trixi_include(joinpath(EXAMPLES_DIR, - "elixir_shallowwater_exner_source_terms.jl"), + "elixir_shallowwater_exner_source_terms_mpm.jl"), l2=[ 8.494087939853228e-5, 0.00037012479603853885, @@ -892,10 +889,7 @@ end # MLSWE ], surface_flux=(FluxPlusDissipation(flux_ersing_etal, DissipationLocalLaxFriedrichs()), - flux_nonconservative_ersing_etal), - friction=ManningFriction(n = 0.01), - sediment_model=MeyerPeterMueller(theta_c = 0.0, - d_s = 1e-3)) + flux_nonconservative_ersing_etal)) # Ensure that we do not have excessive memory allocations # (e.g., from type instabilities) let