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