1 |
#include <iostream> |
2 |
#include <cstdlib> |
3 |
#include <cstring> |
4 |
|
5 |
#include "simError.h" |
6 |
#include "PairCorrType.hpp" |
7 |
|
8 |
|
9 |
PairCorrType::PairCorrType( char* key1, char* key2, int theNatoms, |
10 |
int theNbins ){ |
11 |
|
12 |
nBins = theNbins; |
13 |
|
14 |
strcpy( atom1, key1 ); |
15 |
strcpy( atom2, key2 ); |
16 |
|
17 |
isSelfSelf = false; |
18 |
if( !strcmp( atom1, atom2 ) ) isSelfSelf = true; |
19 |
|
20 |
strcpy( corrType, "Donkey" ); |
21 |
|
22 |
nAtoms = theNatoms; |
23 |
|
24 |
isAtom1 = new bool[nAtoms]; |
25 |
isAtom2 = new bool[nAtoms]; |
26 |
|
27 |
jArray = NULL; |
28 |
|
29 |
correlateMe = false; |
30 |
isInitialized = false; |
31 |
|
32 |
} |
33 |
|
34 |
PairCorrType::~PairCorrType(){ |
35 |
|
36 |
delete[] isAtom1; |
37 |
delete[] isAtom2; |
38 |
|
39 |
} |
40 |
|
41 |
void PairCorrType::initCorr( double theLengthScale, atomName* theNames ){ |
42 |
int i; |
43 |
|
44 |
lengthScale = theLengthScale; |
45 |
delR = lengthScale / nBins; |
46 |
|
47 |
nAtoms1 = 0; |
48 |
nAtoms2 = 0; |
49 |
|
50 |
for( i=0; i<nAtoms; i++){ |
51 |
|
52 |
isAtom1[i] = !strcmp( atom1, theNames[i].name ); |
53 |
if( isAtom1[i] ) nAtoms1++; |
54 |
isAtom2[i] = !strcmp( atom2, theNames[i].name ); |
55 |
if( isAtom2[i] ) nAtoms2++; |
56 |
} |
57 |
|
58 |
if( !strcmp( atom1, "_ALL_" ) ){ |
59 |
for(i=0;i<nAtoms;i++)isAtom1[i] = true; |
60 |
nAtoms1 = nAtoms; |
61 |
} |
62 |
|
63 |
if( !strcmp( atom2, "_ALL_" ) ){ |
64 |
for(i=0;i<nAtoms;i++)isAtom2[i] = true; |
65 |
nAtoms2 = nAtoms; |
66 |
} |
67 |
|
68 |
if(!nAtoms1){ |
69 |
sprintf( painCave.errMsg, |
70 |
"\n" |
71 |
"Atom \"%s\" was not found in the dump file by pair corelation:\n" |
72 |
" %s < %s - %s >\n", |
73 |
atom1, |
74 |
corrType, |
75 |
atom1, |
76 |
atom2 ); |
77 |
painCave.isFatal = 1; |
78 |
simError(); |
79 |
} |
80 |
|
81 |
if(!nAtoms2){ |
82 |
sprintf( painCave.errMsg, |
83 |
"\n" |
84 |
"Atom \"%s\" was not found in the dump file by pair corelation:\n" |
85 |
" %s < %s - %s >\n", |
86 |
atom2, |
87 |
corrType, |
88 |
atom1, |
89 |
atom2 ); |
90 |
painCave.isFatal = 1; |
91 |
simError(); |
92 |
} |
93 |
|
94 |
isInitialized = true; |
95 |
} |
96 |
|
97 |
void PairCorrType::setFrameVolume( double theVolume ){ |
98 |
|
99 |
volume = theVolume; |
100 |
|
101 |
if( isSelfSelf ) pairDensity = nAtoms1 * (nAtoms1 - 1) / volume; |
102 |
else pairDensity = nAtoms1 * nAtoms2 / volume; |
103 |
|
104 |
pairConstant = ( 4.0 * M_PI * pairDens ) / 3.0; |
105 |
|
106 |
} |
107 |
|
108 |
bool PairCorrType::matchI( int i ){ |
109 |
|
110 |
if( !isInitialized ){ |
111 |
sprintf( painCave.errMsg, |
112 |
"Attempt to MatchI in <%s of %s - %s> before identity arrays" |
113 |
" were initialized.\n", |
114 |
corrType, |
115 |
atom1, |
116 |
atom2 ); |
117 |
painCave.isFatal = 1; |
118 |
simError(); |
119 |
} |
120 |
|
121 |
identI = -1; |
122 |
|
123 |
if( isAtom1[i] ){ |
124 |
|
125 |
correlateMe = true; |
126 |
identI = IS_A; |
127 |
jArray = isAtom2; |
128 |
return true; |
129 |
} |
130 |
|
131 |
if( isAtom2[i] ){ |
132 |
|
133 |
correlateMe = true; |
134 |
identI = IS_B; |
135 |
jArray = isAtom1; |
136 |
return true; |
137 |
} |
138 |
|
139 |
correlateMe = false; |
140 |
jArray = NULL; |
141 |
return false; |
142 |
} |
143 |
|
144 |
bool PairCorrType::matchJ( int j ){ |
145 |
|
146 |
if( !isInitialized ){ |
147 |
sprintf( painCave.errMsg, |
148 |
"Attempt to MatchJ in <%s of %s - %s> before identity arrays" |
149 |
" were initialized.\n", |
150 |
corrType, |
151 |
atom1, |
152 |
atom2 ); |
153 |
painCave.isFatal = 1; |
154 |
simError(); |
155 |
} |
156 |
|
157 |
if( correlateMe ){ |
158 |
|
159 |
if( jArray[j] ) return true; |
160 |
} |
161 |
|
162 |
correlateMe = false; |
163 |
jArray = NULL; |
164 |
return false; |
165 |
|
166 |
} |