Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hyperbolic Serre-Green-Naghdi equations #139

Merged
merged 29 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
cfa45d6
first draft of hyperbolic SGN equations
ranocha Aug 17, 2024
74c280c
soliton test case
ranocha Aug 17, 2024
199ee7c
Apply suggestions from code review
ranocha Aug 18, 2024
88eb387
more docs for initial_condition_soliton
ranocha Aug 18, 2024
6ce9a26
adapt variable names as discussed online
ranocha Aug 18, 2024
a1507ee
format
ranocha Aug 18, 2024
343f9aa
fix x -> x_t in initial_condition_soliton
ranocha Aug 18, 2024
806c9ef
add tests
ranocha Aug 18, 2024
4182583
test relaxation
ranocha Aug 18, 2024
bce1367
unit tests
ranocha Aug 18, 2024
d2901f2
test well balancedness
ranocha Aug 18, 2024
5a476c7
format
ranocha Aug 18, 2024
716bcc7
manufactured solution
ranocha Aug 18, 2024
6baf54d
adapt tolerance for CI
ranocha Aug 18, 2024
0e3d122
allow specifying a reduced set of variables and add Dingemans
ranocha Aug 18, 2024
a9980ba
format
ranocha Aug 18, 2024
f01a01f
optimizations for flat bathymetry
ranocha Aug 18, 2024
dbf5c4c
Merge branch 'main' into hr/serre_green_naghdi
ranocha Aug 18, 2024
9c59227
adapt tolerance
ranocha Aug 18, 2024
c67cc13
Apply suggestions from code review
ranocha Aug 18, 2024
871f2c2
Apply suggestions from code review
ranocha Aug 18, 2024
f7813fe
Merge branch 'main' into hr/serre_green_naghdi
ranocha Aug 18, 2024
2688626
adapt test module anmes and tolerances for macOS
ranocha Aug 18, 2024
4ccdfb0
Apply suggestions from code review
ranocha Aug 18, 2024
5679c0c
less code duplication
ranocha Aug 18, 2024
40dc766
prim2phys
ranocha Aug 18, 2024
73a39a0
make prim2phys the default for plotting
ranocha Aug 18, 2024
021e420
Apply suggestions from code review
ranocha Aug 18, 2024
849d405
Merge branch 'main' into hr/serre_green_naghdi
JoshuaLampert Aug 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using OrdinaryDiffEq
using DispersiveShallowWater

###############################################################################
# Semidiscretization of the hyperbolic Serre-Green-Naghdi equations

bathymetry_type = bathymetry_mild_slope
equations = HyperbolicSerreGreenNaghdiEquations1D(bathymetry_type;
lambda = 500.0,
gravity_constant = 9.81)

initial_condition = initial_condition_dingemans
boundary_conditions = boundary_condition_periodic

# create homogeneous mesh
coordinates_min = -138.0
coordinates_max = 46.0
N = 512
mesh = Mesh1D(coordinates_min, coordinates_max, N)

# create solver with periodic SBP operators of accuracy order 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,
boundary_conditions = boundary_conditions)

###############################################################################
# Create `ODEProblem` and run the simulation
tspan = (0.0, 70.0)
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi; interval = 10,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (waterheight_total,
momentum,
entropy,
entropy_modified))

callbacks = CallbackSet(analysis_callback, summary_callback)

saveat = range(tspan..., length = 500)
# optimized time integration methods like this one are much more efficient
# for stiff problems (λ big) than standard methods like Tsit5()
alg = RDPK3SpFSAL35()
sol = solve(ode, alg, abstol = 1e-7, reltol = 1e-7,
save_everystep = false, callback = callbacks, saveat = saveat)
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using OrdinaryDiffEq
using DispersiveShallowWater

###############################################################################
# Semidiscretization of the hyperbolic Serre-Green-Naghdi equations

bathymetry_type = bathymetry_mild_slope
equations = HyperbolicSerreGreenNaghdiEquations1D(bathymetry_type;
lambda = 1.0e4,
gravity_constant = 9.81)

initial_condition = initial_condition_manufactured
source_terms = source_terms_manufactured
boundary_conditions = boundary_condition_periodic

# create homogeneous mesh
coordinates_min = 0.0
coordinates_max = 1.0
N = 50
mesh = Mesh1D(coordinates_min, coordinates_max, N)

# create solver with periodic SBP operators of accuracy order 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,
boundary_conditions = boundary_conditions,
source_terms = source_terms)

###############################################################################
# Create `ODEProblem` and run the simulation
tspan = (0.0, 1.0)
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi; interval = 1000,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (waterheight_total,
momentum, entropy))
callbacks = CallbackSet(analysis_callback, summary_callback)

