-
Notifications
You must be signed in to change notification settings - Fork 109
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
Periodic boundary conditions for Linear and Constant #428
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0fbe454
Implement periodic Linear and Constant. Now they are subtypes of Degr…
jaemolihm fbe4a14
Clean up some comments
jaemolihm b144faa
Add convenience constructors Constant(Periodic()) and Linear(Periodic())
jaemolihm 9217b4a
Add tests for constant and linear periodic interpolation.
jaemolihm 4c963af
Add test on periodic extrapolation
jaemolihm 0c64520
Docs for periodic extrapolation
jaemolihm 12aa51c
Remove Throw(OnGrid()) in the printing of Linear and Constant
jaemolihm d60a53d
Update tests
jaemolihm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -61,4 +61,39 @@ | |||||||||
etp = extrapolate(itp, Flat()) | ||||||||||
@test sum(isnan.(etp)) == 0 | ||||||||||
end | ||||||||||
|
||||||||||
@testset "Linear periodic" begin | ||||||||||
# Constructors | ||||||||||
@test Linear() === Linear(Throw(OnGrid())) | ||||||||||
@test Linear() isa Linear{Throw{OnGrid}} | ||||||||||
@test Linear(Periodic()) === Linear(Periodic(OnCell())) | ||||||||||
@test Linear(Periodic()) isa Linear{Periodic{OnCell}} | ||||||||||
|
||||||||||
Comment on lines
+70
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we need
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed |
||||||||||
xmax = 10 | ||||||||||
f2(x) = sin((x-3)*2pi/xmax - 1) # Periodicity is xmax, not xmax-1 | ||||||||||
A1 = Float64[f2(x) for x in 1:xmax] | ||||||||||
|
||||||||||
for (constructor, copier) in ((interpolate, identity), (interpolate!, copy)) | ||||||||||
isinplace = constructor == interpolate! | ||||||||||
itp = @inferred(constructor(copier(A1), BSpline(Linear()))) | ||||||||||
itp_periodic = @inferred(constructor(copier(A1), BSpline(Linear(Periodic())))) | ||||||||||
|
||||||||||
@test all(Interpolations.lbounds(itp_periodic) .≈ (0.5,)) | ||||||||||
@test all(Interpolations.ubounds(itp_periodic) .≈ (10.5,)) | ||||||||||
|
||||||||||
for x in 1:.2:xmax | ||||||||||
@test itp(x) ≈ itp_periodic(x) | ||||||||||
end | ||||||||||
|
||||||||||
# Interpolation range for periodic should be [0.5, xmax + 0.5] | ||||||||||
for x in 0.5:.1:0.9 | ||||||||||
@test f2(x) ≈ itp_periodic(x) atol=abs(0.1 * f2(x)) | ||||||||||
@test_throws BoundsError itp(x) | ||||||||||
end | ||||||||||
for x in xmax+0.1:.1:xmax+0.5 | ||||||||||
@test f2(x) ≈ itp_periodic(x) atol=abs(0.1 * f2(x)) | ||||||||||
@test_throws BoundsError itp(x) | ||||||||||
end | ||||||||||
end | ||||||||||
end | ||||||||||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
@testset "Periodic extrapolation" begin | ||
xmax = 7 | ||
f(x) = sin((x-3)*2pi/xmax - 1) | ||
A = Float64[f(x) for x in 1:xmax] # Does not include the periodic image | ||
|
||
itp0 = interpolate(A, BSpline(Constant(Periodic()))) | ||
itp1 = interpolate(A, BSpline(Linear(Periodic()))) | ||
itp2 = interpolate(A, BSpline(Quadratic(Periodic(OnCell())))) | ||
itp3 = interpolate(A, BSpline(Cubic(Periodic(OnCell())))) | ||
|
||
etp0 = extrapolate(itp0, Periodic()) | ||
etp1 = extrapolate(itp1, Periodic()) | ||
etp2 = extrapolate(itp2, Periodic()) | ||
etp3 = extrapolate(itp3, Periodic()) | ||
|
||
for x in -xmax:.4:2*xmax | ||
@test etp0(x) ≈ f(x) atol=0.5 | ||
@test etp1(x) ≈ f(x) atol=0.1 | ||
@test etp2(x) ≈ f(x) atol=0.01 | ||
@test etp3(x) ≈ f(x) atol=0.003 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,4 +107,5 @@ using Test | |
|
||
include("type-stability.jl") | ||
include("non1.jl") | ||
include("periodic.jl") | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
bc
stateful here? Or could we always useBC()
to construct it at runtime?It seems that it is sufficient to just
Ask this because previously
typeof(deg)()
works for Interpolations < v0.13.3.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interpolations.jl/src/b-splines/b-splines.jl
Line 142 in a8370bd
I am not sure I understand the question, but I think since the above line uses
deg.bc
, sobc
should be a field.