Accessing array element: splatting VS explicit writing them out

A much more flexible method to implement periodic boundary conditions (which I guess is what you are doing) is to use “ghost cells”. See e.g. Finite difference Laplacian with five-point stencil - #2 by stevengj

This is allocating a new array on every loop iteration, which will be slow. I second the suggestion to use CartesianIndices here — that’s what they are for. (You could also use StaticArrays.jl). See Base.Cartesian · The Julia Language

2 Likes