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

Fix BoundaryAdaptedGrid for only one central point #281

Merged
merged 6 commits into from
Jul 25, 2024
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SummationByPartsOperators"
uuid = "9f78cca6-572e-554e-b819-917d2f1cf240"
author = ["Hendrik Ranocha"]
version = "0.5.65"
version = "0.5.66"

[deps]
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
Expand Down
11 changes: 8 additions & 3 deletions src/SBP_coefficients/MattssonAlmquistVanDerWeide2018Minimal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct BoundaryAdaptedGrid{T,M,Grid} <: AbstractArray{T,1}
xmax::T
xstart::SVector{M,T}
uniform_grid::Grid
Δx::T
end

function BoundaryAdaptedGrid(xmin::T, xmax::T, _xstart::SVector{M,T}, N::Int) where {M,T}
Expand All @@ -35,8 +36,12 @@ function BoundaryAdaptedGrid(xmin::T, xmax::T, _xstart::SVector{M,T}, N::Int) wh

Δx = (xmax - xmin) / (2*_xstart[end] + N + 1 - 2M)
xstart = Δx .* _xstart
uniform_grid = range(xmin + xstart[end] + Δx, xmax - xstart[end] - Δx, length=N-2M)
BoundaryAdaptedGrid{T,M,typeof(uniform_grid)}(xmin, xmax, xstart, uniform_grid)
if N - 2M == 1 # This is to avoid an error if starting and end points are not the same due to rounding errors
uniform_grid = range(xmax - xstart[end] - Δx, xmax - xstart[end] - Δx, length=1)
else
uniform_grid = range(xmin + xstart[end] + Δx, xmax - xstart[end] - Δx, length=N-2M)
end
BoundaryAdaptedGrid{T,M,typeof(uniform_grid)}(xmin, xmax, xstart, uniform_grid, Δx)
end

function BoundaryAdaptedGrid(xmin, xmax, xstart, N)
Expand Down Expand Up @@ -67,7 +72,7 @@ function Base.getindex(grid::BoundaryAdaptedGrid, i::Int)
end

Base.size(grid::BoundaryAdaptedGrid) = (length(grid),)
Base.step(grid::BoundaryAdaptedGrid) = step(grid.uniform_grid)
Base.step(grid::BoundaryAdaptedGrid) = grid.Δx


function construct_grid(::MattssonAlmquistVanDerWeide2018Minimal, accuracy_order, xmin, xmax, N)
Expand Down
6 changes: 6 additions & 0 deletions test/SBP_operators_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1036,4 +1036,10 @@ end
xmin = -1.0, xmax = 1.0,
N = 20)
end

# https://github.com/ranocha/SummationByPartsOperators.jl/pull/281
@testset "PR #281" begin
D = @test_nowarn derivative_operator(MattssonAlmquistVanDerWeide2018Minimal(), 1, 4, 0.0, 1.0, 9)
@test all(isfinite.(Matrix(D)))
end
end
Loading