[edb93c] | 1 | /** \file linkedcell.cpp
|
---|
| 2 | *
|
---|
| 3 | * Function implementations for the class LinkedCell.
|
---|
| 4 | *
|
---|
| 5 | */
|
---|
| 6 |
|
---|
[112b09] | 7 | #include "Helpers/MemDebug.hpp"
|
---|
[edb93c] | 8 |
|
---|
[f66195] | 9 | #include "atom.hpp"
|
---|
| 10 | #include "helpers.hpp"
|
---|
[e1bc68] | 11 | #include "linkedcell.hpp"
|
---|
[e138de] | 12 | #include "log.hpp"
|
---|
[cee0b57] | 13 | #include "molecule.hpp"
|
---|
[357fba] | 14 | #include "tesselation.hpp"
|
---|
[f66195] | 15 | #include "vector.hpp"
|
---|
[357fba] | 16 |
|
---|
| 17 | // ========================================================= class LinkedCell ===========================================
|
---|
| 18 |
|
---|
[e1bc68] | 19 |
|
---|
| 20 | /** Constructor for class LinkedCell.
|
---|
| 21 | */
|
---|
| 22 | LinkedCell::LinkedCell()
|
---|
| 23 | {
|
---|
[042f82] | 24 | LC = NULL;
|
---|
| 25 | for(int i=0;i<NDIM;i++)
|
---|
| 26 | N[i] = 0;
|
---|
| 27 | index = -1;
|
---|
| 28 | RADIUS = 0.;
|
---|
| 29 | max.Zero();
|
---|
| 30 | min.Zero();
|
---|
[e1bc68] | 31 | };
|
---|
| 32 |
|
---|
| 33 | /** Puts all atoms in \a *mol into a linked cell list with cell's lengths of \a RADIUS
|
---|
[357fba] | 34 | * \param *set LCNodeSet class with all LCNode's
|
---|
[e1bc68] | 35 | * \param RADIUS edge length of cells
|
---|
| 36 | */
|
---|
[776b64] | 37 | LinkedCell::LinkedCell(const PointCloud * const set, const double radius)
|
---|
[e1bc68] | 38 | {
|
---|
[357fba] | 39 | TesselPoint *Walker = NULL;
|
---|
[e1bc68] | 40 |
|
---|
[042f82] | 41 | RADIUS = radius;
|
---|
| 42 | LC = NULL;
|
---|
| 43 | for(int i=0;i<NDIM;i++)
|
---|
| 44 | N[i] = 0;
|
---|
| 45 | index = -1;
|
---|
| 46 | max.Zero();
|
---|
| 47 | min.Zero();
|
---|
[a67d19] | 48 | DoLog(1) && (Log() << Verbose(1) << "Begin of LinkedCell" << endl);
|
---|
[caf4ba] | 49 | if ((set == NULL) || (set->IsEmpty())) {
|
---|
[58ed4a] | 50 | DoeLog(1) && (eLog()<< Verbose(1) << "set is NULL or contains no linked cell nodes!" << endl);
|
---|
[042f82] | 51 | return;
|
---|
| 52 | }
|
---|
| 53 | // 1. find max and min per axis of atoms
|
---|
[357fba] | 54 | set->GoToFirst();
|
---|
| 55 | Walker = set->GetPoint();
|
---|
[042f82] | 56 | for (int i=0;i<NDIM;i++) {
|
---|
[0a4f7f] | 57 | max[i] = Walker->node->at(i);
|
---|
| 58 | min[i] = Walker->node->at(i);
|
---|
[042f82] | 59 | }
|
---|
[357fba] | 60 | set->GoToFirst();
|
---|
[1999d8] | 61 | while (!set->IsEnd()) {
|
---|
[357fba] | 62 | Walker = set->GetPoint();
|
---|
[042f82] | 63 | for (int i=0;i<NDIM;i++) {
|
---|
[0a4f7f] | 64 | if (max[i] < Walker->node->at(i))
|
---|
| 65 | max[i] = Walker->node->at(i);
|
---|
| 66 | if (min[i] > Walker->node->at(i))
|
---|
| 67 | min[i] = Walker->node->at(i);
|
---|
[042f82] | 68 | }
|
---|
[357fba] | 69 | set->GoToNext();
|
---|
[042f82] | 70 | }
|
---|
[a67d19] | 71 | DoLog(2) && (Log() << Verbose(2) << "Bounding box is " << min << " and " << max << "." << endl);
|
---|
[6ac7ee] | 72 |
|
---|
[357fba] | 73 | // 2. find then number of cells per axis
|
---|
[042f82] | 74 | for (int i=0;i<NDIM;i++) {
|
---|
[0a4f7f] | 75 | N[i] = static_cast<int>(floor((max[i] - min[i])/RADIUS)+1);
|
---|
[042f82] | 76 | }
|
---|
[a67d19] | 77 | DoLog(2) && (Log() << Verbose(2) << "Number of cells per axis are " << N[0] << ", " << N[1] << " and " << N[2] << "." << endl);
|
---|
[6ac7ee] | 78 |
|
---|
[042f82] | 79 | // 3. allocate the lists
|
---|
[a67d19] | 80 | DoLog(2) && (Log() << Verbose(2) << "Allocating cells ... ");
|
---|
[042f82] | 81 | if (LC != NULL) {
|
---|
[58ed4a] | 82 | DoeLog(1) && (eLog()<< Verbose(1) << "Linked Cell list is already allocated, I do nothing." << endl);
|
---|
[042f82] | 83 | return;
|
---|
| 84 | }
|
---|
[357fba] | 85 | LC = new LinkedNodes[N[0]*N[1]*N[2]];
|
---|
[042f82] | 86 | for (index=0;index<N[0]*N[1]*N[2];index++) {
|
---|
| 87 | LC [index].clear();
|
---|
| 88 | }
|
---|
[a67d19] | 89 | DoLog(0) && (Log() << Verbose(0) << "done." << endl);
|
---|
[6ac7ee] | 90 |
|
---|
[042f82] | 91 | // 4. put each atom into its respective cell
|
---|
[a67d19] | 92 | DoLog(2) && (Log() << Verbose(2) << "Filling cells ... ");
|
---|
[357fba] | 93 | set->GoToFirst();
|
---|
[1999d8] | 94 | while (!set->IsEnd()) {
|
---|
[357fba] | 95 | Walker = set->GetPoint();
|
---|
[042f82] | 96 | for (int i=0;i<NDIM;i++) {
|
---|
[0a4f7f] | 97 | n[i] = static_cast<int>(floor((Walker->node->at(i) - min[i])/RADIUS));
|
---|
[042f82] | 98 | }
|
---|
| 99 | index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2];
|
---|
| 100 | LC[index].push_back(Walker);
|
---|
[e138de] | 101 | //Log() << Verbose(2) << *Walker << " goes into cell " << n[0] << ", " << n[1] << ", " << n[2] << " with No. " << index << "." << endl;
|
---|
[357fba] | 102 | set->GoToNext();
|
---|
[042f82] | 103 | }
|
---|
[a67d19] | 104 | DoLog(0) && (Log() << Verbose(0) << "done." << endl);
|
---|
| 105 | DoLog(1) && (Log() << Verbose(1) << "End of LinkedCell" << endl);
|
---|
[e1bc68] | 106 | };
|
---|
| 107 |
|
---|
[8cd903] | 108 |
|
---|
| 109 | /** Puts all atoms in \a *mol into a linked cell list with cell's lengths of \a RADIUS
|
---|
| 110 | * \param *set LCNodeSet class with all LCNode's
|
---|
| 111 | * \param RADIUS edge length of cells
|
---|
| 112 | */
|
---|
[776b64] | 113 | LinkedCell::LinkedCell(LinkedNodes *set, const double radius)
|
---|
[8cd903] | 114 | {
|
---|
| 115 | class TesselPoint *Walker = NULL;
|
---|
| 116 | RADIUS = radius;
|
---|
| 117 | LC = NULL;
|
---|
| 118 | for(int i=0;i<NDIM;i++)
|
---|
| 119 | N[i] = 0;
|
---|
| 120 | index = -1;
|
---|
| 121 | max.Zero();
|
---|
| 122 | min.Zero();
|
---|
[a67d19] | 123 | DoLog(1) && (Log() << Verbose(1) << "Begin of LinkedCell" << endl);
|
---|
[8cd903] | 124 | if (set->empty()) {
|
---|
[58ed4a] | 125 | DoeLog(1) && (eLog()<< Verbose(1) << "set contains no linked cell nodes!" << endl);
|
---|
[8cd903] | 126 | return;
|
---|
| 127 | }
|
---|
| 128 | // 1. find max and min per axis of atoms
|
---|
| 129 | LinkedNodes::iterator Runner = set->begin();
|
---|
| 130 | for (int i=0;i<NDIM;i++) {
|
---|
[0a4f7f] | 131 | max[i] = (*Runner)->node->at(i);
|
---|
| 132 | min[i] = (*Runner)->node->at(i);
|
---|
[8cd903] | 133 | }
|
---|
| 134 | for (LinkedNodes::iterator Runner = set->begin(); Runner != set->end(); Runner++) {
|
---|
| 135 | Walker = *Runner;
|
---|
| 136 | for (int i=0;i<NDIM;i++) {
|
---|
[0a4f7f] | 137 | if (max[i] < Walker->node->at(i))
|
---|
| 138 | max[i] = Walker->node->at(i);
|
---|
| 139 | if (min[i] > Walker->node->at(i))
|
---|
| 140 | min[i] = Walker->node->at(i);
|
---|
[8cd903] | 141 | }
|
---|
| 142 | }
|
---|
[a67d19] | 143 | DoLog(2) && (Log() << Verbose(2) << "Bounding box is " << min << " and " << max << "." << endl);
|
---|
[8cd903] | 144 |
|
---|
| 145 | // 2. find then number of cells per axis
|
---|
| 146 | for (int i=0;i<NDIM;i++) {
|
---|
[0a4f7f] | 147 | N[i] = static_cast<int>(floor((max[i] - min[i])/RADIUS)+1);
|
---|
[8cd903] | 148 | }
|
---|
[a67d19] | 149 | DoLog(2) && (Log() << Verbose(2) << "Number of cells per axis are " << N[0] << ", " << N[1] << " and " << N[2] << "." << endl);
|
---|
[8cd903] | 150 |
|
---|
| 151 | // 3. allocate the lists
|
---|
[a67d19] | 152 | DoLog(2) && (Log() << Verbose(2) << "Allocating cells ... ");
|
---|
[8cd903] | 153 | if (LC != NULL) {
|
---|
[58ed4a] | 154 | DoeLog(1) && (eLog()<< Verbose(1) << "Linked Cell list is already allocated, I do nothing." << endl);
|
---|
[8cd903] | 155 | return;
|
---|
| 156 | }
|
---|
| 157 | LC = new LinkedNodes[N[0]*N[1]*N[2]];
|
---|
| 158 | for (index=0;index<N[0]*N[1]*N[2];index++) {
|
---|
| 159 | LC [index].clear();
|
---|
| 160 | }
|
---|
[a67d19] | 161 | DoLog(0) && (Log() << Verbose(0) << "done." << endl);
|
---|
[8cd903] | 162 |
|
---|
| 163 | // 4. put each atom into its respective cell
|
---|
[a67d19] | 164 | DoLog(2) && (Log() << Verbose(2) << "Filling cells ... ");
|
---|
[8cd903] | 165 | for (LinkedNodes::iterator Runner = set->begin(); Runner != set->end(); Runner++) {
|
---|
| 166 | Walker = *Runner;
|
---|
| 167 | for (int i=0;i<NDIM;i++) {
|
---|
[0a4f7f] | 168 | n[i] = static_cast<int>(floor((Walker->node->at(i) - min[i])/RADIUS));
|
---|
[8cd903] | 169 | }
|
---|
| 170 | index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2];
|
---|
| 171 | LC[index].push_back(Walker);
|
---|
[e138de] | 172 | //Log() << Verbose(2) << *Walker << " goes into cell " << n[0] << ", " << n[1] << ", " << n[2] << " with No. " << index << "." << endl;
|
---|
[8cd903] | 173 | }
|
---|
[a67d19] | 174 | DoLog(0) && (Log() << Verbose(0) << "done." << endl);
|
---|
| 175 | DoLog(1) && (Log() << Verbose(1) << "End of LinkedCell" << endl);
|
---|
[8cd903] | 176 | };
|
---|
| 177 |
|
---|
[e1bc68] | 178 | /** Destructor for class LinkedCell.
|
---|
| 179 | */
|
---|
| 180 | LinkedCell::~LinkedCell()
|
---|
| 181 | {
|
---|
[042f82] | 182 | if (LC != NULL)
|
---|
| 183 | for (index=0;index<N[0]*N[1]*N[2];index++)
|
---|
| 184 | LC[index].clear();
|
---|
| 185 | delete[](LC);
|
---|
| 186 | for(int i=0;i<NDIM;i++)
|
---|
| 187 | N[i] = 0;
|
---|
| 188 | index = -1;
|
---|
[e1bc68] | 189 | };
|
---|
| 190 |
|
---|
| 191 | /** Checks whether LinkedCell::n[] is each within [0,N[]].
|
---|
| 192 | * \return if all in intervals - true, else -false
|
---|
| 193 | */
|
---|
[776b64] | 194 | bool LinkedCell::CheckBounds() const
|
---|
[e1bc68] | 195 | {
|
---|
[042f82] | 196 | bool status = true;
|
---|
| 197 | for(int i=0;i<NDIM;i++)
|
---|
| 198 | status = status && ((n[i] >=0) && (n[i] < N[i]));
|
---|
[bdc91e] | 199 | // if (!status)
|
---|
| 200 | // DoeLog(1) && (eLog()<< Verbose(1) << "indices are out of bounds!" << endl);
|
---|
[042f82] | 201 | return status;
|
---|
[e1bc68] | 202 | };
|
---|
| 203 |
|
---|
[07051c] | 204 | /** Checks whether LinkedCell::n[] plus relative offset is each within [0,N[]].
|
---|
[266237] | 205 | * Note that for this check we don't admonish if out of bounds.
|
---|
[07051c] | 206 | * \param relative[NDIM] relative offset to current cell
|
---|
| 207 | * \return if all in intervals - true, else -false
|
---|
| 208 | */
|
---|
[776b64] | 209 | bool LinkedCell::CheckBounds(const int relative[NDIM]) const
|
---|
[07051c] | 210 | {
|
---|
| 211 | bool status = true;
|
---|
| 212 | for(int i=0;i<NDIM;i++)
|
---|
| 213 | status = status && ((n[i]+relative[i] >=0) && (n[i]+relative[i] < N[i]));
|
---|
| 214 | return status;
|
---|
| 215 | };
|
---|
| 216 |
|
---|
[e1bc68] | 217 |
|
---|
| 218 | /** Returns a pointer to the current cell.
|
---|
| 219 | * \return LinkedAtoms pointer to current cell, NULL if LinkedCell::n[] are out of bounds.
|
---|
| 220 | */
|
---|
[734816] | 221 | const LinkedCell::LinkedNodes* LinkedCell::GetCurrentCell() const
|
---|
[e1bc68] | 222 | {
|
---|
[042f82] | 223 | if (CheckBounds()) {
|
---|
| 224 | index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2];
|
---|
| 225 | return (&(LC[index]));
|
---|
| 226 | } else {
|
---|
| 227 | return NULL;
|
---|
| 228 | }
|
---|
[e1bc68] | 229 | };
|
---|
| 230 |
|
---|
[07051c] | 231 | /** Returns a pointer to the current cell.
|
---|
| 232 | * \param relative[NDIM] offset for each axis with respect to the current cell LinkedCell::n[NDIM]
|
---|
| 233 | * \return LinkedAtoms pointer to current cell, NULL if LinkedCell::n[]+relative[] are out of bounds.
|
---|
| 234 | */
|
---|
[734816] | 235 | const LinkedCell::LinkedNodes* LinkedCell::GetRelativeToCurrentCell(const int relative[NDIM]) const
|
---|
[07051c] | 236 | {
|
---|
| 237 | if (CheckBounds(relative)) {
|
---|
| 238 | index = (n[0]+relative[0]) * N[1] * N[2] + (n[1]+relative[1]) * N[2] + (n[2]+relative[2]);
|
---|
| 239 | return (&(LC[index]));
|
---|
| 240 | } else {
|
---|
| 241 | return NULL;
|
---|
| 242 | }
|
---|
| 243 | };
|
---|
| 244 |
|
---|
[893bea] | 245 | /** Set the index to the cell containing a given Vector *x.
|
---|
| 246 | * \param *x Vector with coordinates
|
---|
| 247 | * \return Vector is inside bounding box - true, else - false
|
---|
| 248 | */
|
---|
| 249 | bool LinkedCell::SetIndexToVector(const Vector * const x) const
|
---|
| 250 | {
|
---|
| 251 | for (int i=0;i<NDIM;i++)
|
---|
[8cbb97] | 252 | n[i] = (int)floor((x->at(i) - min[i])/RADIUS);
|
---|
[893bea] | 253 |
|
---|
| 254 | return CheckBounds();
|
---|
| 255 | };
|
---|
| 256 |
|
---|
[357fba] | 257 | /** Calculates the index for a given LCNode *Walker.
|
---|
| 258 | * \param *Walker LCNode to set index tos
|
---|
[e1bc68] | 259 | * \return if the atom is also found in this cell - true, else - false
|
---|
| 260 | */
|
---|
[776b64] | 261 | bool LinkedCell::SetIndexToNode(const TesselPoint * const Walker) const
|
---|
[e1bc68] | 262 | {
|
---|
[042f82] | 263 | bool status = false;
|
---|
| 264 | for (int i=0;i<NDIM;i++) {
|
---|
[0a4f7f] | 265 | n[i] = static_cast<int>(floor((Walker->node->at(i) - min[i])/RADIUS));
|
---|
[042f82] | 266 | }
|
---|
| 267 | index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2];
|
---|
| 268 | if (CheckBounds()) {
|
---|
[357fba] | 269 | for (LinkedNodes::iterator Runner = LC[index].begin(); Runner != LC[index].end(); Runner++)
|
---|
[042f82] | 270 | status = status || ((*Runner) == Walker);
|
---|
| 271 | return status;
|
---|
| 272 | } else {
|
---|
[58ed4a] | 273 | DoeLog(1) && (eLog()<< Verbose(1) << "Node at " << *Walker << " is out of bounds." << endl);
|
---|
[042f82] | 274 | return false;
|
---|
| 275 | }
|
---|
[e1bc68] | 276 | };
|
---|
| 277 |
|
---|
[0f4538] | 278 | /** Calculates the interval bounds of the linked cell grid.
|
---|
[bdc91e] | 279 | * \param lower lower bounds
|
---|
| 280 | * \param upper upper bounds
|
---|
[061b06] | 281 | * \param step how deep to check the neighbouring cells (i.e. number of layers to check)
|
---|
[0f4538] | 282 | */
|
---|
[893bea] | 283 | void LinkedCell::GetNeighbourBounds(int lower[NDIM], int upper[NDIM], int step) const
|
---|
[0f4538] | 284 | {
|
---|
| 285 | for (int i=0;i<NDIM;i++) {
|
---|
[bdc91e] | 286 | lower[i] = n[i]-step;
|
---|
| 287 | if (lower[i] < 0)
|
---|
| 288 | lower[i] = 0;
|
---|
| 289 | if (lower[i] >= N[i])
|
---|
| 290 | lower[i] = N[i]-1;
|
---|
| 291 | upper[i] = n[i]+step;
|
---|
| 292 | if (upper[i] >= N[i])
|
---|
| 293 | upper[i] = N[i]-1;
|
---|
| 294 | if (upper[i] < 0)
|
---|
| 295 | upper[i] = 0;
|
---|
[e138de] | 296 | //Log() << Verbose(0) << "axis " << i << " has bounds [" << lower[i] << "," << upper[i] << "]" << endl;
|
---|
[0f4538] | 297 | }
|
---|
| 298 | };
|
---|
| 299 |
|
---|
[734816] | 300 | /** Returns a list with all neighbours from the current LinkedCell::index.
|
---|
| 301 | * \param distance (if no distance, then adjacent cells are taken)
|
---|
| 302 | * \return list of tesselpoints
|
---|
| 303 | */
|
---|
[893bea] | 304 | LinkedCell::LinkedNodes* LinkedCell::GetallNeighbours(const double distance) const
|
---|
[734816] | 305 | {
|
---|
[893bea] | 306 | int Nlower[NDIM], Nupper[NDIM];
|
---|
[734816] | 307 | TesselPoint *Walker = NULL;
|
---|
| 308 | LinkedNodes *TesselList = new LinkedNodes;
|
---|
| 309 |
|
---|
| 310 | // then go through the current and all neighbouring cells and check the contained points for possible candidates
|
---|
[893bea] | 311 | const int step = (distance == 0) ? 1 : (int)floor(distance/RADIUS + 1.);
|
---|
| 312 | GetNeighbourBounds(Nlower, Nupper, step);
|
---|
| 313 |
|
---|
[734816] | 314 | //Log() << Verbose(0) << endl;
|
---|
| 315 | for (n[0] = Nlower[0]; n[0] <= Nupper[0]; n[0]++)
|
---|
| 316 | for (n[1] = Nlower[1]; n[1] <= Nupper[1]; n[1]++)
|
---|
| 317 | for (n[2] = Nlower[2]; n[2] <= Nupper[2]; n[2]++) {
|
---|
| 318 | const LinkedNodes *List = GetCurrentCell();
|
---|
| 319 | //Log() << Verbose(1) << "Current cell is " << n[0] << ", " << n[1] << ", " << n[2] << " with No. " << index << "." << endl;
|
---|
| 320 | if (List != NULL) {
|
---|
| 321 | for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
|
---|
| 322 | Walker = *Runner;
|
---|
| 323 | TesselList->push_back(Walker);
|
---|
| 324 | }
|
---|
| 325 | }
|
---|
| 326 | }
|
---|
| 327 | return TesselList;
|
---|
| 328 | };
|
---|
| 329 |
|
---|
[ffe885] | 330 | /** Set the index to the cell containing a given Vector *x, which is not inside the LinkedCell's domain
|
---|
| 331 | * Note that as we have to check distance from every corner of the closest cell, this function is faw more
|
---|
| 332 | * expensive and if Vector is known to be inside LinkedCell's domain, then SetIndexToVector() should be used.
|
---|
| 333 | * \param *x Vector with coordinates
|
---|
| 334 | * \return minimum squared distance of cell to given vector (if inside of domain, distance is 0)
|
---|
| 335 | */
|
---|
| 336 | double LinkedCell::SetClosestIndexToOutsideVector(const Vector * const x) const
|
---|
| 337 | {
|
---|
| 338 | for (int i=0;i<NDIM;i++) {
|
---|
[8cbb97] | 339 | n[i] = (int)floor((x->at(i) - min[i])/RADIUS);
|
---|
[ffe885] | 340 | if (n[i] < 0)
|
---|
| 341 | n[i] = 0;
|
---|
| 342 | if (n[i] >= N[i])
|
---|
| 343 | n[i] = N[i]-1;
|
---|
| 344 | }
|
---|
| 345 |
|
---|
| 346 | // calculate distance of cell to vector
|
---|
| 347 | double distanceSquared = 0.;
|
---|
| 348 | bool outside = true; // flag whether x is found in- or outside of LinkedCell's domain/closest cell
|
---|
| 349 | Vector corner; // current corner of closest cell
|
---|
| 350 | Vector tester; // Vector pointing from corner to center of closest cell
|
---|
| 351 | Vector Distance; // Vector from corner of closest cell to x
|
---|
| 352 |
|
---|
| 353 | Vector center; // center of the closest cell
|
---|
| 354 | for (int i=0;i<NDIM;i++)
|
---|
[8cbb97] | 355 | center[i] = min[i]+((double)n[i]+.5)*RADIUS;
|
---|
[ffe885] | 356 |
|
---|
| 357 | int c[NDIM];
|
---|
| 358 | for (c[0]=0;c[0]<=1;c[0]++)
|
---|
| 359 | for (c[1]=0; c[1]<=1;c[1]++)
|
---|
| 360 | for (c[2]=0; c[2]<=1;c[2]++) {
|
---|
| 361 | // set up corner
|
---|
| 362 | for (int i=0;i<NDIM;i++)
|
---|
[8cbb97] | 363 | corner[i] = min[i]+RADIUS*((double)n[i]+c[i]);
|
---|
[ffe885] | 364 | // set up distance vector
|
---|
[8cbb97] | 365 | Distance = (*x) - corner;
|
---|
[ffe885] | 366 | const double dist = Distance.NormSquared();
|
---|
| 367 | // check whether distance is smaller
|
---|
| 368 | if (dist< distanceSquared)
|
---|
| 369 | distanceSquared = dist;
|
---|
| 370 | // check whether distance vector goes inside or outside
|
---|
[8cbb97] | 371 | tester = center -corner;
|
---|
| 372 | if (tester.ScalarProduct(Distance) < 0)
|
---|
[ffe885] | 373 | outside = false;
|
---|
| 374 | }
|
---|
| 375 | return (outside ? distanceSquared : 0.);
|
---|
| 376 | };
|
---|
[734816] | 377 |
|
---|
| 378 | /** Returns a list of all TesselPoint with distance less than \a radius to \a *Center.
|
---|
| 379 | * \param radius radius of sphere
|
---|
| 380 | * \param *center center of sphere
|
---|
| 381 | * \return list of all points inside sphere
|
---|
| 382 | */
|
---|
| 383 | LinkedCell::LinkedNodes* LinkedCell::GetPointsInsideSphere(const double radius, const Vector * const center) const
|
---|
| 384 | {
|
---|
| 385 | const double radiusSquared = radius*radius;
|
---|
| 386 | TesselPoint *Walker = NULL;
|
---|
| 387 | LinkedNodes *TesselList = new LinkedNodes;
|
---|
[893bea] | 388 | LinkedNodes *NeighbourList = NULL;
|
---|
[734816] | 389 |
|
---|
[893bea] | 390 | // set index of LC to center of sphere
|
---|
[ffe885] | 391 | const double dist = SetClosestIndexToOutsideVector(center);
|
---|
[061b06] | 392 | if (dist > 2.*radius) {
|
---|
[ffe885] | 393 | DoeLog(1) && (eLog()<< Verbose(1) << "Vector " << *center << " is too far away from any atom in LinkedCell's bounding box." << endl);
|
---|
[734816] | 394 | return TesselList;
|
---|
[061b06] | 395 | } else
|
---|
[a67d19] | 396 | DoLog(1) && (Log() << Verbose(1) << "Distance of closest cell to center of sphere with radius " << radius << " is " << dist << "." << endl);
|
---|
[893bea] | 397 |
|
---|
| 398 | // gather all neighbours first, then look who fulfills distance criteria
|
---|
[061b06] | 399 | NeighbourList = GetallNeighbours(2.*radius-dist);
|
---|
| 400 | //Log() << Verbose(1) << "I found " << NeighbourList->size() << " neighbours to check." << endl;
|
---|
[893bea] | 401 | if (NeighbourList != NULL) {
|
---|
| 402 | for (LinkedNodes::const_iterator Runner = NeighbourList->begin(); Runner != NeighbourList->end(); Runner++) {
|
---|
| 403 | Walker = *Runner;
|
---|
[061b06] | 404 | //Log() << Verbose(1) << "Current neighbour is at " << *Walker->node << "." << endl;
|
---|
[8cbb97] | 405 | if ((center->DistanceSquared(*Walker->node) - radiusSquared) < MYEPSILON) {
|
---|
[893bea] | 406 | TesselList->push_back(Walker);
|
---|
[734816] | 407 | }
|
---|
[893bea] | 408 | }
|
---|
| 409 | delete(NeighbourList);
|
---|
| 410 | } else
|
---|
| 411 | DoeLog(2) && (eLog()<< Verbose(2) << "Around vector " << *center << " there are no atoms." << endl);
|
---|
[734816] | 412 | return TesselList;
|
---|
| 413 | };
|
---|