# | Line 34 | Line 34 | SimInfo::SimInfo(){ | |
---|---|---|
34 | setTemp = 0; | |
35 | thermalTime = 0.0; | |
36 | rCut = 0.0; | |
37 | + | ecr = 0.0; |
38 | + | est = 0.0; |
39 | ||
40 | usePBC = 0; | |
41 | useLJ = 0; | |
# | Line 47 | Line 49 | void SimInfo::setBox(double newBox[3]) { | |
49 | } | |
50 | ||
51 | void SimInfo::setBox(double newBox[3]) { | |
52 | + | |
53 | + | int i, j; |
54 | + | double tempMat[3][3]; |
55 | ||
56 | < | double smallestBoxL, maxCutoff; |
57 | < | int status; |
53 | < | int i; |
56 | > | for(i=0; i<3; i++) |
57 | > | for (j=0; j<3; j++) tempMat[i][j] = 0.0;; |
58 | ||
59 | < | for(i=0; i<9; i++) Hmat[i] = 0.0;; |
59 | > | tempMat[0][0] = newBox[0]; |
60 | > | tempMat[1][1] = newBox[1]; |
61 | > | tempMat[2][2] = newBox[2]; |
62 | ||
63 | < | Hmat[0] = newBox[0]; |
58 | < | Hmat[4] = newBox[1]; |
59 | < | Hmat[8] = newBox[2]; |
63 | > | setBoxM( tempMat ); |
64 | ||
65 | < | calcHmatI(); |
62 | < | calcBoxL(); |
65 | > | } |
66 | ||
67 | < | setFortranBoxSize(Hmat, HmatI, &orthoRhombic); |
67 | > | void SimInfo::setBoxM( double theBox[3][3] ){ |
68 | > | |
69 | > | int i, j, status; |
70 | > | double smallestBoxL, maxCutoff; |
71 | > | double FortranHmat[9]; // to preserve compatibility with Fortran the |
72 | > | // ordering in the array is as follows: |
73 | > | // [ 0 3 6 ] |
74 | > | // [ 1 4 7 ] |
75 | > | // [ 2 5 8 ] |
76 | > | double FortranHmatInv[9]; // the inverted Hmat (for Fortran); |
77 | ||
66 | – | smallestBoxL = boxLx; |
67 | – | if (boxLy < smallestBoxL) smallestBoxL = boxLy; |
68 | – | if (boxLz < smallestBoxL) smallestBoxL = boxLz; |
78 | ||
79 | < | maxCutoff = smallestBoxL / 2.0; |
79 | > | for(i=0; i < 3; i++) |
80 | > | for (j=0; j < 3; j++) Hmat[i][j] = theBox[i][j]; |
81 | > | |
82 | > | // cerr |
83 | > | // << "setting Hmat ->\n" |
84 | > | // << "[ " << Hmat[0][0] << ", " << Hmat[0][1] << ", " << Hmat[0][2] << " ]\n" |
85 | > | // << "[ " << Hmat[1][0] << ", " << Hmat[1][1] << ", " << Hmat[1][2] << " ]\n" |
86 | > | // << "[ " << Hmat[2][0] << ", " << Hmat[2][1] << ", " << Hmat[2][2] << " ]\n"; |
87 | ||
88 | < | if (rList > maxCutoff) { |
89 | < | sprintf( painCave.errMsg, |
74 | < | "New Box size is forcing neighborlist radius down to %lf\n", |
75 | < | maxCutoff ); |
76 | < | painCave.isFatal = 0; |
77 | < | simError(); |
88 | > | calcBoxL(); |
89 | > | calcHmatInv(); |
90 | ||
91 | < | rList = maxCutoff; |
92 | < | |
93 | < | sprintf( painCave.errMsg, |
94 | < | "New Box size is forcing cutoff radius down to %lf\n", |
83 | < | maxCutoff - 1.0 ); |
84 | < | painCave.isFatal = 0; |
85 | < | simError(); |
86 | < | |
87 | < | rCut = rList - 1.0; |
88 | < | |
89 | < | // list radius changed so we have to refresh the simulation structure. |
90 | < | refreshSim(); |
91 | < | } |
92 | < | |
93 | < | if (rCut > maxCutoff) { |
94 | < | sprintf( painCave.errMsg, |
95 | < | "New Box size is forcing cutoff radius down to %lf\n", |
96 | < | maxCutoff ); |
97 | < | painCave.isFatal = 0; |
98 | < | simError(); |
99 | < | |
100 | < | status = 0; |
101 | < | LJ_new_rcut(&rCut, &status); |
102 | < | if (status != 0) { |
103 | < | sprintf( painCave.errMsg, |
104 | < | "Error in recomputing LJ shifts based on new rcut\n"); |
105 | < | painCave.isFatal = 1; |
106 | < | simError(); |
91 | > | for(i=0; i < 3; i++) { |
92 | > | for (j=0; j < 3; j++) { |
93 | > | FortranHmat[3*j + i] = Hmat[i][j]; |
94 | > | FortranHmatInv[3*j + i] = HmatInv[i][j]; |
95 | } | |
96 | } | |
109 | – | } |
97 | ||
98 | < | void SimInfo::setBoxM( double theBox[9] ){ |
112 | < | |
113 | < | int i, status; |
114 | < | double smallestBoxL, maxCutoff; |
115 | < | |
116 | < | for(i=0; i<9; i++) Hmat[i] = theBox[i]; |
117 | < | calcHmatI(); |
118 | < | calcBoxL(); |
119 | < | |
120 | < | setFortranBoxSize(Hmat, HmatI, &orthoRhombic); |
98 | > | setFortranBoxSize(FortranHmat, FortranHmatInv, &orthoRhombic); |
99 | ||
100 | smallestBoxL = boxLx; | |
101 | if (boxLy < smallestBoxL) smallestBoxL = boxLy; | |
# | Line 146 | Line 124 | void SimInfo::setBoxM( double theBox[9] ){ | |
124 | refreshSim(); | |
125 | } | |
126 | ||
127 | < | if (rCut > maxCutoff) { |
127 | > | if( ecr > maxCutoff ){ |
128 | > | |
129 | sprintf( painCave.errMsg, | |
130 | < | "New Box size is forcing cutoff radius down to %lf\n", |
130 | > | "New Box size is forcing electrostatic cutoff radius " |
131 | > | "down to %lf\n", |
132 | maxCutoff ); | |
133 | painCave.isFatal = 0; | |
134 | simError(); | |
135 | ||
136 | < | status = 0; |
137 | < | LJ_new_rcut(&rCut, &status); |
138 | < | if (status != 0) { |
139 | < | sprintf( painCave.errMsg, |
160 | < | "Error in recomputing LJ shifts based on new rcut\n"); |
161 | < | painCave.isFatal = 1; |
162 | < | simError(); |
163 | < | } |
136 | > | ecr = maxCutoff; |
137 | > | est = 0.05 * ecr; |
138 | > | |
139 | > | refreshSim(); |
140 | } | |
141 | + | |
142 | } | |
143 | ||
144 | ||
145 | < | void SimInfo::getBoxM (double theBox[9]) { |
145 | > | void SimInfo::getBoxM (double theBox[3][3]) { |
146 | ||
147 | < | int i; |
148 | < | for(i=0; i<9; i++) theBox[i] = Hmat[i]; |
147 | > | int i, j; |
148 | > | for(i=0; i<3; i++) |
149 | > | for (j=0; j<3; j++) theBox[i][j] = Hmat[i][j]; |
150 | } | |
151 | ||
152 | ||
153 | void SimInfo::scaleBox(double scale) { | |
154 | < | double theBox[9]; |
155 | < | int i; |
154 | > | double theBox[3][3]; |
155 | > | int i, j; |
156 | ||
157 | < | for(i=0; i<9; i++) theBox[i] = Hmat[i]*scale; |
157 | > | // cerr << "Scaling box by " << scale << "\n"; |
158 | ||
159 | + | for(i=0; i<3; i++) |
160 | + | for (j=0; j<3; j++) theBox[i][j] = Hmat[i][j]*scale; |
161 | + | |
162 | setBoxM(theBox); | |
163 | ||
164 | } | |
165 | ||
166 | < | void SimInfo::calcHmatI( void ) { |
167 | < | |
168 | < | double C[3][3]; |
188 | < | double detHmat; |
189 | < | int i, j, k; |
166 | > | void SimInfo::calcHmatInv( void ) { |
167 | > | |
168 | > | int i,j; |
169 | double smallDiag; | |
170 | double tol; | |
171 | double sanity[3][3]; | |
172 | ||
173 | < | // calculate the adjunct of Hmat; |
173 | > | invertMat3( Hmat, HmatInv ); |
174 | ||
175 | < | C[0][0] = ( Hmat[4]*Hmat[8]) - (Hmat[7]*Hmat[5]); |
197 | < | C[1][0] = -( Hmat[1]*Hmat[8]) + (Hmat[7]*Hmat[2]); |
198 | < | C[2][0] = ( Hmat[1]*Hmat[5]) - (Hmat[4]*Hmat[2]); |
175 | > | // Check the inverse to make sure it is sane: |
176 | ||
177 | < | C[0][1] = -( Hmat[3]*Hmat[8]) + (Hmat[6]*Hmat[5]); |
178 | < | C[1][1] = ( Hmat[0]*Hmat[8]) - (Hmat[6]*Hmat[2]); |
179 | < | C[2][1] = -( Hmat[0]*Hmat[5]) + (Hmat[3]*Hmat[2]); |
203 | < | |
204 | < | C[0][2] = ( Hmat[3]*Hmat[7]) - (Hmat[6]*Hmat[4]); |
205 | < | C[1][2] = -( Hmat[0]*Hmat[7]) + (Hmat[6]*Hmat[1]); |
206 | < | C[2][2] = ( Hmat[0]*Hmat[4]) - (Hmat[3]*Hmat[1]); |
207 | < | |
208 | < | // calcutlate the determinant of Hmat |
177 | > | matMul3( Hmat, HmatInv, sanity ); |
178 | > | |
179 | > | // check to see if Hmat is orthorhombic |
180 | ||
181 | < | detHmat = 0.0; |
182 | < | for(i=0; i<3; i++) detHmat += Hmat[i] * C[i][0]; |
181 | > | smallDiag = Hmat[0][0]; |
182 | > | if(smallDiag > Hmat[1][1]) smallDiag = Hmat[1][1]; |
183 | > | if(smallDiag > Hmat[2][2]) smallDiag = Hmat[2][2]; |
184 | > | tol = smallDiag * 1E-6; |
185 | ||
186 | + | orthoRhombic = 1; |
187 | ||
188 | < | // H^-1 = C^T / det(H) |
189 | < | |
190 | < | i=0; |
191 | < | for(j=0; j<3; j++){ |
192 | < | for(k=0; k<3; k++){ |
193 | < | |
194 | < | HmatI[i] = C[j][k] / detHmat; |
221 | < | i++; |
188 | > | for (i = 0; i < 3; i++ ) { |
189 | > | for (j = 0 ; j < 3; j++) { |
190 | > | if (i != j) { |
191 | > | if (orthoRhombic) { |
192 | > | if (Hmat[i][j] >= tol) orthoRhombic = 0; |
193 | > | } |
194 | > | } |
195 | } | |
196 | } | |
197 | + | } |
198 | ||
199 | < | // sanity check |
199 | > | double SimInfo::matDet3(double a[3][3]) { |
200 | > | int i, j, k; |
201 | > | double determinant; |
202 | ||
203 | < | for(i=0; i<3; i++){ |
204 | < | for(j=0; j<3; j++){ |
203 | > | determinant = 0.0; |
204 | > | |
205 | > | for(i = 0; i < 3; i++) { |
206 | > | j = (i+1)%3; |
207 | > | k = (i+2)%3; |
208 | > | |
209 | > | determinant += a[0][i] * (a[1][j]*a[2][k] - a[1][k]*a[2][j]); |
210 | > | } |
211 | > | |
212 | > | return determinant; |
213 | > | } |
214 | > | |
215 | > | void SimInfo::invertMat3(double a[3][3], double b[3][3]) { |
216 | > | |
217 | > | int i, j, k, l, m, n; |
218 | > | double determinant; |
219 | > | |
220 | > | determinant = matDet3( a ); |
221 | > | |
222 | > | if (determinant == 0.0) { |
223 | > | sprintf( painCave.errMsg, |
224 | > | "Can't invert a matrix with a zero determinant!\n"); |
225 | > | painCave.isFatal = 1; |
226 | > | simError(); |
227 | > | } |
228 | > | |
229 | > | for (i=0; i < 3; i++) { |
230 | > | j = (i+1)%3; |
231 | > | k = (i+2)%3; |
232 | > | for(l = 0; l < 3; l++) { |
233 | > | m = (l+1)%3; |
234 | > | n = (l+2)%3; |
235 | ||
236 | < | sanity[i][j] = 0.0; |
231 | < | for(k=0; k<3; k++){ |
232 | < | sanity[i][j] += Hmat[3*k+i] * HmatI[3*j+k]; |
233 | < | } |
236 | > | b[l][i] = (a[j][m]*a[k][n] - a[j][n]*a[k][m]) / determinant; |
237 | } | |
238 | } | |
239 | + | } |
240 | ||
241 | < | cerr << "sanity => \n" |
242 | < | << sanity[0][0] << "\t" << sanity[0][1] << "\t" << sanity [0][2] << "\n" |
239 | < | << sanity[1][0] << "\t" << sanity[1][1] << "\t" << sanity [1][2] << "\n" |
240 | < | << sanity[2][0] << "\t" << sanity[2][1] << "\t" << sanity [2][2] |
241 | < | << "\n"; |
242 | < | |
241 | > | void SimInfo::matMul3(double a[3][3], double b[3][3], double c[3][3]) { |
242 | > | double r00, r01, r02, r10, r11, r12, r20, r21, r22; |
243 | ||
244 | < | // check to see if Hmat is orthorhombic |
244 | > | r00 = a[0][0]*b[0][0] + a[0][1]*b[1][0] + a[0][2]*b[2][0]; |
245 | > | r01 = a[0][0]*b[0][1] + a[0][1]*b[1][1] + a[0][2]*b[2][1]; |
246 | > | r02 = a[0][0]*b[0][2] + a[0][1]*b[1][2] + a[0][2]*b[2][2]; |
247 | ||
248 | < | smallDiag = Hmat[0]; |
249 | < | if(smallDiag > Hmat[4]) smallDiag = Hmat[4]; |
250 | < | if(smallDiag > Hmat[8]) smallDiag = Hmat[8]; |
251 | < | tol = smallDiag * 1E-6; |
248 | > | r10 = a[1][0]*b[0][0] + a[1][1]*b[1][0] + a[1][2]*b[2][0]; |
249 | > | r11 = a[1][0]*b[0][1] + a[1][1]*b[1][1] + a[1][2]*b[2][1]; |
250 | > | r12 = a[1][0]*b[0][2] + a[1][1]*b[1][2] + a[1][2]*b[2][2]; |
251 | > | |
252 | > | r20 = a[2][0]*b[0][0] + a[2][1]*b[1][0] + a[2][2]*b[2][0]; |
253 | > | r21 = a[2][0]*b[0][1] + a[2][1]*b[1][1] + a[2][2]*b[2][1]; |
254 | > | r22 = a[2][0]*b[0][2] + a[2][1]*b[1][2] + a[2][2]*b[2][2]; |
255 | > | |
256 | > | c[0][0] = r00; c[0][1] = r01; c[0][2] = r02; |
257 | > | c[1][0] = r10; c[1][1] = r11; c[1][2] = r12; |
258 | > | c[2][0] = r20; c[2][1] = r21; c[2][2] = r22; |
259 | > | } |
260 | ||
261 | < | orthoRhombic = 1; |
262 | < | for(i=0; (i<9) && orthoRhombic; i++){ |
263 | < | |
264 | < | if( (i%4) ){ // ignore the diagonals (0, 4, and 8) |
265 | < | orthoRhombic = (Hmat[i] <= tol); |
261 | > | void SimInfo::matVecMul3(double m[3][3], double inVec[3], double outVec[3]) { |
262 | > | double a0, a1, a2; |
263 | > | |
264 | > | a0 = inVec[0]; a1 = inVec[1]; a2 = inVec[2]; |
265 | > | |
266 | > | outVec[0] = m[0][0]*a0 + m[0][1]*a1 + m[0][2]*a2; |
267 | > | outVec[1] = m[1][0]*a0 + m[1][1]*a1 + m[1][2]*a2; |
268 | > | outVec[2] = m[2][0]*a0 + m[2][1]*a1 + m[2][2]*a2; |
269 | > | } |
270 | > | |
271 | > | void SimInfo::transposeMat3(double in[3][3], double out[3][3]) { |
272 | > | double temp[3][3]; |
273 | > | int i, j; |
274 | > | |
275 | > | for (i = 0; i < 3; i++) { |
276 | > | for (j = 0; j < 3; j++) { |
277 | > | temp[j][i] = in[i][j]; |
278 | } | |
279 | } | |
280 | < | |
280 | > | for (i = 0; i < 3; i++) { |
281 | > | for (j = 0; j < 3; j++) { |
282 | > | out[i][j] = temp[i][j]; |
283 | > | } |
284 | > | } |
285 | } | |
286 | + | |
287 | + | void SimInfo::printMat3(double A[3][3] ){ |
288 | ||
289 | + | std::cerr |
290 | + | << "[ " << A[0][0] << ", " << A[0][1] << ", " << A[0][2] << " ]\n" |
291 | + | << "[ " << A[1][0] << ", " << A[1][1] << ", " << A[1][2] << " ]\n" |
292 | + | << "[ " << A[2][0] << ", " << A[2][1] << ", " << A[2][2] << " ]\n"; |
293 | + | } |
294 | + | |
295 | + | void SimInfo::printMat9(double A[9] ){ |
296 | + | |
297 | + | std::cerr |
298 | + | << "[ " << A[0] << ", " << A[1] << ", " << A[2] << " ]\n" |
299 | + | << "[ " << A[3] << ", " << A[4] << ", " << A[5] << " ]\n" |
300 | + | << "[ " << A[6] << ", " << A[7] << ", " << A[8] << " ]\n"; |
301 | + | } |
302 | + | |
303 | void SimInfo::calcBoxL( void ){ | |
304 | ||
305 | double dx, dy, dz, dsq; | |
306 | int i; | |
307 | ||
308 | < | // boxVol = h1 (dot) h2 (cross) h3 |
308 | > | // boxVol = Determinant of Hmat |
309 | ||
310 | < | boxVol = Hmat[0] * ( (Hmat[4]*Hmat[8]) - (Hmat[7]*Hmat[5]) ) |
269 | < | + Hmat[1] * ( (Hmat[5]*Hmat[6]) - (Hmat[8]*Hmat[3]) ) |
270 | < | + Hmat[2] * ( (Hmat[3]*Hmat[7]) - (Hmat[6]*Hmat[4]) ); |
310 | > | boxVol = matDet3( Hmat ); |
311 | ||
272 | – | |
312 | // boxLx | |
313 | ||
314 | < | dx = Hmat[0]; dy = Hmat[1]; dz = Hmat[2]; |
314 | > | dx = Hmat[0][0]; dy = Hmat[1][0]; dz = Hmat[2][0]; |
315 | dsq = dx*dx + dy*dy + dz*dz; | |
316 | boxLx = sqrt( dsq ); | |
317 | ||
318 | // boxLy | |
319 | ||
320 | < | dx = Hmat[3]; dy = Hmat[4]; dz = Hmat[5]; |
320 | > | dx = Hmat[0][1]; dy = Hmat[1][1]; dz = Hmat[2][1]; |
321 | dsq = dx*dx + dy*dy + dz*dz; | |
322 | boxLy = sqrt( dsq ); | |
323 | ||
324 | // boxLz | |
325 | ||
326 | < | dx = Hmat[6]; dy = Hmat[7]; dz = Hmat[8]; |
326 | > | dx = Hmat[0][2]; dy = Hmat[1][2]; dz = Hmat[2][2]; |
327 | dsq = dx*dx + dy*dy + dz*dz; | |
328 | boxLz = sqrt( dsq ); | |
329 | ||
# | Line 298 | Line 337 | void SimInfo::wrapVector( double thePos[3] ){ | |
337 | ||
338 | if( !orthoRhombic ){ | |
339 | // calc the scaled coordinates. | |
340 | + | |
341 | + | |
342 | + | matVecMul3(HmatInv, thePos, scaled); |
343 | ||
344 | for(i=0; i<3; i++) | |
303 | – | scaled[i] = |
304 | – | thePos[0]*HmatI[i] + thePos[1]*HmatI[i+3] + thePos[3]*HmatI[i+6]; |
305 | – | |
306 | – | // wrap the scaled coordinates |
307 | – | |
308 | – | for(i=0; i<3; i++) |
345 | scaled[i] -= roundMe(scaled[i]); | |
346 | ||
347 | // calc the wrapped real coordinates from the wrapped scaled coordinates | |
348 | ||
349 | < | for(i=0; i<3; i++) |
350 | < | thePos[i] = |
315 | < | scaled[0]*Hmat[i] + scaled[1]*Hmat[i+3] + scaled[2]*Hmat[i+6]; |
349 | > | matVecMul3(Hmat, scaled, thePos); |
350 | > | |
351 | } | |
352 | else{ | |
353 | // calc the scaled coordinates. | |
354 | ||
355 | for(i=0; i<3; i++) | |
356 | < | scaled[i] = thePos[i]*HmatI[i*4]; |
356 | > | scaled[i] = thePos[i]*HmatInv[i][i]; |
357 | ||
358 | // wrap the scaled coordinates | |
359 | ||
# | Line 328 | Line 363 | void SimInfo::wrapVector( double thePos[3] ){ | |
363 | // calc the wrapped real coordinates from the wrapped scaled coordinates | |
364 | ||
365 | for(i=0; i<3; i++) | |
366 | < | thePos[i] = scaled[i]*Hmat[i*4]; |
366 | > | thePos[i] = scaled[i]*Hmat[i][i]; |
367 | } | |
368 | ||
334 | – | |
369 | } | |
370 | ||
371 |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |