Ignore:
Timestamp:
Apr 9, 2010, 9:55:39 AM (16 years ago)
Author:
heber <heber@…>
Children:
bd8561
Parents:
6250e5
Message:

LinkedNodes is now declared inside LinkedCell and some new functions.

  • as prepraratory measure we placed LinkedNodes as typedef into LinkedCell class. This caused same namespace changes elsewhere where LinkedNodes is used.
  • new function GetallNeighbours() which performs going through linked cells.
  • new function GetPointsInsideaSphere() which performs going through linked cells and returns all neighbours up to a given distance to a given center.

Note: New functions are not yet used elsewhere. Unit test has to be written beforehand.

Signed-off-by: heber <heber@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/linkedcell.cpp

    r6250e5 r6dd8d3  
    220220 * \return LinkedAtoms pointer to current cell, NULL if LinkedCell::n[] are out of bounds.
    221221 */
    222 const LinkedNodes* LinkedCell::GetCurrentCell() const
     222const LinkedCell::LinkedNodes* LinkedCell::GetCurrentCell() const
    223223{
    224224  if (CheckBounds()) {
     
    234234 * \return LinkedAtoms pointer to current cell, NULL if LinkedCell::n[]+relative[] are out of bounds.
    235235 */
    236 const LinkedNodes* LinkedCell::GetRelativeToCurrentCell(const int relative[NDIM]) const
     236const LinkedCell::LinkedNodes* LinkedCell::GetRelativeToCurrentCell(const int relative[NDIM]) const
    237237{
    238238  if (CheckBounds(relative)) {
     
    302302};
    303303
     304/** Returns a list with all neighbours from the current LinkedCell::index.
     305 * \param distance (if no distance, then adjacent cells are taken)
     306 * \return list of tesselpoints
     307 */
     308LinkedCell::LinkedNodes* LinkedCell::GetallNeighbours(const double distance = 0) const
     309{
     310  int N[NDIM], Nlower[NDIM], Nupper[NDIM];
     311  TesselPoint *Walker = NULL;
     312  LinkedNodes *TesselList = new LinkedNodes;
     313
     314  // then go through the current and all neighbouring cells and check the contained points for possible candidates
     315  //Log() << Verbose(1) << "LC Intervals:";
     316  const int step = (distance == 0) ? 1 : (int)floor(distance/RADIUS)+1;
     317  for (int i=0;i<NDIM;i++) {
     318    Nlower[i] = ((N[i]-step) >= 0) ? N[i]-step : 0;
     319    Nupper[i] = ((N[i]+step) < N[i]) ? N[i]+step : N[i]-step;
     320    //Log() << Verbose(0) << " [" << Nlower[i] << "," << Nupper[i] << "] ";
     321  }
     322  //Log() << Verbose(0) << endl;
     323  for (n[0] = Nlower[0]; n[0] <= Nupper[0]; n[0]++)
     324    for (n[1] = Nlower[1]; n[1] <= Nupper[1]; n[1]++)
     325      for (n[2] = Nlower[2]; n[2] <= Nupper[2]; n[2]++) {
     326        const LinkedNodes *List = GetCurrentCell();
     327        //Log() << Verbose(1) << "Current cell is " << n[0] << ", " << n[1] << ", " << n[2] << " with No. " << index << "." << endl;
     328        if (List != NULL) {
     329          for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     330            Walker = *Runner;
     331            TesselList->push_back(Walker);
     332          }
     333        }
     334      }
     335  return TesselList;
     336};
     337
     338
     339/** Returns a list of all TesselPoint with distance less than \a radius to \a *Center.
     340 * \param radius radius of sphere
     341 * \param *center center of sphere
     342 * \return list of all points inside sphere
     343 */
     344LinkedCell::LinkedNodes* LinkedCell::GetPointsInsideSphere(const double radius, const Vector * const center) const
     345{
     346  int N[NDIM], Nlower[NDIM], Nupper[NDIM];
     347  const double radiusSquared = radius*radius;
     348  TesselPoint *Walker = NULL;
     349  LinkedNodes *TesselList = new LinkedNodes;
     350
     351  if (SetIndexToVector(center)) {
     352    for(int i=0;i<NDIM;i++) // store indices of this cell
     353    N[i] = n[i];
     354    //Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << index << "." << endl;
     355  } else {
     356    DoeLog(1) && (eLog()<< Verbose(1) << "Vector " << *center << " is outside of LinkedCell's bounding box." << endl);
     357    return TesselList;
     358  }
     359  // then go through the current and all neighbouring cells and check the contained points for possible candidates
     360  //Log() << Verbose(1) << "LC Intervals:";
     361  for (int i=0;i<NDIM;i++) {
     362    Nlower[i] = ((N[i]-1) >= 0) ? N[i]-1 : 0;
     363    Nupper[i] = ((N[i]+1) < N[i]) ? N[i]+1 : N[i]-1;
     364    //Log() << Verbose(0) << " [" << Nlower[i] << "," << Nupper[i] << "] ";
     365  }
     366  //Log() << Verbose(0) << endl;
     367  for (n[0] = Nlower[0]; n[0] <= Nupper[0]; n[0]++)
     368    for (n[1] = Nlower[1]; n[1] <= Nupper[1]; n[1]++)
     369      for (n[2] = Nlower[2]; n[2] <= Nupper[2]; n[2]++) {
     370        const LinkedNodes *List = GetCurrentCell();
     371        //Log() << Verbose(1) << "Current cell is " << n[0] << ", " << n[1] << ", " << n[2] << " with No. " << index << "." << endl;
     372        if (List != NULL) {
     373          for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     374            Walker = *Runner;
     375            if ((center->DistanceSquared(Walker->node) - radiusSquared) > MYEPSILON) {
     376              TesselList->push_back(Walker);
     377            }
     378          }
     379        }
     380      }
     381  return TesselList;
     382};
Note: See TracChangeset for help on using the changeset viewer.