Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/analysis_correlation.cpp

    ra67d19 r1614174  
    1010#include "analysis_correlation.hpp"
    1111#include "element.hpp"
    12 #include "info.hpp"
    1312#include "log.hpp"
    1413#include "molecule.hpp"
    1514#include "tesselation.hpp"
    1615#include "tesselationhelpers.hpp"
    17 #include "triangleintersectionlist.hpp"
    1816#include "vector.hpp"
    1917#include "verbose.hpp"
    20 #include "World.hpp"
    2118
    2219
     
    3128PairCorrelationMap *PairCorrelation(MoleculeListClass * const &molecules, const element * const type1, const element * const type2 )
    3229{
    33   Info FunctionInfo(__func__);
    3430  PairCorrelationMap *outmap = NULL;
    3531  double distance = 0.;
    3632
    3733  if (molecules->ListOfMolecules.empty()) {
    38     DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
     34    eLog() << Verbose(1) <<"No molecule given." << endl;
    3935    return outmap;
    4036  }
     
    4238  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    4339    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;
    4945        if ((type1 == NULL) || (Walker->type == type1)) {
    5046          for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++)
    5147            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;
    5349              atom *OtherWalker = (*MolOtherWalker)->start;
    5450              while (OtherWalker->next != (*MolOtherWalker)->end) { // only go up to Walker
    5551                OtherWalker = OtherWalker->next;
    56                 DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl);
     52                Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl;
    5753                if (Walker->nr < OtherWalker->nr)
    5854                  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);
    6056                    //Log() << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl;
    6157                    outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) );
     
    8177PairCorrelationMap *PeriodicPairCorrelation(MoleculeListClass * const &molecules, const element * const type1, const element * const type2, const int ranges[NDIM] )
    8278{
    83   Info FunctionInfo(__func__);
    8479  PairCorrelationMap *outmap = NULL;
    8580  double distance = 0.;
     
    9287
    9388  if (molecules->ListOfMolecules.empty()) {
    94     DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
     89    eLog() << Verbose(1) <<"No molecule given." << endl;
    9590    return outmap;
    9691  }
     
    9893  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    9994    if ((*MolWalker)->ActiveFlag) {
    100       double * FullMatrix = ReturnFullMatrixforSymmetric(World::get()->cell_size);
     95      double * FullMatrix = ReturnFullMatrixforSymmetric((*MolWalker)->cell_size);
    10196      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;
    107102        if ((type1 == NULL) || (Walker->type == type1)) {
    108103          periodicX.CopyVector(Walker->node);
     
    117112                for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++)
    118113                  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;
    120115                    atom *OtherWalker = (*MolOtherWalker)->start;
    121116                    while (OtherWalker->next != (*MolOtherWalker)->end) { // only go up to Walker
    122117                      OtherWalker = OtherWalker->next;
    123                       DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl);
     118                      Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl;
    124119                      if (Walker->nr < OtherWalker->nr)
    125120                        if ((type2 == NULL) || (OtherWalker->type == type2)) {
     
    159154CorrelationToPointMap *CorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point )
    160155{
    161   Info FunctionInfo(__func__);
    162156  CorrelationToPointMap *outmap = NULL;
    163157  double distance = 0.;
    164158
    165159  if (molecules->ListOfMolecules.empty()) {
    166     DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
     160    Log() << Verbose(1) <<"No molecule given." << endl;
    167161    return outmap;
    168162  }
     
    170164  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    171165    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;
    177171        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;
    180174          outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) );
    181175        }
     
    196190CorrelationToPointMap *PeriodicCorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point, const int ranges[NDIM] )
    197191{
    198   Info FunctionInfo(__func__);
    199192  CorrelationToPointMap *outmap = NULL;
    200193  double distance = 0.;
     
    204197
    205198  if (molecules->ListOfMolecules.empty()) {
    206     DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
     199    Log() << Verbose(1) <<"No molecule given." << endl;
    207200    return outmap;
    208201  }
     
    210203  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    211204    if ((*MolWalker)->ActiveFlag) {
    212       double * FullMatrix = ReturnFullMatrixforSymmetric(World::get()->cell_size);
     205      double * FullMatrix = ReturnFullMatrixforSymmetric((*MolWalker)->cell_size);
    213206      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;
    219212        if ((type == NULL) || (Walker->type == type)) {
    220213          periodicX.CopyVector(Walker->node);
     
    228221                checkX.MatrixMultiplication(FullMatrix);
    229222                distance = checkX.Distance(point);
    230                 DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
     223                Log() << Verbose(4) << "Current distance is " << distance << "." << endl;
    231224                outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) );
    232225              }
     
    250243CorrelationToSurfaceMap *CorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC )
    251244{
    252   Info FunctionInfo(__func__);
    253245  CorrelationToSurfaceMap *outmap = NULL;
    254246  double distance = 0;
     
    257249
    258250  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;
    260252    return outmap;
    261253  }
     
    263255  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    264256    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;
    270262        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    }
    280271
    281272  return outmap;
     
    297288CorrelationToSurfaceMap *PeriodicCorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] )
    298289{
    299   Info FunctionInfo(__func__);
    300290  CorrelationToSurfaceMap *outmap = NULL;
    301291  double distance = 0;
     
    307297
    308298  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;
    310300    return outmap;
    311301  }
    312302  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);
    318306      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;
    324312        if ((type == NULL) || (Walker->type == type)) {
    325313          periodicX.CopyVector(Walker->node);
    326314          periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
    327315          // go through every range in xyz and get distance
    328           ShortestDistance = -1.;
    329316          for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
    330317            for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
     
    333320                checkX.AddVector(&periodicX);
    334321                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) ) );
    341326                }
    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          }
    346328        }
    347329      }
     
    353335};
    354336
    355 /** Returns the index of the bin for a given value.
     337/** Returns the start of the bin for a given value.
    356338 * \param value value whose bin to look for
    357339 * \param BinWidth width of bin
    358340 * \param BinStart first bin
    359341 */
    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);
     342double GetBin ( const double value, const double BinWidth, const double BinStart )
     343{
     344  double bin =(double) (floor((value - BinStart)/BinWidth));
     345  return (bin*BinWidth+BinStart);
    365346};
    366347
     
    372353void OutputCorrelation( ofstream * const file, const BinPairMap * const map )
    373354{
    374   Info FunctionInfo(__func__);
    375   *file << "BinStart\tCount" << endl;
     355  *file << "# BinStart\tCount" << endl;
    376356  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;
    378358  }
    379359};
     
    385365void OutputPairCorrelation( ofstream * const file, const PairCorrelationMap * const map )
    386366{
    387   Info FunctionInfo(__func__);
    388   *file << "BinStart\tAtom1\tAtom2" << endl;
     367  *file << "# BinStart\tAtom1\tAtom2" << endl;
    389368  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;
    391370  }
    392371};
     
    398377void OutputCorrelationToPoint( ofstream * const file, const CorrelationToPointMap * const map )
    399378{
    400   Info FunctionInfo(__func__);
    401   *file << "BinStart\tAtom::x[i]-point.x[i]" << endl;
     379  *file << "# BinStart\tAtom::x[i]-point.x[i]" << endl;
    402380  for (CorrelationToPointMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
    403381    *file << runner->first;
    404382    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]);
    406384    *file << endl;
    407385  }
     
    414392void OutputCorrelationToSurface( ofstream * const file, const CorrelationToSurfaceMap * const map )
    415393{
    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.