sol = solve(ode, Tsit5(), abstol = 1e-9, reltol = 1e-9,
save_everystep = false, callback = callbacks)
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using OrdinaryDiffEq
using DispersiveShallowWater

###############################################################################
# Semidiscretization of the hyperbolic Serre-Green-Naghdi equations

bathymetry_type = bathymetry_flat
equations = HyperbolicSerreGreenNaghdiEquations1D(bathymetry_type;
lambda = 500.0,
gravity_constant = 9.81)

initial_condition = initial_condition_soliton
boundary_conditions = boundary_condition_periodic

# create homogeneous mesh
coordinates_min = -50.0
coordinates_max = 50.0
N = 512
mesh = Mesh1D(coordinates_min, coordinates_max, N)

# create solver with periodic SBP operators of accuracy order 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,
boundary_conditions = boundary_conditions)

###############################################################################
# Create `ODEProblem` and run the simulation
tspan = (0.0, (xmax(mesh) - xmin(mesh)) / sqrt(1.2 * gravity_constant(equations))) # one period
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi; interval = 100,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (waterheight_total,
entropy_modified))
callbacks = CallbackSet(analysis_callback, summary_callback)

saveat = range(tspan..., length = 100)
# optimized time integration methods like this one are much more efficient
# for stiff problems (λ big) than standard methods like Tsit5()
alg = RDPK3SpFSAL35()
sol = solve(ode, alg, abstol = 1e-7, reltol = 1e-7,
save_everystep = false, callback = callbacks, saveat = saveat)
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using OrdinaryDiffEq
using DispersiveShallowWater
using SummationByPartsOperators: fourier_derivative_operator

###############################################################################
# Semidiscretization of the hyperbolic Serre-Green-Naghdi equations

bathymetry_type = bathymetry_flat
equations = HyperbolicSerreGreenNaghdiEquations1D(bathymetry_type;
lambda = 500.0,
gravity_constant = 9.81)

initial_condition = initial_condition_soliton
boundary_conditions = boundary_condition_periodic

# create homogeneous mesh
coordinates_min = -50.0
coordinates_max = 50.0
N = 512
mesh = Mesh1D(coordinates_min, coordinates_max, N)

# create solver with Fourier pseudospectral collocation method
D1 = fourier_derivative_operator(xmin(mesh), xmax(mesh), nnodes(mesh))
solver = Solver(D1, nothing)

# semidiscretization holds all the necessary data structures for the spatial discretization
semi = Semidiscretization(mesh, equations, initial_condition, solver,
boundary_conditions = boundary_conditions)

###############################################################################
# Create `ODEProblem` and run the simulation
tspan = (0.0, (xmax(mesh) - xmin(mesh)) / sqrt(1.2 * gravity_constant(equations))) # one period
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi; interval = 100,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (waterheight_total,
entropy_modified))
relaxation_callback = RelaxationCallback(invariant = entropy_modified)
# Always put relaxation_callback before analysis_callback to guarantee conservation of the invariant
callbacks = CallbackSet(relaxation_callback, analysis_callback, summary_callback)

# optimized time integration methods like this one are much more efficient
# for stiff problems (λ big) than standard methods like Tsit5()
alg = RDPK3SpFSAL35()
sol = solve(ode, alg, abstol = 1e-7, reltol = 1e-7,
save_everystep = false, callback = callbacks)
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using OrdinaryDiffEq
using DispersiveShallowWater

###############################################################################
# Semidiscretization of the hyperbolic Serre-Green-Naghdi equations

bathymetry_type = bathymetry_mild_slope
equations = HyperbolicSerreGreenNaghdiEquations1D(bathymetry_type;
lambda = 500.0,
gravity_constant = 1.0,
eta0 = 2.0)

# Setup a truly discontinuous bottom topography function for this academic
# testcase of well-balancedness. The errors from the analysis callback are
# not important but the error for this lake-at-rest test case
# `∫|η-η₀|` should be around machine roundoff.
function initial_condition_discontinuous_well_balancedness(x, t,
equations::HyperbolicSerreGreenNaghdiEquations1D,
mesh)
# Set the background values
eta = equations.eta0
v = 0.0
D = equations.eta0 - 1.0

# Setup a discontinuous bottom topography
if x >= 0.5 && x <= 0.75
D = equations.eta0 - 1.5 - 0.5 * sinpi(2.0 * x)
end

w = 0.0 # -h v_x
H = eta + D - equations.eta0

return SVector(eta, v, D, w, H)
end

initial_condition = initial_condition_discontinuous_well_balancedness
boundary_conditions = boundary_condition_periodic

# create homogeneous mesh
coordinates_min = -1.0
coordinates_max = 1.0
N = 512
mesh = Mesh1D(coordinates_min, coordinates_max, N)

