-
Notifications
You must be signed in to change notification settings - Fork 10
Add Shallow water moment equation models in 1D #128
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
Merged
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
f4e006d
add swme
patrickersing b6852ff
add tests
patrickersing 37edadc
add well-balanced test, remove allocations from dissipation term
patrickersing fe15c61
add unit tests
patrickersing f4b5ea6
remove unused import of diagm
patrickersing 683b8cd
fix unit test
patrickersing 3c05f73
add news entry
patrickersing 0ce5d51
add Symbolics dependency for testing
patrickersing 7fe5d19
fix BCs
patrickersing ee509cc
fix unit_test
patrickersing 9612864
fix tests
patrickersing c34240f
update tests
patrickersing 2af0b4a
update test reference
patrickersing d361763
update wb test with wall BC
patrickersing 352b0ef
add unit test
patrickersing 989bd99
add unit test
patrickersing 899c360
apply formatter
patrickersing e53ff79
clean up comments
patrickersing 3f0b2ea
Apply suggestions from code review
patrickersing e9541d4
re-introduce the union for wb test
patrickersing 0bcb5b6
switch to SArrays
patrickersing f70060a
update SArray for linearized swme
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
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
133 changes: 133 additions & 0 deletions
133
examples/tree_1d_dgsem/elixir_shallowwater_linearized_moments_convergence.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,133 @@ | ||
| using OrdinaryDiffEqSSPRK, OrdinaryDiffEqLowStorageRK | ||
| using Trixi | ||
| using TrixiShallowWater | ||
| using Symbolics | ||
|
|
||
| ############################################################################### | ||
| # Semidiscretization of the shallow water linearized moment equations to test convergence against a | ||
| # manufactured solution. | ||
|
|
||
| equations = ShallowWaterLinearizedMomentEquations1D(gravity = 9.81, n_moments = 2) | ||
|
|
||
| ### Create manufactured solution for method of manufactured solutions (MMS) | ||
|
|
||
| # Symbolic Variables | ||
| @variables x_sym, t_sym, g | ||
|
|
||
| # Define Differentials | ||
| Dt, Dx = Differential(t_sym), Differential(x_sym[1]) | ||
|
|
||
| ## Initial condition | ||
| ############################################################################### | ||
| # Primitive Variables | ||
| H = 7 + cos(sqrt(2) * 2 * pi * x_sym) * cos(2 * pi * t_sym) | ||
| v = 0.5 | ||
| b = 2 + 0.5 * sinpi(sqrt(2) * x_sym) | ||
| h = H - b | ||
| a = [1 for i in 1:(equations.n_moments)] | ||
|
|
||
| init = [H, v, a..., b] | ||
|
|
||
| ## PDE | ||
| ############################################################################### | ||
| # precompute the sum term | ||
| sum_moments = sum(h * a[j]^2 / (2j + 1) for j in 1:(equations.n_moments)) | ||
|
|
||
| # additional moment equations | ||
| mom_eqs = [Dt(h * a[i]) + Dx(2 * h * v * a[i]) - v * Dx(h * a[i]) | ||
| for i in 1:(equations.n_moments)] | ||
|
|
||
| # PDE Source Terms | ||
| eqs = [ | ||
| Dt(h) + Dx(h * v), | ||
| Dt(h * v) + Dx(h * v^2 + sum_moments) + g * h * Dx(h + b), | ||
| mom_eqs..., | ||
| 0 | ||
| ] | ||
|
|
||
| ## Create the functions for the manufactured solution | ||
| ######################################################################################## | ||
| # Expand derivatives | ||
| du_exprs = expand_derivatives.(eqs) | ||
|
|
||
| # Build functions | ||
| du_funcs = build_function.(du_exprs, Ref(x_sym), t_sym, g, expression = Val(false)) | ||
|
|
||
| init_funcs = build_function.(init, Ref(x_sym), t_sym, expression = Val(false)) | ||
|
|
||
| # Trixi functions | ||
| function initial_condition_convergence(x, | ||
| t, | ||
| equations::ShallowWaterLinearizedMomentEquations1D) | ||
| prim = SVector{3 + equations.n_moments, Float64}([f(x[1], t) for f in init_funcs]...) | ||
| return prim2cons(prim, equations) | ||
| end | ||
|
|
||
| function source_terms_convergence(u, | ||
| x, | ||
| t, | ||
| equations::ShallowWaterLinearizedMomentEquations1D) | ||
| g = equations.gravity | ||
| return SVector{3 + equations.n_moments, Float64}([f(x[1], t, g) for f in du_funcs]...) | ||
| end | ||
|
|
||
| initial_condition = initial_condition_convergence | ||
|
|
||
| ############################################################################### | ||
| # Get the DG approximation space | ||
| volume_flux = (flux_careaga_etal, flux_nonconservative_careaga_etal) | ||
| surface_flux = (FluxPlusDissipation(flux_careaga_etal, | ||
| DissipationLaxFriedrichsEntropyVariables(max_abs_speed)), | ||
| flux_nonconservative_careaga_etal) | ||
|
|
||
| solver = DGSEM(polydeg = 3, | ||
| surface_flux = surface_flux, | ||
| 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 = 4, | ||
| n_cells_max = 10_000, | ||
| periodicity = true) | ||
|
|
||
| # create the semi discretization object | ||
| semi = SemidiscretizationHyperbolic(mesh, | ||
| equations, | ||
| initial_condition, | ||
| solver, | ||
| source_terms = source_terms_convergence; | ||
| boundary_conditions = boundary_condition_periodic) | ||
|
|
||
| ############################################################################### | ||
| # ODE solvers, callbacks etc. | ||
|
|
||
| tspan = (0.0, 0.05) | ||
| 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 = 200, | ||
| 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 fixed step size | ||
| sol = solve(ode, | ||
| CarpenterKennedy2N54(williamson_condition = false); | ||
| dt = 1e-4, | ||
| ode_default_options()..., | ||
| callback = callbacks,); |
132 changes: 132 additions & 0 deletions
132
examples/tree_1d_dgsem/elixir_shallowwater_moments_convergence.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,132 @@ | ||
| using OrdinaryDiffEqSSPRK, OrdinaryDiffEqLowStorageRK | ||
| using Trixi | ||
| using TrixiShallowWater | ||
| using Symbolics | ||
|
|
||
| ############################################################################### | ||
| # Semidiscretization of the shallow water moment equations to test convergence against a | ||
| # manufactured solution. | ||
|
|
||
| equations = ShallowWaterMomentEquations1D(gravity = 9.81, n_moments = 2) | ||
|
|
||
| ### Create manufactured solution for method of manufactured solutions (MMS) | ||
| n = equations.n_moments | ||
|
|
||
| # Symbolic Variables | ||
| @variables x_sym, t_sym, g | ||
|
|
||
| # Define Differentials | ||
| Dt, Dx = Differential(t_sym), Differential(x_sym) | ||
|
|
||
| ## Initial condition | ||
| ################################################################################################## | ||
| H = 7 + cos(sqrt(2) * 2 * pi * x_sym) * cos(2 * pi * t_sym) | ||
| v = 0.5 | ||
| b = 2 + 0.5 * sinpi(sqrt(2) * x_sym) | ||
| h = H - b | ||
| a = [0.5 for i in 1:n] | ||
|
|
||
| init = [H, v, a..., b] | ||
|
|
||
| ## PDE | ||
| ################################################################################################### | ||
| # precompute the sum term | ||
| sum_moments = sum(h * a[j]^2 / (2j + 1) for j in 1:n) | ||
| sum_A = [sum(h * equations.A[i, j, k] * a[j] * a[k] for j in 1:n, k in 1:n) for i in 1:n] | ||
| sum_B = [sum(equations.B[i, j, k] * a[k] * Dx(h * a[j]) for j in 1:n, k in 1:n) | ||
| for i in 1:n] | ||
|
|
||
| # additional moment equations | ||
| mom_eqs = [Dt(h * a[i]) + Dx(2 * h * v * a[i] + sum_A[i]) - v * Dx(h * a[i]) + sum_B[i] | ||
| for | ||
| i in 1:n] | ||
|
|
||
| # PDE Source Terms | ||
| eqs = [ | ||
| Dt(h) + Dx(h * v), | ||
| Dt(h * v) + Dx(h * v^2 + sum_moments) + g * h * Dx(h + b), | ||
| mom_eqs..., | ||
| 0 | ||
| ] | ||
|
|
||
| ## Create the functions for the manufactured solution | ||
| ################################################################################################### | ||
| # Expand derivatives | ||
| du_exprs = expand_derivatives.(eqs) | ||
|
|
||
| # Build functions | ||
| du_funcs = build_function.(du_exprs, Ref(x_sym), Ref(t_sym), g, expression = Val(false)) | ||
|
|
||
| init_funcs = build_function.(init, Ref(x_sym), t_sym, expression = Val(false)) | ||
|
|
||
| # Trixi functions | ||
| function initial_condition_convergence(x, t, equations::ShallowWaterMomentEquations1D) | ||
| prim = SVector{3 + n, Float64}([f(x[1], t) for f in init_funcs]...) | ||
| return prim2cons(prim, equations) | ||
| end | ||
|
|
||
| function source_terms_convergence(u, x, t, equations::ShallowWaterMomentEquations1D) | ||
| g = equations.gravity | ||
| return SVector{3 + n, Float64}([f(x[1], t, g) for f in du_funcs]...) | ||
| end | ||
|
|
||
| initial_condition = initial_condition_convergence | ||
|
|
||
| ############################################################################### | ||
| # Get the DG approximation space | ||
| volume_flux = (flux_careaga_etal, flux_nonconservative_careaga_etal) | ||
| surface_flux = (FluxPlusDissipation(flux_careaga_etal, | ||
| DissipationLaxFriedrichsEntropyVariables(max_abs_speed)), | ||
| flux_nonconservative_careaga_etal) | ||
|
|
||
| solver = DGSEM(polydeg = 3, | ||
| surface_flux = surface_flux, | ||
| 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 = 4, | ||
| n_cells_max = 10_000, | ||
| periodicity = true) | ||
|
|
||
| # create the semi discretization object | ||
| semi = SemidiscretizationHyperbolic(mesh, | ||
| equations, | ||
| initial_condition, | ||
| solver, | ||
| source_terms = source_terms_convergence; | ||
| boundary_conditions = boundary_condition_periodic) | ||
|
|
||
| ############################################################################### | ||
| # ODE solvers, callbacks etc. | ||
|
|
||
| tspan = (0.0, 0.05) | ||
| 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 = 200, | ||
| 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 fixed step size | ||
| sol = solve(ode, | ||
| CarpenterKennedy2N54(williamson_condition = false); | ||
| dt = 1e-4, | ||
| ode_default_options()..., | ||
| callback = callbacks,); | ||
93 changes: 93 additions & 0 deletions
93
examples/tree_1d_dgsem/elixir_shallowwater_moments_smooth_wave.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,93 @@ | ||
|
|
||
| using OrdinaryDiffEqSSPRK, OrdinaryDiffEqLowStorageRK | ||
| using Trixi | ||
| using TrixiShallowWater | ||
|
|
||
| # Semidiscretization of the shallow water moment equations with two moments | ||
| equations = ShallowWaterMomentEquations1D(gravity = 1.0, n_moments = 2) | ||
|
|
||
| # Initial condition with a smooth wave wave in a periodic domain. | ||
| # See section 4.2 in the paper: | ||
| # Julian Koellermeier and Marvin Rominger (2020) | ||
| # "Analysis and Numerical Simulation of Hyperbolic Shallow Water Moment Equations" | ||
| # [DOI: 10.4208/cicp.OA-2019-0065](https://doi.org/10.4208/cicp.OA-2019-0065) | ||
| function initial_condition_smooth_periodic_wave(x, t, | ||
| equations::Union{ShallowWaterMomentEquations1D, | ||
| ShallowWaterLinearizedMomentEquations1D}) | ||
| H = 1.0 + exp(3.0 * cos(π * (x[1] + 0.5))) / exp(4.0) | ||
| v = 0.25 | ||
| a = zeros(equations.n_moments) | ||
| a[2] = -0.25 | ||
|
|
||
| b = 0.0 | ||
|
|
||
| return prim2cons(SVector(H, v, a..., b), equations) | ||
| end | ||
|
|
||
| initial_condition = initial_condition_smooth_periodic_wave | ||
|
|
||
| ############################################################################### | ||
| # Get the DG approximation space | ||
|
|
||
| volume_flux = (flux_careaga_etal, flux_nonconservative_careaga_etal) | ||
| surface_flux = (FluxPlusDissipation(flux_careaga_etal, | ||
| DissipationLaxFriedrichsEntropyVariables(Trixi.max_abs_speed)), | ||
| flux_nonconservative_careaga_etal) | ||
|
|
||
| indicator_var(u, equations) = u[2]^3 | ||
|
|
||
| basis = LobattoLegendreBasis(3) | ||
| indicator_sc = IndicatorHennemannGassner(equations, basis, | ||
| alpha_max = 0.5, | ||
| alpha_min = 0.001, | ||
| alpha_smooth = true, | ||
| variable = indicator_var) | ||
|
|
||
| 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 [-1, 1] | ||
|
|
||
| coordinates_min = -1.0 | ||
| coordinates_max = 1.0 | ||
|
|
||
| mesh = TreeMesh(coordinates_min, | ||
| coordinates_max, | ||
| initial_refinement_level = 6, # 2^refinement_level | ||
| n_cells_max = 10_000, | ||
| periodicity = true) | ||
|
|
||
| # create the semi discretization object | ||
| semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver, | ||
| source_terms = source_term_manning_friction; | ||
| boundary_conditions = boundary_condition_periodic) | ||
|
|
||
| ############################################################################### | ||
| # ODE solver | ||
| tspan = (0.0, 1.0) | ||
| ode = semidiscretize(semi, tspan) | ||
|
|
||
| ############################################################################### | ||
| # Callbacks | ||
| summary_callback = SummaryCallback() | ||
|
|
||
| analysis_interval = 200 | ||
| analysis_callback = AnalysisCallback(semi, interval = analysis_interval, | ||
| save_analysis = false) | ||
| alive_callback = AliveCallback(analysis_interval = analysis_interval) | ||
| stepsize_callback = StepsizeCallback(cfl = 0.9) | ||
|
|
||
| callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback, | ||
| 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 | ||
| ode_default_options()..., | ||
| callback = callbacks,); |
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.