Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/linkedcell.cpp

    r1999d8 rf66195  
    66
    77
     8#include "atom.hpp"
     9#include "helpers.hpp"
    810#include "linkedcell.hpp"
    9 #include "molecules.hpp"
     11#include "molecule.hpp"
    1012#include "tesselation.hpp"
     13#include "vector.hpp"
    1114
    1215// ========================================================= class LinkedCell ===========================================
     
    9699    //cout << Verbose(2) << *Walker << " goes into cell " << n[0] << ", " << n[1] << ", " << n[2] << " with No. " << index << "." << endl;
    97100    set->GoToNext();
     101  }
     102  cout << "done."  << endl;
     103  cout << Verbose(1) << "End of LinkedCell" << endl;
     104};
     105
     106
     107/** Puts all atoms in \a *mol into a linked cell list with cell's lengths of \a RADIUS
     108 * \param *set LCNodeSet class with all LCNode's
     109 * \param RADIUS edge length of cells
     110 */
     111LinkedCell::LinkedCell(LinkedNodes *set, double radius)
     112{
     113  class TesselPoint *Walker = NULL;
     114  RADIUS = radius;
     115  LC = NULL;
     116  for(int i=0;i<NDIM;i++)
     117    N[i] = 0;
     118  index = -1;
     119  max.Zero();
     120  min.Zero();
     121  cout << Verbose(1) << "Begin of LinkedCell" << endl;
     122  if (set->empty()) {
     123    cerr << "ERROR: set contains no linked cell nodes!" << endl;
     124    return;
     125  }
     126  // 1. find max and min per axis of atoms
     127  LinkedNodes::iterator Runner = set->begin();
     128  for (int i=0;i<NDIM;i++) {
     129    max.x[i] = (*Runner)->node->x[i];
     130    min.x[i] = (*Runner)->node->x[i];
     131  }
     132  for (LinkedNodes::iterator Runner = set->begin(); Runner != set->end(); Runner++) {
     133    Walker = *Runner;
     134    for (int i=0;i<NDIM;i++) {
     135      if (max.x[i] < Walker->node->x[i])
     136        max.x[i] = Walker->node->x[i];
     137      if (min.x[i] > Walker->node->x[i])
     138        min.x[i] = Walker->node->x[i];
     139    }
     140  }
     141  cout << Verbose(2) << "Bounding box is " << min << " and " << max << "." << endl;
     142
     143  // 2. find then number of cells per axis
     144  for (int i=0;i<NDIM;i++) {
     145    N[i] = (int)floor((max.x[i] - min.x[i])/RADIUS)+1;
     146  }
     147  cout << Verbose(2) << "Number of cells per axis are " << N[0] << ", " << N[1] << " and " << N[2] << "." << endl;
     148
     149  // 3. allocate the lists
     150  cout << Verbose(2) << "Allocating cells ... ";
     151  if (LC != NULL) {
     152    cout << Verbose(1) << "ERROR: Linked Cell list is already allocated, I do nothing." << endl;
     153    return;
     154  }
     155  LC = new LinkedNodes[N[0]*N[1]*N[2]];
     156  for (index=0;index<N[0]*N[1]*N[2];index++) {
     157    LC [index].clear();
     158  }
     159  cout << "done."  << endl;
     160
     161  // 4. put each atom into its respective cell
     162  cout << Verbose(2) << "Filling cells ... ";
     163  for (LinkedNodes::iterator Runner = set->begin(); Runner != set->end(); Runner++) {
     164    Walker = *Runner;
     165    for (int i=0;i<NDIM;i++) {
     166      n[i] = (int)floor((Walker->node->x[i] - min.x[i])/RADIUS);
     167    }
     168    index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2];
     169    LC[index].push_back(Walker);
     170    //cout << Verbose(2) << *Walker << " goes into cell " << n[0] << ", " << n[1] << ", " << n[2] << " with No. " << index << "." << endl;
    98171  }
    99172  cout << "done."  << endl;
Note: See TracChangeset for help on using the changeset viewer.