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

Boundary conditions for dispersal #75

Open
virgile-baudrot opened this issue Nov 4, 2020 · 4 comments
Open

Boundary conditions for dispersal #75

virgile-baudrot opened this issue Nov 4, 2020 · 4 comments

Comments

@virgile-baudrot
Copy link
Collaborator

virgile-baudrot commented Nov 4, 2020

I wondered if I put this issue "idea" here or under Dispersal.jl, but since you're going to move kernel there #73... should be the right place.

So, if I'm right, you implemented 2 ways of handling boundary conditions: either Absorbing with RemoveOverflow and 'periodic' with WrapOverflow.

I was first thinking about a 'Reflecting' when 'individuals that arrive at the boundaries are reflected back into the simulation are' since it's common in PDE, but it seems very hard to handle in discrete kernel.

But a 'Restricting' where individuals are kept within the arena is probably easier: the idea is to change the normalization coefficient to take into account only cells within the arena. And actually, I find this one much more relevant in daily animal movement.
'Reflecting' could make sens in a long term period, but it would be much easier to handle by simply repeating 'Restricting' boundary conditions. And 'Absorbing', the RemoveOverflow as it is now, is probably the best for propagules.

The supplementary material of this paper may help to understand what I mean On the approximation of continuous dispersal kernels in discrete‐space models,

Here I am.
I don't think it should be a third method of Overflow or even an option of RemoveOverflow.
I feel like we could handle this diretly with what you called subsampling in dispersalprob function of Dispersal.jl, which deal with probability normalization.

@rafaqz
Copy link
Member

rafaqz commented Nov 4, 2020

Yep there are 2 ways currently. A lot of our simulations have sea or cold temperature boundaries, so the overflow doesn't even come into affect! So I haven't thought about this much. But shouldn't be too hard to do reflecting - basically there are 3 places overflow matters:

  1. When NeighborhoodRules read the padded edge section of the grid, which is zeros in RemoveOverflow and a strip from the other side of the grid in WrapOverflow
  2. When ManualNeighborhoodRules write out into the padding strip (but we don't use these much as they are slow with the current methods).
  3. When ManualRule writes randomly somewhere past the grid edge. In RemoveOverflow inbounds returns the index tuple and false, in WrapOverflow inbounds returns the wrapped index and true.

CellRule doesn't touch other cells, so isn't relevant.

To add a new Overflow mode, you just need to handle those three situations. We can reflect the ManualRule writes pretty easily with an inbounds method for ReflectOverflow. Reflecting the grid padding would also be easy, it would just be a variant on what happens here for WrapOverflow https://github.com/cesaraustralia/DynamicGrids.jl/blob/master/src/overflow.jl#L53

To handle the padding, you just have to copy the 4 strips R wide, and 4 corner squares of R*R - copied from wherever they should come from according to the Overflow method.

But also realize that the convolution style inwards dispersal kernels we mostly use for dispersal don't run in the edge padding at all - so nothing is being sent out there! The issue is what is being copied inwards when they overhang into the padding.

Also all these things probably have bad names, if you have better names we can think of a better scheme. It's really the hardest part of writing this.

Edit: also here is definitely the place, the kernel method is actually moving here from Disperal.jl. My idea is that everything structural and technical is here, and Dispersal.jl is purely a library of formulation that run within the constraints set up by DynamicGrids.jl

The problem with dealing with boundary conditions in Dispersal.jl is rules have to check if they are at the edge all the time and it's very slow, and makes code a lot more complicated. The padding layer is to avoid that complexity and cost.

@virgile-baudrot
Copy link
Collaborator Author

Great. Thank you.
I'm going to work on https://github.com/cesaraustralia/DynamicGrids.jl/blob/master/src/overflow.jl#L53 to try Reflecting the grid padding.

@rafaqz
Copy link
Member

rafaqz commented Nov 8, 2020

Also maybe look here:

https://juliaimages.org/ImageFiltering.jl/stable/function_reference/#Boundaries-and-padding-1

Maybe we should even use their padding function.

@virgile-baudrot
Copy link
Collaborator Author

Seems great indeed.

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

No branches or pull requests

2 participants