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

[WIP] Shallow-water exner equations with wetting/drying #56

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
123 changes: 123 additions & 0 deletions examples/tree_1d_dgsem/elixir_shallowwater_exner_beach.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@

using OrdinaryDiffEq
using Trixi
using TrixiShallowWater

###############################################################################
# Semidiscretization of the SWE-Exner equations

# Equations with Grass model
equations = ShallowWaterExnerEquations1D(gravity_constant = 9.812, H0 = 1.0,
rho_f = 0.5, rho_s = 1.0, porosity = 0.5,
friction = ManningFriction(n = 0.0),
sediment_model = GrassModel(A_g = 0.001),
threshold_desingularization = 1e-6)

"""
initial_condition_beach(x, t, equations:: ShallowWaterExnerEquations1D)

Initial condition to simulate a wave running towards a beach and crashing. Difficult test
including both wetting and drying in the domain using slip wall boundary conditions.
The bottom topography is altered to be differentiable on the domain [0,8] and
differs from the reference below.

The water height and speed functions used here, are adapted from the initial condition
found in section 5.2 of the paper:
- Andreas Bollermann, Sebastian Noelle, Maria Lukáčová-Medvid’ová (2011)
Finite volume evolution Galerkin methods for the shallow water equations with dry beds\n
[DOI: 10.4208/cicp.220210.020710a](https://dx.doi.org/10.4208/cicp.220210.020710a)
"""
function initial_condition_beach(x, t, equations::ShallowWaterExnerEquations1D)
D = 1
delta = 0.02
gamma = sqrt((3 * delta) / (4 * D))
x_a = sqrt((4 * D) / (3 * delta)) * acosh(sqrt(20))

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

View check run for this annotation

Codecov / codecov/patch

examples/tree_1d_dgsem/elixir_shallowwater_exner_beach.jl#L30-L34

Added lines #L30 - L34 were not covered by tests

f = D + 40 * delta * sech(gamma * (8 * x[1] - x_a))^2

Check warning on line 36 in examples/tree_1d_dgsem/elixir_shallowwater_exner_beach.jl

View check run for this annotation

Codecov / codecov/patch

examples/tree_1d_dgsem/elixir_shallowwater_exner_beach.jl#L36

Added line #L36 was not covered by tests

# steep curved beach
h_b = 0.01 + 99 / 409600 * 4^x[1]

Check warning on line 39 in examples/tree_1d_dgsem/elixir_shallowwater_exner_beach.jl

View check run for this annotation

Codecov / codecov/patch

examples/tree_1d_dgsem/elixir_shallowwater_exner_beach.jl#L39

Added line #L39 was not covered by tests

if x[1] >= 6
H = h_b
v = 0.0

Check warning on line 43 in examples/tree_1d_dgsem/elixir_shallowwater_exner_beach.jl

View check run for this annotation

Codecov / codecov/patch

examples/tree_1d_dgsem/elixir_shallowwater_exner_beach.jl#L41-L43

Added lines #L41 - L43 were not covered by tests
else
H = f
v = sqrt(equations.gravity / D) * H

Check warning on line 46 in examples/tree_1d_dgsem/elixir_shallowwater_exner_beach.jl

View check run for this annotation

Codecov / codecov/patch

examples/tree_1d_dgsem/elixir_shallowwater_exner_beach.jl#L45-L46

Added lines #L45 - L46 were not covered by tests
end

H = max(H, h_b + equations.threshold_limiter)
return prim2cons(SVector(H, v, h_b), equations)

Check warning on line 50 in examples/tree_1d_dgsem/elixir_shallowwater_exner_beach.jl

View check run for this annotation

Codecov / codecov/patch

examples/tree_1d_dgsem/elixir_shallowwater_exner_beach.jl#L49-L50

Added lines #L49 - L50 were not covered by tests
end

initial_condition = initial_condition_beach
boundary_condition = boundary_condition_slip_wall

###############################################################################
# Get the DG approximation space

volume_flux = (flux_ersing_etal, flux_nonconservative_ersing_etal)
surface_flux = (FluxPlusDissipation(flux_ersing_etal, DissipationLocalLaxFriedrichs()),
flux_nonconservative_ersing_etal,
hydrostatic_reconstruction_ersing_etal)

basis = LobattoLegendreBasis(3)

indicator_sc = IndicatorHennemannGassnerShallowWater(equations, basis,
alpha_max = 0.5,
alpha_min = 0.001,
alpha_smooth = true,
variable = water_sediment_height)
volume_integral = VolumeIntegralShockCapturingHG(indicator_sc;
volume_flux_dg = volume_flux,
volume_flux_fv = surface_flux)

