1 |
|
#include <cstdlib> |
2 |
|
#include <cstring> |
3 |
+ |
#include <cmath> |
4 |
|
|
5 |
+ |
#include <iostream> |
6 |
+ |
using namespace std; |
7 |
|
|
8 |
|
#include "SimInfo.hpp" |
9 |
|
#define __C |
12 |
|
|
13 |
|
#include "fortranWrappers.hpp" |
14 |
|
|
15 |
+ |
#ifdef IS_MPI |
16 |
+ |
#include "mpiSimulation.hpp" |
17 |
+ |
#endif |
18 |
+ |
|
19 |
+ |
inline double roundMe( double x ){ |
20 |
+ |
return ( x >= 0 ) ? floor( x + 0.5 ) : ceil( x - 0.5 ); |
21 |
+ |
} |
22 |
+ |
|
23 |
+ |
|
24 |
|
SimInfo* currentInfo; |
25 |
|
|
26 |
|
SimInfo::SimInfo(){ |
47 |
|
} |
48 |
|
|
49 |
|
void SimInfo::setBox(double newBox[3]) { |
50 |
< |
double smallestBox, maxCutoff; |
51 |
< |
int status; |
52 |
< |
box_x = newBox[0]; |
41 |
< |
box_y = newBox[1]; |
42 |
< |
box_z = newBox[2]; |
43 |
< |
setFortranBoxSize(newBox); |
50 |
> |
|
51 |
> |
int i; |
52 |
> |
double tempMat[9]; |
53 |
|
|
54 |
< |
smallestBox = box_x; |
46 |
< |
if (box_y < smallestBox) smallestBox = box_y; |
47 |
< |
if (box_z < smallestBox) smallestBox = box_z; |
54 |
> |
for(i=0; i<9; i++) tempMat[i] = 0.0;; |
55 |
|
|
56 |
< |
maxCutoff = smallestBox / 2.0; |
56 |
> |
tempMat[0] = newBox[0]; |
57 |
> |
tempMat[4] = newBox[1]; |
58 |
> |
tempMat[8] = newBox[2]; |
59 |
|
|
60 |
+ |
setBoxM( tempMat ); |
61 |
+ |
|
62 |
+ |
} |
63 |
+ |
|
64 |
+ |
void SimInfo::setBoxM( double theBox[9] ){ |
65 |
+ |
|
66 |
+ |
int i, status; |
67 |
+ |
double smallestBoxL, maxCutoff; |
68 |
+ |
|
69 |
+ |
for(i=0; i<9; i++) Hmat[i] = theBox[i]; |
70 |
+ |
|
71 |
+ |
cerr |
72 |
+ |
<< "setting Hmat ->\n" |
73 |
+ |
<< "[ " << Hmat[0] << ", " << Hmat[3] << ", " << Hmat[6] << " ]\n" |
74 |
+ |
<< "[ " << Hmat[1] << ", " << Hmat[4] << ", " << Hmat[7] << " ]\n" |
75 |
+ |
<< "[ " << Hmat[2] << ", " << Hmat[5] << ", " << Hmat[8] << " ]\n"; |
76 |
+ |
|
77 |
+ |
calcHmatI(); |
78 |
+ |
calcBoxL(); |
79 |
+ |
|
80 |
+ |
|
81 |
+ |
|
82 |
+ |
setFortranBoxSize(Hmat, HmatI, &orthoRhombic); |
83 |
+ |
|
84 |
+ |
smallestBoxL = boxLx; |
85 |
+ |
if (boxLy < smallestBoxL) smallestBoxL = boxLy; |
86 |
+ |
if (boxLz < smallestBoxL) smallestBoxL = boxLz; |
87 |
+ |
|
88 |
+ |
maxCutoff = smallestBoxL / 2.0; |
89 |
+ |
|
90 |
|
if (rList > maxCutoff) { |
91 |
|
sprintf( painCave.errMsg, |
92 |
|
"New Box size is forcing neighborlist radius down to %lf\n", |
125 |
|
} |
126 |
|
} |
127 |
|
} |
128 |
+ |
|
129 |
|
|
130 |
< |
void SimInfo::getBox(double theBox[3]) { |
131 |
< |
theBox[0] = box_x; |
132 |
< |
theBox[1] = box_y; |
133 |
< |
theBox[2] = box_z; |
130 |
> |
void SimInfo::getBoxM (double theBox[9]) { |
131 |
> |
|
132 |
> |
int i; |
133 |
> |
for(i=0; i<9; i++) theBox[i] = Hmat[i]; |
134 |
|
} |
135 |
< |
|
135 |
> |
|
136 |
> |
|
137 |
> |
void SimInfo::scaleBox(double scale) { |
138 |
> |
double theBox[9]; |
139 |
> |
int i; |
140 |
> |
|
141 |
> |
cerr << "Scaling box by " << scale << "\n"; |
142 |
> |
|
143 |
> |
for(i=0; i<9; i++) theBox[i] = Hmat[i]*scale; |
144 |
> |
|
145 |
> |
setBoxM(theBox); |
146 |
> |
|
147 |
> |
} |
148 |
> |
|
149 |
> |
void SimInfo::calcHmatI( void ) { |
150 |
> |
|
151 |
> |
double C[3][3]; |
152 |
> |
double detHmat; |
153 |
> |
int i, j, k; |
154 |
> |
double smallDiag; |
155 |
> |
double tol; |
156 |
> |
double sanity[3][3]; |
157 |
> |
|
158 |
> |
// calculate the adjunct of Hmat; |
159 |
> |
|
160 |
> |
C[0][0] = ( Hmat[4]*Hmat[8]) - (Hmat[7]*Hmat[5]); |
161 |
> |
C[1][0] = -( Hmat[1]*Hmat[8]) + (Hmat[7]*Hmat[2]); |
162 |
> |
C[2][0] = ( Hmat[1]*Hmat[5]) - (Hmat[4]*Hmat[2]); |
163 |
> |
|
164 |
> |
C[0][1] = -( Hmat[3]*Hmat[8]) + (Hmat[6]*Hmat[5]); |
165 |
> |
C[1][1] = ( Hmat[0]*Hmat[8]) - (Hmat[6]*Hmat[2]); |
166 |
> |
C[2][1] = -( Hmat[0]*Hmat[5]) + (Hmat[3]*Hmat[2]); |
167 |
> |
|
168 |
> |
C[0][2] = ( Hmat[3]*Hmat[7]) - (Hmat[6]*Hmat[4]); |
169 |
> |
C[1][2] = -( Hmat[0]*Hmat[7]) + (Hmat[6]*Hmat[1]); |
170 |
> |
C[2][2] = ( Hmat[0]*Hmat[4]) - (Hmat[3]*Hmat[1]); |
171 |
> |
|
172 |
> |
// calcutlate the determinant of Hmat |
173 |
> |
|
174 |
> |
detHmat = 0.0; |
175 |
> |
for(i=0; i<3; i++) detHmat += Hmat[i] * C[i][0]; |
176 |
> |
|
177 |
> |
|
178 |
> |
// H^-1 = C^T / det(H) |
179 |
> |
|
180 |
> |
i=0; |
181 |
> |
for(j=0; j<3; j++){ |
182 |
> |
for(k=0; k<3; k++){ |
183 |
> |
|
184 |
> |
HmatI[i] = C[j][k] / detHmat; |
185 |
> |
i++; |
186 |
> |
} |
187 |
> |
} |
188 |
> |
|
189 |
> |
// sanity check |
190 |
> |
|
191 |
> |
for(i=0; i<3; i++){ |
192 |
> |
for(j=0; j<3; j++){ |
193 |
> |
|
194 |
> |
sanity[i][j] = 0.0; |
195 |
> |
for(k=0; k<3; k++){ |
196 |
> |
sanity[i][j] += Hmat[3*k+i] * HmatI[3*j+k]; |
197 |
> |
} |
198 |
> |
} |
199 |
> |
} |
200 |
> |
|
201 |
> |
cerr << "sanity => \n" |
202 |
> |
<< sanity[0][0] << "\t" << sanity[0][1] << "\t" << sanity [0][2] << "\n" |
203 |
> |
<< sanity[1][0] << "\t" << sanity[1][1] << "\t" << sanity [1][2] << "\n" |
204 |
> |
<< sanity[2][0] << "\t" << sanity[2][1] << "\t" << sanity [2][2] |
205 |
> |
<< "\n"; |
206 |
> |
|
207 |
> |
|
208 |
> |
// check to see if Hmat is orthorhombic |
209 |
> |
|
210 |
> |
smallDiag = Hmat[0]; |
211 |
> |
if(smallDiag > Hmat[4]) smallDiag = Hmat[4]; |
212 |
> |
if(smallDiag > Hmat[8]) smallDiag = Hmat[8]; |
213 |
> |
tol = smallDiag * 1E-6; |
214 |
> |
|
215 |
> |
orthoRhombic = 1; |
216 |
> |
for(i=0; (i<9) && orthoRhombic; i++){ |
217 |
> |
|
218 |
> |
if( (i%4) ){ // ignore the diagonals (0, 4, and 8) |
219 |
> |
orthoRhombic = (Hmat[i] <= tol); |
220 |
> |
} |
221 |
> |
} |
222 |
> |
|
223 |
> |
} |
224 |
> |
|
225 |
> |
void SimInfo::calcBoxL( void ){ |
226 |
> |
|
227 |
> |
double dx, dy, dz, dsq; |
228 |
> |
int i; |
229 |
> |
|
230 |
> |
// boxVol = h1 (dot) h2 (cross) h3 |
231 |
> |
|
232 |
> |
boxVol = Hmat[0] * ( (Hmat[4]*Hmat[8]) - (Hmat[7]*Hmat[5]) ) |
233 |
> |
+ Hmat[1] * ( (Hmat[5]*Hmat[6]) - (Hmat[8]*Hmat[3]) ) |
234 |
> |
+ Hmat[2] * ( (Hmat[3]*Hmat[7]) - (Hmat[6]*Hmat[4]) ); |
235 |
> |
|
236 |
> |
|
237 |
> |
// boxLx |
238 |
> |
|
239 |
> |
dx = Hmat[0]; dy = Hmat[1]; dz = Hmat[2]; |
240 |
> |
dsq = dx*dx + dy*dy + dz*dz; |
241 |
> |
boxLx = sqrt( dsq ); |
242 |
> |
|
243 |
> |
// boxLy |
244 |
> |
|
245 |
> |
dx = Hmat[3]; dy = Hmat[4]; dz = Hmat[5]; |
246 |
> |
dsq = dx*dx + dy*dy + dz*dz; |
247 |
> |
boxLy = sqrt( dsq ); |
248 |
> |
|
249 |
> |
// boxLz |
250 |
> |
|
251 |
> |
dx = Hmat[6]; dy = Hmat[7]; dz = Hmat[8]; |
252 |
> |
dsq = dx*dx + dy*dy + dz*dz; |
253 |
> |
boxLz = sqrt( dsq ); |
254 |
> |
|
255 |
> |
} |
256 |
> |
|
257 |
> |
|
258 |
> |
void SimInfo::wrapVector( double thePos[3] ){ |
259 |
> |
|
260 |
> |
int i, j, k; |
261 |
> |
double scaled[3]; |
262 |
> |
|
263 |
> |
if( !orthoRhombic ){ |
264 |
> |
// calc the scaled coordinates. |
265 |
> |
|
266 |
> |
for(i=0; i<3; i++) |
267 |
> |
scaled[i] = |
268 |
> |
thePos[0]*HmatI[i] + thePos[1]*HmatI[i+3] + thePos[3]*HmatI[i+6]; |
269 |
> |
|
270 |
> |
// wrap the scaled coordinates |
271 |
> |
|
272 |
> |
for(i=0; i<3; i++) |
273 |
> |
scaled[i] -= roundMe(scaled[i]); |
274 |
> |
|
275 |
> |
// calc the wrapped real coordinates from the wrapped scaled coordinates |
276 |
> |
|
277 |
> |
for(i=0; i<3; i++) |
278 |
> |
thePos[i] = |
279 |
> |
scaled[0]*Hmat[i] + scaled[1]*Hmat[i+3] + scaled[2]*Hmat[i+6]; |
280 |
> |
} |
281 |
> |
else{ |
282 |
> |
// calc the scaled coordinates. |
283 |
> |
|
284 |
> |
for(i=0; i<3; i++) |
285 |
> |
scaled[i] = thePos[i]*HmatI[i*4]; |
286 |
> |
|
287 |
> |
// wrap the scaled coordinates |
288 |
> |
|
289 |
> |
for(i=0; i<3; i++) |
290 |
> |
scaled[i] -= roundMe(scaled[i]); |
291 |
> |
|
292 |
> |
// calc the wrapped real coordinates from the wrapped scaled coordinates |
293 |
> |
|
294 |
> |
for(i=0; i<3; i++) |
295 |
> |
thePos[i] = scaled[i]*Hmat[i*4]; |
296 |
> |
} |
297 |
> |
|
298 |
> |
|
299 |
> |
} |
300 |
> |
|
301 |
> |
|
302 |
|
int SimInfo::getNDF(){ |
303 |
|
int ndf_local, ndf; |
304 |
|
|
334 |
|
|
335 |
|
simtype fInfo; |
336 |
|
int isError; |
337 |
+ |
int n_global; |
338 |
|
int* excl; |
339 |
|
|
340 |
|
fInfo.rrf = 0.0; |
341 |
|
fInfo.rt = 0.0; |
342 |
|
fInfo.dielect = 0.0; |
343 |
|
|
137 |
– |
fInfo.box[0] = box_x; |
138 |
– |
fInfo.box[1] = box_y; |
139 |
– |
fInfo.box[2] = box_z; |
140 |
– |
|
344 |
|
fInfo.rlist = rList; |
345 |
|
fInfo.rcut = rCut; |
346 |
|
|
364 |
|
|
365 |
|
excl = Exclude::getArray(); |
366 |
|
|
367 |
+ |
#ifdef IS_MPI |
368 |
+ |
n_global = mpiSim->getTotAtoms(); |
369 |
+ |
#else |
370 |
+ |
n_global = n_atoms; |
371 |
+ |
#endif |
372 |
+ |
|
373 |
|
isError = 0; |
374 |
|
|
375 |
< |
// fInfo; |
376 |
< |
// n_atoms; |
377 |
< |
// identArray; |
169 |
< |
// n_exclude; |
170 |
< |
// excludes; |
171 |
< |
// nGlobalExcludes; |
172 |
< |
// globalExcludes; |
173 |
< |
// isError; |
375 |
> |
setFsimulation( &fInfo, &n_global, &n_atoms, identArray, &n_exclude, excl, |
376 |
> |
&nGlobalExcludes, globalExcludes, molMembershipArray, |
377 |
> |
&isError ); |
378 |
|
|
175 |
– |
setFsimulation( &fInfo, &n_atoms, identArray, &n_exclude, excl, |
176 |
– |
&nGlobalExcludes, globalExcludes, &isError ); |
177 |
– |
|
379 |
|
if( isError ){ |
380 |
|
|
381 |
|
sprintf( painCave.errMsg, |