Skip to content

Commit

Permalink
Add convergence_test (#43)
Browse files Browse the repository at this point in the history
* add convergece_test

* format

* explicitly define accuracy_order in convergence_test relaxation example
  • Loading branch information
JoshuaLampert authored Sep 24, 2023
1 parent 547de79 commit a1a0fb3
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 102 deletions.
176 changes: 88 additions & 88 deletions create_figures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ using DispersiveShallowWater
using Plots

# Use a macro to avoid world age issues when defining new initial conditions etc.
# inside an elixir.
macro plot_elixir(filename, args...)
# inside an example.
macro plot_example(filename, args...)
local ylims_gif = get_kwarg(args, :ylims_gif, nothing)
local ylims_x = get_kwarg(args, :ylims_x, nothing)
local x_values = get_kwarg(args, :x_values, [])
Expand Down Expand Up @@ -54,46 +54,46 @@ function get_kwarg(args, keyword, default_value)
return val
end

EXAMPLES_DIR_BBMBBM = "bbm_bbm_1d"
EXAMPLES_DIR_BBMBBM_VARIABLE = "bbm_bbm_variable_bathymetry_1d"
EXAMPLES_DIR_SVAERD_KALISCH = "svaerd_kalisch_1d"
const EXAMPLES_DIR_BBMBBM = "bbm_bbm_1d"
const EXAMPLES_DIR_BBMBBM_VARIABLE = "bbm_bbm_variable_bathymetry_1d"
const EXAMPLES_DIR_SVAERD_KALISCH = "svaerd_kalisch_1d"

###############################################################################
# Travelling wave solution for one-dimensional BBM-BBM equations with periodic boundary conditions
# using periodic SBP operators
@plot_elixir(joinpath(EXAMPLES_DIR_BBMBBM, "bbm_bbm_1d_basic.jl"),
ylims_gif=[(-8, 4), :auto], tspan=(0.0, 50.0))
@plot_example(joinpath(EXAMPLES_DIR_BBMBBM, "bbm_bbm_1d_basic.jl"),
ylims_gif=[(-8, 4), :auto], tspan=(0.0, 50.0))

###############################################################################
# Travelling wave solution for one-dimensional BBM-BBM equations with periodic boundary conditions
# using discontinuously coupled Legendre SBP operators
@plot_elixir(joinpath(EXAMPLES_DIR_BBMBBM, "bbm_bbm_1d_dg.jl"),
ylims_gif=[(-4, 2), :auto])
@plot_example(joinpath(EXAMPLES_DIR_BBMBBM, "bbm_bbm_1d_dg.jl"),
ylims_gif=[(-4, 2), :auto])

###############################################################################
# Travelling wave solution for one-dimensional BBM-BBM equations with periodic boundary conditions
# using periodic SBP operators and relaxation, is energy-conservative
@plot_elixir(joinpath(EXAMPLES_DIR_BBMBBM, "bbm_bbm_1d_relaxation.jl"),
ylims_gif=[(-8, 4), (-10, 30)],
tspan=(0.0, 30.0))
@plot_example(joinpath(EXAMPLES_DIR_BBMBBM, "bbm_bbm_1d_relaxation.jl"),
ylims_gif=[(-8, 4), (-10, 30)],
tspan=(0.0, 30.0))

###############################################################################
# Travelling wave solution for one-dimensional BBM-BBM equations with periodic boundary conditions
# using periodic SBP operators. Uses the BBM-BBM equations with variable bathymetry, but sets the bathymetry
# as a constant. Should give the same result as "bbm_bbm_1d_basic.jl"
@plot_elixir(joinpath(EXAMPLES_DIR_BBMBBM_VARIABLE,
"bbm_bbm_variable_bathymetry_1d_basic.jl"),
ylims_gif=[(-8, 4), :auto],
tspan=(0.0, 50.0))
@plot_example(joinpath(EXAMPLES_DIR_BBMBBM_VARIABLE,
"bbm_bbm_variable_bathymetry_1d_basic.jl"),
ylims_gif=[(-8, 4), :auto],
tspan=(0.0, 50.0))

###############################################################################
# One-dimensional BBM-BBM equations with a Gaussian bump as initial condition for the water height
# and initially still water. The bathymetry is a sine function. Relaxation is used, so the solution
# is energy-conservative. Uses periodic finite difference SBP operators.
@plot_elixir(joinpath(EXAMPLES_DIR_BBMBBM_VARIABLE,
"bbm_bbm_variable_bathymetry_1d_relaxation.jl"),
ylims_gif=[(-1.5, 6.0), (-10.0, 10.0)],
tspan=(0.0, 10.0))
@plot_example(joinpath(EXAMPLES_DIR_BBMBBM_VARIABLE,
"bbm_bbm_variable_bathymetry_1d_relaxation.jl"),
ylims_gif=[(-1.5, 6.0), (-10.0, 10.0)],
tspan=(0.0, 10.0))

###############################################################################
# One-dimensional BBM-BBM equations with a Gaussian bump as initial condition for the water height
Expand All @@ -108,100 +108,100 @@ EXAMPLES_DIR_SVAERD_KALISCH = "svaerd_kalisch_1d"
# One-dimensional BBM-BBM equations with a Gaussian bump as initial condition for the water height
# and initially still water. The bathymetry is a sine function. Relaxation is used, so the solution
# is energy-conservative. Uses periodic finite difference discontinuously coupled SBP operators.
@plot_elixir(joinpath(EXAMPLES_DIR_BBMBBM_VARIABLE,
"bbm_bbm_variable_bathymetry_1d_upwind_relaxation.jl"),
ylims_gif=[(-1.5, 6.0), (-10.0, 10.0)],
tspan=(0.0, 10.0))
@plot_example(joinpath(EXAMPLES_DIR_BBMBBM_VARIABLE,
"bbm_bbm_variable_bathymetry_1d_upwind_relaxation.jl"),
ylims_gif=[(-1.5, 6.0), (-10.0, 10.0)],
tspan=(0.0, 10.0))

###############################################################################
# One-dimensional BBM-BBM equations with a constant water height
# and initially still water. The bathymetry is discontinuous. Relaxation is used, so the solution
# is energy-conservative. Uses periodic finite difference SBP operators. The solution should be
# (exactly) constant in time.
@plot_elixir(joinpath(EXAMPLES_DIR_BBMBBM_VARIABLE,
"bbm_bbm_variable_bathymetry_1d_well_balanced.jl"),
ylims_gif=[(2.0 - 1e-3, 2.0 + 1e-3), (-1e-3, 1e-3)],
tspan=(0.0, 10.0))
@plot_example(joinpath(EXAMPLES_DIR_BBMBBM_VARIABLE,
"bbm_bbm_variable_bathymetry_1d_well_balanced.jl"),
ylims_gif=[(2.0 - 1e-3, 2.0 + 1e-3), (-1e-3, 1e-3)],
tspan=(0.0, 10.0))

###############################################################################
# One-dimensional BBM-BBM equations with initial condition that models
# a wave make. This setup comes from experiments by W. M. Dingemans.
@plot_elixir(joinpath(EXAMPLES_DIR_BBMBBM_VARIABLE,
"bbm_bbm_variable_bathymetry_1d_dingemans.jl"),
ylims_gif=[(-0.1, 0.9), (-0.3, 0.3)],
ylims_x=[:auto, :auto],
x_values=[3.04, 9.44, 20.04, 26.04, 30.44, 37.04],
tlims=[
(15.0, 45.0),
(19.0, 48.0),
(25.0, 52.0),
(30.0, 60.0),
(33.0, 61.0),
(35.0, 65.0),
],
tspan=(0.0, 70.0))
@plot_example(joinpath(EXAMPLES_DIR_BBMBBM_VARIABLE,
"bbm_bbm_variable_bathymetry_1d_dingemans.jl"),
ylims_gif=[(-0.1, 0.9), (-0.3, 0.3)],
ylims_x=[:auto, :auto],
x_values=[3.04, 9.44, 20.04, 26.04, 30.44, 37.04],
tlims=[
(15.0, 45.0),
(19.0, 48.0),
(25.0, 52.0),
(30.0, 60.0),
(33.0, 61.0),
(35.0, 65.0),
],
tspan=(0.0, 70.0))

###############################################################################
# One-dimensional equations from Svärd and Kalisch with initial condition that models
# a wave make. This setup comes from experiments by W. M. Dingemans.
@plot_elixir(joinpath(EXAMPLES_DIR_SVAERD_KALISCH,
"svaerd_kalisch_1d_dingemans.jl"),
ylims_gif=[(-0.1, 0.9), (-0.3, 0.3)],
ylims_x=[:auto, :auto],
x_values=[3.04, 9.44, 20.04, 26.04, 30.44, 37.04],
tlims=[
(15.0, 45.0),
(19.0, 48.0),
(25.0, 52.0),
(30.0, 60.0),
(33.0, 61.0),
(35.0, 65.0),
],
tspan=(0.0, 70.0))
@plot_example(joinpath(EXAMPLES_DIR_SVAERD_KALISCH,
"svaerd_kalisch_1d_dingemans.jl"),
ylims_gif=[(-0.1, 0.9), (-0.3, 0.3)],
ylims_x=[:auto, :auto],
x_values=[3.04, 9.44, 20.04, 26.04, 30.44, 37.04],
tlims=[
(15.0, 45.0),
(19.0, 48.0),
(25.0, 52.0),
(30.0, 60.0),
(33.0, 61.0),
(35.0, 65.0),
],
tspan=(0.0, 70.0))

###############################################################################
# One-dimensional equations from Svärd and Kalisch with initial condition that models
# a wave make. This setup comes from experiments by W. M. Dingemans.
@plot_elixir(joinpath(EXAMPLES_DIR_SVAERD_KALISCH,
"svaerd_kalisch_1d_dingemans_upwind.jl"),
ylims_gif=[(-0.1, 0.9), (-0.3, 0.3)],
ylims_x=[:auto, :auto],
x_values=[3.04, 9.44, 20.04, 26.04, 30.44, 37.04],
tlims=[
(15.0, 45.0),
(19.0, 48.0),
(25.0, 52.0),
(30.0, 60.0),
(33.0, 61.0),
(35.0, 65.0),
],
tspan=(0.0, 70.0))
@plot_example(joinpath(EXAMPLES_DIR_SVAERD_KALISCH,
"svaerd_kalisch_1d_dingemans_upwind.jl"),
ylims_gif=[(-0.1, 0.9), (-0.3, 0.3)],
ylims_x=[:auto, :auto],
x_values=[3.04, 9.44, 20.04, 26.04, 30.44, 37.04],
tlims=[
(15.0, 45.0),
(19.0, 48.0),
(25.0, 52.0),
(30.0, 60.0),
(33.0, 61.0),
(35.0, 65.0),
],
tspan=(0.0, 70.0))

###############################################################################
# One-dimensional equations from Svärd and Kalisch with initial condition that models
# a wave make. This setup comes from experiments by W. M. Dingemans. Relaxation is used
# to preserve the modified entropy.
@plot_elixir(joinpath(EXAMPLES_DIR_SVAERD_KALISCH,
"svaerd_kalisch_1d_dingemans_relaxation.jl"),
ylims_gif=[(-0.1, 0.9), (-0.3, 0.3)],
ylims_x=[:auto, :auto],
x_values=[3.04, 9.44, 20.04, 26.04, 30.44, 37.04],
tlims=[
(15.0, 45.0),
(19.0, 48.0),
(25.0, 52.0),
(30.0, 60.0),
(33.0, 61.0),
(35.0, 65.0),
],
tspan=(0.0, 70.0))
@plot_example(joinpath(EXAMPLES_DIR_SVAERD_KALISCH,
"svaerd_kalisch_1d_dingemans_relaxation.jl"),
ylims_gif=[(-0.1, 0.9), (-0.3, 0.3)],
ylims_x=[:auto, :auto],
x_values=[3.04, 9.44, 20.04, 26.04, 30.44, 37.04],
tlims=[
(15.0, 45.0),
(19.0, 48.0),
(25.0, 52.0),
(30.0, 60.0),
(33.0, 61.0),
(35.0, 65.0),
],
tspan=(0.0, 70.0))

###############################################################################
# One-dimensional Svärd-Kalisch equations with a constant water height
# and initially still water. The bathymetry is discontinuous. Relaxation is used, so the solution
# is energy-conservative. Uses periodic finite difference SBP operators. The solution should be
# (exactly) constant in time.
@plot_elixir(joinpath(EXAMPLES_DIR_SVAERD_KALISCH,
"svaerd_kalisch_1d_well_balanced.jl"),
ylims=[(2.0 - 1e-3, 2.0 + 1e-3), (-1e-3, 1e-3)],
tspan=(0.0, 10.0))
@plot_example(joinpath(EXAMPLES_DIR_SVAERD_KALISCH,
"svaerd_kalisch_1d_well_balanced.jl"),
ylims=[(2.0 - 1e-3, 2.0 + 1e-3), (-1e-3, 1e-3)],
tspan=(0.0, 10.0))
3 changes: 2 additions & 1 deletion examples/bbm_bbm_1d/bbm_bbm_1d_basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ N = 512
mesh = Mesh1D(coordinates_min, coordinates_max, N + 1)

# create solver with periodic SBP operators of accuracy order 4
solver = Solver(mesh, 4)
accuracy_order = 4
solver = Solver(mesh, accuracy_order)

# semidiscretization holds all the necessary data structures for the spatial discretization
semi = Semidiscretization(mesh, equations, initial_condition, solver,
Expand Down
3 changes: 2 additions & 1 deletion examples/bbm_bbm_1d/bbm_bbm_1d_relaxation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ N = 512
mesh = Mesh1D(coordinates_min, coordinates_max, N + 1)

# create solver with periodic SBP operators of accuracy order 4
solver = Solver(mesh, 4)
accuracy_order = 4
solver = Solver(mesh, accuracy_order)

# semidiscretization holds all the necessary data structures for the spatial discretization
semi = Semidiscretization(mesh, equations, initial_condition, solver,
Expand Down
4 changes: 2 additions & 2 deletions src/DispersiveShallowWater.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ using SummationByPartsOperators: AbstractDerivativeOperator,
derivative_order, integrate
import SummationByPartsOperators: grid, xmin, xmax

include("util.jl")
include("boundary_conditions.jl")
include("mesh.jl")
include("solver.jl")
include("equations/equations.jl")
include("semidiscretization.jl")
include("callbacks_step/callbacks_step.jl")
include("visualization.jl")
include("util.jl")

export examples_dir, get_examples, default_example, trixi_include
export examples_dir, get_examples, default_example, trixi_include, convergence_test

export BBMBBMEquations1D, BBMBBMVariableEquations1D, SvärdKalischEquations1D,
SvaerdKalischEquations1D
Expand Down
12 changes: 12 additions & 0 deletions src/callbacks_step/analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,18 @@ function analyze_integrals!(current_integrals, i, analysis_integrals::Tuple{}, u
nothing
end

# used for error checks and EOC analysis
function (cb::DiscreteCallback{Condition, Affect!})(sol) where {Condition,
Affect! <:
AnalysisCallback}
analysis_callback = cb.affect!
semi = sol.prob.p

l2_error, linf_error = calc_error_norms(sol.u[end], sol.t[end], semi)

return (; l2 = l2_error, linf = linf_error)
end

function analyze(quantity, u_ode, t, semi::Semidiscretization)
integrate_quantity(u_ode -> quantity(u_ode, semi.equations), u_ode, semi)
end
Expand Down
Loading

0 comments on commit a1a0fb3

Please sign in to comment.