Changes in src/analysis_correlation.cpp [58bbd3:112b09]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/analysis_correlation.cpp
r58bbd3 r112b09 5 5 * Author: heber 6 6 */ 7 8 #include "Helpers/MemDebug.hpp" 7 9 8 10 #include <iostream> … … 23 25 /** Calculates the pair correlation between given elements. 24 26 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si)) 25 * \param *molecules list of molecules structure 26 * \param &elements vector of elements to correlate 27 * \param *out output stream for debugging 28 * \param *molecules list of molecules structure 29 * \param *type1 first element or NULL (if any element) 30 * \param *type2 second element or NULL (if any element) 27 31 * \return Map of doubles with values the pair of the two atoms. 28 32 */ 29 PairCorrelationMap *PairCorrelation(MoleculeListClass * const &molecules, const std::vector<element *> &elements)33 PairCorrelationMap *PairCorrelation(MoleculeListClass * const &molecules, const element * const type1, const element * const type2 ) 30 34 { 31 35 Info FunctionInfo(__func__); 32 36 PairCorrelationMap *outmap = NULL; 33 37 double distance = 0.; 34 double *domain = World::getInstance().getDomain();35 38 36 39 if (molecules->ListOfMolecules.empty()) { … … 40 43 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++) 41 44 (*MolWalker)->doCountAtoms(); 42 43 // create all possible pairs of elements44 set <pair<element *, element *> > PairsOfElements;45 if (elements.size() >= 2) {46 for (vector<element *>::const_iterator type1 = elements.begin(); type1 != elements.end(); ++type1)47 for (vector<element *>::const_iterator type2 = elements.begin(); type2 != elements.end(); ++type2)48 if (type1 != type2) {49 PairsOfElements.insert( pair<element *, element*>(*type1,*type2) );50 DoLog(1) && (Log() << Verbose(1) << "Creating element pair " << (*type1)->symbol << " and " << (*type2)->symbol << "." << endl);51 }52 } else if (elements.size() == 1) { // one to all are valid53 element *elemental = *elements.begin();54 PairsOfElements.insert( pair<element *, element*>(elemental,(element *)NULL) );55 PairsOfElements.insert( pair<element *, element*>((element *)NULL,elemental) );56 } else { // all elements valid57 PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );58 }59 60 45 outmap = new PairCorrelationMap; 61 46 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++){ … … 65 50 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) { 66 51 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl); 67 for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++){68 if ((*MolOtherWalker)->ActiveFlag){69 DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);70 for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {71 DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);72 if ((*iter)->getId() < (*runner)->getId()){73 for (set <pair<element *, element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)74 if (( PairRunner->first == (**iter).type) && (PairRunner->second == (**runner).type)) {75 distance = (*iter)->node->PeriodicDistance(*(*runner)->node, domain);52 if ((type1 == NULL) || ((*iter)->type == type1)) { 53 for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++){ 54 if ((*MolOtherWalker)->ActiveFlag) { 55 DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl); 56 for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) { 57 DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl); 58 if ((*iter)->getId() < (*runner)->getId()){ 59 if ((type2 == NULL) || ((*runner)->type == type2)) { 60 distance = (*iter)->node->PeriodicDistance(*(*runner)->node, World::getInstance().getDomain()); 76 61 //Log() << Verbose(1) <<"Inserting " << *(*iter) << " and " << *(*runner) << endl; 77 62 outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) ); 78 63 } 64 } 79 65 } 80 66 } … … 89 75 /** Calculates the pair correlation between given elements. 90 76 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si)) 91 * \param *molecules list of molecules structure 92 * \param &elements vector of elements to correlate 77 * \param *out output stream for debugging 78 * \param *molecules list of molecules structure 79 * \param *type1 first element or NULL (if any element) 80 * \param *type2 second element or NULL (if any element) 93 81 * \param ranges[NDIM] interval boundaries for the periodic images to scan also 94 82 * \return Map of doubles with values the pair of the two atoms. 95 83 */ 96 PairCorrelationMap *PeriodicPairCorrelation(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const int ranges[NDIM] )84 PairCorrelationMap *PeriodicPairCorrelation(MoleculeListClass * const &molecules, const element * const type1, const element * const type2, const int ranges[NDIM] ) 97 85 { 98 86 Info FunctionInfo(__func__); … … 112 100 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++) 113 101 (*MolWalker)->doCountAtoms(); 114 115 // create all possible pairs of elements116 set <pair<element *, element *> > PairsOfElements;117 if (elements.size() >= 2) {118 for (vector<element *>::const_iterator type1 = elements.begin(); type1 != elements.end(); ++type1)119 for (vector<element *>::const_iterator type2 = elements.begin(); type2 != elements.end(); ++type2)120 if (type1 != type2) {121 PairsOfElements.insert( pair<element *, element*>(*type1,*type2) );122 DoLog(1) && (Log() << Verbose(1) << "Creating element pair " << (*type1)->symbol << " and " << (*type2)->symbol << "." << endl);123 }124 } else if (elements.size() == 1) { // one to all are valid125 element *elemental = *elements.begin();126 PairsOfElements.insert( pair<element *, element*>(elemental,(element *)NULL) );127 PairsOfElements.insert( pair<element *, element*>((element *)NULL,elemental) );128 } else { // all elements valid129 PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );130 }131 132 102 outmap = new PairCorrelationMap; 133 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++) {103 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++) 134 104 if ((*MolWalker)->ActiveFlag) { 135 105 double * FullMatrix = ReturnFullMatrixforSymmetric(World::getInstance().getDomain()); 136 106 double * FullInverseMatrix = InverseMatrix(FullMatrix); 137 107 DoeLog(2) && (eLog()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl); 138 eLog() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;139 108 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) { 140 109 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl); 141 periodicX = *(*iter)->node;142 periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3143 // go through every range in xyz and get distance144 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)145 for (n[ 1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)146 for (n[ 2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {147 checkX = Vector(n[0], n[1], n[2]) + periodicX;148 checkX.MatrixMultiplication(FullMatrix);149 for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++){150 if ((*MolOtherWalker)->ActiveFlag) {151 DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);152 for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {153 DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);154 if ((*iter)->getId() < (*runner)->getId()){155 for (set <pair<element *, element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)156 if (( PairRunner->first == (**iter).type) && (PairRunner->second == (**runner).type)) {110 if ((type1 == NULL) || ((*iter)->type == type1)) { 111 periodicX = *(*iter)->node; 112 periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3 113 // go through every range in xyz and get distance 114 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++) 115 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++) 116 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) { 117 checkX = Vector(n[0], n[1], n[2]) + periodicX; 118 checkX.MatrixMultiplication(FullMatrix); 119 for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++) 120 if ((*MolOtherWalker)->ActiveFlag) { 121 DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl); 122 for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) { 123 DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl); 124 if ((*iter)->nr < (*runner)->nr) 125 if ((type2 == NULL) || ((*runner)->type == type2)) { 157 126 periodicOtherX = *(*runner)->node; 158 127 periodicOtherX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3 … … 168 137 } 169 138 } 170 }171 139 } 172 }173 140 } 174 141 } 142 } 175 143 } 176 144 delete[](FullMatrix); 177 145 delete[](FullInverseMatrix); 178 146 } 179 }180 147 181 148 return outmap; … … 183 150 184 151 /** Calculates the distance (pair) correlation between a given element and a point. 185 * \param *molecules list of molecules structure 186 * \param &elements vector of elements to correlate with point 152 * \param *out output stream for debugging 153 * \param *molecules list of molecules structure 154 * \param *type element or NULL (if any element) 187 155 * \param *point vector to the correlation point 188 156 * \return Map of dobules with values as pairs of atom and the vector 189 157 */ 190 CorrelationToPointMap *CorrelationToPoint(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Vector *point )158 CorrelationToPointMap *CorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point ) 191 159 { 192 160 Info FunctionInfo(__func__); 193 161 CorrelationToPointMap *outmap = NULL; 194 162 double distance = 0.; 195 double *cell_size = World::getInstance().getDomain();196 163 197 164 if (molecules->ListOfMolecules.empty()) { … … 207 174 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) { 208 175 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl); 209 for (vector<element *>::const_iterator type = elements.begin(); type != elements.end(); ++type) 210 if ((*type == NULL) || ((*iter)->type == *type)) { 211 distance = (*iter)->node->PeriodicDistance(*point, cell_size); 212 DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl); 213 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> ((*iter), point) ) ); 214 } 176 if ((type == NULL) || ((*iter)->type == type)) { 177 distance = (*iter)->node->PeriodicDistance(*point, World::getInstance().getDomain()); 178 DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl); 179 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> ((*iter), point) ) ); 180 } 215 181 } 216 182 } … … 220 186 221 187 /** Calculates the distance (pair) correlation between a given element, all its periodic images and a point. 222 * \param *molecules list of molecules structure 223 * \param &elements vector of elements to correlate to point 188 * \param *out output stream for debugging 189 * \param *molecules list of molecules structure 190 * \param *type element or NULL (if any element) 224 191 * \param *point vector to the correlation point 225 192 * \param ranges[NDIM] interval boundaries for the periodic images to scan also 226 193 * \return Map of dobules with values as pairs of atom and the vector 227 194 */ 228 CorrelationToPointMap *PeriodicCorrelationToPoint(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Vector *point, const int ranges[NDIM] )195 CorrelationToPointMap *PeriodicCorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point, const int ranges[NDIM] ) 229 196 { 230 197 Info FunctionInfo(__func__); … … 249 216 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) { 250 217 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl); 251 for (vector<element *>::const_iterator type = elements.begin(); type != elements.end(); ++type) 252 if ((*type == NULL) || ((*iter)->type == *type)) { 253 periodicX = *(*iter)->node; 254 periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3 255 // go through every range in xyz and get distance 256 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++) 257 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++) 258 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) { 259 checkX = Vector(n[0], n[1], n[2]) + periodicX; 260 checkX.MatrixMultiplication(FullMatrix); 261 distance = checkX.distance(*point); 262 DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl); 263 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (*iter, point) ) ); 264 } 265 } 218 if ((type == NULL) || ((*iter)->type == type)) { 219 periodicX = *(*iter)->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 = Vector(n[0], n[1], n[2]) + periodicX; 226 checkX.MatrixMultiplication(FullMatrix); 227 distance = checkX.distance(*point); 228 DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl); 229 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (*iter, point) ) ); 230 } 231 } 266 232 } 267 233 delete[](FullMatrix); … … 273 239 274 240 /** Calculates the distance (pair) correlation between a given element and a surface. 275 * \param *molecules list of molecules structure 276 * \param &elements vector of elements to correlate to surface 241 * \param *out output stream for debugging 242 * \param *molecules list of molecules structure 243 * \param *type element or NULL (if any element) 277 244 * \param *Surface pointer to Tesselation class surface 278 245 * \param *LC LinkedCell structure to quickly find neighbouring atoms 279 246 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest 280 247 */ 281 CorrelationToSurfaceMap *CorrelationToSurface(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Tesselation * const Surface, const LinkedCell *LC )248 CorrelationToSurfaceMap *CorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC ) 282 249 { 283 250 Info FunctionInfo(__func__); … … 301 268 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) { 302 269 DoLog(1) && (Log() << Verbose(1) << "\tCurrent atom is " << *(*iter) << "." << endl); 303 for (vector<element *>::const_iterator type = elements.begin(); type != elements.end(); ++type) 304 if ((*type == NULL) || ((*iter)->type == *type)) { 305 TriangleIntersectionList Intersections((*iter)->node,Surface,LC); 306 distance = Intersections.GetSmallestDistance(); 307 triangle = Intersections.GetClosestTriangle(); 308 outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> ((*iter), triangle) ) ); 309 } 270 if ((type == NULL) || ((*iter)->type == type)) { 271 TriangleIntersectionList Intersections((*iter)->node,Surface,LC); 272 distance = Intersections.GetSmallestDistance(); 273 triangle = Intersections.GetClosestTriangle(); 274 outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> ((*iter), triangle) ) ); 275 } 310 276 } 311 277 } else { … … 321 287 * axis an integer from [ -ranges[i], ranges[i] ] onto it and multiply with the domain matrix to bring it back into 322 288 * the real space. Then, we Tesselation::FindClosestTriangleToPoint() and DistanceToTrianglePlane(). 323 * \param *molecules list of molecules structure 324 * \param &elements vector of elements to correlate to surface 289 * \param *out output stream for debugging 290 * \param *molecules list of molecules structure 291 * \param *type element or NULL (if any element) 325 292 * \param *Surface pointer to Tesselation class surface 326 293 * \param *LC LinkedCell structure to quickly find neighbouring atoms … … 328 295 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest 329 296 */ 330 CorrelationToSurfaceMap *PeriodicCorrelationToSurface(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] )297 CorrelationToSurfaceMap *PeriodicCorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] ) 331 298 { 332 299 Info FunctionInfo(__func__); … … 355 322 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) { 356 323 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl); 357 for (vector<element *>::const_iterator type = elements.begin(); type != elements.end(); ++type) 358 if ((*type == NULL) || ((*iter)->type == *type)) { 359 periodicX = *(*iter)->node; 360 periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3 361 // go through every range in xyz and get distance 362 ShortestDistance = -1.; 363 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++) 364 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++) 365 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) { 366 checkX = Vector(n[0], n[1], n[2]) + periodicX; 367 checkX.MatrixMultiplication(FullMatrix); 368 TriangleIntersectionList Intersections(&checkX,Surface,LC); 369 distance = Intersections.GetSmallestDistance(); 370 triangle = Intersections.GetClosestTriangle(); 371 if ((ShortestDistance == -1.) || (distance < ShortestDistance)) { 372 ShortestDistance = distance; 373 ShortestTriangle = triangle; 374 } 324 if ((type == NULL) || ((*iter)->type == type)) { 325 periodicX = *(*iter)->node; 326 periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3 327 // go through every range in xyz and get distance 328 ShortestDistance = -1.; 329 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++) 330 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++) 331 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) { 332 checkX = Vector(n[0], n[1], n[2]) + periodicX; 333 checkX.MatrixMultiplication(FullMatrix); 334 TriangleIntersectionList Intersections(&checkX,Surface,LC); 335 distance = Intersections.GetSmallestDistance(); 336 triangle = Intersections.GetClosestTriangle(); 337 if ((ShortestDistance == -1.) || (distance < ShortestDistance)) { 338 ShortestDistance = distance; 339 ShortestTriangle = triangle; 375 340 } 376 // insert 377 outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(ShortestDistance, pair<atom *, BoundaryTriangleSet*> (*iter, ShortestTriangle) ) ); 378 //Log() << Verbose(1) << "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << "." << endl; 379 } 341 } 342 // insert 343 outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(ShortestDistance, pair<atom *, BoundaryTriangleSet*> (*iter, ShortestTriangle) ) ); 344 //Log() << Verbose(1) << "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << "." << endl; 345 } 380 346 } 381 347 delete[](FullMatrix);
Note:
See TracChangeset
for help on using the changeset viewer.