# create solver with periodic SBP operators of accuracy order 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,
boundary_conditions = boundary_conditions)

###############################################################################
# Create `ODEProblem` and run the simulation
tspan = (0.0, 1.0)
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi; interval = 100,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (waterheight_total,
momentum,
entropy_modified,
lake_at_rest_error))
callbacks = CallbackSet(analysis_callback, summary_callback)

# optimized time integration methods like this one are much more efficient
# for stiff problems (λ big) than standard methods like Tsit5()
alg = RDPK3SpFSAL35()
sol = solve(ode, alg, dt = 2.5e-4, adaptive = false, callback = callbacks)
7 changes: 4 additions & 3 deletions src/DispersiveShallowWater.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
**DispersiveShallowWater.jl** is a Julia package that implements structure-preserving numerical methods for dispersive shallow water models.
It provides provably conservative, entropy-conserving, and well-balanced numerical schemes for some dispersive shallow water models.

The semidiscretizations are based on summation-by-parts (SBP) operators, which are implemented in
The semidiscretizations are based on summation-by-parts (SBP) operators, which are implemented in
[SummationByPartsOperators.jl](https://github.com/ranocha/SummationByPartsOperators.jl). To
obtain fully discrete schemes, the time integration methods from
obtain fully discrete schemes, the time integration methods from
[OrdinaryDiffEq.jl](https://github.com/SciML/OrdinaryDiffEq.jl)
are used to solve the resulting ordinary differential equations.
Fully discrete entropy-conservative methods can be obtained by using the relaxation method provided by DispersiveShallowWater.jl.
Expand Down Expand Up @@ -62,7 +62,7 @@ export examples_dir, get_examples, default_example, convergence_test
export AbstractShallowWaterEquations,
BBMBBMEquations1D, BBMBBMVariableEquations1D,
SvärdKalischEquations1D, SvaerdKalischEquations1D,
SerreGreenNaghdiEquations1D
SerreGreenNaghdiEquations1D, HyperbolicSerreGreenNaghdiEquations1D

export prim2prim, prim2cons, cons2prim,
waterheight_total, waterheight,
Expand All @@ -83,6 +83,7 @@ export boundary_condition_periodic, boundary_condition_reflecting
export bathymetry_flat, bathymetry_mild_slope, bathymetry_variable

export initial_condition_convergence_test,
initial_condition_soliton,
initial_condition_manufactured, source_terms_manufactured,
initial_condition_manufactured_reflecting, source_terms_manufactured_reflecting,
initial_condition_dingemans
Expand Down
34 changes: 34 additions & 0 deletions src/equations/equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,38 @@
"""
default_analysis_integrals(::AbstractEquations) = Symbol[]

"""
DispersiveShallowWater.is_hyperbolic_appproximation(equations)

Returns `Val{true}()` if the equations are a hyperbolic approximation
of another set of equations and `Val{false}()` otherwise (default).
For example, the [`HyperbolicSerreGreenNaghdiEquations1D`](@ref) are
a hyperbolic approximation of the [`SerreGreenNaghdiEquations1D`](@ref).

See also [`hyperbolic_approximation_limit`](@ref).

!!! note "Implementation details"
This function is mostly used for some internal dispatch. For example,
it allows to return a reduced set of variables from initial conditions
for hyperbolic approximations.
"""
is_hyperbolic_appproximation(::AbstractEquations) = Val{false}()

"""
DispersiveShallowWater.hyperbolic_approximation_limit(equations)

If the equations are a hyperbolic approximation of another set of equations,
return the equations of the limit system. Otherwise, return the input equations.

See also [`is_hyperbolic_appproximation`](@ref).

!!! note "Implementation details"
This function is mostly used for some internal dispatch. For example,
it allows to return a reduced set of variables from initial conditions
for hyperbolic approximations.
"""
hyperbolic_approximation_limit(equations::AbstractEquations) = equations

Check warning on line 374 in src/equations/equations.jl

View check run for this annotation

Codecov / codecov/patch

src/equations/equations.jl#L374

Added line #L374 was not covered by tests

abstract type AbstractBathymetry end

struct BathymetryFlat <: AbstractBathymetry end
Expand Down Expand Up @@ -390,4 +422,6 @@
# Serre-Green-Naghdi equations
abstract type AbstractSerreGreenNaghdiEquations{NDIMS, NVARS} <:
AbstractShallowWaterEquations{NDIMS, NVARS} end
const AbstractSerreGreenNaghdiEquations1D = AbstractSerreGreenNaghdiEquations{1}
include("serre_green_naghdi_1d.jl")
include("hyperbolic_serre_green_naghdi_1d.jl")
Loading
Loading