17 #define MIN(A,B) ((A) < (B) ? (A) : (B))
18 #define MAX(A,B) ((A) > (B) ? (A) : (B))
23 static void getTuple(
LinkCell* boxes,
int iBox,
int* ixp,
int* iyp,
int* izp);
87 for (
int i = 0; i < 3; i++)
115 if (! *boxes)
return;
133 getTuple(boxes, iBox, &ix, &iy, &iz);
136 for (
int i=ix-1; i<=ix+1; i++)
137 for (
int j=iy-1; j<=iy+1; j++)
138 for (
int k=iz-1; k<=iz+1; k++)
156 const int gid,
const int iType,
165 iOff += boxes->
nAtoms[iBox];
168 if (iBox < boxes->nLocalBoxes)
171 atoms->
gid[iOff] = gid;
174 atoms->
r[iOff][0] = x;
175 atoms->
r[iOff][1] = y;
176 atoms->
r[iOff][2] = z;
178 atoms->
p[iOff][0] = px;
179 atoms->
p[iOff][1] = py;
180 atoms->
p[iOff][2] = pz;
192 const int* gridSize = boxes->
gridSize;
195 if (iz == gridSize[2])
197 iBox = boxes->
nLocalBoxes + 2*gridSize[2]*gridSize[1] + 2*gridSize[2]*(gridSize[0]+2) +
198 (gridSize[0]+2)*(gridSize[1]+2) + (gridSize[0]+2)*(iy+1) + (ix+1);
203 iBox = boxes->
nLocalBoxes + 2*gridSize[2]*gridSize[1] + 2*gridSize[2]*(gridSize[0]+2) +
204 (gridSize[0]+2)*(iy+1) + (ix+1);
207 else if (iy == gridSize[1])
209 iBox = boxes->
nLocalBoxes + 2*gridSize[2]*gridSize[1] + gridSize[2]*(gridSize[0]+2) +
210 (gridSize[0]+2)*iz + (ix+1);
215 iBox = boxes->
nLocalBoxes + 2*gridSize[2]*gridSize[1] + iz*(gridSize[0]+2) + (ix+1);
218 else if (ix == gridSize[0])
220 iBox = boxes->
nLocalBoxes + gridSize[1]*gridSize[2] + iz*gridSize[1] + iy;
230 iBox = ix + gridSize[0]*iy + gridSize[0]*gridSize[1]*iz;
233 assert(iBox < boxes->nTotalBoxes);
244 int nj = boxes->
nAtoms[jBox];
245 copyAtom(boxes, atoms, iId, iBox, nj, jBox);
251 int ni = boxes->
nAtoms[iBox];
252 if (ni)
copyAtom(boxes, atoms, ni, iBox, iId, iBox);
281 while (ii < boxes->nAtoms[iBox])
285 moveAtom(boxes, atoms, ii, iBox, jBox);
297 localMax =
MAX(localMax, boxes->
nAtoms[ii]);
313 const int iOff =
MAXATOMS*iBox+iAtom;
314 const int jOff =
MAXATOMS*jBox+jAtom;
315 atoms->
gid[jOff] = atoms->
gid[iOff];
317 memcpy(atoms->
r[jOff], atoms->
r[iOff],
sizeof(
real3));
318 memcpy(atoms->
p[jOff], atoms->
p[iOff],
sizeof(
real3));
319 memcpy(atoms->
f[jOff], atoms->
f[iOff],
sizeof(
real3));
320 memcpy(atoms->
U+jOff, atoms->
U+iOff,
sizeof(
real_t));
337 const int* gridSize = boxes->
gridSize;
338 int ix = (int)(floor((rr[0] - localMin[0])*boxes->
invBoxSize[0]));
339 int iy = (int)(floor((rr[1] - localMin[1])*boxes->
invBoxSize[1]));
340 int iz = (int)(floor((rr[2] - localMin[2])*boxes->
invBoxSize[2]));
345 if (rr[0] < localMax[0])
347 if (ix == gridSize[0]) ix = gridSize[0] - 1;
351 if (rr[1] < localMax[1])
353 if (iy == gridSize[1]) iy = gridSize[1] - 1;
357 if (rr[2] < localMax[2])
359 if (iz == gridSize[2]) iz = gridSize[2] - 1;
370 for (
int ii=boxes->
nLocalBoxes; ii<boxes->nTotalBoxes; ++ii)
385 const int* gridSize = boxes->
gridSize;
388 if( iBox < boxes->nLocalBoxes)
390 ix = iBox % gridSize[0];
392 iy = iBox % gridSize[1];
393 iz = iBox / gridSize[1];
400 if (ink < 2*gridSize[1]*gridSize[2])
402 if (ink < gridSize[1]*gridSize[2])
408 ink -= gridSize[1]*gridSize[2];
409 ix = gridSize[0] + 1;
411 iy = 1 + ink % gridSize[1];
412 iz = 1 + ink / gridSize[1];
414 else if (ink < (2 * gridSize[2] * (gridSize[1] + gridSize[0] + 2)))
416 ink -= 2 * gridSize[2] * gridSize[1];
417 if (ink < ((gridSize[0] + 2) *gridSize[2]))
423 ink -= (gridSize[0] + 2) * gridSize[2];
424 iy = gridSize[1] + 1;
426 ix = ink % (gridSize[0] + 2);
427 iz = 1 + ink / (gridSize[0] + 2);
431 ink -= 2 * gridSize[2] * (gridSize[1] + gridSize[0] + 2);
432 if (ink < ((gridSize[0] + 2) * (gridSize[1] + 2)))
438 ink -= (gridSize[0] + 2) * (gridSize[1] + 2);
439 iz = gridSize[2] + 1;
441 ix = ink % (gridSize[0] + 2);
442 iy = ink / (gridSize[0] + 2);