ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/staticProps/GofRtheta.cpp
(Generate patch)

Comparing trunk/OOPSE/staticProps/GofRtheta.cpp (file contents):
Revision 811 by mmeineke, Tue Oct 21 19:33:19 2003 UTC vs.
Revision 879 by mmeineke, Tue Dec 16 20:49:11 2003 UTC

# Line 12 | Line 12 | GofRtheta::GofRtheta( char* key1, char* key2, int theN
12   GofRtheta::GofRtheta( char* key1, char* key2, int theNatoms, int theNbins ):
13    PairCorrType(  key1, key2, theNatoms, theNbins )
14   {
15 <  int i;
15 >  int i, j;
16    
17    strcpy( corrType, "GofRtheta" );
18    
19 <  currHist = new int[nBins];
20 <  currGofRtheta = new double[nBins];
21 <  avgGofRtheta  = new double[nBins];
22 <
19 >  currCosHist   = new int*[nBins];
20 >  currGofRtheta = new double*[nBins];
21 >  avgGofRtheta  = new double*[nBins];
22 >  
23    for(i=0;i<nBins;i++){
24 <    currHist[i] = 0;
25 <    currGofRtheta[i] = 0.0;
26 <    avgGofRtheta[i]  = 0.0;
24 >    currCosHist[i]   = new int[nBins];
25 >    currGofRtheta[i] = new double[nBins];
26 >    avgGofRtheta[i]  = new double[nBins];
27 >    
28 >    for(j=0;j<nBins;j++){
29 >      currCosHist[i][j]   = 0;
30 >      currGofRtheta[i][j] = 0.0;
31 >      avgGofRtheta[i][j]  = 0.0;
32 >    }
33    }
34      
35    nFrames = 0;
# Line 31 | Line 37 | GofRtheta::~GofRtheta(){
37  
38   GofRtheta::~GofRtheta(){
39  
40 <  delete[] currHist;
40 >  int i;
41 >
42 >  for(i=0;i<nBins;i++){
43 >    delete[] currCosHist[i];
44 >    delete[] currGofRtheta[i];
45 >    delete[] avgGofRtheta[i];
46 >  }
47 >
48 >  delete[] currCosHist;
49    delete[] currGofRtheta;
50    delete[] avgGofRtheta;
51   }
52  
53   void GofRtheta::correlate( double Rij[3], double dist,
54 <                      double uHatI[3], double uHatJ[3] ){
55 <  int bin;
56 <
54 >                           double uHatI[3], double uHatJ[3] ){
55 >  int binR, binTheta, i;
56 >  double dot, cosTheta;
57 >  double halfNbins;
58 >  
59    if( correlateMe ){
60 <    
61 <    bin = (int)( dist / delR );
62 <    if( bin < nBins )currHist[bin] += 2;
63 <    
60 >
61 >    if( uHatI != NULL ){
62 >      
63 >      dot= 0.0;
64 >      for(i=0;i<3;i++)
65 >        dot += Rij[i] * uHatI[i];
66 >      
67 >      cosTheta = dot / dist;
68 >      
69 >      binR = (int)( dist / delR );
70 >      if( binR < nBins ){
71 >        
72 >        halfNbins = (nBins-1) * 0.5;
73 >        binTheta = (int)( (cosTheta * halfNbins) + halfNbins );
74 >        
75 >        currCosHist[binR][binTheta] += 1;
76 >      }
77 >    }
78 >    else{
79 >      
80 >      sprintf( painCave.errMsg,
81 >               "GofRtheta error: atom \"%s\" does not have a "
82 >               "directional component\n",
83 >               atom1
84 >               );
85 >      painCave.isFatal = 1;
86 >      simError();
87 >    }    
88    }
89   }
90  
91   void GofRtheta::accumulateFrame( void ){
92 <  int i;
92 >  int i,j;
93    double rLower, rUpper, volSlice;
94    double nIdeal;
95  
# Line 63 | Line 103 | void GofRtheta::accumulateFrame( void ){
103      volSlice = ( rUpper * rUpper * rUpper ) - ( rLower * rLower * rLower );
104      nIdeal = volSlice * pairConstant;
105  
106 <    currGofRtheta[i] = currHist[i] / nIdeal;
107 <    currHist[i] = 0;
106 >    for(j=0;j<nBins;j++){
107 >      
108 >      currGofRtheta[i][j] = (currCosHist[i][j] / nIdeal);
109 >      currCosHist[i][j]   = 0;
110  
111 <    avgGofRtheta[i] += currGofRtheta[i];    
111 >      avgGofRtheta[i][j] += currGofRtheta[i][j];    
112 >    }
113    }
114   }
115  
116  
117   void GofRtheta::writeCorr( char* outPrefix ){
118  
119 <  double rValue, corrValue;
119 >  double rValue, cosValue, deltaCos, corrValue;
120    double rLower, rUpper, volSlice;
121    double nIdeal;
122    int i;
# Line 95 | Line 138 | void GofRtheta::writeCorr( char* outPrefix ){
138      simError();
139    }
140  
141 <  outStream << "#rValue\tcorrValue\n";
141 >  outStream << "#rValue; cosValue; corrValue\n";
142  
100  for(i=0;i<nBins;i++){
143  
144 +  deltaCos = 2.0 / nBins;
145 +  for(i=0;i<nBins;i++){
146 +    
147      rValue = ( i + 0.5 ) * delR;
148 <    corrValue = avgGofRtheta[i] / nFrames;
149 <
150 <    outStream << rValue << "\t" << corrValue << "\n";
148 >    
149 >    for(j=0;j<nBins;j++){
150 >    
151 >      cosValue = -1 + (j * deltaCos);
152 >        
153 >      corrValue = avgGofRtheta[i][j] / nFrames;
154 >      
155 >      outStream << rValue << "; " << cosValue << "; " << corrValue << "\n";
156 >    }
157    }
158  
159    outStream.close();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines