Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/analysis_correlation.cpp

    r1614174 ra67d19  
    1010#include "analysis_correlation.hpp"
    1111#include "element.hpp"
     12#include "info.hpp"
    1213#include "log.hpp"
    1314#include "molecule.hpp"
    1415#include "tesselation.hpp"
    1516#include "tesselationhelpers.hpp"
     17#include "triangleintersectionlist.hpp"
    1618#include "vector.hpp"
    1719#include "verbose.hpp"
     20#include "World.hpp"
    1821
    1922
     
    2831PairCorrelationMap *PairCorrelation(MoleculeListClass * const &molecules, const element * const type1, const element * const type2 )
    2932{
     33  Info FunctionInfo(__func__);
    3034  PairCorrelationMap *outmap = NULL;
    3135  double distance = 0.;
    3236
    3337  if (molecules->ListOfMolecules.empty()) {
    34     eLog() << Verbose(1) <<"No molecule given." << endl;
     38    DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
    3539    return outmap;
    3640  }
     
    3842  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    3943    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);
    4549        if ((type1 == NULL) || (Walker->type == type1)) {
    4650          for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++)
    4751            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);
    4953              atom *OtherWalker = (*MolOtherWalker)->start;
    5054              while (OtherWalker->next != (*MolOtherWalker)->end) { // only go up to Walker
    5155                OtherWalker = OtherWalker->next;
    52                 Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl;
     56                DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl);
    5357                if (Walker->nr < OtherWalker->nr)
    5458                  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);
    5660                    //Log() << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl;
    5761                    outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) );
     
    7781PairCorrelationMap *PeriodicPairCorrelation(MoleculeListClass * const &molecules, const element * const type1, const element * const type2, const int ranges[NDIM] )
    7882{
     83  Info FunctionInfo(__func__);
    7984  PairCorrelationMap *outmap = NULL;
    8085  double distance = 0.;
     
    8792
    8893  if (molecules->ListOfMolecules.empty()) {
    89     eLog() << Verbose(1) <<"No molecule given." << endl;
     94    DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
    9095    return outmap;
    9196  }
     
    9398  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    9499    if ((*MolWalker)->ActiveFlag) {
    95       double * FullMatrix = ReturnFullMatrixforSymmetric((*MolWalker)->cell_size);
     100      double * FullMatrix = ReturnFullMatrixforSymmetric(World::get()->cell_size);
    96101      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);
    102107        if ((type1 == NULL) || (Walker->type == type1)) {
    103108          periodicX.CopyVector(Walker->node);
     
    112117                for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++)
    113118                  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);
    115120                    atom *OtherWalker = (*MolOtherWalker)->start;
    116121                    while (OtherWalker->next != (*MolOtherWalker)->end) { // only go up to Walker
    117122                      OtherWalker = OtherWalker->next;
    118                       Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl;
     123                      DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl);
    119124                      if (Walker->nr < OtherWalker->nr)
    120125                        if ((type2 == NULL) || (OtherWalker->type == type2)) {
     
    154159CorrelationToPointMap *CorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point )
    155160{
     161  Info FunctionInfo(__func__);
    156162  CorrelationToPointMap *outmap = NULL;
    157163  double distance = 0.;
    158164
    159165  if (molecules->ListOfMolecules.empty()) {
    160     Log() << Verbose(1) <<"No molecule given." << endl;
     166    DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
    161167    return outmap;
    162168  }
     
    164170  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    165171    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);
    171177        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);
    174180          outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) );
    175181        }
     
    190196CorrelationToPointMap *PeriodicCorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point, const int ranges[NDIM] )
    191197{
     198  Info FunctionInfo(__func__);
    192199  CorrelationToPointMap *outmap = NULL;
    193200  double distance = 0.;
     
    197204
    198205  if (molecules->ListOfMolecules.empty()) {
    199     Log() << Verbose(1) <<"No molecule given." << endl;
     206    DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
    200207    return outmap;
    201208  }
     
    203210  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    204211    if ((*MolWalker)->ActiveFlag) {
    205       double * FullMatrix = ReturnFullMatrixforSymmetric((*MolWalker)->cell_size);
     212      double * FullMatrix = ReturnFullMatrixforSymmetric(World::get()->cell_size);
    206213      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);
    212219        if ((type == NULL) || (Walker->type == type)) {
    213220          periodicX.CopyVector(Walker->node);
     
    221228                checkX.MatrixMultiplication(FullMatrix);
    222229                distance = checkX.Distance(point);
    223                 Log() << Verbose(4) << "Current distance is " << distance << "." << endl;
     230                DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
    224231                outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) );
    225232              }
     
    243250CorrelationToSurfaceMap *CorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC )
    244251{
     252  Info FunctionInfo(__func__);
    245253  CorrelationToSurfaceMap *outmap = NULL;
    246254  double distance = 0;
     
    249257
    250258  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);
    252260    return outmap;
    253261  }
     
    255263  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    256264    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;
    262270        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
    271280
    272281  return outmap;
     
    288297CorrelationToSurfaceMap *PeriodicCorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] )
    289298{
     299  Info FunctionInfo(__func__);
    290300  CorrelationToSurfaceMap *outmap = NULL;
    291301  double distance = 0;
     
    297307
    298308  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);
    300310    return outmap;
    301311  }
    302312  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);
    306318      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);
    312324        if ((type == NULL) || (Walker->type == type)) {
    313325          periodicX.CopyVector(Walker->node);
    314326          periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
    315327          // go through every range in xyz and get distance
     328          ShortestDistance = -1.;
    316329          for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
    317330            for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
     
    320333                checkX.AddVector(&periodicX);
    321334                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;
    326341                }
    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;
    328346        }
    329347      }
     
    335353};
    336354
    337 /** Returns the start of the bin for a given value.
     355/** Returns the index of the bin for a given value.
    338356 * \param value value whose bin to look for
    339357 * \param BinWidth width of bin
    340358 * \param BinStart first bin
    341359 */
    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);
     360int 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);
    346365};
    347366
     
    353372void OutputCorrelation( ofstream * const file, const BinPairMap * const map )
    354373{
    355   *file << "# BinStart\tCount" << endl;
     374  Info FunctionInfo(__func__);
     375  *file << "BinStart\tCount" << endl;
    356376  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;
    358378  }
    359379};
     
    365385void OutputPairCorrelation( ofstream * const file, const PairCorrelationMap * const map )
    366386{
    367   *file << "# BinStart\tAtom1\tAtom2" << endl;
     387  Info FunctionInfo(__func__);
     388  *file << "BinStart\tAtom1\tAtom2" << endl;
    368389  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;
    370391  }
    371392};
     
    377398void OutputCorrelationToPoint( ofstream * const file, const CorrelationToPointMap * const map )
    378399{
    379   *file << "# BinStart\tAtom::x[i]-point.x[i]" << endl;
     400  Info FunctionInfo(__func__);
     401  *file << "BinStart\tAtom::x[i]-point.x[i]" << endl;
    380402  for (CorrelationToPointMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
    381403    *file << runner->first;
    382404    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]);
    384406    *file << endl;
    385407  }
     
    392414void OutputCorrelationToSurface( ofstream * const file, const CorrelationToSurfaceMap * const map )
    393415{
    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.