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
3 changes: 3 additions & 0 deletions src/discretization/schemes/extrapolation_weights.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ function BoundaryInterpolatorExtrapolator(
boundary_stencil_length = approximation_order
boundary_point_count = endpoint = div(stencil_length, 2)
len = length(x)
if len < boundary_stencil_length + 1
throw(ArgumentError("grid has $len points, but the boundary extrapolation stencil needs at least $(boundary_stencil_length + 1). Provide a finer grid for this variable."))
end
dx = [x[i + 1] - x[i] for i in 1:(length(x) - 1)]
interior_x = (endpoint + 1):(len - endpoint)
low_boundary_x = [zero(T); cumsum(dx[1:(boundary_stencil_length - 1)])]
Expand Down
15 changes: 15 additions & 0 deletions test/Convection_NU/MOL_1D_Linear_Convection_NonUniform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,21 @@ end
end
end

@testset "Coarse grid error" begin
L = 1.0
v = 1.0
tspan = (0.0, 0.25)
u0 = x -> sin(2π * x / L)
u_exact = (x, t) -> translating_sine_exact(x, t, v, L)

# A grid this coarse cannot fit the boundary extrapolation stencil. It used
# to fail with an opaque BoundsError; now it reports an ArgumentError.
xgrid = [0.0, 0.1, 0.3, 0.6, 0.8, 1.0]
@test_throws ArgumentError solve_mms_advection(;
xgrid, v, tspan, u0, u_exact,
)
end

@testset "Periodic boundary conditions" begin
L = 1.0
v = 1.0
Expand Down
Loading