Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions src/equations/bbm_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ function BBMEquation1D(; gravity, D = 1.0, eta0 = 0.0, split_form = true)
BBMEquation1D(gravity, D, eta0, split_form)
end

function check_solver(::BBMEquation1D, solver, boundary_conditions)
if isnothing(solver.D2)
throw(ArgumentError("The BBM equation requires a second-derivative operator. Explicitly set `D2`."))
end
end

"""
initial_condition_convergence_test(x, t, equations::BBMEquation1D, mesh)

Expand Down
6 changes: 6 additions & 0 deletions src/equations/bbm_bbm_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ function BBMBBMEquations1D(; bathymetry_type = bathymetry_variable,
BBMBBMEquations1D(bathymetry_type, gravity, eta0)
end

function check_solver(::BBMBBMEquations1D, solver, boundary_conditions)
if isnothing(solver.D2)
throw(ArgumentError("The BBM-BBM equations require a second-derivative operator. Explicitly set `D2`."))
end
end

"""
initial_condition_convergence_test(x, t, equations::BBMBBMEquations1D, mesh)

Expand Down
33 changes: 20 additions & 13 deletions src/equations/kdv_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ function KdVEquation1D(; gravity, D = 1.0, eta0 = 0.0)
KdVEquation1D(gravity, D, eta0)
end

function check_solver(::KdVEquation1D, solver, boundary_conditions)
if !(solver.D1 isa PeriodicUpwindOperators && isnothing(solver.D3)) &&
isnothing(solver.D3)
throw(ArgumentError("The KdV equation requires a third-derivative operator. Either explicitly set `D3` or set `D1` as an upwind operator."))
end
end

"""
initial_condition_soliton(x, t, equations::KdVEquation1D, mesh)

Expand Down Expand Up @@ -133,14 +140,14 @@ where `D` is the still-water depth.

!!! warning "Parameter constraints"
This conversion is only valid for equations with specific parameter values:
- `gravity = 4/27`
- `D = 3.0`
These values ensure the dimensional KdV equation matches the standard
- `gravity = 4/27`
- `D = 3.0`

These values ensure the dimensional KdV equation matches the standard
non-dimensional form `u_t + u u_x + u_{xxx} = 0`.

This function allows converting solutions from the standard non-dimensional
KdV form commonly found in literature to the dimensional form implemented
This function allows converting solutions from the standard non-dimensional
KdV form commonly found in literature to the dimensional form implemented
in DispersiveShallowWater.jl.

See also [`prim2nondim`](@ref).
Expand All @@ -153,7 +160,7 @@ end
"""
prim2nondim(eta, equations::KdVEquation1D)

Convert the primitive/physical variable `eta` (total water height) to the
Convert the primitive/physical variable `eta` (total water height) to the
non-dimensional variable `u` for the [`KdVEquation1D`](@ref).

The transformation is given by:
Expand All @@ -164,15 +171,15 @@ where `D` is the still-water depth.

!!! warning "Parameter constraints"
This conversion is only valid for equations with specific parameter values:
- `gravity = 4/27`
- `gravity = 4/27`
- `D = 3.0`
These values ensure the dimensional KdV equation matches the standard

These values ensure the dimensional KdV equation matches the standard
non-dimensional form `u_t + u u_x + u_{xxx} = 0`.

This function allows converting solutions from the dimensional form implemented
in DispersiveShallowWater.jl to the standard non-dimensional KdV form
commonly found in literature, enabling comparison with theoretical results
This function allows converting solutions from the dimensional form implemented
in DispersiveShallowWater.jl to the standard non-dimensional KdV form
commonly found in literature, enabling comparison with theoretical results
and other implementations.

See also [`nondim2prim`](@ref).
Expand Down
6 changes: 6 additions & 0 deletions src/equations/svaerd_kalisch_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ function SvaerdKalischEquations1D(; bathymetry_type = bathymetry_variable, gravi
SvaerdKalischEquations1D(bathymetry_type, gravity, eta0, alpha, beta, gamma)
end

function check_solver(::SvaerdKalischEquations1D, solver, ::BoundaryConditionPeriodic)
if isnothing(solver.D2)
throw(ArgumentError("The Svärd-Kalisch equations with periodic boundary conditions require a second-derivative operator. Explicitly set `D2`."))
end
end

"""
initial_condition_manufactured(x, t, equations::SvaerdKalischEquations1D, mesh)

Expand Down
14 changes: 14 additions & 0 deletions src/semidiscretization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function Semidiscretization(mesh, equations, initial_condition, solver;
throw(ArgumentError("Non-periodic derivative operators in `solver` are incompatible with periodic boundary conditions."))
end

check_solver(equations, solver, boundary_conditions)
cache = (;
create_cache(mesh, equations, solver, initial_condition, boundary_conditions,
RealT, uEltype)...,
Expand All @@ -88,6 +89,19 @@ function Semidiscretization(mesh, equations, initial_condition, solver;
solver, cache)
end

"""
check_solver(equations, solver, boundary_conditions)

Check that the `solver` is compatible with the given `equations` and
`boundary_conditions`. The default implementation performs no checks.
Specific equation types can override this method to validate that
required derivative operators are present (e.g., some equations
require `D2` or `D3` to be non-`nothing`).

Throws an `ArgumentError` if the solver is incompatible.
"""
check_solver(equations, solver, boundary_conditions) = nothing

function Base.show(io::IO, semi::Semidiscretization)
@nospecialize semi # reduce precompilation time

Expand Down
23 changes: 23 additions & 0 deletions test/test_unit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,29 @@ end
@test_throws ArgumentError semidiscretize(semi_flat, (0.0, 1.0))
end

@testitem "Solver consistency" setup=[Setup, AdditionalImports] begin
mesh = Mesh1D(-1.0, 1.0, 10)
initial_condition = initial_condition_convergence_test
D1 = periodic_derivative_operator(1, 4, mesh.xmin, mesh.xmax, mesh.N)
solver = Solver(D1)

equations = KdVEquation1D(gravity = 1.0)
@test_throws ArgumentError Semidiscretization(mesh, equations, initial_condition,
solver)

equations = BBMEquation1D(gravity = 1.0)
@test_throws ArgumentError Semidiscretization(mesh, equations, initial_condition,
solver)

equations = BBMBBMEquations1D(gravity = 1.0)
@test_throws ArgumentError Semidiscretization(mesh, equations, initial_condition,
solver)

equations = SvaerdKalischEquations1D(gravity = 1.0)
@test_throws ArgumentError Semidiscretization(mesh, equations, initial_condition,
solver)
end

@testitem "Boundary conditions" setup=[Setup] begin
boundary_conditions = boundary_condition_periodic
@test_nowarn print(boundary_conditions)
Expand Down
Loading