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