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

Add reflecting boundary conditions for Svärd-Kalisch equations #166

Merged
merged 29 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3db9929
add reflecting boundary conditions for Svärd-Kalisch equations
JoshuaLampert Dec 6, 2024
94dad02
Apply suggestions from code review
JoshuaLampert Dec 6, 2024
0d5ca48
add back accidently removed FourierDerivativeOperator
JoshuaLampert Dec 6, 2024
c7f3d4e
also implement upwind operators
JoshuaLampert Dec 8, 2024
9e9d472
reformat
JoshuaLampert Dec 8, 2024
874028b
Apply suggestions from code review
JoshuaLampert Dec 10, 2024
25ad669
Update src/equations/svaerd_kalisch_1d.jl
JoshuaLampert Dec 10, 2024
d8149c6
Merge branch 'main' into reflecting-bc-SK
JoshuaLampert Dec 10, 2024
8fe7401
set stricter time integration tolerances
JoshuaLampert Dec 10, 2024
75ec37f
lower tolerance
JoshuaLampert Dec 10, 2024
8859d06
use Cholesky decomposition
JoshuaLampert Dec 11, 2024
40468f3
Update src/equations/svaerd_kalisch_1d.jl
JoshuaLampert Dec 11, 2024
40f52cb
temporarily add lu decomposition again
JoshuaLampert Dec 11, 2024
f017619
fix scale_by_mass_matrix!
JoshuaLampert Dec 11, 2024
ca345a5
remove LU decomposition again
JoshuaLampert Dec 11, 2024
3fa969f
scale_by_mass_matrix! outside of solve_system_matrix!
JoshuaLampert Dec 11, 2024
82becee
try CI without tolerances
JoshuaLampert Dec 11, 2024
60e800e
reorder imports
JoshuaLampert Dec 11, 2024
08c04e6
fix variable name
JoshuaLampert Dec 11, 2024
94991f3
refactor to reduce code redundancy
JoshuaLampert Dec 11, 2024
320d883
fix
JoshuaLampert Dec 11, 2024
a2d8497
pass boundary_conditions
JoshuaLampert Dec 11, 2024
9bfebe3
format
JoshuaLampert Dec 11, 2024
2d50833
adjust tolerances
JoshuaLampert Dec 11, 2024
209cc76
Apply suggestions from code review
JoshuaLampert Dec 11, 2024
2308121
Update src/equations/equations.jl
JoshuaLampert Dec 11, 2024
3302cd0
begin + 1instead of 2
JoshuaLampert Dec 11, 2024
7358093
set tolerances in tests
JoshuaLampert Dec 11, 2024
7092265
add test for ArgumentError
JoshuaLampert Dec 11, 2024
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
46 changes: 46 additions & 0 deletions examples/svaerd_kalisch_1d/svaerd_kalisch_1d_basic_reflecting.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using OrdinaryDiffEqTsit5
using DispersiveShallowWater
using SummationByPartsOperators: MattssonNordström2004, derivative_operator

###############################################################################
# Semidiscretization of the Svärd-Kalisch equations
# For reflecting boundary conditions, alpha and gamma need to be 0
equations = SvaerdKalischEquations1D(gravity_constant = 1.0, eta0 = 0.0,
alpha = 0.0, beta = 1 / 3, gamma = 0.0)

initial_condition = initial_condition_manufactured_reflecting
source_terms = source_terms_manufactured_reflecting
boundary_conditions = boundary_condition_reflecting

# create homogeneous mesh
coordinates_min = 0.0
coordinates_max = 1.0
N = 512
mesh = Mesh1D(coordinates_min, coordinates_max, N)

# create solver with SBP operators of accuracy order 4
accuracy_order = 4
D1 = derivative_operator(MattssonNordström2004(),
derivative_order = 1, accuracy_order = accuracy_order,
xmin = mesh.xmin, xmax = mesh.xmax, N = mesh.N)
solver = Solver(D1, nothing)

# semidiscretization holds all the necessary data structures for the spatial discretization
semi = Semidiscretization(mesh, equations, initial_condition, solver,
boundary_conditions = boundary_conditions,
source_terms = source_terms)