solver = DGSEM(basis, surface_flux, volume_integral)

###############################################################################
# Create the TreeMesh for the domain [0, 8]

coordinates_min = 0.0
coordinates_max = 8.0

mesh = TreeMesh(coordinates_min, coordinates_max,
initial_refinement_level = 7,
n_cells_max = 10_000,
periodicity = false)

# create the semi discretization object
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
boundary_conditions = boundary_condition)

###############################################################################
# ODE solvers, callbacks etc.

tspan = (0.0, 10.0)
ode = semidiscretize(semi, tspan)

summary_callback = SummaryCallback()

analysis_interval = 100
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
save_analysis = false)

alive_callback = AliveCallback(analysis_interval = analysis_interval)

save_solution = SaveSolutionCallback(dt = 0.2,
save_initial_solution = true,
save_final_solution = true)

stepsize_callback = StepsizeCallback(cfl = 0.3)

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

stage_limiter! = PositivityPreservingLimiterShallowWater(variables = (Trixi.waterheight,))

###############################################################################
# run the simulation
# use a Runge-Kutta method with CFL-based time step
sol = solve(ode, SSPRK43(stage_limiter!);
ode_default_options()..., callback = callbacks, adaptive = false, dt = 1.0);

summary_callback() # print the timer summary
107 changes: 107 additions & 0 deletions examples/tree_1d_dgsem/elixir_shallowwater_exner_well_balanced_dry.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@

using OrdinaryDiffEq
using Trixi
using TrixiShallowWater

###############################################################################
# Semidiscretization of the SWE-Exner equations with a discontinuous sediment bed
# to test well-balancedness

# Equations with Grass model
equations = ShallowWaterExnerEquations1D(gravity_constant = 9.81, H0 = 1.0,
rho_f = 0.5, rho_s = 1.0, porosity = 0.5,
friction = ManningFriction(n = 0.01),
sediment_model = GrassModel(A_g = 0.01))

function initial_condition_steady_state(x, t,

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

View check run for this annotation

Codecov / codecov/patch

examples/tree_1d_dgsem/elixir_shallowwater_exner_well_balanced_dry.jl#L16

Added line #L16 was not covered by tests
equations::ShallowWaterExnerEquations1D)
hv = 0.0

Check warning on line 18 in examples/tree_1d_dgsem/elixir_shallowwater_exner_well_balanced_dry.jl

View check run for this annotation

Codecov / codecov/patch

examples/tree_1d_dgsem/elixir_shallowwater_exner_well_balanced_dry.jl#L18

Added line #L18 was not covered by tests

# discontinuous sediment bed
if -2 < x[1] <= 0
h = 0.25
h_b = equations.threshold_limiter

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

View check run for this annotation

Codecov / codecov/patch

examples/tree_1d_dgsem/elixir_shallowwater_exner_well_balanced_dry.jl#L21-L23

Added lines #L21 - L23 were not covered by tests
else
h = equations.threshold_limiter
h_b = 0.5

Check warning on line 26 in examples/tree_1d_dgsem/elixir_shallowwater_exner_well_balanced_dry.jl

View check run for this annotation

Codecov / codecov/patch

examples/tree_1d_dgsem/elixir_shallowwater_exner_well_balanced_dry.jl#L25-L26

Added lines #L25 - L26 were not covered by tests
end

return SVector(h, hv, h_b)

Check warning on line 29 in examples/tree_1d_dgsem/elixir_shallowwater_exner_well_balanced_dry.jl

View check run for this annotation

Codecov / codecov/patch

examples/tree_1d_dgsem/elixir_shallowwater_exner_well_balanced_dry.jl#L29

Added line #L29 was not covered by tests
end

initial_condition = initial_condition_steady_state

boundary_condition = boundary_condition_slip_wall

###############################################################################
# Get the DG approximation space

volume_flux = (flux_ersing_etal, flux_nonconservative_ersing_etal)

surface_flux = (FluxHydrostaticReconstruction(FluxPlusDissipation(flux_ersing_etal,
DissipationLocalLaxFriedrichs()),
hydrostatic_reconstruction_ersing_etal),
FluxHydrostaticReconstruction(flux_nonconservative_ersing_etal,
hydrostatic_reconstruction_ersing_etal))

basis = LobattoLegendreBasis(3)

indicator_sc = IndicatorHennemannGassnerShallowWater(equations, basis,
alpha_max = 0.5,
alpha_min = 0.001,
alpha_smooth = true,
variable = water_sediment_height)
volume_integral = VolumeIntegralShockCapturingHG(indicator_sc;
volume_flux_dg = volume_flux,
volume_flux_fv = surface_flux)

solver = DGSEM(basis, surface_flux, volume_integral)

###############################################################################
# Get the TreeMesh

coordinates_min = -2.0
coordinates_max = 2.0
mesh = TreeMesh(coordinates_min, coordinates_max,
initial_refinement_level = 4,
n_cells_max = 10_000,
periodicity = false)

# Create the semi discretization object
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
boundary_conditions = boundary_condition)

###############################################################################
# ODE solver
tspan = (0.0, 2.0)
ode = semidiscretize(semi, tspan)

###############################################################################
# Callbacks

summary_callback = SummaryCallback()

analysis_interval = 10000
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
extra_analysis_integrals = (lake_at_rest_error,))

alive_callback = AliveCallback(analysis_interval = analysis_interval)

save_solution = SaveSolutionCallback(dt = 5.0,
save_initial_solution = true,
save_final_solution = true)

stepsize_callback = StepsizeCallback(cfl = 0.5)

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

stage_limiter! = PositivityPreservingLimiterShallowWater(variables = (Trixi.waterheight,))

###############################################################################
# run the simulation
# use a Runge-Kutta method with CFL-based time step
sol = solve(ode, SSPRK43(stage_limiter!);
ode_default_options()..., callback = callbacks, adaptive = false, dt = 1.0);

summary_callback() # print the timer summary
6 changes: 4 additions & 2 deletions src/callbacks_stage/positivity_shallow_water.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ function limiter_shallow_water!(u, variables::NTuple{N, Any},
equations::Union{ShallowWaterEquationsWetDry1D,
ShallowWaterEquationsWetDry2D,
ShallowWaterMultiLayerEquations1D,
ShallowWaterMultiLayerEquations2D},
ShallowWaterMultiLayerEquations2D,
ShallowWaterExnerEquations1D},
solver, cache) where {N}
variable = first(variables)
remaining_variables = Base.tail(variables)
Expand All @@ -99,7 +100,8 @@ function limiter_shallow_water!(u, variables::Tuple{},
equations::Union{ShallowWaterEquationsWetDry1D,
ShallowWaterEquationsWetDry2D,
ShallowWaterMultiLayerEquations1D,
ShallowWaterMultiLayerEquations2D},
ShallowWaterMultiLayerEquations2D,
ShallowWaterExnerEquations1D},
solver, cache)
nothing
end
Expand Down
72 changes: 72 additions & 0 deletions src/callbacks_stage/positivity_shallow_water_dg1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,76 @@

return nothing
end

# !!! warning "Experimental code"
# This is an experimental feature and may change in future releases.
function limiter_shallow_water!(u, threshold::Real, variable,

Check warning on line 177 in src/callbacks_stage/positivity_shallow_water_dg1d.jl

View check run for this annotation

Codecov / codecov/patch

src/callbacks_stage/positivity_shallow_water_dg1d.jl#L177

Added line #L177 was not covered by tests
mesh::Trixi.AbstractMesh{1},
equations::ShallowWaterExnerEquations1D,
dg::DGSEM, cache)
@unpack weights = dg.basis

Check warning on line 181 in src/callbacks_stage/positivity_shallow_water_dg1d.jl

View check run for this annotation

Codecov / codecov/patch

src/callbacks_stage/positivity_shallow_water_dg1d.jl#L181

Added line #L181 was not covered by tests

Trixi.@threaded for element in eachelement(dg, cache)

Check warning on line 183 in src/callbacks_stage/positivity_shallow_water_dg1d.jl

View check run for this annotation

Codecov / codecov/patch

src/callbacks_stage/positivity_shallow_water_dg1d.jl#L183

Added line #L183 was not covered by tests
# determine minimum value
value_min = typemax(eltype(u))
for i in eachnode(dg)
u_node = get_node_vars(u, equations, dg, i, element)
value_min = min(value_min, variable(u_node, equations))
end

Check warning on line 189 in src/callbacks_stage/positivity_shallow_water_dg1d.jl

View check run for this annotation

Codecov / codecov/patch

src/callbacks_stage/positivity_shallow_water_dg1d.jl#L185-L189

Added lines #L185 - L189 were not covered by tests

# detect if limiting is necessary
value_min < threshold - eps() || continue

Check warning on line 192 in src/callbacks_stage/positivity_shallow_water_dg1d.jl

View check run for this annotation

Codecov / codecov/patch

src/callbacks_stage/positivity_shallow_water_dg1d.jl#L192

Added line #L192 was not covered by tests

# compute mean value
u_mean = zero(get_node_vars(u, equations, dg, 1, element))
for i in eachnode(dg)
u_node = get_node_vars(u, equations, dg, i, element)
u_mean += u_node * weights[i]
end

