Imagine an open box repeating itself in a way that a if a particle crossing one of the box boundary is "teleported" on the opposite boundary (typical periodic boundary position in 3D).
Now put a hundred of oscillating particles inside. Each particle position is identified in a uniq fashion through time.
I want to get the average position of each of these particles.
EDIT:
Thanks for your input. But I think I did not explain myself correctly. Please forgive me for that. That's why I removed most of my wordy description and created the following picture as a 1D reduction of my problem instead.

Both pictures:
- This is a 1D projection of the 3D problem.
- The axis is infinite.
- The
blueline represents the 1D unit cell repeated by translation along the axis without overlapping. - The
reddot represents the position of one unique and identified particle. - The
greendots represents the equivalent particles to theredone obtained by translation. These are really equivalent to theredone: same nature, velocity, force field, etc. - As an input, I only have particle positions inside of the 1D unit cell (the
blueline).
Top picture:
- The
redparticle is present in the unit cell for each time step. - I take the particle position $x(t)$ and average it over $t$ to get $\bar{x} = \frac{1}{4}$ of the unit cell in this case (
black arrow).
Bottom picture:
- The
redparticle is crossing the boundary of the unit cell. - However, $x(t)$ is only defined in the unit cell, therefore in this case at:
- $t=0$, the position of the
greenparticle (on the right) is taken into account ; - $t=1$, the position of the
redparticle (on the left) is taken into account - and so on;
- $t=0$, the position of the
- If the average $\bar{x}$ is calculated without much care, it is false since this average is done between two different particles (
red arrowinstead ofblack arrow).
I developed a small algorithm that tries to correct this assuming that $x(t+\Delta t) - x(t) < \frac{\Delta x}{2}$, with $\Delta x$, the size of the unit cell.
However this algorithm is quite slow. I know I can improve the algorithm itself and my implementation of it. But I also know that this is a trivial (and inefficient) way to do it. I also hate to reinvent the wheel again and again...
Do you know any smart implementation or algorithm able to calculate this kind of "periodic" average?