# Arrays with periodic boundaries

**URL:** <https://discourse.julialang.org/t/arrays-with-periodic-boundaries/4015>\
**Category:** New to Julia\
**Created:** [May 31, 2017, 1:56pm UTC](https://discourse.julialang.org/t/arrays-with-periodic-boundaries/4015 "2017-05-31T13:56:01Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [May 31, 2017, 6:10pm UTC](https://discourse.julialang.org/t/arrays-with-periodic-boundaries/4015/4 "2017-05-31T18:10:13Z")

</div>

> [@stefanocampanella](#):
>
> A problem which I encounter very often is dealing with arrays with periodic/cyclic boundaries (es. working on periodic lattices).

If you’re working with e.g. finite-difference approximations and similar lattice-based computations, often it is more flexible to use e.g. “ghost elements” (also called “ghost points”, “ghost cells”, “overlap regions”, “ghost zones”, …): you have an extra array element at each edge of the array that you update with whatever boundary condition you want as needed (e.g. at each time step). The motivation here is:

- For typical lattice-based simulations, you only need to access elements adjacent to the boundaries. You don’t want to pay the price of a specialized `getindex(a, i) = a.a[i % n]` method for _every_ array access just to be able to access one or two extra elements from each end.

- It is much more flexible. It becomes trivial to implement boundary conditions such as: periodic, Dirichlet, quasi/Bloch periodic (periodic × phase), mirror reflection or other symmetries, domain decomposition (boundary conditions that couple different arrays, e.g. on different processors), and so on.

(See e.g. the section on “overlap regions” in chapter 5 of _Principles of Parallel Programming_ by Lin and Snyder.)

---

_[View the full topic](https://discourse.julialang.org/t/arrays-with-periodic-boundaries/4015)._
