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