Skip to content

Commit

Permalink
add first implementation of the ml-swe in 1D
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickersing committed Mar 18, 2024
1 parent 50efb6d commit 35ad119
Show file tree
Hide file tree
Showing 6 changed files with 555 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

using OrdinaryDiffEq
using Trixi
using TrixiShallowWater

###############################################################################
# Semidiscretization of the two-layer shallow water equations

equations = ShallowWaterMultiLayerEquations1D(gravity_constant = 10.0, rhos = (0.9, 1.0))

initial_condition = initial_condition_convergence_test

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

volume_flux = (flux_ersing_etal, flux_nonconservative_ersing_etal)
solver = DGSEM(polydeg = 3,
surface_flux = (flux_ersing_etal, flux_nonconservative_ersing_etal),
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 = 3,
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 = 500
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)

alive_callback = AliveCallback(analysis_interval = analysis_interval)

save_solution = SaveSolutionCallback(interval = 500,
save_initial_solution = true,
save_final_solution = true)

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

###############################################################################
# run the simulation

# use a Runge-Kutta method with automatic (error based) time step size control
sol = solve(ode, RDPK3SpFSAL49(), abstol = 1.0e-8, reltol = 1.0e-8,
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary
12 changes: 7 additions & 5 deletions src/TrixiShallowWater.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using Trixi
# Import additional symbols that are not exported by Trixi.jl
using Trixi: get_node_vars, set_node_vars!, waterheight
using MuladdMacro: @muladd
using StaticArrays: SVector, @SMatrix
using StaticArrays: SVector, @SMatrix, MVector
using Static: True, False
using LinearAlgebra: norm

Expand All @@ -19,15 +19,17 @@ include("solvers/indicators.jl")

# Export types/functions that define the public API of TrixiShallowWater.jl
export ShallowWaterEquationsWetDry1D, ShallowWaterEquationsWetDry2D,
ShallowWaterTwoLayerEquations1D, ShallowWaterTwoLayerEquations2D
ShallowWaterTwoLayerEquations1D, ShallowWaterTwoLayerEquations2D,
ShallowWaterMultiLayerEquations1D

export hydrostatic_reconstruction_chen_noelle, flux_nonconservative_chen_noelle,
min_max_speed_chen_noelle,
flux_hll_chen_noelle
min_max_speed_chen_noelle, flux_hll_chen_noelle,
flux_ersing_etal, flux_es_ersing_etal

export flux_es_ersing_etal
export nlayers, eachlayer

export PositivityPreservingLimiterShallowWater

export IndicatorHennemannGassnerShallowWater

end
28 changes: 28 additions & 0 deletions src/equations/equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,32 @@ include("shallow_water_wet_dry_2d.jl")

include("shallow_water_two_layer_1d.jl")
include("shallow_water_two_layer_2d.jl")

abstract type AbstractShallowWaterMultiLayerEquations{NDIMS, NVARS, NLAYERS} <:
Trixi.AbstractEquations{NDIMS, NVARS} end
include("shallow_water_multilayer_1d.jl")

"""
eachlayer(equations::AbstractShallowWaterMultiLayerEquations)
Return an iterator over the indices that specify the location in relevant data structures
for the layers in `AbstractShallowWaterMultiLayerEquations`.
"""
@inline function eachlayer(equations::AbstractShallowWaterMultiLayerEquations)
Base.OneTo(nlayers(equations))
end

"""
nlayers(equations::AbstractShallowWaterMultiLayerEquations)
Retrieve the number of layers from an equation instance of the `AbstractShallowWaterMultiLayerEquations`.
"""
@inline function nlayers(::AbstractShallowWaterMultiLayerEquations{NDIMS, NVARS,
NLAYERS}) where {
NDIMS,
NVARS,
NLAYERS
}
NLAYERS
end
end # @muladd
Loading

0 comments on commit 35ad119

Please sign in to comment.