| [bcf653] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
| [0aa122] | 4 |  * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
 | 
|---|
| [94d5ac6] | 5 |  * 
 | 
|---|
 | 6 |  *
 | 
|---|
 | 7 |  *   This file is part of MoleCuilder.
 | 
|---|
 | 8 |  *
 | 
|---|
 | 9 |  *    MoleCuilder is free software: you can redistribute it and/or modify
 | 
|---|
 | 10 |  *    it under the terms of the GNU General Public License as published by
 | 
|---|
 | 11 |  *    the Free Software Foundation, either version 2 of the License, or
 | 
|---|
 | 12 |  *    (at your option) any later version.
 | 
|---|
 | 13 |  *
 | 
|---|
 | 14 |  *    MoleCuilder is distributed in the hope that it will be useful,
 | 
|---|
 | 15 |  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
 | 16 |  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
 | 17 |  *    GNU General Public License for more details.
 | 
|---|
 | 18 |  *
 | 
|---|
 | 19 |  *    You should have received a copy of the GNU General Public License
 | 
|---|
 | 20 |  *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
 | 
|---|
| [bcf653] | 21 |  */
 | 
|---|
 | 22 | 
 | 
|---|
| [edb93c] | 23 | /** \file linkedcell.cpp
 | 
|---|
 | 24 |  *
 | 
|---|
| [6bd7e0] | 25 |  * Function implementations for the class LinkedCell_deprecated.
 | 
|---|
| [edb93c] | 26 |  *
 | 
|---|
 | 27 |  */
 | 
|---|
 | 28 | 
 | 
|---|
| [bf3817] | 29 | // include config.h
 | 
|---|
 | 30 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 31 | #include <config.h>
 | 
|---|
 | 32 | #endif
 | 
|---|
 | 33 | 
 | 
|---|
| [ad011c] | 34 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [edb93c] | 35 | 
 | 
|---|
| [e1bc68] | 36 | #include "linkedcell.hpp"
 | 
|---|
| [53c7fc] | 37 | 
 | 
|---|
| [6f0841] | 38 | #include "Atom/atom.hpp"
 | 
|---|
| [ad011c] | 39 | #include "CodePatterns/Verbose.hpp"
 | 
|---|
| [3738f0] | 40 | #include "CodePatterns/Range.hpp"
 | 
|---|
| [ad011c] | 41 | #include "CodePatterns/Log.hpp"
 | 
|---|
| [53c7fc] | 42 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
 | 43 | #include "LinkedCell/IPointCloud.hpp"
 | 
|---|
| [cee0b57] | 44 | #include "molecule.hpp"
 | 
|---|
| [d127c8] | 45 | #include "Tesselation/tesselation.hpp"
 | 
|---|
| [357fba] | 46 | 
 | 
|---|
| [6bd7e0] | 47 | // ========================================================= class LinkedCell_deprecated ===========================================
 | 
|---|
| [357fba] | 48 | 
 | 
|---|
| [6bd7e0] | 49 | /** Constructor for class LinkedCell_deprecated.
 | 
|---|
| [e1bc68] | 50 |  */
 | 
|---|
| [6bd7e0] | 51 | LinkedCell_deprecated::LinkedCell_deprecated() :
 | 
|---|
| [97b825] | 52 |   LC(NULL),
 | 
|---|
| [ff58f1] | 53 |   RADIUS(0.),
 | 
|---|
 | 54 |   index(-1)
 | 
|---|
| [e1bc68] | 55 | {
 | 
|---|
| [042f82] | 56 |   for(int i=0;i<NDIM;i++)
 | 
|---|
 | 57 |     N[i] = 0;
 | 
|---|
 | 58 |   max.Zero();
 | 
|---|
 | 59 |   min.Zero();
 | 
|---|
| [e1bc68] | 60 | };
 | 
|---|
 | 61 | 
 | 
|---|
 | 62 | /** Puts all atoms in \a *mol into a linked cell list with cell's lengths of \a RADIUS
 | 
|---|
| [357fba] | 63 |  * \param *set LCNodeSet class with all LCNode's
 | 
|---|
| [e1bc68] | 64 |  * \param RADIUS edge length of cells
 | 
|---|
 | 65 |  */
 | 
|---|
| [6bd7e0] | 66 | LinkedCell_deprecated::LinkedCell_deprecated(IPointCloud & set, const double radius) :
 | 
|---|
| [97b825] | 67 |   LC(NULL),
 | 
|---|
| [ff58f1] | 68 |   RADIUS(radius),
 | 
|---|
| [97b825] | 69 |   index(-1)
 | 
|---|
| [e1bc68] | 70 | {
 | 
|---|
| [357fba] | 71 |   TesselPoint *Walker = NULL;
 | 
|---|
| [e1bc68] | 72 | 
 | 
|---|
| [042f82] | 73 |   for(int i=0;i<NDIM;i++)
 | 
|---|
 | 74 |     N[i] = 0;
 | 
|---|
 | 75 |   max.Zero();
 | 
|---|
 | 76 |   min.Zero();
 | 
|---|
| [47d041] | 77 |   LOG(1, "Begin of LinkedCell");
 | 
|---|
| [af2c424] | 78 |   if (set.IsEmpty()) {
 | 
|---|
| [47d041] | 79 |     ELOG(1, "set is NULL or contains no linked cell nodes!");
 | 
|---|
| [042f82] | 80 |     return;
 | 
|---|
 | 81 |   }
 | 
|---|
 | 82 |   // 1. find max and min per axis of atoms
 | 
|---|
| [af2c424] | 83 |   set.GoToFirst();
 | 
|---|
 | 84 |   Walker = set.GetPoint();
 | 
|---|
| [042f82] | 85 |   for (int i=0;i<NDIM;i++) {
 | 
|---|
| [d74077] | 86 |     max[i] = Walker->at(i);
 | 
|---|
 | 87 |     min[i] = Walker->at(i);
 | 
|---|
| [042f82] | 88 |   }
 | 
|---|
| [af2c424] | 89 |   set.GoToFirst();
 | 
|---|
 | 90 |   while (!set.IsEnd()) {
 | 
|---|
 | 91 |     Walker = set.GetPoint();
 | 
|---|
| [042f82] | 92 |     for (int i=0;i<NDIM;i++) {
 | 
|---|
| [d74077] | 93 |       if (max[i] < Walker->at(i))
 | 
|---|
 | 94 |         max[i] = Walker->at(i);
 | 
|---|
 | 95 |       if (min[i] > Walker->at(i))
 | 
|---|
 | 96 |         min[i] = Walker->at(i);
 | 
|---|
| [042f82] | 97 |     }
 | 
|---|
| [af2c424] | 98 |     set.GoToNext();
 | 
|---|
| [042f82] | 99 |   }
 | 
|---|
| [47d041] | 100 |   LOG(2, "Bounding box is " << min << " and " << max << ".");
 | 
|---|
| [6ac7ee] | 101 | 
 | 
|---|
| [357fba] | 102 |   // 2. find then number of cells per axis
 | 
|---|
| [042f82] | 103 |   for (int i=0;i<NDIM;i++) {
 | 
|---|
| [0a4f7f] | 104 |     N[i] = static_cast<int>(floor((max[i] - min[i])/RADIUS)+1);
 | 
|---|
| [042f82] | 105 |   }
 | 
|---|
| [47d041] | 106 |   LOG(2, "Number of cells per axis are " << N[0] << ", " << N[1] << " and " << N[2] << ".");
 | 
|---|
| [6ac7ee] | 107 | 
 | 
|---|
| [042f82] | 108 |   // 3. allocate the lists
 | 
|---|
| [47d041] | 109 |   LOG(2, "INFO: Allocating cells ... ");
 | 
|---|
| [042f82] | 110 |   if (LC != NULL) {
 | 
|---|
| [47d041] | 111 |     ELOG(1, "Linked Cell list is already allocated, I do nothing.");
 | 
|---|
| [042f82] | 112 |     return;
 | 
|---|
 | 113 |   }
 | 
|---|
| [c66537] | 114 |   ASSERT(N[0]*N[1]*N[2] < MAX_LINKEDCELLNODES, "Number linked of linked cell nodes exceded hard-coded limit, use greater edge length!");
 | 
|---|
| [34c43a] | 115 |   LC = new TesselPointSTLList[N[0]*N[1]*N[2]];
 | 
|---|
| [042f82] | 116 |   for (index=0;index<N[0]*N[1]*N[2];index++) {
 | 
|---|
 | 117 |     LC [index].clear();
 | 
|---|
 | 118 |   }
 | 
|---|
| [47d041] | 119 |   LOG(0, "done.");
 | 
|---|
| [6ac7ee] | 120 | 
 | 
|---|
| [042f82] | 121 |   // 4. put each atom into its respective cell
 | 
|---|
| [47d041] | 122 |   LOG(2, "INFO: Filling cells ... ");
 | 
|---|
| [af2c424] | 123 |   set.GoToFirst();
 | 
|---|
 | 124 |   while (!set.IsEnd()) {
 | 
|---|
 | 125 |     Walker = set.GetPoint();
 | 
|---|
| [042f82] | 126 |     for (int i=0;i<NDIM;i++) {
 | 
|---|
| [d74077] | 127 |       n[i] = static_cast<int>(floor((Walker->at(i) - min[i])/RADIUS));
 | 
|---|
| [042f82] | 128 |     }
 | 
|---|
 | 129 |     index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2];
 | 
|---|
 | 130 |     LC[index].push_back(Walker);
 | 
|---|
| [47d041] | 131 |     //LOG(2, *Walker << " goes into cell " << n[0] << ", " << n[1] << ", " << n[2] << " with No. " << index << ".");
 | 
|---|
| [af2c424] | 132 |     set.GoToNext();
 | 
|---|
| [042f82] | 133 |   }
 | 
