Changes in src/linkedcell.cpp [caf4ba:717e0c]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/linkedcell.cpp
rcaf4ba r717e0c 1 /** \file linkedcell.cpp 2 * 3 * Function implementations for the class LinkedCell. 4 * 5 */ 6 7 8 #include "atom.hpp" 9 #include "helpers.hpp" 1 10 #include "linkedcell.hpp" 2 #include "molecules.hpp" 11 #include "log.hpp" 12 #include "molecule.hpp" 3 13 #include "tesselation.hpp" 14 #include "vector.hpp" 4 15 5 16 // ========================================================= class LinkedCell =========================================== … … 23 34 * \param RADIUS edge length of cells 24 35 */ 25 LinkedCell::LinkedCell( PointCloud *set,double radius)36 LinkedCell::LinkedCell(const PointCloud * const set, const double radius) 26 37 { 27 38 TesselPoint *Walker = NULL; … … 34 45 max.Zero(); 35 46 min.Zero(); 36 cout<< Verbose(1) << "Begin of LinkedCell" << endl;37 if ( (set == NULL) || (set->IsEmpty())) {38 cerr << "ERROR: set is NULL orcontains no linked cell nodes!" << endl;47 Log() << Verbose(1) << "Begin of LinkedCell" << endl; 48 if (set->IsEmpty()) { 49 eLog() << Verbose(1) << "set contains no linked cell nodes!" << endl; 39 50 return; 40 51 } … … 47 58 } 48 59 set->GoToFirst(); 49 while (!set->Is Last()) {60 while (!set->IsEnd()) { 50 61 Walker = set->GetPoint(); 51 62 for (int i=0;i<NDIM;i++) { … … 57 68 set->GoToNext(); 58 69 } 59 cout<< Verbose(2) << "Bounding box is " << min << " and " << max << "." << endl;70 Log() << Verbose(2) << "Bounding box is " << min << " and " << max << "." << endl; 60 71 61 72 // 2. find then number of cells per axis … … 63 74 N[i] = (int)floor((max.x[i] - min.x[i])/RADIUS)+1; 64 75 } 65 cout<< Verbose(2) << "Number of cells per axis are " << N[0] << ", " << N[1] << " and " << N[2] << "." << endl;76 Log() << Verbose(2) << "Number of cells per axis are " << N[0] << ", " << N[1] << " and " << N[2] << "." << endl; 66 77 67 78 // 3. allocate the lists 68 cout<< Verbose(2) << "Allocating cells ... ";79 Log() << Verbose(2) << "Allocating cells ... "; 69 80 if (LC != NULL) { 70 cout << Verbose(1) << "ERROR:Linked Cell list is already allocated, I do nothing." << endl;81 eLog() << Verbose(1) << "Linked Cell list is already allocated, I do nothing." << endl; 71 82 return; 72 83 } … … 75 86 LC [index].clear(); 76 87 } 77 cout<< "done." << endl;88 Log() << Verbose(0) << "done." << endl; 78 89 79 90 // 4. put each atom into its respective cell 80 cout<< Verbose(2) << "Filling cells ... ";91 Log() << Verbose(2) << "Filling cells ... "; 81 92 set->GoToFirst(); 82 while (!set->Is Last()) {93 while (!set->IsEnd()) { 83 94 Walker = set->GetPoint(); 84 95 for (int i=0;i<NDIM;i++) { … … 87 98 index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2]; 88 99 LC[index].push_back(Walker); 89 // cout<< Verbose(2) << *Walker << " goes into cell " << n[0] << ", " << n[1] << ", " << n[2] << " with No. " << index << "." << endl;100 //Log() << Verbose(2) << *Walker << " goes into cell " << n[0] << ", " << n[1] << ", " << n[2] << " with No. " << index << "." << endl; 90 101 set->GoToNext(); 91 102 } 92 cout << "done." << endl; 93 cout << Verbose(1) << "End of LinkedCell" << endl; 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; 94 175 }; 95 176 … … 112 193 * \return if all in intervals - true, else -false 113 194 */ 114 bool LinkedCell::CheckBounds() 195 bool LinkedCell::CheckBounds() const 115 196 { 116 197 bool status = true; … … 118 199 status = status && ((n[i] >=0) && (n[i] < N[i])); 119 200 if (!status) 120 cerr << "ERROR: indices are out of bounds!" << endl; 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])); 121 215 return status; 122 216 }; … … 126 220 * \return LinkedAtoms pointer to current cell, NULL if LinkedCell::n[] are out of bounds. 127 221 */ 128 LinkedNodes* LinkedCell::GetCurrentCell() 222 const LinkedNodes* LinkedCell::GetCurrentCell() const 129 223 { 130 224 if (CheckBounds()) { … … 136 230 }; 137 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]); 240 return (&(LC[index])); 241 } else { 242 return NULL; 243 } 244 }; 245 138 246 /** Calculates the index for a given LCNode *Walker. 139 247 * \param *Walker LCNode to set index tos 140 248 * \return if the atom is also found in this cell - true, else - false 141 249 */ 142 bool LinkedCell::SetIndexToNode( TesselPoint *Walker)250 bool LinkedCell::SetIndexToNode(const TesselPoint * const Walker) const 143 251 { 144 252 bool status = false; … … 152 260 return status; 153 261 } else { 154 cerr << Verbose(1) << "ERROR:Node at " << *Walker << " is out of bounds." << endl;262 eLog() << Verbose(1) << "Node at " << *Walker << " is out of bounds." << endl; 155 263 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; 156 284 } 157 285 }; … … 161 289 * \return Vector is inside bounding box - true, else - false 162 290 */ 163 bool LinkedCell::SetIndexToVector( Vector *x)291 bool LinkedCell::SetIndexToVector(const Vector * const x) const 164 292 { 165 293 bool status = true;
Note:
See TracChangeset
for help on using the changeset viewer.