###############################################################################
# Create `ODEProblem` and run the simulation
tspan = (0.0, 1.0)
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi; interval = 100,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (waterheight_total,
entropy_modified))
callbacks = CallbackSet(analysis_callback, summary_callback)

saveat = range(tspan..., length = 100)
sol = solve(ode, Tsit5(), abstol = 1e-12, reltol = 1e-12,
save_everystep = false, callback = callbacks, saveat = saveat)
ranocha marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 3 additions & 6 deletions src/equations/bbm_bbm_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,7 @@ function create_cache(mesh, equations::BBMBBMEquations1D{BathymetryFlat},

# homogeneous Neumann boundary conditions
if solver.D1 isa DerivativeOperator ||
solver.D1 isa UniformCoupledOperator ||
solver.D1 isa FourierDerivativeOperator
solver.D1 isa UniformCoupledOperator
JoshuaLampert marked this conversation as resolved.
Show resolved Hide resolved
D1_b = BandedMatrix(solver.D1)
invImD2n = lu(I + 1 / 6 * D^2 * inv(M) * D1_b' * PdM * D1_b)
elseif solver.D1 isa UpwindOperators
Expand Down Expand Up @@ -382,8 +381,7 @@ function create_cache(mesh, equations::BBMBBMEquations1D,

# homogeneous Neumann boundary conditions
if solver.D1 isa DerivativeOperator ||
solver.D1 isa UniformCoupledOperator ||
solver.D1 isa FourierDerivativeOperator
solver.D1 isa UniformCoupledOperator
D1_b = BandedMatrix(solver.D1)
invImD2n = lu(I + 1 / 6 * inv(M) * D1_b' * PdM * K * D1_b)
elseif solver.D1 isa UpwindOperators
Expand Down Expand Up @@ -501,8 +499,7 @@ function rhs!(dq, q, t, mesh, equations::BBMBBMEquations1D, initial_condition,
end
# energy and mass conservative semidiscretization
if solver.D1 isa DerivativeOperator ||
solver.D1 isa UniformCoupledOperator ||
solver.D1 isa FourierDerivativeOperator
solver.D1 isa UniformCoupledOperator
@trixi_timeit timer() "deta hyperbolic" begin
mul!(deta, solver.D1, tmp1)
end
Expand Down
18 changes: 16 additions & 2 deletions src/equations/equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,22 @@ abstract type AbstractSerreGreenNaghdiEquations{NDIMS, NVARS} <:
include("serre_green_naghdi_1d.jl")
include("hyperbolic_serre_green_naghdi_1d.jl")

function solve_system_matrix!(dv, system_matrix, rhs,
equations::Union{SvaerdKalischEquations1D,
SerreGreenNaghdiEquations1D},
D1, cache, ::BoundaryConditionPeriodic)
scale_by_mass_matrix!(rhs, D1)
solve_system_matrix!(dv, system_matrix, rhs, equations, D1, cache)
end

function solve_system_matrix!(dv, system_matrix, rhs,
equations::Union{SvaerdKalischEquations1D,
SerreGreenNaghdiEquations1D},
D1, cache, ::BoundaryConditionReflecting)
scale_by_mass_matrix!(rhs, D1)
solve_system_matrix!(dv, system_matrix, (@view rhs[2:(end - 1)]), equations, D1, cache)
JoshuaLampert marked this conversation as resolved.
Show resolved Hide resolved
end

function solve_system_matrix!(dv, system_matrix, rhs,
::Union{SvaerdKalischEquations1D,
SerreGreenNaghdiEquations1D},
Expand All @@ -565,7 +581,6 @@ function solve_system_matrix!(dv, system_matrix, rhs,
(; factorization) = cache
cholesky!(factorization, system_matrix; check = false)
if issuccess(factorization)
scale_by_mass_matrix!(rhs, D1)
# see https://github.com/JoshuaLampert/DispersiveShallowWater.jl/issues/122
dv .= factorization \ rhs
else
Expand All @@ -575,7 +590,6 @@ function solve_system_matrix!(dv, system_matrix, rhs,
end
else
factorization = cholesky!(system_matrix)
scale_by_mass_matrix!(rhs, D1)
ldiv!(dv, factorization, rhs)
end
return nothing
Expand Down
36 changes: 21 additions & 15 deletions src/equations/serre_green_naghdi_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -314,19 +314,22 @@ end
function rhs!(dq, q, t, mesh,
equations::SerreGreenNaghdiEquations1D,
initial_condition,
::BoundaryConditionPeriodic,
boundary_conditions::BoundaryConditionPeriodic,
source_terms::Nothing,
solver, cache)
if cache.D1 isa PeriodicUpwindOperators
rhs_sgn_upwind!(dq, q, equations, source_terms, cache, equations.bathymetry_type)
rhs_sgn_upwind!(dq, q, equations, source_terms, cache, equations.bathymetry_type,
boundary_conditions)
else
rhs_sgn_central!(dq, q, equations, source_terms, cache, equations.bathymetry_type)
rhs_sgn_central!(dq, q, equations, source_terms, cache, equations.bathymetry_type,
boundary_conditions)
end

return nothing
end

function rhs_sgn_central!(dq, q, equations, source_terms, cache, ::BathymetryFlat)
function rhs_sgn_central!(dq, q, equations, source_terms, cache, ::BathymetryFlat,
boundary_conditions::BoundaryConditionPeriodic)
# Unpack physical parameters and SBP operator `D1` as well as the
# SBP operator in sparse matrix form `D1mat`
g = gravity_constant(equations)
Expand Down Expand Up @@ -399,14 +402,15 @@ function rhs_sgn_central!(dq, q, equations, source_terms, cache, ::BathymetryFla
end

@trixi_timeit timer() "solving elliptic system" begin
solve_system_matrix!(dv, system_matrix, tmp,
equations, D1, cache)
solve_system_matrix!(dv, system_matrix,
tmp, equations, D1, cache, boundary_conditions)
end

return nothing
end

function rhs_sgn_upwind!(dq, q, equations, source_terms, cache, ::BathymetryFlat)
function rhs_sgn_upwind!(dq, q, equations, source_terms, cache, ::BathymetryFlat,
boundary_conditions::BoundaryConditionPeriodic)
# Unpack physical parameters and SBP operator `D1` as well as the
# SBP upwind operator in sparse matrix form `D1mat_minus`
g = gravity_constant(equations)
Expand Down Expand Up @@ -484,15 +488,16 @@ function rhs_sgn_upwind!(dq, q, equations, source_terms, cache, ::BathymetryFlat
end

@trixi_timeit timer() "solving elliptic system" begin
solve_system_matrix!(dv, system_matrix, tmp,
equations, D1, cache)
solve_system_matrix!(dv, system_matrix,
tmp, equations, D1, cache, boundary_conditions)
end

return nothing
end

function rhs_sgn_central!(dq, q, equations, source_terms, cache,
::Union{BathymetryMildSlope, BathymetryVariable})
::Union{BathymetryMildSlope, BathymetryVariable},
boundary_conditions::BoundaryConditionPeriodic)
# Unpack physical parameters and SBP operator `D1` as well as the
# SBP operator in sparse matrix form `D1mat`
g = gravity_constant(equations)
Expand Down Expand Up @@ -589,15 +594,16 @@ function rhs_sgn_central!(dq, q, equations, source_terms, cache,
end

@trixi_timeit timer() "solving elliptic system" begin
solve_system_matrix!(dv, system_matrix, tmp,
equations, D1, cache)
solve_system_matrix!(dv, system_matrix,
tmp, equations, D1, cache, boundary_conditions)
end

return nothing
end

function rhs_sgn_upwind!(dq, q, equations, source_terms, cache,
::Union{BathymetryMildSlope, BathymetryVariable})
::Union{BathymetryMildSlope, BathymetryVariable},
boundary_conditions::BoundaryConditionPeriodic)
# Unpack physical parameters and SBP operator `D1` as well as the
# SBP operator in sparse matrix form `D1mat`
g = gravity_constant(equations)
Expand Down Expand Up @@ -702,8 +708,8 @@ function rhs_sgn_upwind!(dq, q, equations, source_terms, cache,
end

@trixi_timeit timer() "solving elliptic system" begin
solve_system_matrix!(dv, system_matrix, tmp,
equations, D1, cache)
solve_system_matrix!(dv, system_matrix,
tmp, equations, D1, cache, boundary_conditions)
end

return nothing
Expand Down
Loading
Loading