Take the 2-minute tour ×
Physics Stack Exchange is a question and answer site for active researchers, academics and students of physics. It's 100% free, no registration required.

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.

1D simplification

Both pictures:

  • This is a 1D projection of the 3D problem.
  • The axis is infinite.
  • The blue line represents the 1D unit cell repeated by translation along the axis without overlapping.
  • The red dot represents the position of one unique and identified particle.
  • The green dots represents the equivalent particles to the red one obtained by translation. These are really equivalent to the red one: same nature, velocity, force field, etc.
  • As an input, I only have particle positions inside of the 1D unit cell (the blue line).

Top picture:

  • The red particle 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 red particle 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 green particle (on the right) is taken into account ;
    • $t=1$, the position of the red particle (on the left) is taken into account
    • and so on;
  • If the average $\bar{x}$ is calculated without much care, it is false since this average is done between two different particles (red arrow instead of black 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?

share|improve this question
    
Periodic (or even antiperiodic) boundary conditions do not spoil translation invariance! This means that if you start with a translation-invariant Hamiltonian (or Lagrangian) and if you impose p.b.c., then the system will stay invariant w.r.t. spatial translations. The density function of 'particle position' should be completely flat. As for your implementation, most programming languages have some 'modulo' function even for real number, IIRC. Then after a move, you just put (symbolically) 'position_i = modulo(position_i,sizeofbox)' and you're done. –  Vibert Feb 10 '13 at 11:19
    
The problem is the reverse: I have all the positions within the box already. Let me give a simple 1D example: the system is 10 units long. There is one particle at 9.5 units through the first steps, that particle shall go from 9.5 to 10.5 then from 10.5 to 9.5. What I already get, actually, as particle positions is: from 9.5 to 10 ; from 0 to 0.5 ; from 0.5 to 0; from 10 to 9.5. The average position of that particle should be 0 (or 10, I don't care) but if I don't pay attention, I'd get 5 units instead. I want to know if there is a smart way to get 0 units in such a case. –  Gael Feb 10 '13 at 11:28
    
OK, I see. I mean that you should NEVER have the particle at position 10.5 (or in general at position > 10). After you propose the move 9.5 -> 10.5, you should check that it has position < 10. Since this isn't true here, you substract 10 and place the particle at 0.5. However, the notion of 'average position' you're working with doesn't exist, since a periodic 1D system lives on a circle. If $x_1 = 0$ rad and $x_2 = \pi$ rad, what is their average: $\pi/2$ or $3\pi/2$? The answer you find depends on your conventions. –  Vibert Feb 10 '13 at 11:36
    
@Gael When you say the particle gets teleported to the opposite side, do you mean the opposite side of the same box, or forward of the next box? –  JKL Feb 10 '13 at 12:10
2  
To clarify my point: if you do things 'right' (such that all positions are in the interval $x \in [0,10[$, you'll eventually get an average of $x = 5$ units. But this number has no physical value: it reflects your choice of conventions. If you had chosen your box to lie, say, in the interval $[6,16[$, you'd have found an average of $\langle x \rangle = 11.$ –  Vibert Feb 10 '13 at 17:58
show 1 more comment

1 Answer 1

Just to be clear, it sounds like your system is a 3-torus, $$\mathbb{T}^3 = S^1\times S^1\times S^1$$

Position should then be modulo the length of the relevant dimension. The trick is an understanding that any particle can never be more than $\frac{L}{2}$ distance from the center point of the cube in any one direction (although total distance might be greater as calculated with Pythagorean Theorem, but this can never exceed $D = \sqrt{{(0.5L_x)}^2+{(0.5L_y)}^2+{(0.5L_z)}^2}$).

I would try something like this; define the position of the particles relative to the center of the cube and give the particle a sign flip each time it crosses a boundary. So if velocity is positive along a given axis, and the distance from the center reference goes above $\frac{L}{2}$ then multiply by $-1$. You should then be able to calculate and average position of particles relative to the center of the box.

I would also add that you would have to code so that the final instantaneous velocity when you reach a boundary becomes the initial velocity on the other side of the boundary, this would be dependent on how you are calculating velocities with your script.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.