Check warning on line 199 in src/callbacks_stage/positivity_shallow_water_dg1d.jl

View check run for this annotation

Codecov / codecov/patch

src/callbacks_stage/positivity_shallow_water_dg1d.jl#L195-L199

Added lines #L195 - L199 were not covered by tests

# note that the reference element is [-1,1]^ndims(dg), thus the weights sum to 2
u_mean = u_mean / 2^ndims(mesh)

Check warning on line 202 in src/callbacks_stage/positivity_shallow_water_dg1d.jl

View check run for this annotation

Codecov / codecov/patch

src/callbacks_stage/positivity_shallow_water_dg1d.jl#L202

Added line #L202 was not covered by tests

# We compute the value directly with the mean values.
value_mean = variable(u_mean, equations)
theta = (value_mean - threshold) / (value_mean - value_min)

Check warning on line 206 in src/callbacks_stage/positivity_shallow_water_dg1d.jl

View check run for this annotation

Codecov / codecov/patch

src/callbacks_stage/positivity_shallow_water_dg1d.jl#L205-L206

Added lines #L205 - L206 were not covered by tests

for i in eachnode(dg)
u_node = get_node_vars(u, equations, dg, i, element)
h_node = waterheight(u_node, equations)
h_mean = waterheight(u_mean, equations)

Check warning on line 211 in src/callbacks_stage/positivity_shallow_water_dg1d.jl

View check run for this annotation

Codecov / codecov/patch

src/callbacks_stage/positivity_shallow_water_dg1d.jl#L208-L211

Added lines #L208 - L211 were not covered by tests

u[1, i, element] = theta * h_node + (1 - theta) * h_mean
end
end

Check warning on line 215 in src/callbacks_stage/positivity_shallow_water_dg1d.jl

View check run for this annotation

Codecov / codecov/patch

src/callbacks_stage/positivity_shallow_water_dg1d.jl#L213-L215

Added lines #L213 - L215 were not covered by tests

# "Safety" application of the wet/dry thresholds over all the DG nodes
# on the current `element` after the limiting above in order to avoid dry nodes.
# If the value_mean < threshold before applying limiter, there
# could still be dry nodes afterwards due to logic of the limiting.
# Additionally, a velocity desingularization is applied to avoid numerical
# problems near dry states.
Trixi.@threaded for element in eachelement(dg, cache)
for i in eachnode(dg)
u_node = get_node_vars(u, equations, dg, i, element)
h, hv, h_b = u_node

Check warning on line 226 in src/callbacks_stage/positivity_shallow_water_dg1d.jl

View check run for this annotation

Codecov / codecov/patch

src/callbacks_stage/positivity_shallow_water_dg1d.jl#L223-L226

Added lines #L223 - L226 were not covered by tests

# Velocity desingularization
hv = h * (2.0 * h * hv) /

Check warning on line 229 in src/callbacks_stage/positivity_shallow_water_dg1d.jl

View check run for this annotation

Codecov / codecov/patch

src/callbacks_stage/positivity_shallow_water_dg1d.jl#L229

Added line #L229 was not covered by tests
(h^2 + max(h^2, equations.threshold_desingularization))

# Ensure positivity and zero velocity at dry states
if h <= threshold
h = threshold
hv = zero(eltype(u))

Check warning on line 235 in src/callbacks_stage/positivity_shallow_water_dg1d.jl

View check run for this annotation

Codecov / codecov/patch

src/callbacks_stage/positivity_shallow_water_dg1d.jl#L233-L235

Added lines #L233 - L235 were not covered by tests
end

u_node = SVector(h, hv, h_b)

Check warning on line 238 in src/callbacks_stage/positivity_shallow_water_dg1d.jl

View check run for this annotation

Codecov / codecov/patch

src/callbacks_stage/positivity_shallow_water_dg1d.jl#L238

Added line #L238 was not covered by tests

set_node_vars!(u, u_node, equations, dg, i, element)
end
end

Check warning on line 242 in src/callbacks_stage/positivity_shallow_water_dg1d.jl

View check run for this annotation

Codecov / codecov/patch

src/callbacks_stage/positivity_shallow_water_dg1d.jl#L240-L242

Added lines #L240 - L242 were not covered by tests

return nothing

Check warning on line 244 in src/callbacks_stage/positivity_shallow_water_dg1d.jl

View check run for this annotation

Codecov / codecov/patch

src/callbacks_stage/positivity_shallow_water_dg1d.jl#L244

Added line #L244 was not covered by tests
end
end # @muladd
Loading
Loading