Changeset ef016c for molecuilder/src
- Timestamp:
- Apr 9, 2010, 1:39:03 PM (15 years ago)
- Children:
- e760c1
- Parents:
- bd8561
- Location:
- molecuilder/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/linkedcell.cpp
rbd8561 ref016c 244 244 }; 245 245 246 /** Set the index to the cell containing a given Vector *x. 247 * \param *x Vector with coordinates 248 * \return Vector is inside bounding box - true, else - false 249 */ 250 bool LinkedCell::SetIndexToVector(const Vector * const x) const 251 { 252 for (int i=0;i<NDIM;i++) 253 n[i] = (int)floor((x->x[i] - min.x[i])/RADIUS); 254 255 return CheckBounds(); 256 }; 257 246 258 /** Calculates the index for a given LCNode *Walker. 247 259 * \param *Walker LCNode to set index tos … … 269 281 * \param *upper upper bounds 270 282 */ 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] << "] "; 283 void LinkedCell::GetNeighbourBounds(int lower[NDIM], int upper[NDIM], int step) const 284 { 285 for (int i=0;i<NDIM;i++) { 286 lower[i] = 0; 287 for (int s=step; s>0;--s) 288 if ((n[i]-s) >= 0) { 289 lower[i] = n[i]-s; 290 break; 291 } 292 upper[i] = 0; 293 for (int s=step; s>0;--s) 294 if ((n[i]+s) < N[i]) { 295 upper[i] = n[i]+s; 296 break; 297 } 298 //Log() << Verbose(0) << " [" << lower[i] << "," << upper[i] << "] "; 277 299 // check for this axis whether the point is outside of our grid 278 300 if (n[i] < 0) … … 285 307 }; 286 308 287 /** Calculates the index for a given Vector *x.288 * \param *x Vector with coordinates289 * \return Vector is inside bounding box - true, else - false290 */291 bool LinkedCell::SetIndexToVector(const Vector * const x) const292 {293 bool status = true;294 for (int i=0;i<NDIM;i++) {295 n[i] = (int)floor((x->x[i] - min.x[i])/RADIUS);296 if (max.x[i] < x->x[i])297 status = false;298 if (min.x[i] > x->x[i])299 status = false;300 }301 return status;302 };303 304 309 /** Returns a list with all neighbours from the current LinkedCell::index. 305 310 * \param distance (if no distance, then adjacent cells are taken) 306 311 * \return list of tesselpoints 307 312 */ 308 LinkedCell::LinkedNodes* LinkedCell::GetallNeighbours(const double distance = 0) const309 { 310 int N [NDIM], Nlower[NDIM], Nupper[NDIM];313 LinkedCell::LinkedNodes* LinkedCell::GetallNeighbours(const double distance) const 314 { 315 int Nlower[NDIM], Nupper[NDIM]; 311 316 TesselPoint *Walker = NULL; 312 317 LinkedNodes *TesselList = new LinkedNodes; 313 318 314 319 // 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 } 320 const int step = (distance == 0) ? 1 : (int)floor(distance/RADIUS + 1.); 321 GetNeighbourBounds(Nlower, Nupper, step); 322 322 323 //Log() << Verbose(0) << endl; 323 324 for (n[0] = Nlower[0]; n[0] <= Nupper[0]; n[0]++) … … 344 345 LinkedCell::LinkedNodes* LinkedCell::GetPointsInsideSphere(const double radius, const Vector * const center) const 345 346 { 346 int N[NDIM], Nlower[NDIM], Nupper[NDIM];347 347 const double radiusSquared = radius*radius; 348 348 TesselPoint *Walker = NULL; 349 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 { 350 LinkedNodes *NeighbourList = NULL; 351 352 // set index of LC to center of sphere 353 if (!SetIndexToVector(center)) { 356 354 DoeLog(1) && (eLog()<< Verbose(1) << "Vector " << *center << " is outside of LinkedCell's bounding box." << endl); 357 355 return TesselList; 358 356 } 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 } 357 358 // gather all neighbours first, then look who fulfills distance criteria 359 NeighbourList = GetallNeighbours(radius); 360 if (NeighbourList != NULL) { 361 for (LinkedNodes::const_iterator Runner = NeighbourList->begin(); Runner != NeighbourList->end(); Runner++) { 362 Walker = *Runner; 363 if ((center->DistanceSquared(Walker->node) - radiusSquared) < MYEPSILON) { 364 TesselList->push_back(Walker); 380 365 } 366 } 367 delete(NeighbourList); 368 } else 369 DoeLog(2) && (eLog()<< Verbose(2) << "Around vector " << *center << " there are no atoms." << endl); 381 370 return TesselList; 382 371 }; -
molecuilder/src/linkedcell.hpp
rbd8561 ref016c 63 63 bool CheckBounds()const ; 64 64 bool CheckBounds(const int relative[NDIM])const ; 65 void GetNeighbourBounds(int lower[NDIM], int upper[NDIM] )const ;65 void GetNeighbourBounds(int lower[NDIM], int upper[NDIM], int step = 1)const ; 66 66 67 LinkedCell::LinkedNodes* GetallNeighbours(const double distance ) const;67 LinkedCell::LinkedNodes* GetallNeighbours(const double distance = 0) const; 68 68 LinkedCell::LinkedNodes* GetPointsInsideSphere(const double radius, const Vector * const center) const; 69 69
Note:
See TracChangeset
for help on using the changeset viewer.