| 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 |
GofRomega::GofRomega( char* key1, char* key2, int theNatoms, int theNbins ): |
| 13 |
PairCorrType( key1, key2, theNatoms, theNbins ) |
| 14 |
{ |
| 15 |
int i, j; |
| 16 |
|
| 17 |
strcpy( corrType, "GofRomega" ); |
| 18 |
|
| 19 |
currCosHist = new int*[nBins]; |
| 20 |
currGofRomega = new double*[nBins]; |
| 21 |
avgGofRomega = new double*[nBins]; |
| 22 |
|
| 23 |
for(i=0;i<nBins;i++){ |
| 24 |
currCosHist[i] = new int[nBins]; |
| 25 |
currGofRomega[i] = new double[nBins]; |
| 26 |
avgGofRomega[i] = new double[nBins]; |
| 27 |
|
| 28 |
for(j=0;j<nBins;j++){ |
| 29 |
currCosHist[i][j] = 0; |
| 30 |
currGofRomega[i][j] = 0.0; |
| 31 |
avgGofRomega[i][j] = 0.0; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
nFrames = 0; |
| 36 |
} |
| 37 |
|
| 38 |
GofRomega::~GofRomega(){ |
| 39 |
|
| 40 |
int i; |
| 41 |
|
| 42 |
for(i=0;i<nBins;i++){ |
| 43 |
delete[] currCosHist[i]; |
| 44 |
delete[] currGofRomega[i]; |
| 45 |
delete[] avgGofRomega[i]; |
| 46 |
} |
| 47 |
|
| 48 |
delete[] currCosHist; |
| 49 |
delete[] currGofRomega; |
| 50 |
delete[] avgGofRomega; |
| 51 |
} |
| 52 |
|
| 53 |
void GofRomega::correlate( double Rij[3], double dist, |
| 54 |
double uHatI[3], double uHatJ[3] ){ |
| 55 |
int binR, binOmega, i; |
| 56 |
double dot, cosOmega; |
| 57 |
double halfNbins; |
| 58 |
|
| 59 |
if( correlateMe ){ |
| 60 |
|
| 61 |
if( uHatI != NULL ){ |
| 62 |
|
| 63 |
if( uHatJ != NULL ){ |
| 64 |
|
| 65 |
dot= 0.0; |
| 66 |
for(i=0;i<3;i++) |
| 67 |
dot += uHatJ[i] * uHatI[i]; |
| 68 |
|
| 69 |
cosOmega = dot; |
| 70 |
|
| 71 |
binR = (int)( dist / delR ); |
| 72 |
if( binR < nBins ){ |
| 73 |
|
| 74 |
halfNbins = (nBins-1) * 0.5; |
| 75 |
binOmega = (int)( (cosOmega * halfNbins) + halfNbins ); |
| 76 |
|
| 77 |
currCosHist[binR][binOmega] += 1; |
| 78 |
} |
| 79 |
} |
| 80 |
else{ |
| 81 |
|
| 82 |
sprintf( painCave.errMsg, |
| 83 |
"GofRomega error: atom \"%s\" does not have a " |
| 84 |
"directional component\n", |
| 85 |
atom2 |
| 86 |
); |
| 87 |
painCave.isFatal = 1; |
| 88 |
simError(); |
| 89 |
} |
| 90 |
} |
| 91 |
else{ |
| 92 |
|
| 93 |
sprintf( painCave.errMsg, |
| 94 |
"GofRomega error: atom \"%s\" does not have a " |
| 95 |
"directional component\n", |
| 96 |
atom1 |
| 97 |
); |
| 98 |
painCave.isFatal = 1; |
| 99 |
simError(); |
| 100 |
} |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
void GofRomega::accumulateFrame( void ){ |
| 107 |
int i,j; |
| 108 |
double rLower, rUpper, volSlice; |
| 109 |
double nIdeal; |
| 110 |
|
| 111 |
nFrames++; |
| 112 |
|
| 113 |
for(i=0;i<nBins;i++){ |
| 114 |
|
| 115 |
rLower = i * delR; |
| 116 |
rUpper = rLower + delR; |
| 117 |
|
| 118 |
volSlice = ( rUpper * rUpper * rUpper ) - ( rLower * rLower * rLower ); |
| 119 |
nIdeal = volSlice * pairConstant; |
| 120 |
|
| 121 |
for(j=0;j<nBins;j++){ |
| 122 |
|
| 123 |
currGofRomega[i][j] = (currCosHist[i][j] / nIdeal); |
| 124 |
currCosHist[i][j] = 0; |
| 125 |
|
| 126 |
avgGofRomega[i][j] += currGofRomega[i][j]; |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
void GofRomega::writeCorr( char* outPrefix ){ |
| 133 |
|
| 134 |
double rValue, cosValue, deltaCos, corrValue; |
| 135 |
double rLower, rUpper, volSlice; |
| 136 |
double nIdeal; |
| 137 |
int i,j; |
| 138 |
char outName[200]; |
| 139 |
|
| 140 |
sprintf( outName, |
| 141 |
"%s-%s-%s.GofRomega", |
| 142 |
outPrefix, |
| 143 |
atom1, |
| 144 |
atom2 ); |
| 145 |
ofstream outStream( outName ); |
| 146 |
|
| 147 |
if( !outStream ){ |
| 148 |
|
| 149 |
sprintf( painCave.errMsg, |
| 150 |
"Error opening \"%s\" for output.\n", |
| 151 |
outName ); |
| 152 |
painCave.isFatal = 1; |
| 153 |
simError(); |
| 154 |
} |
| 155 |
|
| 156 |
outStream << "#rValue; cosValue; corrValue\n"; |
| 157 |
|
| 158 |
|
| 159 |
deltaCos = 2.0 / nBins; |
| 160 |
for(i=0;i<nBins;i++){ |
| 161 |
|
| 162 |
rValue = ( i + 0.5 ) * delR; |
| 163 |
|
| 164 |
for(j=0;j<nBins;j++){ |
| 165 |
|
| 166 |
cosValue = -1 + (j * deltaCos); |
| 167 |
|
| 168 |
corrValue = avgGofRomega[i][j] / nFrames; |
| 169 |
|
| 170 |
outStream << rValue << "; " << cosValue << "; " << corrValue << "\n"; |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
outStream.close(); |
| 175 |
} |