Skip to content
This repository has been archived by the owner on Feb 9, 2020. It is now read-only.

Extrapolation not working for some BCs #31

Closed
tomasaschan opened this issue Jul 14, 2014 · 9 comments
Closed

Extrapolation not working for some BCs #31

tomasaschan opened this issue Jul 14, 2014 · 9 comments

Comments

@tomasaschan
Copy link
Collaborator

There are still some boundary conditions for which InterpCubic (from #19) isn't working correctly. See e.g. this comment on #29.

@tomasaschan
Copy link
Collaborator Author

Acutally, it appears that it's not only for cubic interpolation we have problems with some BCs:

using Grid

f(x) = sin(2pi * (x-1) / 10)
yirefl = InterpGrid(f(1:11),BCreflect,InterpLinear)
yiperi = InterpGrid(f(1:11),BCperiodic,InterpLinear)

df = vcat(
DataFrame(x=-9:.1:40,y=[yirefl[x]+2 for x in -9:.1:40],t="BCreflect"),
DataFrame(x=-9:.1:40,y=[yiperi[x]-1 for x in -9:.1:40],t="BCperiodic"),
)
plot(df,x=:x,y=:y,color=:t,Geom.path,Guide.colorkey("Boundary condition"))

grid

There's a weird shift in BCreflect, stemming from reflecting around the half-point outside the data set rather than around the edge, and similarly in BCperiodic. Also, neither seem to work at all for indices x<1, i.e. to the left of the given data set.

(If the final datapoint is left out from the BCperiodic case, i.e. f(1:10) instead of f(1:11), it looks good for large indices. Still bad for x<1 though.)

@tomasaschan tomasaschan changed the title Cubic interpolation not working for some BCs Extrapolation not working for some BCs Aug 29, 2014
@timholy
Copy link
Owner

timholy commented Aug 29, 2014

This definition of reflection is consistent with a reflection of a vector x begin defined as [x, x[end:-1:1]]. It's also the definition used by matlab in their image transformations.

The thing below 1 is just weird, gotta look into that.

@tomasaschan
Copy link
Collaborator Author

@timholy Yeah, I guess it makes a lot of sense for imaging applications, but it really doesn't for physics applications. For example, interpolating the electric field along a ray path, when the signal hits a reflecting surface could be done using BCreflect if the reflection point was the last node, rather than at the half-point outside. Maybe Interpolations.jl should have two reflecting boundary conditions, which do this differently (one nice for images and one nice for physics)?

@timholy
Copy link
Owner

timholy commented Aug 29, 2014

I'm not sure it's physics vs images. Who says the reflecting surface is positioned exactly at a node? Perhaps I might have set my grid points to be a half-node away from the edge.

But flexibility would be good. I'm not sure we want to support any choice in the interval [0,1], but certainly on-node and half-node seem reasonable.

@tomasaschan
Copy link
Collaborator Author

Yeah, I didn't like the naming either, but I had to distinguish between them somehow :P Supporting both seems like the target then. Hopefully, on-node reflection will be good enough for cases when the current behavior between the two near-edge nodes is unsatisfactory for some reason.

@timholy
Copy link
Owner

timholy commented Aug 29, 2014

Sounds good to me.

@cmundi
Copy link

cmundi commented Mar 17, 2015

Joining very late. In most applications of field theories (EM, QM, solid state, etc.) it is essential to be able to place the boundary at node or mid-node. There are even some edge (pun!) cases where quarter-intervals are numerically convenient. Having node and mid-node will cover most cases and help users write more transparently correct code.

@tomasaschan
Copy link
Collaborator Author

@cmundi: Both node and mid-node are supported in Interpolations.jl in terms of the GridBehavior type argument - if the boundaries should be on the outermost datapoint, use OnGrid, while if you want the boundary a half-interval outside the otuermost datapoint, use OnCell.

@cmundi
Copy link

cmundi commented Mar 18, 2015

Perfect! Thanks for your reply.
On Mar 17, 2015 9:48 AM, "Tomas Lycken" notifications@github.com wrote:

@cmundi https://github.com/cmundi: Both node and mid-node are supported
in Interpolations.jl in terms of the GridBehavior type argument - if the
boundaries should be on the outermost datapoint, use OnGrid, while if you
want the boundary a half-interval outside the otuermost datapoint, use
OnCell.


Reply to this email directly or view it on GitHub
#31 (comment).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants