| [c4d4df] | 1 | /*
 | 
|---|
 | 2 |  * analysis.cpp
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  *  Created on: Oct 13, 2009
 | 
|---|
 | 5 |  *      Author: heber
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | #include <iostream>
 | 
|---|
 | 9 | 
 | 
|---|
 | 10 | #include "analysis_correlation.hpp"
 | 
|---|
 | 11 | #include "element.hpp"
 | 
|---|
| [3930eb] | 12 | #include "info.hpp"
 | 
|---|
| [e138de] | 13 | #include "log.hpp"
 | 
|---|
| [c4d4df] | 14 | #include "molecule.hpp"
 | 
|---|
 | 15 | #include "tesselation.hpp"
 | 
|---|
 | 16 | #include "tesselationhelpers.hpp"
 | 
|---|
| [8db598] | 17 | #include "triangleintersectionlist.hpp"
 | 
|---|
| [c4d4df] | 18 | #include "vector.hpp"
 | 
|---|
| [a5551b] | 19 | #include "verbose.hpp"
 | 
|---|
| [b34306] | 20 | #include "World.hpp"
 | 
|---|
| [c4d4df] | 21 | 
 | 
|---|
 | 22 | 
 | 
|---|
 | 23 | /** Calculates the pair correlation between given elements.
 | 
|---|
 | 24 |  * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
 | 
|---|
 | 25 |  * \param *out output stream for debugging
 | 
|---|
| [a5551b] | 26 |  * \param *molecules list of molecules structure
 | 
|---|
| [c4d4df] | 27 |  * \param *type1 first element or NULL (if any element)
 | 
|---|
 | 28 |  * \param *type2 second element or NULL (if any element)
 | 
|---|
 | 29 |  * \return Map of doubles with values the pair of the two atoms.
 | 
|---|
 | 30 |  */
 | 
|---|
| [e138de] | 31 | PairCorrelationMap *PairCorrelation(MoleculeListClass * const &molecules, const element * const type1, const element * const type2 )
 | 
|---|
| [c4d4df] | 32 | {
 | 
|---|
| [3930eb] | 33 |   Info FunctionInfo(__func__);
 | 
|---|
| [c4d4df] | 34 |   PairCorrelationMap *outmap = NULL;
 | 
|---|
 | 35 |   double distance = 0.;
 | 
|---|
 | 36 | 
 | 
|---|
| [a5551b] | 37 |   if (molecules->ListOfMolecules.empty()) {
 | 
|---|
| [58ed4a] | 38 |     DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
 | 
|---|
| [c4d4df] | 39 |     return outmap;
 | 
|---|
 | 40 |   }
 | 
|---|
 | 41 |   outmap = new PairCorrelationMap;
 | 
|---|
| [a5551b] | 42 |   for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
 | 
|---|
 | 43 |     if ((*MolWalker)->ActiveFlag) {
 | 
|---|
| [58ed4a] | 44 |       DoeLog(2) && (eLog()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
 | 
|---|
| [a5551b] | 45 |       atom *Walker = (*MolWalker)->start;
 | 
|---|
 | 46 |       while (Walker->next != (*MolWalker)->end) {
 | 
|---|
 | 47 |         Walker = Walker->next;
 | 
|---|
| [a67d19] | 48 |         DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl);
 | 
|---|
| [a5551b] | 49 |         if ((type1 == NULL) || (Walker->type == type1)) {
 | 
|---|
 | 50 |           for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++)
 | 
|---|
 | 51 |             if ((*MolOtherWalker)->ActiveFlag) {
 | 
|---|
| [a67d19] | 52 |               DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
 | 
|---|
| [a5551b] | 53 |               atom *OtherWalker = (*MolOtherWalker)->start;
 | 
|---|
 | 54 |               while (OtherWalker->next != (*MolOtherWalker)->end) { // only go up to Walker
 | 
|---|
 | 55 |                 OtherWalker = OtherWalker->next;
 | 
|---|
| [a67d19] | 56 |                 DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl);
 | 
|---|
| [a5551b] | 57 |                 if (Walker->nr < OtherWalker->nr)
 | 
|---|
 | 58 |                   if ((type2 == NULL) || (OtherWalker->type == type2)) {
 | 
|---|
| [8cbb97] | 59 |                     distance = Walker->node->PeriodicDistance(*OtherWalker->node, World::getInstance().getDomain());
 | 
|---|
| [e138de] | 60 |                     //Log() << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl;
 | 
|---|
| [a5551b] | 61 |                     outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) );
 | 
|---|
 | 62 |                   }
 | 
|---|
 | 63 |               }
 | 
|---|
| [c4d4df] | 64 |           }
 | 
|---|
| [a5551b] | 65 |         }
 | 
|---|
| [c4d4df] | 66 |       }
 | 
|---|
 | 67 |     }
 | 
|---|
 | 68 | 
 | 
|---|
 | 69 |   return outmap;
 | 
|---|
 | 70 | };
 | 
|---|
 | 71 | 
 | 
|---|
| [7ea9e6] | 72 | /** Calculates the pair correlation between given elements.
 | 
|---|
 | 73 |  * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
 | 
|---|
 | 74 |  * \param *out output stream for debugging
 | 
|---|
 | 75 |  * \param *molecules list of molecules structure
 | 
|---|
 | 76 |  * \param *type1 first element or NULL (if any element)
 | 
|---|
 | 77 |  * \param *type2 second element or NULL (if any element)
 | 
|---|
 | 78 |  * \param ranges[NDIM] interval boundaries for the periodic images to scan also
 | 
|---|
 | 79 |  * \return Map of doubles with values the pair of the two atoms.
 | 
|---|
 | 80 |  */
 | 
|---|
| [e138de] | 81 | PairCorrelationMap *PeriodicPairCorrelation(MoleculeListClass * const &molecules, const element * const type1, const element * const type2, const int ranges[NDIM] )
 | 
|---|
| [7ea9e6] | 82 | {
 | 
|---|
| [3930eb] | 83 |   Info FunctionInfo(__func__);
 | 
|---|
| [7ea9e6] | 84 |   PairCorrelationMap *outmap = NULL;
 | 
|---|
 | 85 |   double distance = 0.;
 | 
|---|
 | 86 |   int n[NDIM];
 | 
|---|
 | 87 |   Vector checkX;
 | 
|---|
 | 88 |   Vector periodicX;
 | 
|---|
 | 89 |   int Othern[NDIM];
 | 
|---|
 | 90 |   Vector checkOtherX;
 | 
|---|
 | 91 |   Vector periodicOtherX;
 | 
|---|
 | 92 | 
 | 
|---|
 | 93 |   if (molecules->ListOfMolecules.empty()) {
 | 
|---|
| [58ed4a] | 94 |     DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
 | 
|---|
| [7ea9e6] | 95 |     return outmap;
 | 
|---|
 | 96 |   }
 | 
|---|
 | 97 |   outmap = new PairCorrelationMap;
 | 
|---|
 | 98 |   for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
 | 
|---|
 | 99 |     if ((*MolWalker)->ActiveFlag) {
 | 
|---|
| [5f612ee] | 100 |       double * FullMatrix = ReturnFullMatrixforSymmetric(World::getInstance().getDomain());
 | 
|---|
| [1614174] | 101 |       double * FullInverseMatrix = InverseMatrix(FullMatrix);
 | 
|---|
| [58ed4a] | 102 |       DoeLog(2) && (eLog()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
 | 
|---|
| [7ea9e6] | 103 |       atom *Walker = (*MolWalker)->start;
 | 
|---|
 | 104 |       while (Walker->next != (*MolWalker)->end) {
 | 
|---|
 | 105 |         Walker = Walker->next;
 | 
|---|
| [a67d19] | 106 |         DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl);
 | 
|---|
| [7ea9e6] | 107 |         if ((type1 == NULL) || (Walker->type == type1)) {
 | 
|---|
| [273382] | 108 |           periodicX = *(Walker->node);
 | 
|---|
| [7ea9e6] | 109 |           periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
 | 
|---|
 | 110 |           // go through every range in xyz and get distance
 | 
|---|
 | 111 |           for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
 | 
|---|
 | 112 |             for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
 | 
|---|
 | 113 |               for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
 | 
|---|
| [273382] | 114 |                 checkX = Vector(n[0], n[1], n[2]) + periodicX;
 | 
|---|
| [7ea9e6] | 115 |                 checkX.MatrixMultiplication(FullMatrix);
 | 
|---|
 | 116 |                 for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++)
 | 
|---|
 | 117 |                   if ((*MolOtherWalker)->ActiveFlag) {
 | 
|---|
| [a67d19] | 118 |                     DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
 | 
|---|
| [7ea9e6] | 119 |                     atom *OtherWalker = (*MolOtherWalker)->start;
 | 
|---|
 | 120 |                     while (OtherWalker->next != (*MolOtherWalker)->end) { // only go up to Walker
 | 
|---|
 | 121 |                       OtherWalker = OtherWalker->next;
 | 
|---|
| [a67d19] | 122 |                       DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl);
 | 
|---|
| [7ea9e6] | 123 |                       if (Walker->nr < OtherWalker->nr)
 | 
|---|
 | 124 |                         if ((type2 == NULL) || (OtherWalker->type == type2)) {
 | 
|---|
| [273382] | 125 |                           periodicOtherX = *(OtherWalker->node);
 | 
|---|
| [7ea9e6] | 126 |                           periodicOtherX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
 | 
|---|
 | 127 |                           // go through every range in xyz and get distance
 | 
|---|
 | 128 |                           for (Othern[0]=-ranges[0]; Othern[0] <= ranges[0]; Othern[0]++)
 | 
|---|
 | 129 |                             for (Othern[1]=-ranges[1]; Othern[1] <= ranges[1]; Othern[1]++)
 | 
|---|
 | 130 |                               for (Othern[2]=-ranges[2]; Othern[2] <= ranges[2]; Othern[2]++) {
 | 
|---|
| [273382] | 131 |                                 checkOtherX = Vector(Othern[0], Othern[1], Othern[2]) + periodicOtherX;
 | 
|---|
| [7ea9e6] | 132 |                                 checkOtherX.MatrixMultiplication(FullMatrix);
 | 
|---|
| [1513a74] | 133 |                                 distance = checkX.distance(checkOtherX);
 | 
|---|
| [e138de] | 134 |                                 //Log() << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl;
 | 
|---|
| [7ea9e6] | 135 |                                 outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) );
 | 
|---|
 | 136 |                               }
 | 
|---|
 | 137 |                         }
 | 
|---|
 | 138 |                   }
 | 
|---|
 | 139 |               }
 | 
|---|
 | 140 |             }
 | 
|---|
 | 141 |         }
 | 
|---|
 | 142 |       }
 | 
|---|
| [1614174] | 143 |       Free(&FullMatrix);
 | 
|---|
 | 144 |       Free(&FullInverseMatrix);
 | 
|---|
| [7ea9e6] | 145 |     }
 | 
|---|
 | 146 | 
 | 
|---|
 | 147 |   return outmap;
 | 
|---|
 | 148 | };
 | 
|---|
 | 149 | 
 | 
|---|
| [c4d4df] | 150 | /** Calculates the distance (pair) correlation between a given element and a point.
 | 
|---|
 | 151 |  * \param *out output stream for debugging
 | 
|---|
| [a5551b] | 152 |  * \param *molecules list of molecules structure
 | 
|---|
| [c4d4df] | 153 |  * \param *type element or NULL (if any element)
 | 
|---|
 | 154 |  * \param *point vector to the correlation point
 | 
|---|
 | 155 |  * \return Map of dobules with values as pairs of atom and the vector
 | 
|---|
 | 156 |  */
 | 
|---|
| [e138de] | 157 | CorrelationToPointMap *CorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point )
 | 
|---|
| [c4d4df] | 158 | {
 | 
|---|
| [3930eb] | 159 |   Info FunctionInfo(__func__);
 | 
|---|
| [c4d4df] | 160 |   CorrelationToPointMap *outmap = NULL;
 | 
|---|
 | 161 |   double distance = 0.;
 | 
|---|
 | 162 | 
 | 
|---|
| [a5551b] | 163 |   if (molecules->ListOfMolecules.empty()) {
 | 
|---|
| [a67d19] | 164 |     DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
 | 
|---|
| [c4d4df] | 165 |     return outmap;
 | 
|---|
 | 166 |   }
 | 
|---|
 | 167 |   outmap = new CorrelationToPointMap;
 | 
|---|
| [a5551b] | 168 |   for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
 | 
|---|
 | 169 |     if ((*MolWalker)->ActiveFlag) {
 | 
|---|
| [a67d19] | 170 |       DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
 | 
|---|
| [a5551b] | 171 |       atom *Walker = (*MolWalker)->start;
 | 
|---|
 | 172 |       while (Walker->next != (*MolWalker)->end) {
 | 
|---|
 | 173 |         Walker = Walker->next;
 | 
|---|
| [a67d19] | 174 |         DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl);
 | 
|---|
| [a5551b] | 175 |         if ((type == NULL) || (Walker->type == type)) {
 | 
|---|
| [8cbb97] | 176 |           distance = Walker->node->PeriodicDistance(*point, World::getInstance().getDomain());
 | 
|---|
| [a67d19] | 177 |           DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
 | 
|---|
| [a5551b] | 178 |           outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) );
 | 
|---|
 | 179 |         }
 | 
|---|
 | 180 |       }
 | 
|---|
| [c4d4df] | 181 |     }
 | 
|---|
 | 182 | 
 | 
|---|
 | 183 |   return outmap;
 | 
|---|
 | 184 | };
 | 
|---|
 | 185 | 
 | 
|---|
| [7ea9e6] | 186 | /** Calculates the distance (pair) correlation between a given element, all its periodic images and a point.
 | 
|---|
 | 187 |  * \param *out output stream for debugging
 | 
|---|
 | 188 |  * \param *molecules list of molecules structure
 | 
|---|
 | 189 |  * \param *type element or NULL (if any element)
 | 
|---|
 | 190 |  * \param *point vector to the correlation point
 | 
|---|
 | 191 |  * \param ranges[NDIM] interval boundaries for the periodic images to scan also
 | 
|---|
 | 192 |  * \return Map of dobules with values as pairs of atom and the vector
 | 
|---|
 | 193 |  */
 | 
|---|
| [e138de] | 194 | CorrelationToPointMap *PeriodicCorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point, const int ranges[NDIM] )
 | 
|---|
| [7ea9e6] | 195 | {
 | 
|---|
| [3930eb] | 196 |   Info FunctionInfo(__func__);
 | 
|---|
| [7ea9e6] | 197 |   CorrelationToPointMap *outmap = NULL;
 | 
|---|
 | 198 |   double distance = 0.;
 | 
|---|
 | 199 |   int n[NDIM];
 | 
|---|
 | 200 |   Vector periodicX;
 | 
|---|
 | 201 |   Vector checkX;
 | 
|---|
 | 202 | 
 | 
|---|
 | 203 |   if (molecules->ListOfMolecules.empty()) {
 | 
|---|
| [a67d19] | 204 |     DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
 | 
|---|
| [7ea9e6] | 205 |     return outmap;
 | 
|---|
 | 206 |   }
 | 
|---|
 | 207 |   outmap = new CorrelationToPointMap;
 | 
|---|
 | 208 |   for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
 | 
|---|
 | 209 |     if ((*MolWalker)->ActiveFlag) {
 | 
|---|
| [5f612ee] | 210 |       double * FullMatrix = ReturnFullMatrixforSymmetric(World::getInstance().getDomain());
 | 
|---|
| [1614174] | 211 |       double * FullInverseMatrix = InverseMatrix(FullMatrix);
 | 
|---|
| [a67d19] | 212 |       DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
 | 
|---|
| [7ea9e6] | 213 |       atom *Walker = (*MolWalker)->start;
 | 
|---|
 | 214 |       while (Walker->next != (*MolWalker)->end) {
 | 
|---|
 | 215 |         Walker = Walker->next;
 | 
|---|
| [a67d19] | 216 |         DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl);
 | 
|---|
| [7ea9e6] | 217 |         if ((type == NULL) || (Walker->type == type)) {
 | 
|---|
| [273382] | 218 |           periodicX = *(Walker->node);
 | 
|---|
| [7ea9e6] | 219 |           periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
 | 
|---|
 | 220 |           // go through every range in xyz and get distance
 | 
|---|
 | 221 |           for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
 | 
|---|
 | 222 |             for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
 | 
|---|
 | 223 |               for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
 | 
|---|
| [273382] | 224 |                 checkX = Vector(n[0], n[1], n[2]) + periodicX;
 | 
|---|
| [7ea9e6] | 225 |                 checkX.MatrixMultiplication(FullMatrix);
 | 
|---|
| [1513a74] | 226 |                 distance = checkX.distance(*point);
 | 
|---|
| [a67d19] | 227 |                 DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
 | 
|---|
| [7ea9e6] | 228 |                 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) );
 | 
|---|
 | 229 |               }
 | 
|---|
 | 230 |         }
 | 
|---|
 | 231 |       }
 | 
|---|
| [1614174] | 232 |       Free(&FullMatrix);
 | 
|---|
 | 233 |       Free(&FullInverseMatrix);
 | 
|---|
| [7ea9e6] | 234 |     }
 | 
|---|
 | 235 | 
 | 
|---|
 | 236 |   return outmap;
 | 
|---|
 | 237 | };
 | 
|---|
 | 238 | 
 | 
|---|
| [c4d4df] | 239 | /** Calculates the distance (pair) correlation between a given element and a surface.
 | 
|---|
 | 240 |  * \param *out output stream for debugging
 | 
|---|
| [a5551b] | 241 |  * \param *molecules list of molecules structure
 | 
|---|
| [c4d4df] | 242 |  * \param *type element or NULL (if any element)
 | 
|---|
 | 243 |  * \param *Surface pointer to Tesselation class surface
 | 
|---|
 | 244 |  * \param *LC LinkedCell structure to quickly find neighbouring atoms
 | 
|---|
 | 245 |  * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
 | 
|---|
 | 246 |  */
 | 
|---|
| [e138de] | 247 | CorrelationToSurfaceMap *CorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC )
 | 
|---|
| [c4d4df] | 248 | {
 | 
|---|
| [3930eb] | 249 |   Info FunctionInfo(__func__);
 | 
|---|
| [c4d4df] | 250 |   CorrelationToSurfaceMap *outmap = NULL;
 | 
|---|
| [99593f] | 251 |   double distance = 0;
 | 
|---|
| [c4d4df] | 252 |   class BoundaryTriangleSet *triangle = NULL;
 | 
|---|
 | 253 |   Vector centroid;
 | 
|---|
| [7ea9e6] | 254 | 
 | 
|---|
 | 255 |   if ((Surface == NULL) || (LC == NULL) || (molecules->ListOfMolecules.empty())) {
 | 
|---|
| [58ed4a] | 256 |     DoeLog(1) && (eLog()<< Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
 | 
|---|
| [7ea9e6] | 257 |     return outmap;
 | 
|---|
 | 258 |   }
 | 
|---|
 | 259 |   outmap = new CorrelationToSurfaceMap;
 | 
|---|
 | 260 |   for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
 | 
|---|
 | 261 |     if ((*MolWalker)->ActiveFlag) {
 | 
|---|
| [a67d19] | 262 |       DoLog(1) && (Log() << Verbose(1) << "Current molecule is " << (*MolWalker)->name << "." << endl);
 | 
|---|
| [7ea9e6] | 263 |       atom *Walker = (*MolWalker)->start;
 | 
|---|
 | 264 |       while (Walker->next != (*MolWalker)->end) {
 | 
|---|
 | 265 |         Walker = Walker->next;
 | 
|---|
| [8db598] | 266 |         //Log() << Verbose(1) << "Current atom is " << *Walker << "." << endl;
 | 
|---|
| [7ea9e6] | 267 |         if ((type == NULL) || (Walker->type == type)) {
 | 
|---|
| [8db598] | 268 |           TriangleIntersectionList Intersections(Walker->node,Surface,LC);
 | 
|---|
 | 269 |           distance = Intersections.GetSmallestDistance();
 | 
|---|
 | 270 |           triangle = Intersections.GetClosestTriangle();
 | 
|---|
 | 271 |           outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> (Walker, triangle) ) );
 | 
|---|
| [7ea9e6] | 272 |         }
 | 
|---|
 | 273 |       }
 | 
|---|
| [8db598] | 274 |     } else
 | 
