Skip to content

Commit

Permalink
Fix BoundaryAdaptedGrid for only one central point (#281)
Browse files Browse the repository at this point in the history
* fix BoundaryAdaptedGrid for only one central point

* fix step for general intervals

* store Δx in BoundaryAdaptedGrid

* set version to v0.5.66

* add test

* fix test
  • Loading branch information
JoshuaLampert committed Jul 25, 2024
1 parent 560c6d8 commit 9dc6ca8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
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

2 comments on commit 9dc6ca8

@ranocha
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/111733

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.66 -m "<description of version>" 9dc6ca8977e25ba47433bb75e0416955b91940fe
git push origin v0.5.66

Please sign in to comment.