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