I'm trying to build neighbor list in molecular dynamics 3D simulation which is particle based simulation and there is periodic boundary condition. Usual choice for performance is choosing constructing cell with width of 0.5*r_cut
where r_cut
is pair interaction cutoff.
However, with choice of the cell width, I cannot put integer number of cell. For example, if my r_cut
is 2.5
and the box length is 21
in a direction. I can only put 8 undeformed cells in it and there remains 1 deformed cell with the width of 1.0
.
When a particle is not around the periodic box boundary, I can obtain neighbor list of that particle by only checking 4 (2 in each positive and negative direction) in each dimension. But when the particle is around boundary, it's not sufficient to check 4 cells. There are three cases.
1) if the particle is in the cell which is at the boundary, then checking 4 (=2+2) cells is enough.
2) if the particle is in the cell which is the next to the cell which is at boundary, then I should check 5 cells, since because of deformed cell I should check one more cell. Checking only 2 cell in the direction cannot make neighbor farther than 0.5*r_cut+epsilon
at worst case where epsilon
is the width of deformed cell.
3) if the particle is in the cell which is the second next to the cell which is at boundary, I should also check 5 cells for the same reason as 2).
I know that this could be implemented through if-else
statement with 3 branches but I realize that it could be vulnerable to bug for the increased complexity. Is there smarter way of implementing this scheme?
Aucun commentaire:
Enregistrer un commentaire