|---|
| [47d041] | 134 |   LOG(0, "done.");
 | 
|---|
 | 135 |   LOG(1, "End of LinkedCell");
 | 
|---|
| [e1bc68] | 136 | };
 | 
|---|
 | 137 | 
 | 
|---|
| [8cd903] | 138 | 
 | 
|---|
| [6bd7e0] | 139 | /** Destructor for class LinkedCell_deprecated.
 | 
|---|
| [e1bc68] | 140 |  */
 | 
|---|
| [6bd7e0] | 141 | LinkedCell_deprecated::~LinkedCell_deprecated()
 | 
|---|
| [e1bc68] | 142 | {
 | 
|---|
| [042f82] | 143 |   if (LC != NULL)
 | 
|---|
 | 144 |   for (index=0;index<N[0]*N[1]*N[2];index++)
 | 
|---|
 | 145 |     LC[index].clear();
 | 
|---|
 | 146 |   delete[](LC);
 | 
|---|
 | 147 |   for(int i=0;i<NDIM;i++)
 | 
|---|
 | 148 |     N[i] = 0;
 | 
|---|
 | 149 |   index = -1;
 | 
|---|
| [e1bc68] | 150 | };
 | 
|---|
 | 151 | 
 | 
|---|
| [6bd7e0] | 152 | /** Checks whether LinkedCell_deprecated::n[] is each within [0,N[]].
 | 
|---|
| [e1bc68] | 153 |  * \return if all in intervals - true, else -false
 | 
|---|
 | 154 |  */
 | 
|---|
| [6bd7e0] | 155 | bool LinkedCell_deprecated::CheckBounds() const
 | 
|---|
| [e1bc68] | 156 | {
 | 
|---|
| [042f82] | 157 |   bool status = true;
 | 
|---|
 | 158 |   for(int i=0;i<NDIM;i++)
 | 
|---|
 | 159 |     status = status && ((n[i] >=0) && (n[i] < N[i]));
 | 
|---|
| [bdc91e] | 160 | //  if (!status)
 | 
|---|
| [47d041] | 161 | //    ELOG(1, "indices are out of bounds!");
 | 
|---|
| [042f82] | 162 |   return status;
 | 
|---|
| [e1bc68] | 163 | };
 | 
|---|
 | 164 | 
 | 
|---|
| [6bd7e0] | 165 | /** Checks whether LinkedCell_deprecated::n[] plus relative offset is each within [0,N[]].
 | 
|---|
| [266237] | 166 |  * Note that for this check we don't admonish if out of bounds.
 | 
|---|
| [07051c] | 167 |  * \param relative[NDIM] relative offset to current cell
 | 
|---|
 | 168 |  * \return if all in intervals - true, else -false
 | 
|---|
 | 169 |  */
 | 
|---|
| [6bd7e0] | 170 | bool LinkedCell_deprecated::CheckBounds(const int relative[NDIM]) const
 | 
