Functions to maintain link cell structures for fast pair finding. More...
#include "linkCells.h"#include <stdio.h>#include <string.h>#include <assert.h>#include <math.h>#include "parallel.h"#include "memUtils.h"#include "decomposition.h"#include "performanceTimers.h"#include "CoMDTypes.h"
Go to the source code of this file.
Macros | |
| #define | MIN(A, B) ((A) < (B) ? (A) : (B)) |
| #define | MAX(A, B) ((A) > (B) ? (A) : (B)) |
Functions | |
| static void | copyAtom (LinkCell *boxes, Atoms *atoms, int iAtom, int iBox, int jAtom, int jBox) |
| Copy atom iAtom in link cell iBox to atom jAtom in link cell jBox. More... | |
| static int | getBoxFromCoord (LinkCell *boxes, real_t rr[3]) |
| Get the index of the link cell that contains the specified coordinate. More... | |
| static void | emptyHaloCells (LinkCell *boxes) |
| Set the number of atoms to zero in all halo link cells. More... | |
| static void | getTuple (LinkCell *boxes, int iBox, int *ixp, int *iyp, int *izp) |
| Get the grid coordinates of the link cell with index iBox. More... | |
| LinkCell * | initLinkCells (const Domain *domain, real_t cutoff) |
| In CoMD 1.1, atoms are stored in link cells. More... | |
| void | destroyLinkCells (LinkCell **boxes) |
| int | getNeighborBoxes (LinkCell *boxes, int iBox, int *nbrBoxes) |
| void | putAtomInBox (LinkCell *boxes, Atoms *atoms, const int gid, const int iType, const real_t x, const real_t y, const real_t z, const real_t px, const real_t py, const real_t pz) |
| int | getBoxFromTuple (LinkCell *boxes, int ix, int iy, int iz) |
| Calculates the link cell index from the grid coords. More... | |
| void | moveAtom (LinkCell *boxes, Atoms *atoms, int iId, int iBox, int jBox) |
| Move an atom from one link cell to another. More... | |
| void | updateLinkCells (LinkCell *boxes, Atoms *atoms) |
| Update link cell data structures when the atoms have moved. More... | |
| int | maxOccupancy (LinkCell *boxes) |
Functions to maintain link cell structures for fast pair finding.
Definition in file linkCells.c.
| #define MAX | ( | A, | |
| B | |||
| ) | ((A) > (B) ? (A) : (B)) |
Definition at line 18 of file linkCells.c.
| #define MIN | ( | A, | |
| B | |||
| ) | ((A) < (B) ? (A) : (B)) |
Definition at line 17 of file linkCells.c.
Copy atom iAtom in link cell iBox to atom jAtom in link cell jBox.
Any data at jAtom, jBox is overwritten. This routine can be used to re-order atoms within a link cell.
Definition at line 311 of file linkCells.c.

| void destroyLinkCells | ( | LinkCell ** | boxes | ) |
Definition at line 112 of file linkCells.c.


|
static |
Set the number of atoms to zero in all halo link cells.
Definition at line 368 of file linkCells.c.

Get the index of the link cell that contains the specified coordinate.
This can be either a halo or a local link cell.
Because the rank ownership of an atom is strictly determined by the atom's position, we need to take care that all ranks will agree which rank owns an atom. The conditionals at the end of this function are special care to ensure that all ranks make compatible link cell assignments for atoms that are near a link cell boundaries. If no ranks claim an atom in a local cell it will be lost. If multiple ranks claim an atom it will be duplicated.
Definition at line 333 of file linkCells.c.


| int getBoxFromTuple | ( | LinkCell * | boxes, |
| int | ix, | ||
| int | iy, | ||
| int | iz | ||
| ) |
Calculates the link cell index from the grid coords.
The valid coordinate range in direction ii is [-1, gridSize[ii]]. Any coordinate that involves a -1 or gridSize[ii] is a halo link cell. Because of the order in which the local and halo link cells are stored the indices of the halo cells are special cases.
Definition at line 189 of file linkCells.c.

| int getNeighborBoxes | ( | LinkCell * | boxes, |
| int | iBox, | ||
| int * | nbrBoxes | ||
| ) |
Populates the nbrBoxes array with the 27 boxes that are adjacent to iBox. The count is 27 instead of 26 because iBox is included in the list (as neighbor 13). Caller is responsible to alloc and free nbrBoxes.
Definition at line 130 of file linkCells.c.


|
static |
Get the grid coordinates of the link cell with index iBox.
Local cells are easy as they use a standard 1D->3D mapping. Halo cell are special cases.
| [in] | iBox | Index to link cell for which tuple is needed. |
| [out] | ixp | x grid coord of link cell. |
| [out] | iyp | y grid coord of link cell. |
| [out] | izp | z grid coord of link cell. |
Definition at line 382 of file linkCells.c.

