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

Fix boundary_condition_slip_wall for SWE #1798

Merged
merged 6 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
83 changes: 83 additions & 0 deletions examples/tree_2d_dgsem/elixir_shallowwater_wall.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using OrdinaryDiffEq
using Trixi

###############################################################################
# Semidiscretization of the shallow water equations

equations = ShallowWaterEquations2D(gravity_constant = 9.81, H0 = 3.25)

# An initial condition with a perturbation in the waterheight to test boundary_condition_slip_wall
function initial_condition_well_balancedness(x, t, equations::ShallowWaterEquations2D)
patrickersing marked this conversation as resolved.
Show resolved Hide resolved
# Set the background values
H = equations.H0
v1 = 0.0
v2 = 0.0

x1, x2 = x
b = 0.0
patrickersing marked this conversation as resolved.
Show resolved Hide resolved

# Waterheight perturbation
r = (x[1])^2 + (x[2])^2
patrickersing marked this conversation as resolved.
Show resolved Hide resolved
H = H + 0.5 * exp(-10 * r)

return prim2cons(SVector(H, v1, v2, b), equations)
end

initial_condition = initial_condition_well_balancedness

boundary_condition = boundary_condition_slip_wall

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

volume_flux = (flux_wintermeyer_etal, flux_nonconservative_ersing_etal)
surface_flux = (flux_lax_friedrichs, flux_nonconservative_ersing_etal)
solver = DGSEM(polydeg = 3, surface_flux = surface_flux,
volume_integral = VolumeIntegralFluxDifferencing(volume_flux))

###############################################################################
# Get the TreeMesh and setup a non-periodic mesh

coordinates_min = (-1.0, -1.0)
coordinates_max = (1.0, 1.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 solvers, callbacks etc.

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

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

summary_callback = SummaryCallback()

analysis_interval = 1000
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)

alive_callback = AliveCallback(analysis_interval = analysis_interval)

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

stepsize_callback = StepsizeCallback(cfl = 1.0)

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

###############################################################################
# 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
8 changes: 6 additions & 2 deletions src/equations/shallow_water_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,12 @@ Should be used together with [`TreeMesh`](@ref).
u_boundary = SVector(u_inner[1], u_inner[2], -u_inner[3], u_inner[4])
end

# compute and return the flux using `boundary_condition_slip_wall` routine above
flux = surface_flux_function(u_inner, u_boundary, orientation, equations)
# Calculate boundary flux
if iseven(direction) # u_inner is "left" of boundary, u_boundary is "right" of boundary
flux = surface_flux_function(u_inner, u_boundary, orientation, equations)
else # u_boundary is "left" of boundary, u_inner is "right" of boundary
flux = surface_flux_function(u_boundary, u_inner, orientation, equations)
end

return flux
end
Expand Down
25 changes: 25 additions & 0 deletions test/test_tree_2d_shallowwater.jl
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,31 @@ end
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
end
end

@trixi_testset "elixir_shallowwater_wall.jl" begin
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_shallowwater_wall.jl"),
l2=[
0.10982800604156373,
0.2696758586410491,
0.26967585864104954,
0.0,
],
linf=[
0.4962808878041378,
0.6577212830580099,
0.6577212830580086,
0.0,
],
tspan=(0.0, 0.25))
# Ensure that we do not have excessive memory allocations
# (e.g., from type instabilities)
let
t = sol.t[end]
u_ode = sol.u[end]
du_ode = similar(u_ode)
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
end
end
end

end # module
Loading