Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/linkedcell.cpp

    r717e0c rcaf4ba  
    1 /** \file linkedcell.cpp
    2  *
    3  * Function implementations for the class LinkedCell.
    4  *
    5  */
    6 
    7 
    8 #include "atom.hpp"
    9 #include "helpers.hpp"
    101#include "linkedcell.hpp"
    11 #include "log.hpp"
    12 #include "molecule.hpp"
     2#include "molecules.hpp"
    133#include "tesselation.hpp"
    14 #include "vector.hpp"
    154
    165// ========================================================= class LinkedCell ===========================================
     
    3423 * \param RADIUS edge length of cells
    3524 */
    36 LinkedCell::LinkedCell(const PointCloud * const set, const double radius)
     25LinkedCell::LinkedCell(PointCloud *set, double radius)
    3726{
    3827  TesselPoint *Walker = NULL;
     
    4534  max.Zero();
    4635  min.Zero();
    47   Log() << Verbose(1) << "Begin of LinkedCell" << endl;
    48   if (set->IsEmpty()) {
    49     eLog() << Verbose(1) << "set contains no linked cell nodes!" << endl;
     36  cout << Verbose(1) << "Begin of LinkedCell" << endl;
     37  if ((set == NULL) || (set->IsEmpty())) {
     38    cerr << "ERROR: set is NULL or contains no linked cell nodes!" << endl;
    5039    return;
    5140  }
     
    5847  }
    5948  set->GoToFirst();
    60   while (!set->IsEnd()) {
     49  while (!set->IsLast()) {
    6150    Walker = set->GetPoint();
    6251    for (int i=0;i<NDIM;i++) {
     
    6857    set->GoToNext();
    6958  }
    70   Log() << Verbose(2) << "Bounding box is " << min << " and " << max << "." << endl;
     59  cout << Verbose(2) << "Bounding box is " << min << " and " << max << "." << endl;
    7160
    7261  // 2. find then number of cells per axis
     
    7463    N[i] = (int)floor((max.x[i] - min.x[i])/RADIUS)+1;
    7564  }
    76   Log() << Verbose(2) << "Number of cells per axis are " << N[0] << ", " << N[1] << " and " << N[2] << "." << endl;
     65  cout << Verbose(2) << "Number of cells per axis are " << N[0] << ", " << N[1] << " and " << N[2] << "." << endl;
    7766
    7867  // 3. allocate the lists
    79   Log() << Verbose(2) << "Allocating cells ... ";
     68  cout << Verbose(2) << "Allocating cells ... ";
    8069  if (LC != NULL) {
    81     eLog() << Verbose(1) << "Linked Cell list is already allocated, I do nothing." << endl;
     70    cout << Verbose(1) << "ERROR: Linked Cell list is already allocated, I do nothing." << endl;
    8271    return;
    8372  }
     
    8675    LC [index].clear();
    8776  }
    88   Log() << Verbose(0) << "done."  << endl;
     77  cout << "done."  << endl;
    8978
    9079  // 4. put each atom into its respective cell
    91   Log() << Verbose(2) << "Filling cells ... ";
     80  cout << Verbose(2) << "Filling cells ... ";
    9281  set->GoToFirst();
    93   while (!set->IsEnd()) {
     82  while (!set->IsLast()) {
    9483    Walker = set->GetPoint();
    9584    for (int i=0;i<NDIM;i++) {
     
    9887    index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2];
    9988    LC[index].push_back(Walker);
    100     //Log() << Verbose(2) << *Walker << " goes into cell " << n[0] << ", " << n[1] << ", " << n[2] << " with No. " << index << "." << endl;
     89    //cout << Verbose(2) << *Walker << " goes into cell " << n[0] << ", " << n[1] << ", " << n[2] << " with No. " << index << "." << endl;
    10190    set->GoToNext();
    10291  }
    103   Log() << Verbose(0) << "done."  << endl;
    104   Log() << Verbose(1) << "End of LinkedCell" << endl;
    105 };
    106 
    107 
    108 /** Puts all atoms in \a *mol into a linked cell list with cell's lengths of \a RADIUS
    109  * \param *set LCNodeSet class with all LCNode's
    110  * \param RADIUS edge length of cells
    111  */
    112 LinkedCell::LinkedCell(LinkedNodes *set, const double radius)
    113 {
    114   class TesselPoint *Walker = NULL;
    115   RADIUS = radius;
    116   LC = NULL;
    117   for(int i=0;i<NDIM;i++)
    118     N[i] = 0;
    119   index = -1;
    120   max.Zero();
    121   min.Zero();
    122   Log() << Verbose(1) << "Begin of LinkedCell" << endl;
    123   if (set->empty()) {
    124     eLog() << Verbose(1) << "set contains no linked cell nodes!" << endl;
    125     return;
    126   }
    127   // 1. find max and min per axis of atoms
    128   LinkedNodes::iterator Runner = set->begin();
    129   for (int i=0;i<NDIM;i++) {
    130     max.x[i] = (*Runner)->node->x[i];
    131     min.x[i] = (*Runner)->node->x[i];
    132   }
    133   for (LinkedNodes::iterator Runner = set->begin(); Runner != set->end(); Runner++) {
    134     Walker = *Runner;
    135     for (int i=0;i<NDIM;i++) {
    136       if (max.x[i] < Walker->node->x[i])
    137         max.x[i] = Walker->node->x[i];
    138       if (min.x[i] > Walker->node->x[i])
    139         min.x[i] = Walker->node->x[i];
    140     }
    141   }
    142   Log() << Verbose(2) << "Bounding box is " << min << " and " << max << "." << endl;
    143 
    144   // 2. find then number of cells per axis
    145   for (int i=0;i<NDIM;i++) {
    146     N[i] = (int)floor((max.x[i] - min.x[i])/RADIUS)+1;
    147   }
    148   Log() << Verbose(2) << "Number of cells per axis are " << N[0] << ", " << N[1] << " and " << N[2] << "." << endl;
    149 
    150   // 3. allocate the lists
    151   Log() << Verbose(2) << "Allocating cells ... ";
    152   if (LC != NULL) {
    153     eLog() << Verbose(1) << "Linked Cell list is already allocated, I do nothing." << endl;
    154     return;
    155   }
    156   LC = new LinkedNodes[N[0]*N[1]*N[2]];
    157   for (index=0;index<N[0]*N[1]*N[2];index++) {
    158     LC [index].clear();
    159   }
    160   Log() << Verbose(0) << "done."  << endl;
    161 
    162   // 4. put each atom into its respective cell
    163   Log() << Verbose(2) << "Filling cells ... ";
    164   for (LinkedNodes::iterator Runner = set->begin(); Runner != set->end(); Runner++) {
    165     Walker = *Runner;
    166     for (int i=0;i<NDIM;i++) {
    167       n[i] = (int)floor((Walker->node->x[i] - min.x[i])/RADIUS);
    168     }
    169     index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2];
    170     LC[index].push_back(Walker);
    171     //Log() << Verbose(2) << *Walker << " goes into cell " << n[0] << ", " << n[1] << ", " << n[2] << " with No. " << index << "." << endl;
    172   }
    173   Log() << Verbose(0) << "done."  << endl;
    174   Log() << Verbose(1) << "End of LinkedCell" << endl;
     92  cout << "done."  << endl;
     93  cout << Verbose(1) << "End of LinkedCell" << endl;
    17594};
    17695
     
    193112 * \return if all in intervals - true, else -false
    194113 */
    195 bool LinkedCell::CheckBounds() const
     114bool LinkedCell::CheckBounds()
    196115{
    197116  bool status = true;
     
    199118    status = status && ((n[i] >=0) && (n[i] < N[i]));
    200119  if (!status)
    201   eLog() << Verbose(1) << "indices are out of bounds!" << endl;
    202   return status;
    203 };
    204 
    205 /** Checks whether LinkedCell::n[] plus relative offset is each within [0,N[]].
    206  * Note that for this check we don't admonish if out of bounds.
    207  * \param relative[NDIM] relative offset to current cell
    208  * \return if all in intervals - true, else -false
    209  */
    210 bool LinkedCell::CheckBounds(const int relative[NDIM]) const
    211 {
    212   bool status = true;
    213   for(int i=0;i<NDIM;i++)
    214     status = status && ((n[i]+relative[i] >=0) && (n[i]+relative[i] < N[i]));
     120  cerr << "ERROR: indices are out of bounds!" << endl;
    215121  return status;
    216122};
     
    220126 * \return LinkedAtoms pointer to current cell, NULL if LinkedCell::n[] are out of bounds.
    221127 */
    222 const LinkedNodes* LinkedCell::GetCurrentCell() const
     128LinkedNodes* LinkedCell::GetCurrentCell()
    223129{
    224130  if (CheckBounds()) {
    225131    index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2];
    226     return (&(LC[index]));
    227   } else {
    228     return NULL;
    229   }
    230 };
    231 
    232 /** Returns a pointer to the current cell.
    233  * \param relative[NDIM] offset for each axis with respect to the current cell LinkedCell::n[NDIM]
    234  * \return LinkedAtoms pointer to current cell, NULL if LinkedCell::n[]+relative[] are out of bounds.
    235  */
    236 const LinkedNodes* LinkedCell::GetRelativeToCurrentCell(const int relative[NDIM]) const
    237 {
    238   if (CheckBounds(relative)) {
    239     index = (n[0]+relative[0]) * N[1] * N[2] + (n[1]+relative[1]) * N[2] + (n[2]+relative[2]);
    240132    return (&(LC[index]));
    241133  } else {
     
    248140 * \return if the atom is also found in this cell - true, else - false
    249141 */
    250 bool LinkedCell::SetIndexToNode(const TesselPoint * const Walker) const
     142bool LinkedCell::SetIndexToNode(TesselPoint *Walker)
    251143{
    252144  bool status = false;
     
    260152    return status;
    261153  } else {
    262     eLog() << Verbose(1) << "Node at " << *Walker << " is out of bounds." << endl;
     154    cerr << Verbose(1) << "ERROR: Node at " << *Walker << " is out of bounds." << endl;
    263155    return false;
    264   }
    265 };
    266 
    267 /** Calculates the interval bounds of the linked cell grid.
    268  * \param *lower lower bounds
    269  * \param *upper upper bounds
    270  */
    271 void LinkedCell::GetNeighbourBounds(int lower[NDIM], int upper[NDIM]) const
    272 {
    273   for (int i=0;i<NDIM;i++) {
    274     lower[i] = ((n[i]-1) >= 0) ? n[i]-1 : 0;
    275     upper[i] = ((n[i]+1) < N[i]) ? n[i]+1 : N[i]-1;
    276     //Log() << Verbose(0) << " [" << Nlower[i] << "," << Nupper[i] << "] ";
    277     // check for this axis whether the point is outside of our grid
    278     if (n[i] < 0)
    279       upper[i] = lower[i];
    280     if (n[i] > N[i])
    281       lower[i] = upper[i];
    282 
    283     //Log() << Verbose(0) << "axis " << i << " has bounds [" << lower[i] << "," << upper[i] << "]" << endl;
    284156  }
    285157};
     
    289161 * \return Vector is inside bounding box - true, else - false
    290162 */
    291 bool LinkedCell::SetIndexToVector(const Vector * const x) const
     163bool LinkedCell::SetIndexToVector(Vector *x)
    292164{
    293165  bool status = true;
Note: See TracChangeset for help on using the changeset viewer.