1 |
#include <iostream> |
2 |
#include <fstream> |
3 |
|
4 |
#include <cstring> |
5 |
#include <cmath> |
6 |
|
7 |
#include "simError.h" |
8 |
#include "PairCorrType.hpp" |
9 |
|
10 |
using namespace std; |
11 |
|
12 |
GofR::GofR( char* key1, char* key2, int theNatoms, int theNbins ): |
13 |
PairCorrType( key1, key2, theNatoms, theNbins ) |
14 |
{ |
15 |
int i; |
16 |
|
17 |
strcpy( corrType, "GofR" ); |
18 |
|
19 |
currHist = new int[nBins]; |
20 |
currGofR = new double[nBins]; |
21 |
avgGofR = new double[nBins]; |
22 |
|
23 |
for(i=0;i<nBins;i++){ |
24 |
currHist[i] = 0; |
25 |
currGofR[i] = 0.0; |
26 |
avgGofR[i] = 0.0; |
27 |
} |
28 |
|
29 |
nFrames = 0; |
30 |
} |
31 |
|
32 |
GofR::~GofR(){ |
33 |
|
34 |
delete[] currHist; |
35 |
delete[] currGofR; |
36 |
delete[] avgGofR; |
37 |
} |
38 |
|
39 |
void GofR::correlate( double Rij[3], double dist, |
40 |
double uHatI[3], double uHatJ[3] ){ |
41 |
int bin; |
42 |
|
43 |
if( correlateMe ){ |
44 |
|
45 |
bin = (int)( dist / delR ); |
46 |
if( bin < nBins )currHist[bin] += 2; |
47 |
|
48 |
} |
49 |
} |
50 |
|
51 |
void GofR::accumulateFrame( void ){ |
52 |
int i; |
53 |
double rLower, rUpper, volSlice; |
54 |
double nIdeal; |
55 |
|
56 |
nFrames++; |
57 |
|
58 |
for(i=0;i<nBins;i++){ |
59 |
|
60 |
rLower = i * delR; |
61 |
rUpper = rLower + delR; |
62 |
|
63 |
volSlice = ( rUpper * rUpper * rUpper ) - ( rLower * rLower * rLower ); |
64 |
nIdeal = volSlice * pairConstant; |
65 |
|
66 |
currGofR[i] = currHist[i] / nIdeal; |
67 |
currHist[i] = 0; |
68 |
|
69 |
avgGofR[i] += currGofR[i]; |
70 |
} |
71 |
} |
72 |
|
73 |
|
74 |
void GofR::writeCorr( char* outPrefix ){ |
75 |
|
76 |
double rValue, corrValue; |
77 |
double rLower, rUpper, volSlice; |
78 |
double nIdeal; |
79 |
int i; |
80 |
char outName[200]; |
81 |
|
82 |
sprintf( outName, |
83 |
"%s-%s-%s.GofR", |
84 |
outPrefix, |
85 |
atom1, |
86 |
atom2 ); |
87 |
ofstream outStream( outName ); |
88 |
|
89 |
if( !outStream ){ |
90 |
|
91 |
sprintf( painCave.errMsg, |
92 |
"Error opening \"%s\" for output.\n", |
93 |
outName ); |
94 |
painCave.isFatal = 1; |
95 |
simError(); |
96 |
} |
97 |
|
98 |
outStream << "#rValue\tcorrValue\n"; |
99 |
|
100 |
for(i=0;i<nBins;i++){ |
101 |
|
102 |
rValue = ( i + 0.5 ) * delR; |
103 |
corrValue = avgGofR[i] / nFrames; |
104 |
|
105 |
outStream << rValue << "\t" << corrValue << "\n"; |
106 |
} |
107 |
|
108 |
outStream.close(); |
109 |
} |