Beispiel #1
0
void moveAtom(simflat_t *s, int iId, int iBox, int jBox) {
  int nj,ni;
  nj = s->natoms[jBox];
  copyAtom(s,iId, iBox, nj, jBox);
  s->natoms[jBox]++;
  if(s->natoms[jBox]>= MAXATOMS) simulationAbort(-11,"Increase maxatoms");

  s->natoms[iBox]--;
  ni = s->natoms[iBox];
  if(ni) copyAtom(s,ni,iBox,iId,iBox);
  
  return;
}
Beispiel #2
0
// Copy selection
void Clipboard::copySelection(Model* m, bool quiet)
{
	Messenger::enter("Clipboard::copySelection");
	if (m->nSelected() == 0)
	{
		Messenger::print("Nothing selected to copy.");
		Messenger::exit("Clipboard::copySelection");
		return;
	}
	
	// Clear the clipboard first and make sure atom ids are valid
	clear();
	
	// Copy atoms
	if (!quiet) Messenger::print("Copying %i atoms from model '%s'...", m->nSelected(), qPrintable(m->name()));
	for (RefListItem<Atom,int>* ri = m->selection(); ri != NULL; ri = ri->next) copyAtom(ri->item);
	renumberAtoms();
	
	// Copy bonds
	if (!quiet) Messenger::print("bonds...");
	copyBonds();
	if (!quiet) Messenger::print(" Done.");
	
	Messenger::exit("Clipboard::copySelection");
}
/// Move an atom from one link cell to another.
/// \param iId [in]  The index with box iBox of the atom to be moved.
/// \param iBox [in] The index of the link cell the particle is moving from.
/// \param jBox [in] The index of the link cell the particle is moving to.
void moveAtom(LinkCell* boxes, Atoms* atoms, int iId, int iBox, int jBox)
{
   int nj = boxes->nAtoms[jBox];
   copyAtom(boxes, atoms, iId, iBox, nj, jBox);
   boxes->nAtoms[jBox]++;

   assert(boxes->nAtoms[jBox] < MAXATOMS);

   boxes->nAtoms[iBox]--;
   int ni = boxes->nAtoms[iBox];
   if (ni) copyAtom(boxes, atoms, ni, iBox, iId, iBox);

   if (jBox > boxes->nLocalBoxes)
      --atoms->nLocal;
   
   return;
}
Beispiel #4
0
// Copy model
void Clipboard::copyAll(Model* m, bool quiet)
{
	Messenger::enter("Clipboard::copyAll");
	
	// Clear the clipboard first and make sure atom ids are valid
	clear();
	
	// Copy atoms
	if (!quiet) Messenger::print("Copying all atoms from model '%s'...", qPrintable(m->name()));
	for (Atom* i = m->atoms(); i != NULL; i = i->next) copyAtom(i);
	renumberAtoms();
	if (!quiet) Messenger::print("bonds...");
	
	// Copy bonds
	copyBonds();
	if (!quiet) Messenger::print(" Done.");
	
	Messenger::exit("Clipboard::copyAll");
}
Beispiel #5
0
//This copies a cell from one box buffer to another and sorts it in the process.
void copySortedCell(LinkCell *sourceBoxes, LinkCell *destBoxes, Atoms *sourceAtoms, Atoms *destAtoms, int iBox)
{
    const int numAtoms = sourceBoxes->nAtoms[iBox];
    int highestGID, lowestGID;
    int atomOffset = MAXATOMS * iBox;
    highestGID = lowestGID = sourceAtoms->gid[atomOffset];
    for(int i = atomOffset; i < atomOffset + numAtoms; i++) {
        if(sourceAtoms->gid[i] < lowestGID) {
            lowestGID = sourceAtoms->gid[i];
        }
        if(sourceAtoms->gid[i] > highestGID) {
            highestGID = sourceAtoms->gid[i];
        }
    }

    int targetAtom = nextHighestAtom(sourceAtoms, atomOffset, numAtoms, highestGID, lowestGID - 1);
    for(int atomNum = 0; atomNum < numAtoms; atomNum++) {
        copyAtom(sourceAtoms, destAtoms, atomNum, iBox, targetAtom, iBox);
        targetAtom = nextHighestAtom(sourceAtoms, atomOffset, numAtoms, highestGID, sourceAtoms->gid[atomOffset + targetAtom]);
    }
    destBoxes->nAtoms[iBox] = sourceBoxes->nAtoms[iBox];
}
Beispiel #6
0
// Copy selection
void Clipboard::copyMarked(Model* m)
{
	Messenger::enter("Clipboard::copyMarked");
	if (m->nMarked() == 0)
	{
		Messenger::print("Nothing marked to copy.");
		Messenger::exit("Clipboard::copyMarked");
		return;
	}
	
	// Clear the clipboard first and make sure atom ids are valid
	clear();
	
	// Copy atoms
	for (RefListItem<Atom,int>* ri = m->selection(true); ri != NULL; ri = ri->next) copyAtom(ri->item);
	renumberAtoms();
	
	// Copy bonds
	copyBonds();
	
	Messenger::exit("Clipboard::copyMarked");
}
Beispiel #7
0
//The correctness of the task dependencies here depends on the assumption that there are no
//dependencies between this function and the function that last wrote the position
void updateLinkCells(LinkCell* boxes, LinkCell* boxesBuffer, Atoms* atoms, Atoms* atomsBuffer)
{
    real3  *atomF = atoms->f;
    real3  *atomR = atoms->r;
    real3  *atomP = atoms->p;
    real3  *atomsBufferR = atomsBuffer->r;

    int dep[9];
    for(int z=0; z < sim->boxes->gridSize[2]; z++) {
        for(int y=0; y < sim->boxes->gridSize[1]; y++) {
            int rowBox = z*sim->boxes->gridSize[1]*sim->boxes->gridSize[0]+y*sim->boxes->gridSize[0];
            getNeighborRows(boxes, y, z, dep);
#pragma omp task depend(out: atomsBufferR[rowBox*MAXATOMS]) \
                 depend( in: atomR[dep[0]*MAXATOMS], atomR[dep[1]*MAXATOMS], atomR[dep[2]*MAXATOMS], \
                             atomR[dep[3]*MAXATOMS], atomR[dep[4]*MAXATOMS], atomR[dep[5]*MAXATOMS], \
                             atomR[dep[6]*MAXATOMS], atomR[dep[7]*MAXATOMS], atomR[dep[8]*MAXATOMS] )
            {   //This task pulls all atoms that belong in cell iBox from multiple cells in the main buffer to cell iBox in the secondary buffer
                startTimer(redistributeTimer);
                for(int iBox=rowBox; iBox < rowBox + sim->boxes->gridSize[0]; iBox++) {
                    boxesBuffer->nAtoms[iBox] = 0;
                    int firstCopy = 0;
                    for(int i=0; i<27; i++) {
                        int neighborBox = boxes->nbrBoxes[iBox][i];
                        if(neighborBox != iBox || firstCopy == 0) {
                            if(neighborBox == iBox)
                                firstCopy = 1;
                            for(int atomNum = 0; atomNum < boxes->nAtoms[neighborBox]; atomNum++) {
                                real3 tempPosition;
                                for(int i=0; i<3; i++) {
                                    tempPosition[i] = atoms->r[neighborBox*MAXATOMS + atomNum][i];
                                    if(tempPosition[i] >= boxes->localMax[i]) {
                                        tempPosition[i] -= boxes->localMax[i];
                                    } else if(tempPosition[i] <= boxes->localMin[i]) {
                                        tempPosition[i] += boxes->localMax[i];
                                    }
                                }
                                if(iBox == getBoxFromCoord(boxes, tempPosition)) {
                                    copyAtom(atoms, atomsBuffer, atomNum, neighborBox, boxesBuffer->nAtoms[iBox], iBox);
                                    for(int i=0; i<3; i++) {
                                        atomsBuffer->r[iBox*MAXATOMS + boxesBuffer->nAtoms[iBox]][i] = tempPosition[i];
                                    }
                                    boxesBuffer->nAtoms[iBox]++;
                                }
                            }
                        }
                    }
                }
                stopTimer(redistributeTimer);
            }
        }
    }

    //This loop copies the cells from the buffer back to the main buffer while sorting them.
    for(int z=0; z < sim->boxes->gridSize[2]; z++) {
        for(int y=0; y < sim->boxes->gridSize[1]; y++) {
            int rowBox = z*sim->boxes->gridSize[1]*sim->boxes->gridSize[0]+y*sim->boxes->gridSize[0];
            int *nAtoms = &sim->boxes->nAtoms[rowBox];
#pragma omp task depend(in : atomsBufferR[rowBox*MAXATOMS]) \
                 depend(out: nAtoms, \
                             atomF[rowBox*MAXATOMS], atomR[rowBox*MAXATOMS],\
                             atomP[rowBox*MAXATOMS] )
            {
                startTimer(redistributeSortTimer);
                for(int iBox=rowBox; iBox < rowBox + sim->boxes->gridSize[0]; iBox++) {
                    copySortedCell(boxesBuffer, boxes, atomsBuffer, atoms, iBox);
                }
                stopTimer(redistributeSortTimer);
            }
        }
    }
}