-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1275 from trixi-framework/dev
Upwind finite difference SBP solver
- Loading branch information
Showing
34 changed files
with
2,766 additions
and
79 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,64 @@ | ||
#src # Upwind FD SBP schemes | ||
|
||
# General tensor product SBP methods are supported via the `DGMulti` solver | ||
# in a reasonably complete way, see [the previous tutorial](@ref DGMulti_2). | ||
# Nevertheless, there is also experimental support for SBP methods with | ||
# other solver and mesh types. | ||
|
||
# The first step is to set up an SBP operator. A classical (central) SBP | ||
# operator can be created as follows. | ||
using Trixi | ||
D_SBP = derivative_operator(SummationByPartsOperators.MattssonNordström2004(), | ||
derivative_order=1, accuracy_order=2, | ||
xmin=0.0, xmax=1.0, N=11) | ||
# Instead of prefixing the source of coefficients `MattssonNordström2004()`, | ||
# you can also load the package SummationByPartsOperators.jl. Either way, | ||
# this yields an object representing the operator efficiently. If you want to | ||
# compare it to coefficients presented in the literature, you can convert it | ||
# to a matrix. | ||
Matrix(D_SBP) | ||
|
||
# Upwind SBP operators are a concept introduced in 2017 by Ken Mattsson. You can | ||
# create them as follows. | ||
D_upw = upwind_operators(SummationByPartsOperators.Mattsson2017, | ||
derivative_order=1, accuracy_order=2, | ||
xmin=0.0, xmax=1.0, N=11) | ||
# Upwind operators are derivative operators biased towards one direction. | ||
# The "minus" variants has a bias towards the left side, i.e., it uses values | ||
# from more nodes to the left than from the right to compute the discrete | ||
# derivative approximation at a given node (in the interior of the domain). | ||
# In matrix form, this means more non-zero entries are left from the diagonal. | ||
Matrix(D_upw.minus) | ||
# Analogously, the "plus" variant has a bias towards the right side. | ||
Matrix(D_upw.plus) | ||
# For more information on upwind SBP operators, please refer to the documentation | ||
# of [SummationByPartsOperators.jl](https://github.com/ranocha/SummationByPartsOperators.jl) | ||
# and references cited there. | ||
|
||
# The basic idea of upwind SBP schemes is to apply a flux vector splitting and | ||
# use appropriate upwind operators for both parts of the flux. In 1D, this means | ||
# to split the flux | ||
# ```math | ||
# f(u) = f^-(u) + f^+(u) | ||
# ``` | ||
# such that $f^-(u)$ is associated with left-going waves and $f^+(u)$ with | ||
# right-going waves. Then, we apply upwind SBP operators $D^-, D^+$ with an | ||
# appropriate upwind bias, resulting in | ||
# ```math | ||
# \partial_x f(u) \approx D^+ f^-(u) + D^- f^+(u) | ||
# ``` | ||
# Note that the established notations of upwind operators $D^\pm$ and flux | ||
# splittings $f^\pm$ clash. The right-going waves from $f^+$ need an operator | ||
# biased towards their upwind side, i.e., the left side. This upwind bias is | ||
# provided by the operator $D^-$. | ||
|
||
# Many classical flux vector splittings have been developed for finite volume | ||
# methods and are described in the book "Riemann Solvers and Numerical Methods | ||
# for Fluid Dynamics: A Practical Introduction" of Eleuterio F. Toro (2009), | ||
# [DOI: 10.1007/b79761](https://doi.org/10.1007/b79761). One such a well-known | ||
# splitting provided by Trixi.jl is [`splitting_steger_warming`](@ref). | ||
|
||
# Trixi.jl comes with several example setups using upwind SBP methods with | ||
# flux vector splitting, e.g., | ||
# - [`elixir_euler_vortex.jl`](https://github.com/trixi-framework/Trixi.jl/blob/main/examples/tree_2d_fdsbp/elixir_euler_vortex.jl) | ||
# - [`elixir_euler_taylor_green_vortex.jl`](https://github.com/trixi-framework/Trixi.jl/blob/main/examples/tree_3d_fdsbp/elixir_euler_taylor_green_vortex.jl) |
This file contains 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 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,64 @@ | ||
# !!! warning "Experimental implementation (upwind SBP)" | ||
# This is an experimental feature and may change in future releases. | ||
|
||
using OrdinaryDiffEq | ||
using Trixi | ||
|
||
############################################################################### | ||
# semidiscretization of the (inviscid) Burgers' equation | ||
|
||
equations = InviscidBurgersEquation1D() | ||
|
||
initial_condition = initial_condition_convergence_test | ||
|
||
D_upw = upwind_operators(SummationByPartsOperators.Mattsson2017, | ||
derivative_order=1, | ||
accuracy_order=4, | ||
xmin=-1.0, xmax=1.0, | ||
N=32) | ||
flux_splitting = splitting_lax_friedrichs | ||
solver = FDSBP(D_upw, | ||
surface_integral=SurfaceIntegralUpwind(flux_splitting), | ||
volume_integral=VolumeIntegralUpwind(flux_splitting)) | ||
|
||
coordinates_min = 0.0 | ||
coordinates_max = 1.0 | ||
mesh = TreeMesh(coordinates_min, coordinates_max, | ||
initial_refinement_level=3, | ||
n_cells_max=10_000) | ||
|
||
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver, | ||
source_terms=source_terms_convergence_test) | ||
|
||
|
||
############################################################################### | ||
# ODE solvers, callbacks etc. | ||
|
||
tspan = (0.0, 2.0) | ||
ode = semidiscretize(semi, tspan) | ||
|
||
summary_callback = SummaryCallback() | ||
|
||
analysis_interval = 200 | ||
analysis_callback = AnalysisCallback(semi, interval=analysis_interval, | ||
extra_analysis_errors=(:l2_error_primitive, | ||
:linf_error_primitive)) | ||
|
||
alive_callback = AliveCallback(analysis_interval=analysis_interval) | ||
|
||
save_solution = SaveSolutionCallback(interval=100, | ||
save_initial_solution=true, | ||
save_final_solution=true, | ||
solution_variables=cons2prim) | ||
|
||
callbacks = CallbackSet(summary_callback, | ||
analysis_callback, alive_callback, | ||
save_solution) | ||
|
||
|
||
############################################################################### | ||
# run the simulation | ||
|
||
sol = solve(ode, SSPRK43(), abstol=1.0e-9, reltol=1.0e-9, | ||
save_everystep=false, callback=callbacks); | ||
summary_callback() # print the timer summary |
This file contains 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,60 @@ | ||
# !!! warning "Experimental implementation (upwind SBP)" | ||
# This is an experimental feature and may change in future releases. | ||
|
||
using OrdinaryDiffEq | ||
using Trixi | ||
|
||
############################################################################### | ||
# semidiscretization of the (inviscid) Burgers' equation | ||
|
||
equations = InviscidBurgersEquation1D() | ||
|
||
function initial_condition_linear_stability(x, t, equation::InviscidBurgersEquation1D) | ||
k = 1 | ||
2 + sinpi(k * (x[1] - 0.7)) |> SVector | ||
end | ||
|
||
D_upw = upwind_operators(SummationByPartsOperators.Mattsson2017, | ||
derivative_order=1, | ||
accuracy_order=4, | ||
xmin=-1.0, xmax=1.0, | ||
N=16) | ||
flux_splitting = splitting_lax_friedrichs | ||
solver = FDSBP(D_upw, | ||
surface_integral=SurfaceIntegralUpwind(flux_splitting), | ||
volume_integral=VolumeIntegralUpwind(flux_splitting)) | ||
|
||
coordinates_min = -1.0 | ||
coordinates_max = 1.0 | ||
mesh = TreeMesh(coordinates_min, coordinates_max, | ||
initial_refinement_level=4, | ||
n_cells_max=10_000) | ||
|
||
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_linear_stability, solver) | ||
|
||
|
||
############################################################################### | ||
# ODE solvers, callbacks etc. | ||
|
||
tspan = (0.0, 2.0) | ||
ode = semidiscretize(semi, tspan) | ||
|
||
summary_callback = SummaryCallback() | ||
|
||
analysis_interval = 1000 | ||
analysis_callback = AnalysisCallback(semi, interval=analysis_interval, | ||
extra_analysis_errors=(:l2_error_primitive, | ||
:linf_error_primitive)) | ||
|
||
alive_callback = AliveCallback(analysis_interval=analysis_interval) | ||
|
||
callbacks = CallbackSet(summary_callback, | ||
analysis_callback, alive_callback) | ||
|
||
|
||
############################################################################### | ||
# run the simulation | ||
|
||
sol = solve(ode, SSPRK43(), abstol=1.0e-6, reltol=1.0e-6, | ||
save_everystep=false, callback=callbacks); | ||
summary_callback() # print the timer summary |
This file contains 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,64 @@ | ||
# !!! warning "Experimental implementation (upwind SBP)" | ||
# This is an experimental feature and may change in future releases. | ||
|
||
using OrdinaryDiffEq | ||
using Trixi | ||
|
||
############################################################################### | ||
# semidiscretization of the compressible Euler equations | ||
|
||
equations = CompressibleEulerEquations1D(1.4) | ||
|
||
initial_condition = initial_condition_convergence_test | ||
|
||
D_upw = upwind_operators(SummationByPartsOperators.Mattsson2017, | ||
derivative_order=1, | ||
accuracy_order=4, | ||
xmin=-1.0, xmax=1.0, | ||
N=32) | ||
flux_splitting = splitting_steger_warming | ||
solver = FDSBP(D_upw, | ||
surface_integral=SurfaceIntegralUpwind(flux_splitting), | ||
volume_integral=VolumeIntegralUpwind(flux_splitting)) | ||
|
||
coordinates_min = 0.0 | ||
coordinates_max = 2.0 | ||
mesh = TreeMesh(coordinates_min, coordinates_max, | ||
initial_refinement_level=1, | ||
n_cells_max=10_000) | ||
|
||
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver, | ||
source_terms=source_terms_convergence_test) | ||
|
||
|
||
############################################################################### | ||
# ODE solvers, callbacks etc. | ||
|
||
tspan = (0.0, 2.0) | ||
ode = semidiscretize(semi, tspan) | ||
|
||
summary_callback = SummaryCallback() | ||
|
||
analysis_interval = 100 | ||
analysis_callback = AnalysisCallback(semi, interval=analysis_interval, | ||
extra_analysis_errors=(:l2_error_primitive, | ||
:linf_error_primitive)) | ||
|
||
alive_callback = AliveCallback(analysis_interval=analysis_interval) | ||
|
||
save_solution = SaveSolutionCallback(interval=100, | ||
save_initial_solution=true, | ||
save_final_solution=true, | ||
solution_variables=cons2prim) | ||
|
||
callbacks = CallbackSet(summary_callback, | ||
analysis_callback, alive_callback, | ||
save_solution) | ||
|
||
|
||
############################################################################### | ||
# run the simulation | ||
|
||
sol = solve(ode, SSPRK43(), abstol=1.0e-6, reltol=1.0e-6, | ||
save_everystep=false, callback=callbacks) | ||
summary_callback() # print the timer summary |
Oops, something went wrong.