Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/analysis_correlation.cpp

    r112b09 r36166d  
    99
    1010#include <iostream>
     11#include <iomanip>
    1112
    1213#include "analysis_correlation.hpp"
     
    1920#include "triangleintersectionlist.hpp"
    2021#include "vector.hpp"
     22#include "Matrix.hpp"
    2123#include "verbose.hpp"
    2224#include "World.hpp"
     25#include "Box.hpp"
    2326
    2427
    2528/** Calculates the pair correlation between given elements.
    2629 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
    27  * \param *out output stream for debugging
    28  * \param *molecules list of molecules structure
    29  * \param *type1 first element or NULL (if any element)
    30  * \param *type2 second element or NULL (if any element)
     30 * \param *molecules list of molecules structure
     31 * \param &elements vector of elements to correlate
    3132 * \return Map of doubles with values the pair of the two atoms.
    3233 */
    33 PairCorrelationMap *PairCorrelation(MoleculeListClass * const &molecules, const element * const type1, const element * const type2 )
     34PairCorrelationMap *PairCorrelation(MoleculeListClass * const &molecules, const std::vector<element *> &elements)
    3435{
    3536  Info FunctionInfo(__func__);
    3637  PairCorrelationMap *outmap = NULL;
    3738  double distance = 0.;
     39  Box &domain = World::getInstance().getDomain();
    3840
    3941  if (molecules->ListOfMolecules.empty()) {
     
    4345  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    4446    (*MolWalker)->doCountAtoms();
     47
     48  // create all possible pairs of elements
     49  set <pair<element *, element *> > PairsOfElements;
     50  if (elements.size() >= 2) {
     51    for (vector<element *>::const_iterator type1 = elements.begin(); type1 != elements.end(); ++type1)
     52      for (vector<element *>::const_iterator type2 = elements.begin(); type2 != elements.end(); ++type2)
     53        if (type1 != type2) {
     54          PairsOfElements.insert( pair<element *, element*>(*type1,*type2) );
     55          DoLog(1) && (Log() << Verbose(1) << "Creating element pair " << (*type1)->symbol << " and " << (*type2)->symbol << "." << endl);
     56        }
     57  } else if (elements.size() == 1) { // one to all are valid
     58    element *elemental = *elements.begin();
     59    PairsOfElements.insert( pair<element *, element*>(elemental,(element *)NULL) );
     60    PairsOfElements.insert( pair<element *, element*>((element *)NULL,elemental) );
     61  } else { // all elements valid
     62    PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
     63  }
     64
    4565  outmap = new PairCorrelationMap;
    4666  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++){
     
    5070      for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
    5171        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
    52         if ((type1 == NULL) || ((*iter)->type == type1)) {
    53           for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++){
    54             if ((*MolOtherWalker)->ActiveFlag) {
    55               DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
    56               for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
    57                 DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);
    58                 if ((*iter)->getId() < (*runner)->getId()){
    59                   if ((type2 == NULL) || ((*runner)->type == type2)) {
    60                     distance = (*iter)->node->PeriodicDistance(*(*runner)->node,  World::getInstance().getDomain());
     72        for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++){
     73          if ((*MolOtherWalker)->ActiveFlag) {
     74            DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
     75            for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
     76              DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);
     77              if ((*iter)->getId() < (*runner)->getId()){
     78                for (set <pair<element *, element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
     79                  if ((PairRunner->first == (**iter).type) && (PairRunner->second == (**runner).type)) {
     80                    distance = domain.periodicDistance(*(*iter)->node,*(*runner)->node);
    6181                    //Log() << Verbose(1) <<"Inserting " << *(*iter) << " and " << *(*runner) << endl;
    6282                    outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) );
    6383                  }
    64                 }
    6584              }
    6685            }
     
    7594/** Calculates the pair correlation between given elements.
    7695 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
    77  * \param *out output stream for debugging
    78  * \param *molecules list of molecules structure
    79  * \param *type1 first element or NULL (if any element)
    80  * \param *type2 second element or NULL (if any element)
     96 * \param *molecules list of molecules structure
     97 * \param &elements vector of elements to correlate
    8198 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
    8299 * \return Map of doubles with values the pair of the two atoms.
    83100 */
    84 PairCorrelationMap *PeriodicPairCorrelation(MoleculeListClass * const &molecules, const element * const type1, const element * const type2, const int ranges[NDIM] )
     101PairCorrelationMap *PeriodicPairCorrelation(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const int ranges[NDIM] )
    85102{
    86103  Info FunctionInfo(__func__);
     
    100117  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    101118    (*MolWalker)->doCountAtoms();
     119
     120  // create all possible pairs of elements
     121  set <pair<element *, element *> > PairsOfElements;
     122  if (elements.size() >= 2) {
     123    for (vector<element *>::const_iterator type1 = elements.begin(); type1 != elements.end(); ++type1)
     124      for (vector<element *>::const_iterator type2 = elements.begin(); type2 != elements.end(); ++type2)
     125        if (type1 != type2) {
     126          PairsOfElements.insert( pair<element *, element*>(*type1,*type2) );
     127          DoLog(1) && (Log() << Verbose(1) << "Creating element pair " << (*type1)->symbol << " and " << (*type2)->symbol << "." << endl);
     128        }
     129  } else if (elements.size() == 1) { // one to all are valid
     130    element *elemental = *elements.begin();
     131    PairsOfElements.insert( pair<element *, element*>(elemental,(element *)NULL) );
     132    PairsOfElements.insert( pair<element *, element*>((element *)NULL,elemental) );
     133  } else { // all elements valid
     134    PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
     135  }
     136
    102137  outmap = new PairCorrelationMap;
    103   for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    104     if ((*MolWalker)->ActiveFlag) {
    105       double * FullMatrix = ReturnFullMatrixforSymmetric(World::getInstance().getDomain());
    106       double * FullInverseMatrix = InverseMatrix(FullMatrix);
     138  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++){
     139    if ((*MolWalker)->ActiveFlag) {
     140      Matrix FullMatrix = World::getInstance().getDomain().getM();
     141      Matrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
    107142      DoeLog(2) && (eLog()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
     143      eLog() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
    108144      for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
    109145        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
    110         if ((type1 == NULL) || ((*iter)->type == type1)) {
    111           periodicX = *(*iter)->node;
    112           periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
    113           // go through every range in xyz and get distance
    114           for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
    115             for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
    116               for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
    117                 checkX = Vector(n[0], n[1], n[2]) + periodicX;
    118                 checkX.MatrixMultiplication(FullMatrix);
    119                 for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++)
    120                   if ((*MolOtherWalker)->ActiveFlag) {
    121                     DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
    122                     for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
    123                       DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);
    124                       if ((*iter)->nr < (*runner)->nr)
    125                         if ((type2 == NULL) || ((*runner)->type == type2)) {
    126                           periodicOtherX = *(*runner)->node;
    127                           periodicOtherX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
     146        periodicX = FullInverseMatrix * (*(*iter)->node); // x now in [0,1)^3
     147        // go through every range in xyz and get distance
     148        for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
     149          for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
     150            for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
     151              checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
     152              for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++){
     153                if ((*MolOtherWalker)->ActiveFlag) {
     154                  DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
     155                  for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
     156                    DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);
     157                    if ((*iter)->getId() < (*runner)->getId()){
     158                      for (set <pair<element *, element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
     159                        if ((PairRunner->first == (**iter).type) && (PairRunner->second == (**runner).type)) {
     160                          periodicOtherX = FullInverseMatrix * (*(*runner)->node); // x now in [0,1)^3
    128161                          // go through every range in xyz and get distance
    129162                          for (Othern[0]=-ranges[0]; Othern[0] <= ranges[0]; Othern[0]++)
    130163                            for (Othern[1]=-ranges[1]; Othern[1] <= ranges[1]; Othern[1]++)
    131164                              for (Othern[2]=-ranges[2]; Othern[2] <= ranges[2]; Othern[2]++) {
    132                                 checkOtherX = Vector(Othern[0], Othern[1], Othern[2]) + periodicOtherX;
    133                                 checkOtherX.MatrixMultiplication(FullMatrix);
     165                                checkOtherX = FullMatrix * (Vector(Othern[0], Othern[1], Othern[2]) + periodicOtherX);
    134166                                distance = checkX.distance(checkOtherX);
    135167                                //Log() << Verbose(1) <<"Inserting " << *(*iter) << " and " << *(*runner) << endl;
     
    137169                              }
    138170                        }
     171                    }
    139172                  }
     173                }
    140174              }
    141175            }
    142         }
    143       }
    144       delete[](FullMatrix);
    145       delete[](FullInverseMatrix);
    146     }
     176      }
     177    }
     178  }
    147179
    148180  return outmap;
     
    150182
    151183/** Calculates the distance (pair) correlation between a given element and a point.
    152  * \param *out output stream for debugging
    153  * \param *molecules list of molecules structure
    154  * \param *type element or NULL (if any element)
     184 * \param *molecules list of molecules structure
     185 * \param &elements vector of elements to correlate with point
    155186 * \param *point vector to the correlation point
    156187 * \return Map of dobules with values as pairs of atom and the vector
    157188 */
    158 CorrelationToPointMap *CorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point )
     189CorrelationToPointMap *CorrelationToPoint(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Vector *point )
    159190{
    160191  Info FunctionInfo(__func__);
    161192  CorrelationToPointMap *outmap = NULL;
    162193  double distance = 0.;
     194  Box &domain = World::getInstance().getDomain();
    163195
    164196  if (molecules->ListOfMolecules.empty()) {
     
    174206      for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
    175207        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
    176         if ((type == NULL) || ((*iter)->type == type)) {
    177           distance = (*iter)->node->PeriodicDistance(*point, World::getInstance().getDomain());
    178           DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
    179           outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> ((*iter), point) ) );
    180         }
     208        for (vector<element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
     209          if ((*type == NULL) || ((*iter)->type == *type)) {
     210            distance = domain.periodicDistance(*(*iter)->node,*point);
     211            DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
     212            outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> ((*iter), point) ) );
     213          }
    181214      }
    182215    }
     
    186219
    187220/** Calculates the distance (pair) correlation between a given element, all its periodic images and a point.
    188  * \param *out output stream for debugging
    189  * \param *molecules list of molecules structure
    190  * \param *type element or NULL (if any element)
     221 * \param *molecules list of molecules structure
     222 * \param &elements vector of elements to correlate to point
    191223 * \param *point vector to the correlation point
    192224 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
    193225 * \return Map of dobules with values as pairs of atom and the vector
    194226 */
    195 CorrelationToPointMap *PeriodicCorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point, const int ranges[NDIM] )
     227CorrelationToPointMap *PeriodicCorrelationToPoint(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Vector *point, const int ranges[NDIM] )
    196228{
    197229  Info FunctionInfo(__func__);
     
    211243  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    212244    if ((*MolWalker)->ActiveFlag) {
    213       double * FullMatrix = ReturnFullMatrixforSymmetric(World::getInstance().getDomain());
    214       double * FullInverseMatrix = InverseMatrix(FullMatrix);
     245      Matrix FullMatrix = World::getInstance().getDomain().getM();
     246      Matrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
    215247      DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
    216248      for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
    217249        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
    218         if ((type == NULL) || ((*iter)->type == type)) {
    219           periodicX = *(*iter)->node;
    220           periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
    221           // go through every range in xyz and get distance
    222           for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
    223             for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
    224               for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
    225                 checkX = Vector(n[0], n[1], n[2]) + periodicX;
    226                 checkX.MatrixMultiplication(FullMatrix);
    227                 distance = checkX.distance(*point);
    228                 DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
    229                 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (*iter, point) ) );
    230               }
    231         }
    232       }
    233       delete[](FullMatrix);
    234       delete[](FullInverseMatrix);
     250        for (vector<element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
     251          if ((*type == NULL) || ((*iter)->type == *type)) {
     252            periodicX = FullInverseMatrix * (*(*iter)->node); // x now in [0,1)^3
     253            // go through every range in xyz and get distance
     254            for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
     255              for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
     256                for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
     257                  checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
     258                  distance = checkX.distance(*point);
     259                  DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
     260                  outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (*iter, point) ) );
     261                }
     262          }
     263      }
    235264    }
    236265
     
    239268
    240269/** Calculates the distance (pair) correlation between a given element and a surface.
    241  * \param *out output stream for debugging
    242  * \param *molecules list of molecules structure
    243  * \param *type element or NULL (if any element)
     270 * \param *molecules list of molecules structure
     271 * \param &elements vector of elements to correlate to surface
    244272 * \param *Surface pointer to Tesselation class surface
    245273 * \param *LC LinkedCell structure to quickly find neighbouring atoms
    246274 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
    247275 */
    248 CorrelationToSurfaceMap *CorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC )
     276CorrelationToSurfaceMap *CorrelationToSurface(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Tesselation * const Surface, const LinkedCell *LC )
    249277{
    250278  Info FunctionInfo(__func__);
     
    268296      for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
    269297        DoLog(1) && (Log() << Verbose(1) << "\tCurrent atom is " << *(*iter) << "." << endl);
    270         if ((type == NULL) || ((*iter)->type == type)) {
    271           TriangleIntersectionList Intersections((*iter)->node,Surface,LC);
    272           distance = Intersections.GetSmallestDistance();
    273           triangle = Intersections.GetClosestTriangle();
    274           outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> ((*iter), triangle) ) );
    275         }
     298        for (vector<element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
     299          if ((*type == NULL) || ((*iter)->type == *type)) {
     300            TriangleIntersectionList Intersections((*iter)->node,Surface,LC);
     301            distance = Intersections.GetSmallestDistance();
     302            triangle = Intersections.GetClosestTriangle();
     303            outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> ((*iter), triangle) ) );
     304          }
    276305      }
    277306    } else {
     
    287316 * axis an integer from [ -ranges[i], ranges[i] ] onto it and multiply with the domain matrix to bring it back into
    288317 * the real space. Then, we Tesselation::FindClosestTriangleToPoint() and DistanceToTrianglePlane().
    289  * \param *out output stream for debugging
    290  * \param *molecules list of molecules structure
    291  * \param *type element or NULL (if any element)
     318 * \param *molecules list of molecules structure
     319 * \param &elements vector of elements to correlate to surface
    292320 * \param *Surface pointer to Tesselation class surface
    293321 * \param *LC LinkedCell structure to quickly find neighbouring atoms
     
    295323 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
    296324 */
    297 CorrelationToSurfaceMap *PeriodicCorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] )
     325CorrelationToSurfaceMap *PeriodicCorrelationToSurface(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] )
    298326{
    299327  Info FunctionInfo(__func__);
     
    317345  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    318346    if ((*MolWalker)->ActiveFlag) {
    319       double * FullMatrix = ReturnFullMatrixforSymmetric(World::getInstance().getDomain());
    320       double * FullInverseMatrix = InverseMatrix(FullMatrix);
     347      Matrix FullMatrix = World::getInstance().getDomain().getM();
     348      Matrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
    321349      DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
    322350      for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
    323351        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
    324         if ((type == NULL) || ((*iter)->type == type)) {
    325           periodicX = *(*iter)->node;
    326           periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3
    327           // go through every range in xyz and get distance
    328           ShortestDistance = -1.;
    329           for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
    330             for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
    331               for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
    332                 checkX = Vector(n[0], n[1], n[2]) + periodicX;
    333                 checkX.MatrixMultiplication(FullMatrix);
    334                 TriangleIntersectionList Intersections(&checkX,Surface,LC);
    335                 distance = Intersections.GetSmallestDistance();
    336                 triangle = Intersections.GetClosestTriangle();
    337                 if ((ShortestDistance == -1.) || (distance < ShortestDistance)) {
    338                   ShortestDistance = distance;
    339                   ShortestTriangle = triangle;
     352        for (vector<element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
     353          if ((*type == NULL) || ((*iter)->type == *type)) {
     354            periodicX = FullInverseMatrix * (*(*iter)->node); // x now in [0,1)^3
     355            // go through every range in xyz and get distance
     356            ShortestDistance = -1.;
     357            for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
     358              for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
     359                for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
     360                  checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
     361                  TriangleIntersectionList Intersections(&checkX,Surface,LC);
     362                  distance = Intersections.GetSmallestDistance();
     363                  triangle = Intersections.GetClosestTriangle();
     364                  if ((ShortestDistance == -1.) || (distance < ShortestDistance)) {
     365                    ShortestDistance = distance;
     366                    ShortestTriangle = triangle;
     367                  }
    340368                }
    341               }
    342           // insert
    343           outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(ShortestDistance, pair<atom *, BoundaryTriangleSet*> (*iter, ShortestTriangle) ) );
    344           //Log() << Verbose(1) << "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << "." << endl;
    345         }
    346       }
    347       delete[](FullMatrix);
    348       delete[](FullInverseMatrix);
     369            // insert
     370            outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(ShortestDistance, pair<atom *, BoundaryTriangleSet*> (*iter, ShortestTriangle) ) );
     371            //Log() << Verbose(1) << "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << "." << endl;
     372          }
     373      }
    349374    }
    350375
Note: See TracChangeset for help on using the changeset viewer.