Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
575af7a
add geostrophic adjustment elixir
patrickersing Mar 7, 2025
92829a8
Add boundary conditions for fixed water height and momentum
patrickersing Apr 28, 2025
87565e3
Merge branch 'main' into geostrophic_adjustment
patrickersing Apr 28, 2025
a6f55c0
Use the new gravity parameter and correct boundary condition assignments
patrickersing Apr 28, 2025
df56ef5
fix gravity parameter in test_unit.jl
patrickersing Apr 28, 2025
a2bf1ac
switch to OrdinaryDiffEq subpackages in the new elixirs
patrickersing Apr 28, 2025
251fcd5
remove unnecessary lines in unit test
patrickersing Apr 28, 2025
cfbc207
Use Trixi.download instead of Base.download
patrickersing Apr 28, 2025
7bab2dd
increase iterations for coverage testing
patrickersing Apr 28, 2025
e24d587
apply formatter
patrickersing Apr 28, 2025
ab8fab7
specify maxiters for coverage overwrite
patrickersing Apr 28, 2025
8b66350
create equation specific constructor for the BCs
patrickersing Apr 28, 2025
02b99cf
fix tests
patrickersing Apr 28, 2025
da4c8b4
enforce correct output types for the boundary value function
patrickersing Apr 29, 2025
fd54bde
Apply suggestions from code review
patrickersing Apr 30, 2025
d34cd2c
apply suggestions from code review part 2
patrickersing Apr 30, 2025
cde6fd6
add BC in for SWE-1D together with moving-water steady state test cases
patrickersing May 1, 2025
6382f07
fix typos
patrickersing May 1, 2025
73de3c5
Merge branch 'main' into geostrophic_adjustment
patrickersing May 1, 2025
4c9e180
additional unit test to trigger ArgumentError for BoundaryConditionWa…
patrickersing May 1, 2025
65c4bf5
add news item
patrickersing May 1, 2025
befee41
Merge branch 'main' into geostrophic_adjustment
patrickersing May 2, 2025
93bd252
Apply changes from code review
patrickersing May 5, 2025
d3fd8ff
Apply changes from code review - part 2
patrickersing May 5, 2025
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
94 changes: 94 additions & 0 deletions examples/tree_2d_dgsem/elixir_shallowwater_inflow_outflow.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using OrdinaryDiffEqSSPRK, OrdinaryDiffEqLowStorageRK
using Trixi
using TrixiShallowWater

###############################################################################
# semidiscretization of the shallow water equations to test inflow/outflow boundary conditions

equations = ShallowWaterEquationsWetDry2D(gravity = 9.81)

# Setup initial conditions for a smooth channel flow with constant water height and velocity
function initial_condition_channel_flow(x, t, equations::ShallowWaterEquationsWetDry2D)
H = 1.0
v1 = -0.1
v2 = -0.1
b = 0.0

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

initial_condition = initial_condition_channel_flow

# Setup boundary conditions.
# At the inlet, we prescribe the momentum, starting with a negative value to simulate outflow,
# and gradually transitioning to a positive value to simulate inflow. At the outlet, we prescribe
# the water height as a time-dependent cosine wave. This setup is designed to test the behavior
# of the boundary conditions under both inflow and outflow scenarios.
boundary_condition_inflow = BoundaryConditionMomentum(t -> -0.1 + 0.05 * t,
t -> -0.1 + 0.05 * t,
equations)
boundary_condition_outflow = BoundaryConditionWaterHeight(t -> 1.0 + 0.1 * cos(π / 2 * t),
equations)
boundary_conditions = (x_neg = boundary_condition_inflow,
x_pos = boundary_condition_outflow,
y_neg = boundary_condition_inflow,
y_pos = boundary_condition_outflow)

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

volume_flux = (flux_wintermeyer_etal, flux_nonconservative_wintermeyer_etal)
surface_flux = (FluxPlusDissipation(flux_wintermeyer_etal, DissipationLocalLaxFriedrichs()),
flux_nonconservative_wintermeyer_etal)
polydeg = 3
solver = DGSEM(polydeg = polydeg,
surface_flux = surface_flux,
volume_integral = VolumeIntegralFluxDifferencing(volume_flux))

###############################################################################
# Create the StructuredMesh
coordinates_min = (-10.0, -10.0)
coordinates_max = (10.0, 10.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_conditions)

###############################################################################
# ODE solver

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

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

summary_callback = SummaryCallback()

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

alive_callback = AliveCallback(analysis_interval = analysis_interval)

save_solution = SaveSolutionCallback(dt = 1.0,
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);
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@

using OrdinaryDiffEqSSPRK, OrdinaryDiffEqLowStorageRK
using Trixi
using TrixiShallowWater

###############################################################################
# semidiscretization of the shallow water equations to test inflow/outflow boundary conditions

equations = ShallowWaterEquationsWetDry2D(gravity = 9.81)

# Setup initial conditions for a smooth channel flow with constant water height and velocity
function initial_condition_channel_flow(x, t, equations::ShallowWaterEquationsWetDry2D)
H = 1.0
v1 = 0.4
v2 = 0.4
b = 0.0

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

initial_condition = initial_condition_channel_flow

# Setup boundary conditions.
# At the inlet, we prescribe constant momentum to simulate inflow.
# At the outlet, we prescribe the water height as a time-dependent cosine wave.
boundary_condition_inflow = BoundaryConditionMomentum(0.4, 0.4, equations)
boundary_condition_outflow = BoundaryConditionWaterHeight(t -> 1.0 + 0.1 * cos(π / 2 * t),
equations)

boundary_conditions = Dict(:Bottom => boundary_condition_inflow,
:Top => boundary_condition_outflow,
:Left => boundary_condition_slip_wall,
:Right => boundary_condition_slip_wall)

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

volume_flux = (flux_wintermeyer_etal, flux_nonconservative_wintermeyer_etal)
surface_flux = (FluxPlusDissipation(flux_wintermeyer_etal, DissipationLocalLaxFriedrichs()),
flux_nonconservative_wintermeyer_etal)
polydeg = 3
solver = DGSEM(polydeg = polydeg,
surface_flux = surface_flux,
volume_integral = VolumeIntegralFluxDifferencing(volume_flux))

###############################################################################
# Get the unstructured quad mesh from a file (downloads the file if not available locally)
default_mesh_file = joinpath(@__DIR__, "mesh_wobbly_channel.mesh")
isfile(default_mesh_file) ||
Trixi.download("https://gist.githubusercontent.com/andrewwinters5000/431baa423ce86aadba70d38a3194947b/raw/50914cb30e72e9a58d4723e161476435c6dea182/mesh_wobbly_channel.mesh",
default_mesh_file)
mesh_file = default_mesh_file

mesh = UnstructuredMesh2D(mesh_file, periodicity = false)

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

###############################################################################
# ODE solver

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

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

summary_callback = SummaryCallback()

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

alive_callback = AliveCallback(analysis_interval = analysis_interval)

save_solution = SaveSolutionCallback(dt = 0.4,
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);
5 changes: 4 additions & 1 deletion src/TrixiShallowWater.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ module TrixiShallowWater
# https://github.com/trixi-framework/TrixiShallowWater.jl/pull/10#discussion_r1433720559
using Trixi
# Import additional symbols that are not exported by Trixi.jl
using Trixi: get_node_vars, set_node_vars!, waterheight
using Trixi: get_node_vars, set_node_vars!
using MuladdMacro: @muladd
using StaticArrays: SVector, @SMatrix, MVector
using Static: True, False
using LinearAlgebra: norm
using Roots: Order2, solve, ZeroProblem

include("equations/equations.jl")
include("equations/numerical_fluxes.jl")
Expand All @@ -31,6 +32,8 @@ export hydrostatic_reconstruction_chen_noelle, flux_nonconservative_chen_noelle,
export ManningFriction, MeyerPeterMueller, GrassModel, ShieldsStressModel,
dissipation_roe, water_sediment_height, source_term_bottom_friction

export BoundaryConditionWaterHeight, BoundaryConditionMomentum

export nlayers, eachlayer

export PositivityPreservingLimiterShallowWater
Expand Down
10 changes: 10 additions & 0 deletions src/equations/equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
@muladd begin
#! format: noindent

# Struct used for multiple dispatch on boundary conditions that set the water height at the boundary.
struct BoundaryConditionWaterHeight{F <: Function}
h_boundary::F
end

# Struct used for multiple dispatch on boundary conditions that set the momentum at the boundary.
struct BoundaryConditionMomentum{F <: Function}
hv_boundary::F
end

####################################################################################################
# Include files with actual implementations for different systems of equations.

Expand Down
Loading
Loading