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