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