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