| 1 | /* | 
|---|
| 2 | * analysis.cpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: Oct 13, 2009 | 
|---|
| 5 | *      Author: heber | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | #include <iostream> | 
|---|
| 9 |  | 
|---|
| 10 | #include "analysis_correlation.hpp" | 
|---|
| 11 | #include "element.hpp" | 
|---|
| 12 | #include "info.hpp" | 
|---|
| 13 | #include "log.hpp" | 
|---|
| 14 | #include "molecule.hpp" | 
|---|
| 15 | #include "tesselation.hpp" | 
|---|
| 16 | #include "tesselationhelpers.hpp" | 
|---|
| 17 | #include "triangleintersectionlist.hpp" | 
|---|
| 18 | #include "vector.hpp" | 
|---|
| 19 | #include "verbose.hpp" | 
|---|
| 20 |  | 
|---|
| 21 |  | 
|---|
| 22 | /** Calculates the pair correlation between given elements. | 
|---|
| 23 | * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si)) | 
|---|
| 24 | * \param *out output stream for debugging | 
|---|
| 25 | * \param *molecules list of molecules structure | 
|---|
| 26 | * \param *type1 first element or NULL (if any element) | 
|---|
| 27 | * \param *type2 second element or NULL (if any element) | 
|---|
| 28 | * \return Map of doubles with values the pair of the two atoms. | 
|---|
| 29 | */ | 
|---|
| 30 | PairCorrelationMap *PairCorrelation(MoleculeListClass * const &molecules, const element * const type1, const element * const type2 ) | 
|---|
| 31 | { | 
|---|
| 32 | Info FunctionInfo(__func__); | 
|---|
| 33 | PairCorrelationMap *outmap = NULL; | 
|---|
| 34 | double distance = 0.; | 
|---|
| 35 |  | 
|---|
| 36 | if (molecules->ListOfMolecules.empty()) { | 
|---|
| 37 | eLog() << Verbose(1) <<"No molecule given." << endl; | 
|---|
| 38 | return outmap; | 
|---|
| 39 | } | 
|---|
| 40 | outmap = new PairCorrelationMap; | 
|---|
| 41 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++) | 
|---|
| 42 | if ((*MolWalker)->ActiveFlag) { | 
|---|
| 43 | eLog() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl; | 
|---|
| 44 | atom *Walker = (*MolWalker)->start; | 
|---|
| 45 | while (Walker->next != (*MolWalker)->end) { | 
|---|
| 46 | Walker = Walker->next; | 
|---|
| 47 | Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl; | 
|---|
| 48 | if ((type1 == NULL) || (Walker->type == type1)) { | 
|---|
| 49 | for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++) | 
|---|
| 50 | if ((*MolOtherWalker)->ActiveFlag) { | 
|---|
| 51 | Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl; | 
|---|
| 52 | atom *OtherWalker = (*MolOtherWalker)->start; | 
|---|
| 53 | while (OtherWalker->next != (*MolOtherWalker)->end) { // only go up to Walker | 
|---|
| 54 | OtherWalker = OtherWalker->next; | 
|---|
| 55 | Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl; | 
|---|
| 56 | if (Walker->nr < OtherWalker->nr) | 
|---|
| 57 | if ((type2 == NULL) || (OtherWalker->type == type2)) { | 
|---|
| 58 | distance = Walker->node->PeriodicDistance(OtherWalker->node, (*MolWalker)->cell_size); | 
|---|
| 59 | //Log() << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl; | 
|---|
| 60 | outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) ); | 
|---|
| 61 | } | 
|---|
| 62 | } | 
|---|
| 63 | } | 
|---|
| 64 | } | 
|---|
| 65 | } | 
|---|
| 66 | } | 
|---|
| 67 |  | 
|---|
| 68 | return outmap; | 
|---|
| 69 | }; | 
|---|
| 70 |  | 
|---|
| 71 | /** Calculates the pair correlation between given elements. | 
|---|
| 72 | * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si)) | 
|---|
| 73 | * \param *out output stream for debugging | 
|---|
| 74 | * \param *molecules list of molecules structure | 
|---|
| 75 | * \param *type1 first element or NULL (if any element) | 
|---|
| 76 | * \param *type2 second element or NULL (if any element) | 
|---|
| 77 | * \param ranges[NDIM] interval boundaries for the periodic images to scan also | 
|---|
| 78 | * \return Map of doubles with values the pair of the two atoms. | 
|---|
| 79 | */ | 
|---|
| 80 | PairCorrelationMap *PeriodicPairCorrelation(MoleculeListClass * const &molecules, const element * const type1, const element * const type2, const int ranges[NDIM] ) | 
|---|
| 81 | { | 
|---|
| 82 | Info FunctionInfo(__func__); | 
|---|
| 83 | PairCorrelationMap *outmap = NULL; | 
|---|
| 84 | double distance = 0.; | 
|---|
| 85 | int n[NDIM]; | 
|---|
| 86 | Vector checkX; | 
|---|
| 87 | Vector periodicX; | 
|---|
| 88 | int Othern[NDIM]; | 
|---|
| 89 | Vector checkOtherX; | 
|---|
| 90 | Vector periodicOtherX; | 
|---|
| 91 |  | 
|---|
| 92 | if (molecules->ListOfMolecules.empty()) { | 
|---|
| 93 | eLog() << Verbose(1) <<"No molecule given." << endl; | 
|---|
| 94 | return outmap; | 
|---|
| 95 | } | 
|---|
| 96 | outmap = new PairCorrelationMap; | 
|---|
| 97 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++) | 
|---|
| 98 | if ((*MolWalker)->ActiveFlag) { | 
|---|
| 99 | double * FullMatrix = ReturnFullMatrixforSymmetric((*MolWalker)->cell_size); | 
|---|
| 100 | double * FullInverseMatrix = InverseMatrix(FullMatrix); | 
|---|
| 101 | eLog() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl; | 
|---|
| 102 | atom *Walker = (*MolWalker)->start; | 
|---|
| 103 | while (Walker->next != (*MolWalker)->end) { | 
|---|
| 104 | Walker = Walker->next; | 
|---|
| 105 | Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl; | 
|---|
| 106 | if ((type1 == NULL) || (Walker->type == type1)) { | 
|---|
| 107 | periodicX.CopyVector(Walker->node); | 
|---|
| 108 | periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3 | 
|---|
| 109 | // go through every range in xyz and get distance | 
|---|
| 110 | for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++) | 
|---|
| 111 | for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++) | 
|---|
| 112 | for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) { | 
|---|
| 113 | checkX.Init(n[0], n[1], n[2]); | 
|---|
| 114 | checkX.AddVector(&periodicX); | 
|---|
| 115 | checkX.MatrixMultiplication(FullMatrix); | 
|---|
| 116 | for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++) | 
|---|
| 117 | if ((*MolOtherWalker)->ActiveFlag) { | 
|---|
| 118 | Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl; | 
|---|
| 119 | atom *OtherWalker = (*MolOtherWalker)->start; | 
|---|
| 120 | while (OtherWalker->next != (*MolOtherWalker)->end) { // only go up to Walker | 
|---|
| 121 | OtherWalker = OtherWalker->next; | 
|---|
| 122 | Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl; | 
|---|
| 123 | if (Walker->nr < OtherWalker->nr) | 
|---|
| 124 | if ((type2 == NULL) || (OtherWalker->type == type2)) { | 
|---|
| 125 | periodicOtherX.CopyVector(OtherWalker->node); | 
|---|
| 126 | periodicOtherX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3 | 
|---|
| 127 | // go through every range in xyz and get distance | 
|---|
| 128 | for (Othern[0]=-ranges[0]; Othern[0] <= ranges[0]; Othern[0]++) | 
|---|
| 129 | for (Othern[1]=-ranges[1]; Othern[1] <= ranges[1]; Othern[1]++) | 
|---|
| 130 | for (Othern[2]=-ranges[2]; Othern[2] <= ranges[2]; Othern[2]++) { | 
|---|
| 131 | checkOtherX.Init(Othern[0], Othern[1], Othern[2]); | 
|---|
| 132 | checkOtherX.AddVector(&periodicOtherX); | 
|---|
| 133 | checkOtherX.MatrixMultiplication(FullMatrix); | 
|---|
| 134 | distance = checkX.Distance(&checkOtherX); | 
|---|
| 135 | //Log() << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl; | 
|---|
| 136 | outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) ); | 
|---|
| 137 | } | 
|---|
| 138 | } | 
|---|
| 139 | } | 
|---|
| 140 | } | 
|---|
| 141 | } | 
|---|
| 142 | } | 
|---|
| 143 | } | 
|---|
| 144 | Free(&FullMatrix); | 
|---|
| 145 | Free(&FullInverseMatrix); | 
|---|
| 146 | } | 
|---|
| 147 |  | 
|---|
| 148 | return outmap; | 
|---|
| 149 | }; | 
|---|
| 150 |  | 
|---|
| 151 | /** Calculates the distance (pair) correlation between a given element and a point. | 
|---|
| 152 | * \param *out output stream for debugging | 
|---|
| 153 | * \param *molecules list of molecules structure | 
|---|
| 154 | * \param *type element or NULL (if any element) | 
|---|
| 155 | * \param *point vector to the correlation point | 
|---|
| 156 | * \return Map of dobules with values as pairs of atom and the vector | 
|---|
| 157 | */ | 
|---|
| 158 | CorrelationToPointMap *CorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point ) | 
|---|
| 159 | { | 
|---|
| 160 | Info FunctionInfo(__func__); | 
|---|
| 161 | CorrelationToPointMap *outmap = NULL; | 
|---|
| 162 | double distance = 0.; | 
|---|
| 163 |  | 
|---|
| 164 | if (molecules->ListOfMolecules.empty()) { | 
|---|
| 165 | Log() << Verbose(1) <<"No molecule given." << endl; | 
|---|
| 166 | return outmap; | 
|---|
| 167 | } | 
|---|
| 168 | outmap = new CorrelationToPointMap; | 
|---|
| 169 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++) | 
|---|
| 170 | if ((*MolWalker)->ActiveFlag) { | 
|---|
| 171 | Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl; | 
|---|
| 172 | atom *Walker = (*MolWalker)->start; | 
|---|
| 173 | while (Walker->next != (*MolWalker)->end) { | 
|---|
| 174 | Walker = Walker->next; | 
|---|
| 175 | Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl; | 
|---|
| 176 | if ((type == NULL) || (Walker->type == type)) { | 
|---|
| 177 | distance = Walker->node->PeriodicDistance(point, (*MolWalker)->cell_size); | 
|---|
| 178 | Log() << Verbose(4) << "Current distance is " << distance << "." << endl; | 
|---|
| 179 | outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) ); | 
|---|
| 180 | } | 
|---|
| 181 | } | 
|---|
| 182 | } | 
|---|
| 183 |  | 
|---|
| 184 | return outmap; | 
|---|
| 185 | }; | 
|---|
| 186 |  | 
|---|
| 187 | /** Calculates the distance (pair) correlation between a given element, all its periodic images and a point. | 
|---|
| 188 | * \param *out output stream for debugging | 
|---|
| 189 | * \param *molecules list of molecules structure | 
|---|
| 190 | * \param *type element or NULL (if any element) | 
|---|
| 191 | * \param *point vector to the correlation point | 
|---|
| 192 | * \param ranges[NDIM] interval boundaries for the periodic images to scan also | 
|---|
| 193 | * \return Map of dobules with values as pairs of atom and the vector | 
|---|
| 194 | */ | 
|---|
| 195 | CorrelationToPointMap *PeriodicCorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point, const int ranges[NDIM] ) | 
|---|
| 196 | { | 
|---|
| 197 | Info FunctionInfo(__func__); | 
|---|
| 198 | CorrelationToPointMap *outmap = NULL; | 
|---|
| 199 | double distance = 0.; | 
|---|
| 200 | int n[NDIM]; | 
|---|
| 201 | Vector periodicX; | 
|---|
| 202 | Vector checkX; | 
|---|
| 203 |  | 
|---|
| 204 | if (molecules->ListOfMolecules.empty()) { | 
|---|
| 205 | Log() << Verbose(1) <<"No molecule given." << endl; | 
|---|
| 206 | return outmap; | 
|---|
| 207 | } | 
|---|
| 208 | outmap = new CorrelationToPointMap; | 
|---|
| 209 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++) | 
|---|
| 210 | if ((*MolWalker)->ActiveFlag) { | 
|---|
| 211 | double * FullMatrix = ReturnFullMatrixforSymmetric((*MolWalker)->cell_size); | 
|---|
| 212 | double * FullInverseMatrix = InverseMatrix(FullMatrix); | 
|---|
| 213 | Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl; | 
|---|
| 214 | atom *Walker = (*MolWalker)->start; | 
|---|
| 215 | while (Walker->next != (*MolWalker)->end) { | 
|---|
| 216 | Walker = Walker->next; | 
|---|
| 217 | Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl; | 
|---|
| 218 | if ((type == NULL) || (Walker->type == type)) { | 
|---|
| 219 | periodicX.CopyVector(Walker->node); | 
|---|
| 220 | periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3 | 
|---|
| 221 | // go through every range in xyz and get distance | 
|---|
| 222 | for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++) | 
|---|
| 223 | for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++) | 
|---|
| 224 | for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) { | 
|---|
| 225 | checkX.Init(n[0], n[1], n[2]); | 
|---|
| 226 | checkX.AddVector(&periodicX); | 
|---|
| 227 | checkX.MatrixMultiplication(FullMatrix); | 
|---|
| 228 | distance = checkX.Distance(point); | 
|---|
| 229 | Log() << Verbose(4) << "Current distance is " << distance << "." << endl; | 
|---|
| 230 | outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) ); | 
|---|
| 231 | } | 
|---|
| 232 | } | 
|---|
| 233 | } | 
|---|
| 234 | Free(&FullMatrix); | 
|---|
| 235 | Free(&FullInverseMatrix); | 
|---|
| 236 | } | 
|---|
| 237 |  | 
|---|
| 238 | return outmap; | 
|---|
| 239 | }; | 
|---|
| 240 |  | 
|---|
| 241 | /** Calculates the distance (pair) correlation between a given element and a surface. | 
|---|
| 242 | * \param *out output stream for debugging | 
|---|
| 243 | * \param *molecules list of molecules structure | 
|---|
| 244 | * \param *type element or NULL (if any element) | 
|---|
| 245 | * \param *Surface pointer to Tesselation class surface | 
|---|
| 246 | * \param *LC LinkedCell structure to quickly find neighbouring atoms | 
|---|
| 247 | * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest | 
|---|
| 248 | */ | 
|---|
| 249 | CorrelationToSurfaceMap *CorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC ) | 
|---|
| 250 | { | 
|---|
| 251 | Info FunctionInfo(__func__); | 
|---|
| 252 | CorrelationToSurfaceMap *outmap = NULL; | 
|---|
| 253 | double distance = 0; | 
|---|
| 254 | class BoundaryTriangleSet *triangle = NULL; | 
|---|
| 255 | Vector centroid; | 
|---|
| 256 |  | 
|---|
| 257 | if ((Surface == NULL) || (LC == NULL) || (molecules->ListOfMolecules.empty())) { | 
|---|
| 258 | eLog() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl; | 
|---|
| 259 | return outmap; | 
|---|
| 260 | } | 
|---|
| 261 | outmap = new CorrelationToSurfaceMap; | 
|---|
| 262 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++) | 
|---|
| 263 | if ((*MolWalker)->ActiveFlag) { | 
|---|
| 264 | Log() << Verbose(1) << "Current molecule is " << (*MolWalker)->name << "." << endl; | 
|---|
| 265 | atom *Walker = (*MolWalker)->start; | 
|---|
| 266 | while (Walker->next != (*MolWalker)->end) { | 
|---|
| 267 | Walker = Walker->next; | 
|---|
| 268 | //Log() << Verbose(1) << "Current atom is " << *Walker << "." << endl; | 
|---|
| 269 | if ((type == NULL) || (Walker->type == type)) { | 
|---|
| 270 | TriangleIntersectionList Intersections(Walker->node,Surface,LC); | 
|---|
| 271 | distance = Intersections.GetSmallestDistance(); | 
|---|
| 272 | triangle = Intersections.GetClosestTriangle(); | 
|---|
| 273 | outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> (Walker, triangle) ) ); | 
|---|
| 274 | } | 
|---|
| 275 | } | 
|---|
| 276 | } else | 
|---|
| 277 | Log() << Verbose(1) << "molecule " << (*MolWalker)->name << " is not active." << endl; | 
|---|
| 278 |  | 
|---|
| 279 |  | 
|---|
| 280 | return outmap; | 
|---|
| 281 | }; | 
|---|
| 282 |  | 
|---|
| 283 | /** Calculates the distance (pair) correlation between a given element, all its periodic images and and a surface. | 
|---|
| 284 | * Note that we also put all periodic images found in the cells given by [ -ranges[i], ranges[i] ] and i=0,...,NDIM-1. | 
|---|
| 285 | * I.e. We multiply the atom::node with the inverse of the domain matrix, i.e. transform it to \f$[0,0^3\f$, then add per | 
|---|
| 286 | * axis an integer from [ -ranges[i], ranges[i] ] onto it and multiply with the domain matrix to bring it back into | 
|---|
| 287 | * the real space. Then, we Tesselation::FindClosestTriangleToPoint() and DistanceToTrianglePlane(). | 
|---|
| 288 | * \param *out output stream for debugging | 
|---|
| 289 | * \param *molecules list of molecules structure | 
|---|
| 290 | * \param *type element or NULL (if any element) | 
|---|
| 291 | * \param *Surface pointer to Tesselation class surface | 
|---|
| 292 | * \param *LC LinkedCell structure to quickly find neighbouring atoms | 
|---|
| 293 | * \param ranges[NDIM] interval boundaries for the periodic images to scan also | 
|---|
| 294 | * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest | 
|---|
| 295 | */ | 
|---|
| 296 | CorrelationToSurfaceMap *PeriodicCorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] ) | 
|---|
| 297 | { | 
|---|
| 298 | Info FunctionInfo(__func__); | 
|---|
| 299 | CorrelationToSurfaceMap *outmap = NULL; | 
|---|
| 300 | double distance = 0; | 
|---|
| 301 | class BoundaryTriangleSet *triangle = NULL; | 
|---|
| 302 | Vector centroid; | 
|---|
| 303 | int n[NDIM]; | 
|---|
| 304 | Vector periodicX; | 
|---|
| 305 | Vector checkX; | 
|---|
| 306 |  | 
|---|
| 307 | if ((Surface == NULL) || (LC == NULL) || (molecules->ListOfMolecules.empty())) { | 
|---|
| 308 | Log() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl; | 
|---|
| 309 | return outmap; | 
|---|
| 310 | } | 
|---|
| 311 | outmap = new CorrelationToSurfaceMap; | 
|---|
| 312 | double ShortestDistance = 0.; | 
|---|
| 313 | BoundaryTriangleSet *ShortestTriangle = NULL; | 
|---|
| 314 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++) | 
|---|
| 315 | if ((*MolWalker)->ActiveFlag) { | 
|---|
| 316 | double * FullMatrix = ReturnFullMatrixforSymmetric((*MolWalker)->cell_size); | 
|---|
| 317 | double * FullInverseMatrix = InverseMatrix(FullMatrix); | 
|---|
| 318 | Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl; | 
|---|
| 319 | atom *Walker = (*MolWalker)->start; | 
|---|
| 320 | while (Walker->next != (*MolWalker)->end) { | 
|---|
| 321 | Walker = Walker->next; | 
|---|
| 322 | Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl; | 
|---|
| 323 | if ((type == NULL) || (Walker->type == type)) { | 
|---|
| 324 | periodicX.CopyVector(Walker->node); | 
|---|
| 325 | periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3 | 
|---|
| 326 | // go through every range in xyz and get distance | 
|---|
| 327 | ShortestDistance = -1.; | 
|---|
| 328 | for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++) | 
|---|
| 329 | for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++) | 
|---|
| 330 | for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) { | 
|---|
| 331 | checkX.Init(n[0], n[1], n[2]); | 
|---|
| 332 | checkX.AddVector(&periodicX); | 
|---|
| 333 | checkX.MatrixMultiplication(FullMatrix); | 
|---|
| 334 | triangle = Surface->FindClosestTriangleToVector(&checkX, LC); | 
|---|
| 335 | distance = Surface->GetDistanceSquaredToTriangle(checkX, triangle); | 
|---|
| 336 | if ((ShortestDistance == -1.) || (distance < ShortestDistance)) { | 
|---|
| 337 | ShortestDistance = distance; | 
|---|
| 338 | ShortestTriangle = triangle; | 
|---|
| 339 | } | 
|---|
| 340 | } | 
|---|
| 341 | // insert | 
|---|
| 342 | ShortestDistance = sqrt(ShortestDistance); | 
|---|
| 343 | outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(ShortestDistance, pair<atom *, BoundaryTriangleSet*> (Walker, ShortestTriangle) ) ); | 
|---|
| 344 | //Log() << Verbose(1) << "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << "." << endl; | 
|---|
| 345 | } | 
|---|
| 346 | } | 
|---|
| 347 | Free(&FullMatrix); | 
|---|
| 348 | Free(&FullInverseMatrix); | 
|---|
| 349 | } | 
|---|
| 350 |  | 
|---|
| 351 | return outmap; | 
|---|
| 352 | }; | 
|---|
| 353 |  | 
|---|
| 354 | /** Returns the start of the bin for a given value. | 
|---|
| 355 | * \param value value whose bin to look for | 
|---|
| 356 | * \param BinWidth width of bin | 
|---|
| 357 | * \param BinStart first bin | 
|---|
| 358 | */ | 
|---|
| 359 | double GetBin ( const double value, const double BinWidth, const double BinStart ) | 
|---|
| 360 | { | 
|---|
| 361 | Info FunctionInfo(__func__); | 
|---|
| 362 | double bin =(double) (floor((value - BinStart)/BinWidth)); | 
|---|
| 363 | return (bin*BinWidth+BinStart); | 
|---|
| 364 | }; | 
|---|
| 365 |  | 
|---|
| 366 |  | 
|---|
| 367 | /** Prints correlation (double, int) pairs to file. | 
|---|
| 368 | * \param *file file to write to | 
|---|
| 369 | * \param *map map to write | 
|---|
| 370 | */ | 
|---|
| 371 | void OutputCorrelation( ofstream * const file, const BinPairMap * const map ) | 
|---|
| 372 | { | 
|---|
| 373 | Info FunctionInfo(__func__); | 
|---|
| 374 | *file << "BinStart\tCount" << endl; | 
|---|
| 375 | for (BinPairMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) { | 
|---|
| 376 | *file << setprecision(8) << runner->first << "\t" << runner->second << endl; | 
|---|
| 377 | } | 
|---|
| 378 | }; | 
|---|
| 379 |  | 
|---|
| 380 | /** Prints correlation (double, (atom*,atom*) ) pairs to file. | 
|---|
| 381 | * \param *file file to write to | 
|---|
| 382 | * \param *map map to write | 
|---|
| 383 | */ | 
|---|
| 384 | void OutputPairCorrelation( ofstream * const file, const PairCorrelationMap * const map ) | 
|---|
| 385 | { | 
|---|
| 386 | Info FunctionInfo(__func__); | 
|---|
| 387 | *file << "BinStart\tAtom1\tAtom2" << endl; | 
|---|
| 388 | for (PairCorrelationMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) { | 
|---|
| 389 | *file << setprecision(8) << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl; | 
|---|
| 390 | } | 
|---|
| 391 | }; | 
|---|
| 392 |  | 
|---|
| 393 | /** Prints correlation (double, int) pairs to file. | 
|---|
| 394 | * \param *file file to write to | 
|---|
| 395 | * \param *map map to write | 
|---|
| 396 | */ | 
|---|
| 397 | void OutputCorrelationToPoint( ofstream * const file, const CorrelationToPointMap * const map ) | 
|---|
| 398 | { | 
|---|
| 399 | Info FunctionInfo(__func__); | 
|---|
| 400 | *file << "BinStart\tAtom::x[i]-point.x[i]" << endl; | 
|---|
| 401 | for (CorrelationToPointMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) { | 
|---|
| 402 | *file << runner->first; | 
|---|
| 403 | for (int i=0;i<NDIM;i++) | 
|---|
| 404 | *file << "\t" << setprecision(8) << (runner->second.first->node->x[i] - runner->second.second->x[i]); | 
|---|
| 405 | *file << endl; | 
|---|
| 406 | } | 
|---|
| 407 | }; | 
|---|
| 408 |  | 
|---|
| 409 | /** Prints correlation (double, int) pairs to file. | 
|---|
| 410 | * \param *file file to write to | 
|---|
| 411 | * \param *map map to write | 
|---|
| 412 | */ | 
|---|
| 413 | void OutputCorrelationToSurface( ofstream * const file, const CorrelationToSurfaceMap * const map ) | 
|---|
| 414 | { | 
|---|
| 415 | Info FunctionInfo(__func__); | 
|---|
| 416 | *file << "BinStart\tTriangle" << endl; | 
|---|
| 417 | if (!map->empty()) | 
|---|
| 418 | for (CorrelationToSurfaceMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) { | 
|---|
| 419 | *file << setprecision(8) << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl; | 
|---|
| 420 | } | 
|---|
| 421 | }; | 
|---|
| 422 |  | 
|---|