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