-
Notifications
You must be signed in to change notification settings - Fork 113
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
More boundary conditions for quadratic B-splines #9
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
e3a54e7
Fix OnCell behavior for Quadratic{Flat}
eab1f6b
Visual tests + fixes
a592b30
First attempt at linear bc/extrap for B2
9a6e413
Scrap ExtendInner BC
901192b
Infrastructure for padding the equation system
fa8597d
Implement a few more BC:s + whitespace and test fixes
61aab26
Fix some issues after rebasing
60fe887
Free BC for Quadratic B-splines
3d732f8
Periodic BC/extrapolation
ca4028a
Export aux methods with info about interp type
cbede84
Notebook with visualizations of behavior
7797dde
Fix one (of several) problems with multidim interpol.
224621a
Fix broken size implementation (resolves #14)
1caf957
Fix broken multidimensional interpolation
ad9ac84
Rename LinearBC -> Line (with typealias Natural)
b62cb23
Simple 2D tests
1437812
Run select tests from Grid.jl
ebf038d
Cleanup
c94432d
Added 2D example to IJulia notebook
1fa3fe9
Disable Grid tests for now, since they're so brittle
e54edfb
Non-randomized tests for on-grid evaluation
7f71a69
Add boundary tests
f86ce88
Fix BoundsError in linear interpolation
99e05e3
Code cleanup in constant.jl
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# This assumes integral values ixm_d, ix_d, ixp_d, and ixpp_d (typically ixm_d = ix_d-1, ixp_d = ix_d+1, except at boundaries), | ||
# coefficients cm_d, c_d, cp_d, and cpp_d, and an array itp.coefs | ||
function index_gen(::Type{Cubic}, N::Integer, offsets...) | ||
if length(offsets) < N | ||
d = length(offsets)+1 | ||
symm, sym, symp, sympp = symbol(string("cm_",d)), symbol(string("c_",d)), symbol(string("cp_",d)), symbol(string("cpp_",d)) | ||
return :($symm * $(index_gen(Cubic, N, offsets...,-1)) + $sym * $(index_gen(Cubic, N, offsets..., 0)) + | ||
$symp * $(index_gen(Cubic, N, offsets..., 1)) + $sympp * $(index_gen(Cubic, N, offsets..., 2))) | ||
else | ||
indices = [offsetsym(offsets[d], d) for d = 1:N] | ||
return :(itp.coefs[$(indices...)]) | ||
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 |
---|---|---|
@@ -1,27 +1,119 @@ | ||
|
||
abstract ExtrapolationBehavior | ||
type ExtrapError <: ExtrapolationBehavior end | ||
|
||
type ExtrapError <: ExtrapolationBehavior end | ||
function extrap_gen(::OnGrid, ::ExtrapError, N) | ||
quote | ||
@nexprs $N d->(1 <= x_d <= size(itp,d) || throw(BoundsError())) | ||
end | ||
end | ||
extrap_gen(::OnCell, e::ExtrapError, N) = extrap_gen(OnGrid(), e, N) | ||
function extrap_gen(::OnCell, ::ExtrapError, N) | ||
quote | ||
@nexprs $N d->(.5 <= x_d <= size(itp,d) + .5 || throw(BoundsError())) | ||
end | ||
end | ||
|
||
type ExtrapNaN <: ExtrapolationBehavior end | ||
|
||
function extrap_gen(::OnGrid, ::ExtrapNaN, N) | ||
quote | ||
@nexprs $N d->(1 <= x_d <= size(itp,d) || return convert(T, NaN)) | ||
end | ||
end | ||
extrap_gen(::OnCell, e::ExtrapNaN, N) = extrap_gen(OnGrid(), e, N) | ||
function extrap_gen(::OnCell, ::ExtrapNaN, N) | ||
quote | ||
@nexprs $N d->(.5 <= x_d <= size(itp,d) + .5 || return convert(T, NaN)) | ||
end | ||
end | ||
|
||
type ExtrapConstant <: ExtrapolationBehavior end | ||
function extrap_gen(::OnGrid, ::ExtrapConstant, N) | ||
quote | ||
@nexprs $N d->(x_d = clamp(x_d, 1, size(itp,d))) | ||
end | ||
end | ||
extrap_gen(::OnCell, e::ExtrapConstant, N) = extrap_gen(OnGrid(), e, N) | ||
function extrap_gen(::OnCell, ::ExtrapConstant, N) | ||
quote | ||
@nexprs $N d->(x_d = clamp(x_d, .5, size(itp,d)+.5)) | ||
end | ||
end | ||
|
||
type ExtrapReflect <: ExtrapolationBehavior end | ||
function extrap_gen(::OnGrid, ::ExtrapReflect, N) | ||
quote | ||
@nexprs $N d->begin | ||
# translate x_d to inside the domain, and count the translations | ||
ntransl = 0 | ||
while x_d < 1 | ||
x_d += size(itp, d) - 1 | ||
ntransl += 1 | ||
end | ||
while x_d > size(itp, d) | ||
x_d -= size(itp, d) - 1 | ||
ntransl += 1 | ||
end | ||
|
||
# if odd number of translations, also reflect inside the domain | ||
if ntransl > 0 && mod(ntransl, 2) != 0 | ||
x_d = size(itp, d) + 1 - x_d | ||
end | ||
end | ||
end | ||
end | ||
function extrap_gen(::OnCell, ::ExtrapReflect, N) | ||
quote | ||
@nexprs $N d->begin | ||
# translate x_d to inside the domain, and count the translations | ||
ntransl = 0 | ||
while x_d < .5 | ||
x_d += size(itp,d) | ||
ntransl += 1 | ||
end | ||
while x_d > size(itp,d) + .5 | ||
x_d -= size(itp,d) | ||
ntransl += 1 | ||
end | ||
|
||
# if odd number of translations, also reflect inside the domain | ||
if ntransl > 0 && mod(ntransl, 2) != 0 | ||
x_d = size(itp, d) + 1 - x_d | ||
end | ||
end | ||
end | ||
end | ||
|
||
type ExtrapPeriodic <: ExtrapolationBehavior end | ||
function extrap_gen(::GridRepresentation, ::ExtrapPeriodic, N) | ||
quote | ||
@nexprs $N d->begin | ||
# translate x_d to inside the domain | ||
n = convert(typeof(x_d), size(itp,d)) | ||
while x_d < .5 | ||
x_d += n | ||
end | ||
while x_d >= n + .5 | ||
x_d -= n | ||
end | ||
end | ||
end | ||
end | ||
|
||
type ExtrapLinear <: ExtrapolationBehavior end | ||
function extrap_gen(::OnGrid, ::ExtrapLinear, N) | ||
quote | ||
@nexprs $N d->begin | ||
if x_d < 1 | ||
fx_d = x_d - convert(typeof(x_d), 1) | ||
|
||
k = -4*itp.coefs[1] | ||
return itp[1] - k * fx_d | ||
end | ||
if x_d > size(itp, d) | ||
s_d = size(itp,d) | ||
fx_d = x_d - convert(typeof(x_d), s_d) | ||
|
||
k = itp[s_d] - itp[s_d - 1] | ||
return itp[s_d] + k * fx_d | ||
end | ||
end | ||
end | ||
end | ||
extrap_gen(::OnCell, e::ExtrapLinear, N) = extrap_gen(OnGrid(), e, N) |
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
Oops, something went wrong.
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.
I suspect you can just use
mapslices
to write this.FYI in julia 0.4
@ngenerate
is not needed nearly as much for looping anymore thanks toeachindex
and the raw elements it's built on (IndexIterator
andCartesianIndex
). For example, you can writeand
I
will iterate over your slices.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.
That sounds awesome - I'll have to take a look at that!
Given
@staged function
(or whatever the syntax ended up being) in 0.4, I have intended to re-work these bits to eventually remove the dependency on Base.Cartesian, too, but first I want to get this working (so I have some reference to compare against when re-building it).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.
(Another main reason I don't want to do this yet is that I tried 0.4-dev for a while, but the chaos was a little too much for me, so I decided to wait for 0.4-pre before I started porting things...)