ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/staticProps/AllCorr.cpp
Revision: 810
Committed: Fri Oct 17 21:19:07 2003 UTC (20 years, 8 months ago) by mmeineke
File size: 6701 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

# Content
1 #include <stdlib.h>
2 #include <math.h>
3 #include <vector>
4
5 #include "simError.h"
6 #include "AllCorr.hpp"
7
8
9 AllCorr::AllCorr(){
10
11 pairCorrs = NULL;
12 haveFrames = false;
13 pairCorrSet = false;
14 haveLength = false;
15 haveNbins = false;
16 }
17
18 AllCorr::~AllCorr(){
19 int i;
20
21 if( pairCorrs != NULL ){
22 for(i=0; i<nPairs; i++)
23 delete pairCorrs[i];
24 delete[] pairCorrs;
25 }
26 }
27
28 void AllCorr::setMaxLength( double theLength ){
29 maxLength = theLength;
30 haveLength = true;
31 }
32
33 void AllCorr::setNbins( int theNbins ){
34 nBins = theNbins;
35 haveNbins = true;
36 }
37
38 void AllCorr::setFrames( SimInfo* theInfoArray, int theNframes,
39 DumpReader* theReader ){
40 int i;
41
42
43 infoArray = theInfoArray;
44 nFrames = theNframes;
45 reader = theReader;
46
47 nAtoms = infoArray[0].n_atoms;
48
49
50 // allocate the first frame's atom arrays
51
52 (infoArray[0].getConfiguration())->createArrays(infoArray[0].n_atoms);
53 for (i = 0; i < infoArray[0].n_atoms; i++)
54 infoArray[0].atoms[i]->setCoords();
55
56 // read in the first frame's positions
57
58 reader->readFrame( &(infoArray[0]), 0 );
59
60 if( !haveLength ){
61 maxLength = infoArray[0].getMaxCutoff();
62 haveLength = true;
63 }
64
65 haveFrames = true;
66 }
67
68 void AllCorr::setPairCorrList( vector <PairCorrList> &theList ){
69
70 int i;
71 char pair1[PCL_NAME_LENGTH];
72 char pair2[PCL_NAME_LENGTH];
73
74 if( !haveFrames ){
75 sprintf( painCave.errMsg,
76 "\n"
77 "AllCorr Error: attempt to create the pair correlations without"
78 " first setting the Frames\n" );
79 painCave.isFatal = 1;
80 simError();
81 }
82
83 if( !haveNbins ){
84 sprintf( painCave.errMsg,
85 "\n"
86 "AllCorr Error: attempt to create the pair correlations without"
87 " first setting nBins\n" );
88 painCave.isFatal = 1;
89 simError();
90 }
91
92
93 nPairs = (int)theList.size();
94 pairCorrs = new PairCorrType*[nPairs];
95
96 for(i=0;i<nPairs;i++){
97
98 theList[i].getAtom1( pair1 );
99 theList[i].getAtom2( pair2 );
100
101 switch( theList[i].getType() ){
102
103 case gofr:
104 pairCorrs[i] = new GofR(pair1, pair2, nAtoms, nBins);
105 break;
106
107 default:
108
109 sprintf( painCave.errMsg,
110 "AllCorr Error: Unrecognized pair corr type in "
111 " setPairCorrList()->theList[%d]\n",
112 i );
113 painCave.isFatal = 1;
114 simError();
115 break;
116 }
117 }
118
119 pairCorrSet = true;
120 }
121
122 void AllCorr::initCorrelations( char* theOutPrefix, bool theIsSeparateOut,
123 bool theHavePairCorrs,
124 bool theHaveStaticCorrs ){
125 int i;
126 atomName* theNames = new atomName[nAtoms];
127
128 havePairCorrs = theHavePairCorrs;
129 haveStaticCorrs = theHaveStaticCorrs;
130
131 if( havePairCorrs){
132
133 if(!pairCorrSet){
134 sprintf( painCave.errMsg,
135 "AllCorr error: Attempt to initialize pair correlations "
136 " without first setting the pair correlation list.\n" );
137 painCave.isFatal = 1;
138 simError();
139 }
140
141 for(i=0;i<nAtoms;i++){
142
143 strcpy(theNames[i].name, infoArray[0].atoms[i]->getType() );
144 }
145
146 for(i=0;i<nPairs;i++){
147 pairCorrs[i]->initCorr(maxLength, theNames );
148 }
149 }
150
151 if( haveStaticCorrs ){
152
153 // empty for now
154 }
155
156 strcpy(outPrefix, theOutPrefix);
157 isSeparateOut = theIsSeparateOut;
158 }
159
160
161 void AllCorr::calcCorrelations(){
162
163 SimInfo* currInfo;
164 int i,j,k,l;
165 double rij[3], rDist, uHatI[3], uHatJ[3];
166 double* grndOut = NULL;
167 double dSqr, ri[3], rj[3];
168 DirectionalAtom* dAtom;
169 double frameVolume;
170
171
172 for(k=0; k<nFrames; k++){
173
174 currInfo = &(infoArray[k]);
175
176 // skip the first frame, as it is already initialized
177 if( k != 0 ){
178
179 // allocate the frame's atom arrays
180
181 (currInfo->getConfiguration())->createArrays(currInfo->n_atoms);
182 for (i = 0; i < currInfo->n_atoms; i++)
183 currInfo->atoms[i]->setCoords();
184
185 // read in the frame's positions
186
187 reader->readFrame( &(infoArray[k]), 0 );
188 }
189
190 frameVolume = currInfo->boxVol;
191 this->setFrameVolume( frameVolume );
192
193 if(havePairCorrs){
194
195 // do the pair loop
196
197 for(i=0;i<(nAtoms-1);i++){
198
199 if( this->matchI(i) ){
200
201 for(j=i+1;j<nAtoms;j++){
202
203 if( this->matchJ(j) ){
204
205 // calc rdist and rij;
206
207 currInfo->atoms[i]->getPos( ri );
208
209 currInfo->atoms[j]->getPos( rj );
210
211 for(l=0;l<3;l++)
212 rij[l] = rj[l] - ri[l];
213
214 currInfo->wrapVector( rij );
215
216 dSqr=0;
217 for(l=0;l<3;l++)
218 dSqr += rij[l] * rij[l];
219
220 rDist = sqrt( dSqr );
221
222 if( currInfo->atoms[i]->isDirectional() ){
223
224 dAtom = (DirectionalAtom*)currInfo->atoms[i];
225 dAtom->getU( uHatI );
226
227 if( currInfo->atoms[j]->isDirectional() ){
228
229 dAtom = (DirectionalAtom*)currInfo->atoms[j];
230 dAtom->getU( uHatJ );
231
232 this->pairCorrelate( rij, rDist, uHatI, uHatJ );
233 }
234 else{
235
236 this->pairCorrelate( rij, rDist, uHatI, grndOut );
237 }
238 }
239 else if( currInfo->atoms[j]->isDirectional() ){
240
241 dAtom = (DirectionalAtom*)currInfo->atoms[j];
242 dAtom->getU( uHatJ );
243
244 this->pairCorrelate( rij, rDist, grndOut, uHatJ );
245 }
246 else{
247 this->pairCorrelate( rij, rDist, grndOut, grndOut );
248 }
249 }
250 }
251 }
252 }
253 }
254
255 if( haveStaticCorrs ){
256
257 // empty for now
258
259 }
260
261 // accumulate the averages for this frame
262
263 this->accumulateFrame();
264
265 // de-allocate the frame
266
267 (currInfo->getConfiguration())->destroyArrays();
268 }
269
270 this->writeCorrs();
271 }
272
273 bool AllCorr::matchI(int i){
274
275 int k;
276 bool result;
277
278 result = false;
279
280 for(k=0;k<nPairs;k++)
281 result = (result || pairCorrs[k]->matchI(i) );
282
283 return result;
284 }
285
286 bool AllCorr::matchJ(int j){
287
288 int k;
289 bool result;
290
291 result = false;
292
293 for(k=0;k<nPairs;k++)
294 result = (result || pairCorrs[k]->matchJ(j) );
295
296 return result;
297 }
298
299 void AllCorr::pairCorrelate( double Rij[3], double dist,
300 double uHatI[3], double uHatJ[3] ){
301
302 int i;
303
304 for(i=0;i<nPairs;i++)
305 pairCorrs[i]->correlate( Rij, dist, uHatI, uHatJ );
306 }
307
308 void AllCorr::setFrameVolume( double theVolume ){
309
310 int i;
311
312 if( havePairCorrs ){
313
314 for(i=0;i<nPairs;i++)
315 pairCorrs[i]->setFrameVolume( theVolume );
316 }
317
318 if( haveStaticCorrs ){
319
320 // empty for now
321 }
322 }
323
324 void AllCorr::accumulateFrame( void ){
325
326 int i;
327
328 if( havePairCorrs ){
329
330 for(i=0;i<nPairs;i++)
331 pairCorrs[i]->accumulateFrame();
332 }
333
334 if( haveStaticCorrs ){
335
336 // empty for now
337 }
338 }
339
340 void AllCorr::writeCorrs( void ){
341 int i;
342
343 if( isSeparateOut ){
344
345 if( havePairCorrs ){
346
347 for(i=0;i<nPairs;i++)
348 pairCorrs[i]->writeCorr( outPrefix );
349 }
350
351 if( haveStaticCorrs ){
352
353 // empty for now
354 }
355
356 }
357 else{
358
359 // empty for now
360 }
361
362 }