-
Notifications
You must be signed in to change notification settings - Fork 10
Add inlet/outlet BCs for the 2D-SWE #91
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
Merged
andrewwinters5000
merged 24 commits into
trixi-framework:main
from
patrickersing:geostrophic_adjustment
May 6, 2025
Merged
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 92829a8
Add boundary conditions for fixed water height and momentum
patrickersing 87565e3
Merge branch 'main' into geostrophic_adjustment
patrickersing a6f55c0
Use the new gravity parameter and correct boundary condition assignments
patrickersing df56ef5
fix gravity parameter in test_unit.jl
patrickersing a2bf1ac
switch to OrdinaryDiffEq subpackages in the new elixirs
patrickersing 251fcd5
remove unnecessary lines in unit test
patrickersing cfbc207
Use Trixi.download instead of Base.download
patrickersing 7bab2dd
increase iterations for coverage testing
patrickersing e24d587
apply formatter
patrickersing ab8fab7
specify maxiters for coverage overwrite
patrickersing 8b66350
create equation specific constructor for the BCs
patrickersing 02b99cf
fix tests
patrickersing da4c8b4
enforce correct output types for the boundary value function
patrickersing fd54bde
Apply suggestions from code review
patrickersing d34cd2c
apply suggestions from code review part 2
patrickersing cde6fd6
add BC in for SWE-1D together with moving-water steady state test cases
patrickersing 6382f07
fix typos
patrickersing 73de3c5
Merge branch 'main' into geostrophic_adjustment
patrickersing 4c9e180
additional unit test to trigger ArgumentError for BoundaryConditionWa…
patrickersing 65c4bf5
add news item
patrickersing befee41
Merge branch 'main' into geostrophic_adjustment
patrickersing 93bd252
Apply changes from code review
patrickersing d3fd8ff
Apply changes from code review - part 2
patrickersing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
examples/tree_2d_dgsem/elixir_shallowwater_inflow_outflow.jl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
patrickersing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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); | ||
94 changes: 94 additions & 0 deletions
94
examples/unstructured_2d_dgsem/elixir_shallowwater_inflow_outflow.jl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
andrewwinters5000 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.