|---|
| [a67d19] | 275 |       DoLog(1) && (Log() << Verbose(1) << "molecule " << (*MolWalker)->name << " is not active." << endl);
 | 
|---|
| [7ea9e6] | 276 | 
 | 
|---|
 | 277 |   return outmap;
 | 
|---|
 | 278 | };
 | 
|---|
 | 279 | 
 | 
|---|
 | 280 | /** Calculates the distance (pair) correlation between a given element, all its periodic images and and a surface.
 | 
|---|
 | 281 |  * Note that we also put all periodic images found in the cells given by [ -ranges[i], ranges[i] ] and i=0,...,NDIM-1.
 | 
|---|
 | 282 |  * I.e. We multiply the atom::node with the inverse of the domain matrix, i.e. transform it to \f$[0,0^3\f$, then add per
 | 
|---|
 | 283 |  * axis an integer from [ -ranges[i], ranges[i] ] onto it and multiply with the domain matrix to bring it back into
 | 
|---|
 | 284 |  * the real space. Then, we Tesselation::FindClosestTriangleToPoint() and DistanceToTrianglePlane().
 | 
|---|
 | 285 |  * \param *out output stream for debugging
 | 
|---|
 | 286 |  * \param *molecules list of molecules structure
 | 
|---|
 | 287 |  * \param *type element or NULL (if any element)
 | 
|---|
 | 288 |  * \param *Surface pointer to Tesselation class surface
 | 
|---|
 | 289 |  * \param *LC LinkedCell structure to quickly find neighbouring atoms
 | 
|---|
 | 290 |  * \param ranges[NDIM] interval boundaries for the periodic images to scan also
 | 
|---|
 | 291 |  * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
 | 
|---|
 | 292 |  */
 | 
|---|
| [e138de] | 293 | CorrelationToSurfaceMap *PeriodicCorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] )
 | 
|---|
| [7ea9e6] | 294 | {
 | 
|---|
| [3930eb] | 295 |   Info FunctionInfo(__func__);
 | 
|---|
| [7ea9e6] | 296 |   CorrelationToSurfaceMap *outmap = NULL;
 | 
|---|
 | 297 |   double distance = 0;
 | 
|---|
 | 298 |   class BoundaryTriangleSet *triangle = NULL;
 | 
|---|
 | 299 |   Vector centroid;
 | 
|---|
| [99593f] | 300 |   int n[NDIM];
 | 
|---|
 | 301 |   Vector periodicX;
 | 
|---|
 | 302 |   Vector checkX;
 | 
|---|
| [c4d4df] | 303 | 
 | 
|---|
| [a5551b] | 304 |   if ((Surface == NULL) || (LC == NULL) || (molecules->ListOfMolecules.empty())) {
 | 
|---|
| [a67d19] | 305 |     DoLog(1) && (Log() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
 | 
|---|
| [c4d4df] | 306 |     return outmap;
 | 
|---|
 | 307 |   }
 | 
|---|
 | 308 |   outmap = new CorrelationToSurfaceMap;
 | 
|---|
| [244a84] | 309 |   double ShortestDistance = 0.;
 | 
|---|
 | 310 |   BoundaryTriangleSet *ShortestTriangle = NULL;
 | 
|---|
| [a5551b] | 311 |   for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
 | 
|---|
 | 312 |     if ((*MolWalker)->ActiveFlag) {
 | 
|---|
| [5f612ee] | 313 |       double * FullMatrix = ReturnFullMatrixforSymmetric(World::getInstance().getDomain());
 | 
|---|
| [1614174] | 314 |       double * FullInverseMatrix = InverseMatrix(FullMatrix);
 | 
|---|
| [a67d19] | 315 |       DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
 | 
|---|
| [a5551b] | 316 |       atom *Walker = (*MolWalker)->start;
 | 
|---|
 | 317 |       while (Walker->next != (*MolWalker)->end) {
 | 
|---|
 | 318 |         Walker = Walker->next;
 | 
|---|
| [a67d19] | 319 |         DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl);
 | 
|---|
| [a5551b] | 320 |         if ((type == NULL) || (Walker->type == type)) {
 | 
|---|
| [273382] | 321 |           periodicX = *(Walker->node);
 | 
|---|
| [99593f] | 322 |           periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
 | 
|---|
 | 323 |           // go through every range in xyz and get distance
 | 
|---|
| [244a84] | 324 |           ShortestDistance = -1.;
 | 
|---|
| [99593f] | 325 |           for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
 | 
|---|
 | 326 |             for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
 | 
|---|
 | 327 |               for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
 | 
|---|
| [273382] | 328 |                 checkX = Vector(n[0], n[1], n[2]) + periodicX;
 | 
|---|
| [99593f] | 329 |                 checkX.MatrixMultiplication(FullMatrix);
 | 
|---|
| [58ed4a] | 330 |                 TriangleIntersectionList Intersections(&checkX,Surface,LC);
 | 
|---|
 | 331 |                 distance = Intersections.GetSmallestDistance();
 | 
|---|
 | 332 |                 triangle = Intersections.GetClosestTriangle();
 | 
|---|
| [244a84] | 333 |                 if ((ShortestDistance == -1.) || (distance < ShortestDistance)) {
 | 
|---|
 | 334 |                   ShortestDistance = distance;
 | 
|---|
 | 335 |                   ShortestTriangle = triangle;
 | 
|---|
| [99593f] | 336 |                 }
 | 
|---|
| [244a84] | 337 |               }
 | 
|---|
 | 338 |           // insert
 | 
|---|
 | 339 |           outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(ShortestDistance, pair<atom *, BoundaryTriangleSet*> (Walker, ShortestTriangle) ) );
 | 
|---|
 | 340 |           //Log() << Verbose(1) << "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << "." << endl;
 | 
|---|
| [a5551b] | 341 |         }
 | 
|---|
| [c4d4df] | 342 |       }
 | 
|---|
| [1614174] | 343 |       Free(&FullMatrix);
 | 
|---|
 | 344 |       Free(&FullInverseMatrix);
 | 
|---|
| [c4d4df] | 345 |     }
 | 
|---|
 | 346 | 
 | 
|---|
 | 347 |   return outmap;
 | 
|---|
 | 348 | };
 | 
|---|
 | 349 | 
 | 
|---|
| [bd61b41] | 350 | /** Returns the index of the bin for a given value.
 | 
|---|
| [c4d4df] | 351 |  * \param value value whose bin to look for
 | 
|---|
 | 352 |  * \param BinWidth width of bin
 | 
|---|
 | 353 |  * \param BinStart first bin
 | 
|---|
 | 354 |  */
 | 
|---|
| [bd61b41] | 355 | int GetBin ( const double value, const double BinWidth, const double BinStart )
 | 
|---|
| [c4d4df] | 356 | {
 | 
|---|
| [3930eb] | 357 |   Info FunctionInfo(__func__);
 | 
|---|
| [bd61b41] | 358 |   int bin =(int) (floor((value - BinStart)/BinWidth));
 | 
|---|
 | 359 |   return (bin);
 | 
|---|
| [c4d4df] | 360 | };
 | 
|---|
 | 361 | 
 | 
|---|
 | 362 | 
 | 
|---|
 | 363 | /** Prints correlation (double, int) pairs to file.
 | 
|---|
 | 364 |  * \param *file file to write to
 | 
|---|
 | 365 |  * \param *map map to write
 | 
|---|
 | 366 |  */
 | 
