ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/staticProps/GofR.cpp
Revision: 810
Committed: Fri Oct 17 21:19:07 2003 UTC (20 years, 9 months ago) by mmeineke
File size: 1884 byte(s)
Log Message:
added the staticProps directory to the build list
for both configure  and configure.in


fixed a number of bugs in the staticProps code. gofr is now working.

File Contents

# User Rev Content
1 mmeineke 803 #include <iostream>
2     #include <fstream>
3    
4     #include <cstring>
5     #include <cmath>
6    
7 mmeineke 810 #include "simError.h"
8 mmeineke 803 #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 mmeineke 810 void GofR::correlate( double Rij[3], double dist,
40     double uHatI[3], double uHatJ[3] ){
41 mmeineke 803 int bin;
42 mmeineke 810
43 mmeineke 803 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 mmeineke 810 double nIdeal;
55 mmeineke 803
56     nFrames++;
57    
58     for(i=0;i<nBins;i++){
59    
60     rLower = i * delR;
61     rUpper = rLower + delR;
62    
63 mmeineke 810 volSlice = ( rUpper * rUpper * rUpper ) - ( rLower * rLower * rLower );
64 mmeineke 803 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 mmeineke 810 double rLower, rUpper, volSlice;
78     double nIdeal;
79 mmeineke 803 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 mmeineke 810 outStream << "#rValue\tcorrValue\n";
99 mmeineke 803
100     for(i=0;i<nBins;i++){
101 mmeineke 810
102 mmeineke 803 rValue = ( i + 0.5 ) * delR;
103     corrValue = avgGofR[i] / nFrames;
104    
105     outStream << rValue << "\t" << corrValue << "\n";
106     }
107    
108     outStream.close();
109     }