|---|
| [07051c] | 171 | {
 | 
|---|
 | 172 |   bool status = true;
 | 
|---|
 | 173 |   for(int i=0;i<NDIM;i++)
 | 
|---|
 | 174 |     status = status && ((n[i]+relative[i] >=0) && (n[i]+relative[i] < N[i]));
 | 
|---|
 | 175 |   return status;
 | 
|---|
 | 176 | };
 | 
|---|
 | 177 | 
 | 
|---|
| [e1bc68] | 178 | 
 | 
|---|
 | 179 | /** Returns a pointer to the current cell.
 | 
|---|
| [6bd7e0] | 180 |  * \return LinkedAtoms pointer to current cell, NULL if LinkedCell_deprecated::n[] are out of bounds.
 | 
|---|
| [e1bc68] | 181 |  */
 | 
|---|
| [6bd7e0] | 182 | const TesselPointSTLList* LinkedCell_deprecated::GetCurrentCell() const
 | 
|---|
| [e1bc68] | 183 | {
 | 
|---|
| [042f82] | 184 |   if (CheckBounds()) {
 | 
|---|
 | 185 |     index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2];
 | 
|---|
 | 186 |     return (&(LC[index]));
 | 
|---|
 | 187 |   } else {
 | 
|---|
 | 188 |     return NULL;
 | 
|---|
 | 189 |   }
 | 
|---|
| [e1bc68] | 190 | };
 | 
|---|
 | 191 | 
 | 
|---|
| [07051c] | 192 | /** Returns a pointer to the current cell.
 | 
|---|
| [6bd7e0] | 193 |  * \param relative[NDIM] offset for each axis with respect to the current cell LinkedCell_deprecated::n[NDIM]
 | 
|---|
 | 194 |  * \return LinkedAtoms pointer to current cell, NULL if LinkedCell_deprecated::n[]+relative[] are out of bounds.
 | 
|---|
| [07051c] | 195 |  */
 | 
|---|
| [6bd7e0] | 196 | const TesselPointSTLList* LinkedCell_deprecated::GetRelativeToCurrentCell(const int relative[NDIM]) const
 | 
|---|
| [07051c] | 197 | {
 | 
|---|
 | 198 |   if (CheckBounds(relative)) {
 | 
|---|
 | 199 |     index = (n[0]+relative[0]) * N[1] * N[2] + (n[1]+relative[1]) * N[2] + (n[2]+relative[2]);
 | 
|---|
 | 200 |     return (&(LC[index]));
 | 
|---|
 | 201 |   } else {
 | 
|---|
 | 202 |     return NULL;
 | 
|---|
 | 203 |   }
 | 
|---|
 | 204 | };
 | 
|---|
 | 205 | 
 | 
|---|
| [893bea] | 206 | /** Set the index to the cell containing a given Vector *x.
 | 
|---|
 | 207 |  * \param *x Vector with coordinates
 | 
|---|
 | 208 |  * \return Vector is inside bounding box - true, else - false
 | 
|---|
 | 209 |  */
 | 
|---|
| [6bd7e0] | 210 | bool LinkedCell_deprecated::SetIndexToVector(const Vector & x) const
 | 
|---|
| [893bea] | 211 | {
 | 
|---|
 | 212 |   for (int i=0;i<NDIM;i++)
 | 
|---|
| [d74077] | 213 |     n[i] = (int)floor((x.at(i) - min[i])/RADIUS);
 | 
|---|
| [893bea] | 214 | 
 | 
|---|
 | 215 |   return CheckBounds();
 | 
|---|
 | 216 | };
 | 
|---|
 | 217 | 
 | 
|---|
| [357fba] | 218 | /** Calculates the index for a given LCNode *Walker.
 | 
|---|
 | 219 |  * \param *Walker LCNode to set index tos
 | 
|---|
| [e1bc68] | 220 |  * \return if the atom is also found in this cell - true, else - false
 | 
|---|
 | 221 |  */
 | 
|---|
| [6bd7e0] | 222 | bool LinkedCell_deprecated::SetIndexToNode(const TesselPoint * const Walker) const
 | 
|---|
| [e1bc68] | 223 | {
 | 
|---|
| [042f82] | 224 |   bool status = false;
 | 
|---|
 | 225 |   for (int i=0;i<NDIM;i++) {
 | 
|---|
| [d74077] | 226 |     n[i] = static_cast<int>(floor((Walker->at(i) - min[i])/RADIUS));
 | 
|---|
| [042f82] | 227 |   }
 | 
|---|
 | 228 |   index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2];
 | 
|---|
 | 229 |   if (CheckBounds()) {
 | 
|---|
| [34c43a] | 230 |     for (TesselPointSTLList::iterator Runner = LC[index].begin(); Runner != LC[index].end(); Runner++)
 | 
|---|
| [042f82] | 231 |       status = status || ((*Runner) == Walker);
 | 
|---|
 | 232 |     return status;
 | 
|---|
 | 233 |   } else {
 | 
|---|
| [47d041] | 234 |     ELOG(1, "Node at " << *Walker << " is out of bounds.");
 | 
|---|
| [042f82] | 235 |     return false;
 | 
|---|
 | 236 |   }
 | 
|---|
| [e1bc68] | 237 | };
 | 
|---|
 | 238 | 
 | 
|---|
| [0f4538] | 239 | /** Calculates the interval bounds of the linked cell grid.
 | 
|---|
| [bdc91e] | 240 |  * \param lower lower bounds
 | 
|---|
 | 241 |  * \param upper upper bounds
 | 
|---|
| [061b06] | 242 |  * \param step how deep to check the neighbouring cells (i.e. number of layers to check)
 | 
|---|
| [0f4538] | 243 |  */
 | 
|---|
| [6bd7e0] | 244 | void LinkedCell_deprecated::GetNeighbourBounds(int lower[NDIM], int upper[NDIM], int step) const
 | 
|---|
| [0f4538] | 245 | {
 | 
|---|
 | 246 |   for (int i=0;i<NDIM;i++) {
 | 
|---|
| [bdc91e] | 247 |     lower[i] = n[i]-step;
 | 
|---|
 | 248 |     if (lower[i] < 0)
 | 
|---|
 | 249 |       lower[i] = 0;
 | 
|---|
 | 250 |     if (lower[i] >= N[i])
 | 
|---|
 | 251 |       lower[i] = N[i]-1;
 | 
|---|
 | 252 |     upper[i] = n[i]+step;
 | 
|---|
 | 253 |     if (upper[i] >= N[i])
 | 
|---|
 | 254 |       upper[i] = N[i]-1;
 | 
|---|
 | 255 |     if (upper[i] < 0)
 | 
|---|
 | 256 |       upper[i] = 0;
 | 
|---|
| [47d041] | 257 |     //LOG(0, "axis " << i << " has bounds [" << lower[i] << "," << upper[i] << "]");
 | 
|---|
| [0f4538] | 258 |   }
 | 
|---|
 | 259 | };
 | 
|---|
 | 260 | 
 | 
|---|
| [6bd7e0] | 261 | /** Returns a list with all neighbours from the current LinkedCell_deprecated::index.
 | 
|---|
| [734816] | 262 |  * \param distance (if no distance, then adjacent cells are taken)
 | 
|---|
 | 263 |  * \return list of tesselpoints
 | 
|---|
 | 264 |  */
 | 
|---|
| [6bd7e0] | 265 | TesselPointSTLList* LinkedCell_deprecated::GetallNeighbours(const double distance) const
 | 
|---|
| [734816] | 266 | {
 | 
|---|
| [893bea] | 267 |   int Nlower[NDIM], Nupper[NDIM];
 | 
|---|
| [734816] | 268 |   TesselPoint *Walker = NULL;
 | 
|---|
| [34c43a] | 269 |   TesselPointSTLList *TesselList = new TesselPointSTLList;
 | 
|---|
| [734816] | 270 | 
 | 
|---|
 | 271 |   // then go through the current and all neighbouring cells and check the contained points for possible candidates
 | 
|---|
| [893bea] | 272 |   const int step = (distance == 0) ? 1 : (int)floor(distance/RADIUS + 1.);
 | 
|---|
 | 273 |   GetNeighbourBounds(Nlower, Nupper, step);
 | 
|---|
 | 274 | 
 | 
|---|
| [734816] | 275 |   for (n[0] = Nlower[0]; n[0] <= Nupper[0]; n[0]++)
 | 
|---|
 | 276 |     for (n[1] = Nlower[1]; n[1] <= Nupper[1]; n[1]++)
 | 
|---|
 | 277 |       for (n[2] = Nlower[2]; n[2] <= Nupper[2]; n[2]++) {
 | 
|---|
| [34c43a] | 278 |         const TesselPointSTLList *List = GetCurrentCell();
 | 
|---|
| [47d041] | 279 |         //LOG(1, "Current cell is " << n[0] << ", " << n[1] << ", " << n[2] << " with No. " << index << ".");
 | 
|---|
| [734816] | 280 |         if (List != NULL) {
 | 
|---|
| [34c43a] | 281 |           for (TesselPointSTLList::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
 | 
|---|
| [734816] | 282 |             Walker = *Runner;
 | 
|---|
 | 283 |             TesselList->push_back(Walker);
 | 
|---|
 | 284 |           }
 | 
|---|
 | 285 |         }
 | 
|---|
 | 286 |       }
 | 
|---|
 | 287 |   return TesselList;
 | 
|---|
 | 288 | };
 | 
|---|
 | 289 | 
 | 
|---|
| [6bd7e0] | 290 | /** Set the index to the cell containing a given Vector *x, which is not inside the LinkedCell_deprecated's domain
 | 
|---|
| [ffe885] | 291 |  * Note that as we have to check distance from every corner of the closest cell, this function is faw more
 | 
|---|
| [6bd7e0] | 292 |  * expensive and if Vector is known to be inside LinkedCell_deprecated's domain, then SetIndexToVector() should be used.
 | 
|---|
| [ffe885] | 293 |  * \param *x Vector with coordinates
 | 
|---|
 | 294 |  * \return minimum squared distance of cell to given vector (if inside of domain, distance is 0)
 | 
|---|
 | 295 |  */
 | 
|---|
| [6bd7e0] | 296 | double LinkedCell_deprecated::SetClosestIndexToOutsideVector(const Vector * const x) const
 | 
|---|
| [ffe885] | 297 | {
 | 
|---|
 | 298 |   for (int i=0;i<NDIM;i++) {
 | 
|---|
| [8cbb97] | 299 |     n[i] = (int)floor((x->at(i) - min[i])/RADIUS);
 | 
|---|
| [ffe885] | 300 |     if (n[i] < 0)
 | 
|---|
 | 301 |       n[i] = 0;
 | 
|---|
 | 302 |     if (n[i] >= N[i])
 | 
|---|
 | 303 |       n[i] = N[i]-1;
 | 
|---|
 | 304 |   }
 | 
|---|
 | 305 | 
 | 
|---|
 | 306 |   // calculate distance of cell to vector
 | 
|---|
 | 307 |   double distanceSquared = 0.;
 | 
|---|
| [6bd7e0] | 308 |   bool outside = true;  // flag whether x is found in- or outside of LinkedCell_deprecated's domain/closest cell
 | 
|---|
| [ffe885] | 309 |   Vector corner; // current corner of closest cell
 | 
|---|
 | 310 |   Vector tester; // Vector pointing from corner to center of closest cell
 | 
|---|
 | 311 |   Vector Distance;  // Vector from corner of closest cell to x
 | 
|---|
 | 312 | 
 | 
|---|
 | 313 |   Vector center;  // center of the closest cell
 | 
|---|
 | 314 |   for (int i=0;i<NDIM;i++)
 | 
|---|
| [8cbb97] | 315 |     center[i] = min[i]+((double)n[i]+.5)*RADIUS;
 | 
|---|
| [ffe885] | 316 | 
 | 
|---|
 | 317 |   int c[NDIM];
 | 
|---|
 | 318 |   for (c[0]=0;c[0]<=1;c[0]++)
 | 
|---|
 | 319 |     for (c[1]=0; c[1]<=1;c[1]++)
 | 
|---|
 | 320 |       for (c[2]=0; c[2]<=1;c[2]++) {
 | 
|---|
 | 321 |         // set up corner
 | 
|---|
 | 322 |         for (int i=0;i<NDIM;i++)
 | 
|---|
| [8cbb97] | 323 |           corner[i] = min[i]+RADIUS*((double)n[i]+c[i]);
 | 
|---|
| [ffe885] | 324 |         // set up distance vector
 | 
|---|
| [8cbb97] | 325 |         Distance = (*x) - corner;
 | 
|---|
| [ffe885] | 326 |         const double dist = Distance.NormSquared();
 | 
|---|
 | 327 |         // check whether distance is smaller
 | 
|---|
 | 328 |         if (dist< distanceSquared)
 | 
|---|
 | 329 |           distanceSquared = dist;
 | 
|---|
 | 330 |         // check whether distance vector goes inside or outside
 | 
|---|
| [8cbb97] | 331 |         tester = center -corner;
 | 
|---|
 | 332 |         if (tester.ScalarProduct(Distance) < 0)
 | 
|---|
| [ffe885] | 333 |           outside = false;
 | 
|---|
 | 334 |       }
 | 
|---|
 | 335 |   return (outside ? distanceSquared : 0.);
 | 
|---|
 | 336 | };
 | 
|---|
| [734816] | 337 | 
 | 
|---|
 | 338 | /** Returns a list of all TesselPoint with distance less than \a radius to \a *Center.
 | 
|---|
 | 339 |  * \param radius radius of sphere
 | 
|---|
 | 340 |  * \param *center center of sphere
 | 
|---|
 | 341 |  * \return list of all points inside sphere
 | 
|---|
 | 342 |  */
 | 
|---|
| [6bd7e0] | 343 | TesselPointSTLList* LinkedCell_deprecated::GetPointsInsideSphere(const double radius, const Vector * const center) const
 | 
|---|
| [734816] | 344 | {
 | 
|---|
 | 345 |   const double radiusSquared = radius*radius;
 | 
|---|
 | 346 |   TesselPoint *Walker = NULL;
 | 
|---|
| [34c43a] | 347 |   TesselPointSTLList *TesselList = new TesselPointSTLList;
 | 
|---|
 | 348 |   TesselPointSTLList *NeighbourList = NULL;
 | 
|---|
| [734816] | 349 | 
 | 
|---|
| [893bea] | 350 |   // set index of LC to center of sphere
 | 
|---|
| [ffe885] | 351 |   const double dist = SetClosestIndexToOutsideVector(center);
 | 
|---|
| [061b06] | 352 |   if (dist > 2.*radius) {
 | 
|---|
| [47d041] | 353 |     ELOG(1, "Vector " << *center << " is too far away from any atom in LinkedCell's bounding box.");
 | 
|---|
| [734816] | 354 |     return TesselList;
 | 
|---|
| [061b06] | 355 |   } else
 | 
|---|
| [ce7bfd] | 356 |     LOG(3, "DEBUG: Distance of closest cell to center of sphere with radius " << radius << " is " << dist << ".");
 | 
|---|
| [893bea] | 357 | 
 | 
|---|
 | 358 |   // gather all neighbours first, then look who fulfills distance criteria
 | 
|---|
| [061b06] | 359 |   NeighbourList = GetallNeighbours(2.*radius-dist);
 | 
|---|
| [47d041] | 360 |   //LOG(1, "I found " << NeighbourList->size() << " neighbours to check.");
 | 
|---|
| [893bea] | 361 |   if (NeighbourList != NULL) {
 | 
|---|
| [34c43a] | 362 |     for (TesselPointSTLList::const_iterator Runner = NeighbourList->begin(); Runner != NeighbourList->end(); Runner++) {
 | 
|---|
| [893bea] | 363 |       Walker = *Runner;
 | 
|---|
| [47d041] | 364 |       //LOG(1, "Current neighbour is at " << *Walker->node << ".");
 | 
|---|
| [d74077] | 365 |       if ((Walker->DistanceSquared(*center) - radiusSquared) < MYEPSILON) {
 | 
|---|
| [893bea] | 366 |         TesselList->push_back(Walker);
 | 
|---|
| [734816] | 367 |       }
 | 
|---|
| [893bea] | 368 |     }
 | 
|---|
 | 369 |     delete(NeighbourList);
 | 
|---|
 | 370 |   } else
 | 
|---|
| [47d041] | 371 |     ELOG(2, "Around vector " << *center << " there are no atoms.");
 | 
|---|
| [734816] | 372 |   return TesselList;
 | 
|---|
 | 373 | };
 | 
|---|