|---|
| [a5551b] | 367 | void OutputCorrelation( ofstream * const file, const BinPairMap * const map )
 | 
|---|
| [c4d4df] | 368 | {
 | 
|---|
| [3930eb] | 369 |   Info FunctionInfo(__func__);
 | 
|---|
| [790807] | 370 |   *file << "BinStart\tCount" << endl;
 | 
|---|
| [776b64] | 371 |   for (BinPairMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
 | 
|---|
| [775d133] | 372 |     *file << setprecision(8) << runner->first << "\t" << runner->second << endl;
 | 
|---|
| [c4d4df] | 373 |   }
 | 
|---|
 | 374 | };
 | 
|---|
| [b1f254] | 375 | 
 | 
|---|
 | 376 | /** Prints correlation (double, (atom*,atom*) ) pairs to file.
 | 
|---|
 | 377 |  * \param *file file to write to
 | 
|---|
 | 378 |  * \param *map map to write
 | 
|---|
 | 379 |  */
 | 
|---|
| [a5551b] | 380 | void OutputPairCorrelation( ofstream * const file, const PairCorrelationMap * const map )
 | 
|---|
| [b1f254] | 381 | {
 | 
|---|
| [3930eb] | 382 |   Info FunctionInfo(__func__);
 | 
|---|
| [790807] | 383 |   *file << "BinStart\tAtom1\tAtom2" << endl;
 | 
|---|
| [776b64] | 384 |   for (PairCorrelationMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
 | 
|---|
| [775d133] | 385 |     *file << setprecision(8) << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl;
 | 
|---|
| [b1f254] | 386 |   }
 | 
|---|
 | 387 | };
 | 
|---|
 | 388 | 
 | 
|---|
 | 389 | /** Prints correlation (double, int) pairs to file.
 | 
|---|
 | 390 |  * \param *file file to write to
 | 
|---|
 | 391 |  * \param *map map to write
 | 
|---|
 | 392 |  */
 | 
|---|
| [a5551b] | 393 | void OutputCorrelationToPoint( ofstream * const file, const CorrelationToPointMap * const map )
 | 
|---|
| [b1f254] | 394 | {
 | 
|---|
| [3930eb] | 395 |   Info FunctionInfo(__func__);
 | 
|---|
| [790807] | 396 |   *file << "BinStart\tAtom::x[i]-point.x[i]" << endl;
 | 
|---|
| [776b64] | 397 |   for (CorrelationToPointMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
 | 
|---|
| [b1f254] | 398 |     *file << runner->first;
 | 
|---|
 | 399 |     for (int i=0;i<NDIM;i++)
 | 
|---|
| [8cbb97] | 400 |       *file << "\t" << setprecision(8) << (runner->second.first->node->at(i) - runner->second.second->at(i));
 | 
|---|
| [b1f254] | 401 |     *file << endl;
 | 
|---|
 | 402 |   }
 | 
|---|
 | 403 | };
 | 
|---|
 | 404 | 
 | 
|---|
 | 405 | /** Prints correlation (double, int) pairs to file.
 | 
|---|
 | 406 |  * \param *file file to write to
 | 
|---|
 | 407 |  * \param *map map to write
 | 
|---|
 | 408 |  */
 | 
|---|
| [a5551b] | 409 | void OutputCorrelationToSurface( ofstream * const file, const CorrelationToSurfaceMap * const map )
 | 
|---|
| [b1f254] | 410 | {
 | 
|---|
| [3930eb] | 411 |   Info FunctionInfo(__func__);
 | 
|---|
| [790807] | 412 |   *file << "BinStart\tTriangle" << endl;
 | 
|---|
| [8db598] | 413 |   if (!map->empty())
 | 
|---|
 | 414 |     for (CorrelationToSurfaceMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
 | 
|---|
 | 415 |       *file << setprecision(8) << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl;
 | 
|---|
 | 416 |     }
 | 
|---|
| [b1f254] | 417 | };
 | 
|---|
 | 418 | 
 | 
|---|