Skip to content

Instantly share code, notes, and snippets.

@pjanik
Created October 26, 2012 14:28
Show Gist options
  • Save pjanik/3959142 to your computer and use it in GitHub Desktop.
Save pjanik/3959142 to your computer and use it in GitHub Desktop.
updateShortRangeForces = function () {
// Fast path if Lennard Jones interaction is disabled.
if (!useLennardJonesInteraction) return;
var rows = cellList.getRowsNum(),
cols = cellList.getColsNum(),
i, j, temp, cellIdx, cell1, cell2,
a, b, atom1Idx, cell1Len, cell2Len,
n, nLen, cellNeighbors;
for (i = 0; i < rows; i++) {
temp = i * cols;
for (j = 0; j < cols; j++) {
cellIdx = temp + j;
cell1 = cellList.getCell(cellIdx);
cellNeighbors = cellList.getNeighboringCells(i, j);
for (a = 0, cell1Len = cell1.length; a < cell1Len; a++) {
atom1Idx = cell1[a];
// Interactions inside the cell.
for (b = 0; b < a; b++) {
calculateLJInteraction(atom1Idx, cell1[b]);
}
// Interactions between neighboring cells.
for (n = 0, nLen = cellNeighbors.length; n < nLen; n++) {
cell2 = cellNeighbors[n];
for (b = 0, cell2Len = cell2.length; b < cell2Len; b++) {
calculateLJInteraction(atom1Idx, cell2[b]);
}
}
}
}
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment