Talk:Periodic boundary conditions

Untitled
Way too specific. periodic boundary conditions are way more general than the specific applications of molecular dynamics simulations. Most of the text is irrelevant. —Preceding unsigned comment added by 128.101.142.157 (talk) 19:18, 16 February 2008 (UTC)

implementation trick
For something like MD, when looping through each particle, conventional wisdom is that any "if" statement is slow. I don't know if this is still true on modern CPUs and with good compilers. But, if you want to avoid an "if" statement, then here's an old trick:

"if" statement version: (loop over particles) if (x < -xsize/2.0) x=x+xsize if (x >= xsize/2.0) x=x-xsize (end loop)

version without "if" statements: (loop over particles) BC = xsize * f( x / xSize ); x -= BC (end loop)

where f is a function defined such that f(x) = 1 if x > 1/2, f(x) = 0 if -1/2 < x < 1/2, and f(x) = -1 if x < -1/2 (with the assumption that the particle is never more than one box-length away).

Of course, if "f" is defined using an "if" statement, then there's no benefit, but if you have a clever implementation of f, using, e.g. bit-shifts, or a bit-mask, etc., then the code can see a real speed improvement. Lavaka (talk) 16:09, 23 October 2008 (UTC)

Assessment comment
Substituted at 02:39, 30 April 2016 (UTC)