Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/analysis_correlation.cpp

    rb34306 rbd61b41  
    1515#include "tesselation.hpp"
    1616#include "tesselationhelpers.hpp"
    17 #include "triangleintersectionlist.hpp"
    1817#include "vector.hpp"
    1918#include "verbose.hpp"
    20 #include "World.hpp"
    2119
    2220
     
    5755                if (Walker->nr < OtherWalker->nr)
    5856                  if ((type2 == NULL) || (OtherWalker->type == type2)) {
    59                     distance = Walker->node->PeriodicDistance(OtherWalker->node, World::get()->cell_size);
     57                    distance = Walker->node->PeriodicDistance(OtherWalker->node, (*MolWalker)->cell_size);
    6058                    //Log() << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl;
    6159                    outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) );
     
    9896  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    9997    if ((*MolWalker)->ActiveFlag) {
    100       double * FullMatrix = ReturnFullMatrixforSymmetric(World::get()->cell_size);
     98      double * FullMatrix = ReturnFullMatrixforSymmetric((*MolWalker)->cell_size);
    10199      double * FullInverseMatrix = InverseMatrix(FullMatrix);
    102100      eLog() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
     
    176174        Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;
    177175        if ((type == NULL) || (Walker->type == type)) {
    178           distance = Walker->node->PeriodicDistance(point, World::get()->cell_size);
     176          distance = Walker->node->PeriodicDistance(point, (*MolWalker)->cell_size);
    179177          Log() << Verbose(4) << "Current distance is " << distance << "." << endl;
    180178          outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) );
     
    210208  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    211209    if ((*MolWalker)->ActiveFlag) {
    212       double * FullMatrix = ReturnFullMatrixforSymmetric(World::get()->cell_size);
     210      double * FullMatrix = ReturnFullMatrixforSymmetric((*MolWalker)->cell_size);
    213211      double * FullInverseMatrix = InverseMatrix(FullMatrix);
    214212      Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
     
    257255
    258256  if ((Surface == NULL) || (LC == NULL) || (molecules->ListOfMolecules.empty())) {
    259     eLog() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl;
     257    Log() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl;
    260258    return outmap;
    261259  }
     
    263261  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    264262    if ((*MolWalker)->ActiveFlag) {
    265       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;
     263      Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
     264      atom *Walker = (*MolWalker)->start;
     265      while (Walker->next != (*MolWalker)->end) {
     266        Walker = Walker->next;
     267        Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;
    270268        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       Log() << Verbose(1) << "molecule " << (*MolWalker)->name << " is not active." << endl;
    279 
     269          triangle = Surface->FindClosestTriangleToPoint(Walker->node, LC );
     270          if (triangle != NULL) {
     271            distance = DistanceToTrianglePlane(Walker->node, triangle);
     272            outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> (Walker, triangle) ) );
     273          }
     274        }
     275      }
     276    }
    280277
    281278  return outmap;
     
    311308  }
    312309  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);
     310  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
     311    if ((*MolWalker)->ActiveFlag) {
     312      double * FullMatrix = ReturnFullMatrixforSymmetric((*MolWalker)->cell_size);
    318313      double * FullInverseMatrix = InverseMatrix(FullMatrix);
    319314      Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
     
    326321          periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
    327322          // go through every range in xyz and get distance
    328           ShortestDistance = -1.;
    329323          for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
    330324            for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
     
    333327                checkX.AddVector(&periodicX);
    334328                checkX.MatrixMultiplication(FullMatrix);
    335                 triangle = Surface->FindClosestTriangleToVector(&checkX, LC);
    336                 distance = Surface->GetDistanceSquaredToTriangle(checkX, triangle);
    337                 if ((ShortestDistance == -1.) || (distance < ShortestDistance)) {
    338                   ShortestDistance = distance;
    339                   ShortestTriangle = triangle;
     329                triangle = Surface->FindClosestTriangleToPoint(&checkX, LC );
     330                if (triangle != NULL) {
     331                  distance = DistanceToTrianglePlane(&checkX, triangle);
     332                  outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> (Walker, triangle) ) );
    340333                }
    341               }
    342           // insert
    343           ShortestDistance = sqrt(ShortestDistance);
    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;
     334          }
    346335        }
    347336      }
     
    353342};
    354343
    355 /** Returns the start of the bin for a given value.
     344/** Returns the index of the bin for a given value.
    356345 * \param value value whose bin to look for
    357346 * \param BinWidth width of bin
    358347 * \param BinStart first bin
    359348 */
    360 double GetBin ( const double value, const double BinWidth, const double BinStart )
    361 {
    362   Info FunctionInfo(__func__);
    363   double bin =(double) (floor((value - BinStart)/BinWidth));
    364   return (bin*BinWidth+BinStart);
     349int GetBin ( const double value, const double BinWidth, const double BinStart )
     350{
     351  Info FunctionInfo(__func__);
     352  int bin =(int) (floor((value - BinStart)/BinWidth));
     353  return (bin);
    365354};
    366355
     
    373362{
    374363  Info FunctionInfo(__func__);
    375   *file << "BinStart\tCount" << endl;
     364  *file << "# BinStart\tCount" << endl;
    376365  for (BinPairMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
    377     *file << setprecision(8) << runner->first << "\t" << runner->second << endl;
     366    *file << runner->first << "\t" << runner->second << endl;
    378367  }
    379368};
     
    386375{
    387376  Info FunctionInfo(__func__);
    388   *file << "BinStart\tAtom1\tAtom2" << endl;
     377  *file << "# BinStart\tAtom1\tAtom2" << endl;
    389378  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;
     379    *file << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl;
    391380  }
    392381};
     
    399388{
    400389  Info FunctionInfo(__func__);
    401   *file << "BinStart\tAtom::x[i]-point.x[i]" << endl;
     390  *file << "# BinStart\tAtom::x[i]-point.x[i]" << endl;
    402391  for (CorrelationToPointMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
    403392    *file << runner->first;
    404393    for (int i=0;i<NDIM;i++)
    405       *file << "\t" << setprecision(8) << (runner->second.first->node->x[i] - runner->second.second->x[i]);
     394      *file << "\t" << (runner->second.first->node->x[i] - runner->second.second->x[i]);
    406395    *file << endl;
    407396  }
     
    415404{
    416405  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 
     406  *file << "# BinStart\tTriangle" << endl;
     407  for (CorrelationToSurfaceMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
     408    *file << runner->first << "\t" << *(runner->second.second) << endl;
     409  }
     410};
     411
Note: See TracChangeset for help on using the changeset viewer.