Changes in src/analysis_correlation.cpp [1614174:a67d19]
- File:
-
- 1 edited
-
src/analysis_correlation.cpp (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/analysis_correlation.cpp
r1614174 ra67d19 10 10 #include "analysis_correlation.hpp" 11 11 #include "element.hpp" 12 #include "info.hpp" 12 13 #include "log.hpp" 13 14 #include "molecule.hpp" 14 15 #include "tesselation.hpp" 15 16 #include "tesselationhelpers.hpp" 17 #include "triangleintersectionlist.hpp" 16 18 #include "vector.hpp" 17 19 #include "verbose.hpp" 20 #include "World.hpp" 18 21 19 22 … … 28 31 PairCorrelationMap *PairCorrelation(MoleculeListClass * const &molecules, const element * const type1, const element * const type2 ) 29 32 { 33 Info FunctionInfo(__func__); 30 34 PairCorrelationMap *outmap = NULL; 31 35 double distance = 0.; 32 36 33 37 if (molecules->ListOfMolecules.empty()) { 34 eLog() << Verbose(1) <<"No molecule given." << endl;38 DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl); 35 39 return outmap; 36 40 } … … 38 42 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++) 39 43 if ((*MolWalker)->ActiveFlag) { 40 eLog() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;41 atom *Walker = (*MolWalker)->start; 42 while (Walker->next != (*MolWalker)->end) { 43 Walker = Walker->next; 44 Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;44 DoeLog(2) && (eLog()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl); 45 atom *Walker = (*MolWalker)->start; 46 while (Walker->next != (*MolWalker)->end) { 47 Walker = Walker->next; 48 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl); 45 49 if ((type1 == NULL) || (Walker->type == type1)) { 46 50 for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++) 47 51 if ((*MolOtherWalker)->ActiveFlag) { 48 Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl;52 DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl); 49 53 atom *OtherWalker = (*MolOtherWalker)->start; 50 54 while (OtherWalker->next != (*MolOtherWalker)->end) { // only go up to Walker 51 55 OtherWalker = OtherWalker->next; 52 Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl;56 DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl); 53 57 if (Walker->nr < OtherWalker->nr) 54 58 if ((type2 == NULL) || (OtherWalker->type == type2)) { 55 distance = Walker->node->PeriodicDistance(OtherWalker->node, (*MolWalker)->cell_size);59 distance = Walker->node->PeriodicDistance(OtherWalker->node, World::get()->cell_size); 56 60 //Log() << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl; 57 61 outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) ); … … 77 81 PairCorrelationMap *PeriodicPairCorrelation(MoleculeListClass * const &molecules, const element * const type1, const element * const type2, const int ranges[NDIM] ) 78 82 { 83 Info FunctionInfo(__func__); 79 84 PairCorrelationMap *outmap = NULL; 80 85 double distance = 0.; … … 87 92 88 93 if (molecules->ListOfMolecules.empty()) { 89 eLog() << Verbose(1) <<"No molecule given." << endl;94 DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl); 90 95 return outmap; 91 96 } … … 93 98 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++) 94 99 if ((*MolWalker)->ActiveFlag) { 95 double * FullMatrix = ReturnFullMatrixforSymmetric( (*MolWalker)->cell_size);100 double * FullMatrix = ReturnFullMatrixforSymmetric(World::get()->cell_size); 96 101 double * FullInverseMatrix = InverseMatrix(FullMatrix); 97 eLog() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;98 atom *Walker = (*MolWalker)->start; 99 while (Walker->next != (*MolWalker)->end) { 100 Walker = Walker->next; 101 Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;102 DoeLog(2) && (eLog()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl); 103 atom *Walker = (*MolWalker)->start; 104 while (Walker->next != (*MolWalker)->end) { 105 Walker = Walker->next; 106 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl); 102 107 if ((type1 == NULL) || (Walker->type == type1)) { 103 108 periodicX.CopyVector(Walker->node); … … 112 117 for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++) 113 118 if ((*MolOtherWalker)->ActiveFlag) { 114 Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl;119 DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl); 115 120 atom *OtherWalker = (*MolOtherWalker)->start; 116 121 while (OtherWalker->next != (*MolOtherWalker)->end) { // only go up to Walker 117 122 OtherWalker = OtherWalker->next; 118 Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl;123 DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl); 119 124 if (Walker->nr < OtherWalker->nr) 120 125 if ((type2 == NULL) || (OtherWalker->type == type2)) { … … 154 159 CorrelationToPointMap *CorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point ) 155 160 { 161 Info FunctionInfo(__func__); 156 162 CorrelationToPointMap *outmap = NULL; 157 163 double distance = 0.; 158 164 159 165 if (molecules->ListOfMolecules.empty()) { 160 Log() << Verbose(1) <<"No molecule given." << endl;166 DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl); 161 167 return outmap; 162 168 } … … 164 170 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++) 165 171 if ((*MolWalker)->ActiveFlag) { 166 Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;167 atom *Walker = (*MolWalker)->start; 168 while (Walker->next != (*MolWalker)->end) { 169 Walker = Walker->next; 170 Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;172 DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl); 173 atom *Walker = (*MolWalker)->start; 174 while (Walker->next != (*MolWalker)->end) { 175 Walker = Walker->next; 176 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl); 171 177 if ((type == NULL) || (Walker->type == type)) { 172 distance = Walker->node->PeriodicDistance(point, (*MolWalker)->cell_size);173 Log() << Verbose(4) << "Current distance is " << distance << "." << endl;178 distance = Walker->node->PeriodicDistance(point, World::get()->cell_size); 179 DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl); 174 180 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) ); 175 181 } … … 190 196 CorrelationToPointMap *PeriodicCorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point, const int ranges[NDIM] ) 191 197 { 198 Info FunctionInfo(__func__); 192 199 CorrelationToPointMap *outmap = NULL; 193 200 double distance = 0.; … … 197 204 198 205 if (molecules->ListOfMolecules.empty()) { 199 Log() << Verbose(1) <<"No molecule given." << endl;206 DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl); 200 207 return outmap; 201 208 } … … 203 210 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++) 204 211 if ((*MolWalker)->ActiveFlag) { 205 double * FullMatrix = ReturnFullMatrixforSymmetric( (*MolWalker)->cell_size);212 double * FullMatrix = ReturnFullMatrixforSymmetric(World::get()->cell_size); 206 213 double * FullInverseMatrix = InverseMatrix(FullMatrix); 207 Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;208 atom *Walker = (*MolWalker)->start; 209 while (Walker->next != (*MolWalker)->end) { 210 Walker = Walker->next; 211 Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;214 DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl); 215 atom *Walker = (*MolWalker)->start; 216 while (Walker->next != (*MolWalker)->end) { 217 Walker = Walker->next; 218 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl); 212 219 if ((type == NULL) || (Walker->type == type)) { 213 220 periodicX.CopyVector(Walker->node); … … 221 228 checkX.MatrixMultiplication(FullMatrix); 222 229 distance = checkX.Distance(point); 223 Log() << Verbose(4) << "Current distance is " << distance << "." << endl;230 DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl); 224 231 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) ); 225 232 } … … 243 250 CorrelationToSurfaceMap *CorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC ) 244 251 { 252 Info FunctionInfo(__func__); 245 253 CorrelationToSurfaceMap *outmap = NULL; 246 254 double distance = 0; … … 249 257 250 258 if ((Surface == NULL) || (LC == NULL) || (molecules->ListOfMolecules.empty())) { 251 Log() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl;259 DoeLog(1) && (eLog()<< Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl); 252 260 return outmap; 253 261 } … … 255 263 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++) 256 264 if ((*MolWalker)->ActiveFlag) { 257 Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;258 atom *Walker = (*MolWalker)->start; 259 while (Walker->next != (*MolWalker)->end) { 260 Walker = Walker->next; 261 Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;265 DoLog(1) && (Log() << Verbose(1) << "Current molecule is " << (*MolWalker)->name << "." << endl); 266 atom *Walker = (*MolWalker)->start; 267 while (Walker->next != (*MolWalker)->end) { 268 Walker = Walker->next; 269 //Log() << Verbose(1) << "Current atom is " << *Walker << "." << endl; 262 270 if ((type == NULL) || (Walker->type == type)) { 263 triangle = Surface->FindClosestTriangleToPoint(Walker->node, LC ); 264 if (triangle != NULL) { 265 distance = DistanceToTrianglePlane(Walker->node, triangle); 266 outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> (Walker, triangle) ) ); 267 } 268 } 269 } 270 } 271 TriangleIntersectionList Intersections(Walker->node,Surface,LC); 272 distance = Intersections.GetSmallestDistance(); 273 triangle = Intersections.GetClosestTriangle(); 274 outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> (Walker, triangle) ) ); 275 } 276 } 277 } else 278 DoLog(1) && (Log() << Verbose(1) << "molecule " << (*MolWalker)->name << " is not active." << endl); 279 271 280 272 281 return outmap; … … 288 297 CorrelationToSurfaceMap *PeriodicCorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] ) 289 298 { 299 Info FunctionInfo(__func__); 290 300 CorrelationToSurfaceMap *outmap = NULL; 291 301 double distance = 0; … … 297 307 298 308 if ((Surface == NULL) || (LC == NULL) || (molecules->ListOfMolecules.empty())) { 299 Log() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl;309 DoLog(1) && (Log() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl); 300 310 return outmap; 301 311 } 302 312 outmap = new CorrelationToSurfaceMap; 303 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++) 304 if ((*MolWalker)->ActiveFlag) { 305 double * FullMatrix = ReturnFullMatrixforSymmetric((*MolWalker)->cell_size); 313 double ShortestDistance = 0.; 314 BoundaryTriangleSet *ShortestTriangle = NULL; 315 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++) 316 if ((*MolWalker)->ActiveFlag) { 317 double * FullMatrix = ReturnFullMatrixforSymmetric(World::get()->cell_size); 306 318 double * FullInverseMatrix = InverseMatrix(FullMatrix); 307 Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;308 atom *Walker = (*MolWalker)->start; 309 while (Walker->next != (*MolWalker)->end) { 310 Walker = Walker->next; 311 Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;319 DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl); 320 atom *Walker = (*MolWalker)->start; 321 while (Walker->next != (*MolWalker)->end) { 322 Walker = Walker->next; 323 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl); 312 324 if ((type == NULL) || (Walker->type == type)) { 313 325 periodicX.CopyVector(Walker->node); 314 326 periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3 315 327 // go through every range in xyz and get distance 328 ShortestDistance = -1.; 316 329 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++) 317 330 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++) … … 320 333 checkX.AddVector(&periodicX); 321 334 checkX.MatrixMultiplication(FullMatrix); 322 triangle = Surface->FindClosestTriangleToPoint(&checkX, LC ); 323 if (triangle != NULL) { 324 distance = DistanceToTrianglePlane(&checkX, triangle); 325 outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> (Walker, triangle) ) ); 335 TriangleIntersectionList Intersections(&checkX,Surface,LC); 336 distance = Intersections.GetSmallestDistance(); 337 triangle = Intersections.GetClosestTriangle(); 338 if ((ShortestDistance == -1.) || (distance < ShortestDistance)) { 339 ShortestDistance = distance; 340 ShortestTriangle = triangle; 326 341 } 327 } 342 } 343 // insert 344 outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(ShortestDistance, pair<atom *, BoundaryTriangleSet*> (Walker, ShortestTriangle) ) ); 345 //Log() << Verbose(1) << "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << "." << endl; 328 346 } 329 347 } … … 335 353 }; 336 354 337 /** Returns the startof the bin for a given value.355 /** Returns the index of the bin for a given value. 338 356 * \param value value whose bin to look for 339 357 * \param BinWidth width of bin 340 358 * \param BinStart first bin 341 359 */ 342 double GetBin ( const double value, const double BinWidth, const double BinStart ) 343 { 344 double bin =(double) (floor((value - BinStart)/BinWidth)); 345 return (bin*BinWidth+BinStart); 360 int GetBin ( const double value, const double BinWidth, const double BinStart ) 361 { 362 Info FunctionInfo(__func__); 363 int bin =(int) (floor((value - BinStart)/BinWidth)); 364 return (bin); 346 365 }; 347 366 … … 353 372 void OutputCorrelation( ofstream * const file, const BinPairMap * const map ) 354 373 { 355 *file << "# BinStart\tCount" << endl; 374 Info FunctionInfo(__func__); 375 *file << "BinStart\tCount" << endl; 356 376 for (BinPairMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) { 357 *file << runner->first << "\t" << runner->second << endl;377 *file << setprecision(8) << runner->first << "\t" << runner->second << endl; 358 378 } 359 379 }; … … 365 385 void OutputPairCorrelation( ofstream * const file, const PairCorrelationMap * const map ) 366 386 { 367 *file << "# BinStart\tAtom1\tAtom2" << endl; 387 Info FunctionInfo(__func__); 388 *file << "BinStart\tAtom1\tAtom2" << endl; 368 389 for (PairCorrelationMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) { 369 *file << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl;390 *file << setprecision(8) << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl; 370 391 } 371 392 }; … … 377 398 void OutputCorrelationToPoint( ofstream * const file, const CorrelationToPointMap * const map ) 378 399 { 379 *file << "# BinStart\tAtom::x[i]-point.x[i]" << endl; 400 Info FunctionInfo(__func__); 401 *file << "BinStart\tAtom::x[i]-point.x[i]" << endl; 380 402 for (CorrelationToPointMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) { 381 403 *file << runner->first; 382 404 for (int i=0;i<NDIM;i++) 383 *file << "\t" << (runner->second.first->node->x[i] - runner->second.second->x[i]);405 *file << "\t" << setprecision(8) << (runner->second.first->node->x[i] - runner->second.second->x[i]); 384 406 *file << endl; 385 407 } … … 392 414 void OutputCorrelationToSurface( ofstream * const file, const CorrelationToSurfaceMap * const map ) 393 415 { 394 *file << "# BinStart\tTriangle" << endl; 395 for (CorrelationToSurfaceMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) { 396 *file << runner->first << "\t" << *(runner->second.second) << endl; 397 } 398 }; 399 416 Info FunctionInfo(__func__); 417 *file << "BinStart\tTriangle" << endl; 418 if (!map->empty()) 419 for (CorrelationToSurfaceMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) { 420 *file << setprecision(8) << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl; 421 } 422 }; 423
Note:
See TracChangeset
for help on using the changeset viewer.
