Skip to content

Commit

Permalink
fix convergence tests 2
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickersing committed Aug 12, 2024
1 parent 9973b06 commit a265e6e
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 45 deletions.
109 changes: 109 additions & 0 deletions examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_grass.jl
Original file line number Diff line number Diff line change
@@ -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,

Check warning on line 15 in examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_grass.jl

View check run for this annotation

Codecov / codecov/patch

examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_grass.jl#L15

Added line #L15 was not covered by tests
equations::ShallowWaterExnerEquations1D)
ω = sqrt(2) * pi

Check warning on line 17 in examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_grass.jl

View check run for this annotation

Codecov / codecov/patch

examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_grass.jl#L17

Added line #L17 was not covered by tests

h = 2.0 + cos* x[1]) * cos* t)
v = 0.5
h_b = 2.0 + sin* x[1]) * cos* t)

Check warning on line 21 in examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_grass.jl

View check run for this annotation

Codecov / codecov/patch

examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_grass.jl#L19-L21

Added lines #L19 - L21 were not covered by tests

return SVector(h, h * v, h_b)

Check warning on line 23 in examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_grass.jl

View check run for this annotation

Codecov / codecov/patch

examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_grass.jl#L23

Added line #L23 was not covered by tests
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,

Check warning on line 34 in examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_grass.jl

View check run for this annotation

Codecov / codecov/patch

examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_grass.jl#L34

Added line #L34 was not covered by tests
equations::ShallowWaterExnerEquations1D{T,
S,
GrassModel{T}}) where {
T,
S
}
ω = sqrt(2.0) * pi
A_g = equations.sediment_model.A_g

Check warning on line 42 in examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_grass.jl

View check run for this annotation

Codecov / codecov/patch

examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_grass.jl#L41-L42

Added lines #L41 - L42 were not covered by tests

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 * ω) * ω +

Check warning on line 45 in examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_grass.jl

View check run for this annotation

Codecov / codecov/patch

examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_grass.jl#L44-L45

Added lines #L44 - L45 were not covered by tests
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)

Check warning on line 51 in examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_grass.jl

View check run for this annotation

Codecov / codecov/patch

examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_grass.jl#L50-L51

Added lines #L50 - L51 were not covered by tests
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
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Check warning on line 16 in examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_mpm.jl

View check run for this annotation

Codecov / codecov/patch

examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_mpm.jl#L16

Added line #L16 was not covered by tests
Expand Down Expand Up @@ -64,34 +65,6 @@ end
return SVector(h, hv, h_b)

Check warning on line 65 in examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_mpm.jl

View check run for this annotation

Codecov / codecov/patch

examples/tree_1d_dgsem/elixir_shallowwater_exner_source_terms_mpm.jl#L65

Added line #L65 was not covered by tests
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

###############################################################################
Expand Down
22 changes: 8 additions & 14 deletions test/test_tree_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit a265e6e

Please sign in to comment.