1 | /*
|
---|
2 | * analysis.hpp
|
---|
3 | *
|
---|
4 | * Created on: Oct 13, 2009
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef ANALYSIS_HPP_
|
---|
9 | #define ANALYSIS_HPP_
|
---|
10 |
|
---|
11 | using namespace std;
|
---|
12 |
|
---|
13 | /*********************************************** includes ***********************************/
|
---|
14 |
|
---|
15 | // include config.h
|
---|
16 | #ifdef HAVE_CONFIG_H
|
---|
17 | #include <config.h>
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | #include <fstream>
|
---|
21 |
|
---|
22 | // STL headers
|
---|
23 | #include <map>
|
---|
24 | #include <vector>
|
---|
25 |
|
---|
26 | #include "defs.hpp"
|
---|
27 |
|
---|
28 | #include "atom.hpp"
|
---|
29 | #include "verbose.hpp"
|
---|
30 |
|
---|
31 | /****************************************** forward declarations *****************************/
|
---|
32 |
|
---|
33 | class BoundaryTriangleSet;
|
---|
34 | class element;
|
---|
35 | class LinkedCell;
|
---|
36 | class Tesselation;
|
---|
37 | class Vector;
|
---|
38 |
|
---|
39 | /********************************************** definitions *********************************/
|
---|
40 |
|
---|
41 | typedef multimap<double, pair<atom *, atom *> > PairCorrelationMap;
|
---|
42 | typedef multimap<double, pair<atom *, const Vector *> > CorrelationToPointMap;
|
---|
43 | typedef multimap<double, pair<atom *, BoundaryTriangleSet *> > CorrelationToSurfaceMap;
|
---|
44 | typedef map<double, int> BinPairMap;
|
---|
45 |
|
---|
46 | /********************************************** declarations *******************************/
|
---|
47 |
|
---|
48 | PairCorrelationMap *PairCorrelation(std::vector<molecule *> &molecules, const std::vector<element *> &elements);
|
---|
49 | CorrelationToPointMap *CorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<element *> &elements, const Vector *point );
|
---|
50 | CorrelationToSurfaceMap *CorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<element *> &elements, const Tesselation * const Surface, const LinkedCell *LC );
|
---|
51 | PairCorrelationMap *PeriodicPairCorrelation(std::vector<molecule *> &molecules, const std::vector<element *> &elements, const int ranges[NDIM] );
|
---|
52 | CorrelationToPointMap *PeriodicCorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<element *> &elements, const Vector *point, const int ranges[NDIM] );
|
---|
53 | CorrelationToSurfaceMap *PeriodicCorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<element *> &elements, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] );
|
---|
54 | int GetBin ( const double value, const double BinWidth, const double BinStart );
|
---|
55 | void OutputCorrelation( ofstream * const file, const BinPairMap * const map );
|
---|
56 | void OutputPairCorrelation( ofstream * const file, const PairCorrelationMap * const map );
|
---|
57 | void OutputCorrelationToPoint( ofstream * const file, const CorrelationToPointMap * const map );
|
---|
58 | void OutputCorrelationToSurface( ofstream * const file, const CorrelationToSurfaceMap * const map );
|
---|
59 |
|
---|
60 |
|
---|
61 | /** Searches for lowest and highest value in a given map of doubles.
|
---|
62 | * \param *map map of doubles to scan
|
---|
63 | * \param &min minimum on return
|
---|
64 | * \param &max maximum on return
|
---|
65 | */
|
---|
66 | template <typename T> void GetMinMax ( T *map, double &min, double &max)
|
---|
67 | {
|
---|
68 | min = 0.;
|
---|
69 | max = 0.;
|
---|
70 | bool FirstMinFound = false;
|
---|
71 | bool FirstMaxFound = false;
|
---|
72 |
|
---|
73 | if (map == NULL) {
|
---|
74 | DoeLog(0) && (eLog()<< Verbose(0) << "Nothing to min/max, map is NULL!" << endl);
|
---|
75 | performCriticalExit();
|
---|
76 | return;
|
---|
77 | }
|
---|
78 |
|
---|
79 | for (typename T::iterator runner = map->begin(); runner != map->end(); ++runner) {
|
---|
80 | if ((min > runner->first) || (!FirstMinFound)) {
|
---|
81 | min = runner->first;
|
---|
82 | FirstMinFound = true;
|
---|
83 | }
|
---|
84 | if ((max < runner->first) || (!FirstMaxFound)) {
|
---|
85 | max = runner->first;
|
---|
86 | FirstMaxFound = true;
|
---|
87 | }
|
---|
88 | }
|
---|
89 | };
|
---|
90 |
|
---|
91 | /** Puts given correlation data into bins of given size (histogramming).
|
---|
92 | * Note that BinStart and BinEnd are desired to fill the complete range, even where Bins are zero. If this is
|
---|
93 | * not desired, give equal BinStart and BinEnd and the map will contain only Bins where the count is one or greater. If a
|
---|
94 | * certain start value is desired, give BinStart and a BinEnd that is smaller than BinStart, then only BinEnd will be
|
---|
95 | * calculated automatically, i.e. BinStart = 0. and BinEnd = -1. .
|
---|
96 | * Also note that the range is given inclusive, i.e. [ BinStart, BinEnd ].
|
---|
97 | * \param *map map of doubles to count
|
---|
98 | * \param BinWidth desired width of the binds
|
---|
99 | * \param BinStart first bin
|
---|
100 | * \param BinEnd last bin
|
---|
101 | * \return Map of doubles (the bins) with counts as values
|
---|
102 | */
|
---|
103 | template <typename T> BinPairMap *BinData ( T *map, const double BinWidth, const double BinStart, const double BinEnd )
|
---|
104 | {
|
---|
105 | BinPairMap *outmap = new BinPairMap;
|
---|
106 | int bin = 0;
|
---|
107 | double start = 0.;
|
---|
108 | double end = 0.;
|
---|
109 | pair <BinPairMap::iterator, bool > BinPairMapInserter;
|
---|
110 |
|
---|
111 | if (map == NULL) {
|
---|
112 | DoeLog(0) && (eLog()<< Verbose(0) << "Nothing to bin, is NULL!" << endl);
|
---|
113 | performCriticalExit();
|
---|
114 | return outmap;
|
---|
115 | }
|
---|
116 |
|
---|
117 | if (BinStart == BinEnd) { // if same, find range ourselves
|
---|
118 | GetMinMax( map, start, end);
|
---|
119 | } else if (BinEnd < BinStart) { // if BinEnd smaller, just look for new max
|
---|
120 | GetMinMax( map, start, end);
|
---|
121 | start = BinStart;
|
---|
122 | } else { // else take both values
|
---|
123 | start = BinStart;
|
---|
124 | end = BinEnd;
|
---|
125 | }
|
---|
126 | for (int runner = 0; runner <= ceil((end-start)/BinWidth); runner++)
|
---|
127 | outmap->insert( pair<double, int> ((double)runner*BinWidth+start, 0) );
|
---|
128 |
|
---|
129 | for (typename T::iterator runner = map->begin(); runner != map->end(); ++runner) {
|
---|
130 | bin = GetBin (runner->first, BinWidth, start);
|
---|
131 | BinPairMapInserter = outmap->insert ( pair<double, int> ((double)bin*BinWidth+start, 1) );
|
---|
132 | if (!BinPairMapInserter.second) { // bin already present, increase
|
---|
133 | BinPairMapInserter.first->second += 1;
|
---|
134 | }
|
---|
135 | }
|
---|
136 |
|
---|
137 | return outmap;
|
---|
138 | };
|
---|
139 |
|
---|
140 | #endif /* ANALYSIS_HPP_ */
|
---|