In CoMD 1.1, atoms are stored in link cells.
Link cells are widely used in classical MD to avoid an O(N^2) search for atoms that interact. Link cells are formed by subdividing the local spatial domain with a Cartesian grid where the grid spacing in each direction is at least as big as he potential's cutoff distance. Because atoms don't interact beyond the potential cutoff, for an atom iAtom in any given link cell, we can be certain that all atoms that interact with iAtom are contained in the same link cell, or one of the 26 neighboring link cells.
CoMD chooses the link cell size (boxSize) on each axis to be the shortest possible distance, longer than cutoff, such that the local domain size divided by boxSize is an integer. I.e., the link cells are commensurate with with the local domain size. While this does not result in the smallest possible link cells, it does allow us to keep a strict separation between the link cells that are entirely inside the local domain and those that represent halo regions.
The number of local link cells in each direction is stored in gridSize. Local link cells have 3D grid coordinates (ix, iy, iz) where ix, iy, and iz can range from 0 to gridSize[iAxis]-1, whiere iAxis is 0 for x, 1 for y and 2 for the z direction. The number of local link cells is thus nLocalBoxes = gridSize[0]*gridSize[1]*gridSize[2].
The local link cells are surrounded by one complete shell of halo link cells. The halo cells provide temporary storage for halo or "ghost" atoms that belong to other tasks, but whose coordinates are needed locally to complete the force calculation. Halo link cells have at least one coordinate with a value of either -1 or gridSize[iAxis].
Because CoMD stores data in ordinary 1D C arrays, a mapping is needed from the 3D grid coords to a 1D array index. For the local cells we use the conventional mapping ix + iy*nx + iz*nx*ny. This keeps all of the local cells in a contiguous region of memory starting from the beginning of any relevant array and makes it easy to iterate the local cells in a single loop. Halo cells are mapped differently. After the local cells, the two planes of link cells that are face neighbors with local cells across the -x or +x axis are next. These are followed by face neighbors across the -y and +y axis (including cells that are y-face neighbors with an x-plane of halo cells), followed by all remaining cells in the -z and +z planes of halo cells. The total number of link cells (on each rank) is nTotalBoxes.
Data storage arrays that are used in association with link cells should be allocated to store nTotalBoxes*MAXATOMS items. Data for the first atom in linkCell iBox is stored at index iBox*MAXATOMS. Data for subsequent atoms in the same link cell are stored sequentially, and the number of atoms in link cell iBox is nAtoms[iBox].
| [in] | cutoff | The cutoff distance of the potential. |
Definition at line 82 of file linkCells.c.


| int maxOccupancy | ( | LinkCell * | boxes | ) |
Definition at line 293 of file linkCells.c.


Move an atom from one link cell to another.
| iId | [in] The index with box iBox of the atom to be moved. |
| iBox | [in] The index of the link cell the particle is moving from. |
| jBox | [in] The index of the link cell the particle is moving to. |
Definition at line 242 of file linkCells.c.


| void putAtomInBox | ( | LinkCell * | boxes, |
| Atoms * | atoms, | ||
| const int | gid, | ||
| const int | iType, | ||
| const real_t | x, | ||
| const real_t | y, | ||
| const real_t | z, | ||
| const real_t | px, | ||
| const real_t | py, | ||
| const real_t | pz | ||
| ) |
Finds the appropriate link cell for an atom based on the spatial coordinates and stores data in that link cell.
| [in] | gid | The global of the atom. |
| [in] | iType | The species index of the atom. |
| [in] | x | The x-coordinate of the atom. |
| [in] | y | The y-coordinate of the atom. |
| [in] | z | The z-coordinate of the atom. |
| [in] | px | The x-component of the atom's momentum. |
| [in] | py | The y-component of the atom's momentum. |
| [in] | pz | The z-component of the atom's momentum. |
Definition at line 155 of file linkCells.c.


Update link cell data structures when the atoms have moved.
This is the first step in returning data structures to a consistent state after the atoms move each time step. First we discard all atoms in the halo link cells. These are all atoms that are currently stored on other ranks and so any information we have about them is stale. Next, we move any atoms that have crossed link cell boundaries into their new link cells. It is likely that some atoms will be moved into halo link cells. Since we have deleted halo atoms from other tasks, it is clear that any atoms that are in halo cells at the end of this routine have just transitioned from local to halo atoms. Such atom must be sent to other tasks by a halo exchange to avoid being lost.
Definition at line 273 of file linkCells.c.

