#include "linkedcell.hpp" #include "molecules.hpp" /** Constructor for class LinkedCell. */ LinkedCell::LinkedCell() { LC = NULL; for(int i=0;istart->next == mol->end) { cerr << "ERROR: molecule contains no atoms!" << endl; return; } // 1. find max and min per axis of atoms Walker = mol->start->next; for (int i=0;ix.x[i]; min.x[i] = Walker->x.x[i]; } while (Walker != mol->end) { for (int i=0;ix.x[i]) max.x[i] = Walker->x.x[i]; if (min.x[i] > Walker->x.x[i]) min.x[i] = Walker->x.x[i]; } Walker = Walker->next; } cout << Verbose(2) << "Bounding box is " << min << " and " << max << "." << endl; // 2. find then umber of cells per axis for (int i=0;istart; while (Walker->next != mol->end) { Walker = Walker->next; for (int i=0;ix.x[i] - min.x[i])/RADIUS); } index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2]; LC[index].push_back(Walker); cout << Verbose(2) << *Walker << " goes into cell " << n[0] << ", " << n[1] << ", " << n[2] << " with No. " << index << "." << endl; } cout << Verbose(1) << "End of LinkedCell" << endl; }; /** Destructor for class LinkedCell. */ LinkedCell::~LinkedCell() { if (LC != NULL) for (index=0;index=0) && (n[i] < N[i])); if (!status) cerr << "ERROR: indices are out of bounds!" << endl; return status; }; /** Returns a pointer to the current cell. * \return LinkedAtoms pointer to current cell, NULL if LinkedCell::n[] are out of bounds. */ LinkedAtoms* LinkedCell::GetCurrentCell() { if (CheckBounds()) { index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2]; return (&(LC[index])); } else { return NULL; } }; /** Calculates the index for a given atom *Walker. * \param *Walker atom to set index to * \return if the atom is also found in this cell - true, else - false */ bool LinkedCell::SetIndexToAtom(atom *Walker) { bool status = false; for (int i=0;ix.x[i] - min.x[i])/RADIUS); } index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2]; if (CheckBounds()) { for (LinkedAtoms::iterator Runner = LC[index].begin(); Runner != LC[index].end(); Runner++) status = status || ((*Runner) == Walker); return status; } else { cerr << Verbose(1) << "ERROR: Atom "<< *Walker << " at " << Walker->x << " is out of bounds." << endl; return false; } }; /** Calculates the index for a given Vector *x. * \param *x Vector with coordinates * \return Vector is inside bounding box - true, else - false */ bool LinkedCell::SetIndexToVector(Vector *x) { bool status = true; for (int i=0;ix[i] - min.x[i])/RADIUS); if (max.x[i] < x->x[i]) status = false; if (min.x[i] > x->x[i]) status = false; } return status; };