ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/props/GofR.cpp
Revision: 802
Committed: Thu Oct 9 22:09:52 2003 UTC (20 years, 9 months ago) by mmeineke
File size: 1791 byte(s)
Log Message:
Contiuned work on staticProps. should be in a position where it will compile and run first runs.

File Contents

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