1 |
< |
#include <cstdlib> |
2 |
< |
#include <cstring> |
3 |
< |
#include <cmath> |
1 |
> |
#include <stdlib.h> |
2 |
> |
#include <string.h> |
3 |
> |
#include <math.h> |
4 |
|
|
5 |
|
#include <iostream> |
6 |
|
using namespace std; |
20 |
|
return ( x >= 0 ) ? floor( x + 0.5 ) : ceil( x - 0.5 ); |
21 |
|
} |
22 |
|
|
23 |
+ |
inline double min( double a, double b ){ |
24 |
+ |
return (a < b ) ? a : b; |
25 |
+ |
} |
26 |
|
|
27 |
|
SimInfo* currentInfo; |
28 |
|
|
29 |
|
SimInfo::SimInfo(){ |
30 |
|
excludes = NULL; |
31 |
|
n_constraints = 0; |
32 |
+ |
nZconstraints = 0; |
33 |
|
n_oriented = 0; |
34 |
|
n_dipoles = 0; |
35 |
|
ndf = 0; |
36 |
|
ndfRaw = 0; |
37 |
+ |
nZconstraints = 0; |
38 |
|
the_integrator = NULL; |
39 |
|
setTemp = 0; |
40 |
|
thermalTime = 0.0; |
42 |
|
rCut = 0.0; |
43 |
|
ecr = 0.0; |
44 |
|
est = 0.0; |
40 |
– |
oldEcr = 0.0; |
41 |
– |
oldRcut = 0.0; |
45 |
|
|
46 |
< |
haveOrigRcut = 0; |
47 |
< |
haveOrigEcr = 0; |
46 |
> |
haveRcut = 0; |
47 |
> |
haveEcr = 0; |
48 |
|
boxIsInit = 0; |
49 |
|
|
50 |
< |
|
50 |
> |
resetTime = 1e99; |
51 |
|
|
52 |
+ |
orthoTolerance = 1E-6; |
53 |
+ |
useInitXSstate = true; |
54 |
+ |
|
55 |
|
usePBC = 0; |
56 |
|
useLJ = 0; |
57 |
|
useSticky = 0; |
58 |
< |
useDipole = 0; |
58 |
> |
useCharges = 0; |
59 |
> |
useDipoles = 0; |
60 |
|
useReactionField = 0; |
61 |
|
useGB = 0; |
62 |
|
useEAM = 0; |
63 |
|
|
64 |
+ |
myConfiguration = new SimState(); |
65 |
+ |
|
66 |
|
wrapMeSimInfo( this ); |
67 |
|
} |
68 |
|
|
69 |
+ |
|
70 |
|
SimInfo::~SimInfo(){ |
71 |
|
|
72 |
+ |
delete myConfiguration; |
73 |
+ |
|
74 |
|
map<string, GenericData*>::iterator i; |
75 |
|
|
76 |
|
for(i = properties.begin(); i != properties.end(); i++) |
77 |
|
delete (*i).second; |
78 |
< |
|
67 |
< |
|
78 |
> |
|
79 |
|
} |
80 |
|
|
81 |
|
void SimInfo::setBox(double newBox[3]) { |
96 |
|
|
97 |
|
void SimInfo::setBoxM( double theBox[3][3] ){ |
98 |
|
|
99 |
< |
int i, j, status; |
89 |
< |
double smallestBoxL, maxCutoff; |
99 |
> |
int i, j; |
100 |
|
double FortranHmat[9]; // to preserve compatibility with Fortran the |
101 |
|
// ordering in the array is as follows: |
102 |
|
// [ 0 3 6 ] |
104 |
|
// [ 2 5 8 ] |
105 |
|
double FortranHmatInv[9]; // the inverted Hmat (for Fortran); |
106 |
|
|
97 |
– |
|
107 |
|
if( !boxIsInit ) boxIsInit = 1; |
108 |
|
|
109 |
|
for(i=0; i < 3; i++) |
147 |
|
|
148 |
|
void SimInfo::calcHmatInv( void ) { |
149 |
|
|
150 |
+ |
int oldOrtho; |
151 |
|
int i,j; |
152 |
|
double smallDiag; |
153 |
|
double tol; |
154 |
|
double sanity[3][3]; |
155 |
|
|
156 |
|
invertMat3( Hmat, HmatInv ); |
147 |
– |
|
148 |
– |
// Check the inverse to make sure it is sane: |
157 |
|
|
150 |
– |
matMul3( Hmat, HmatInv, sanity ); |
151 |
– |
|
158 |
|
// check to see if Hmat is orthorhombic |
159 |
|
|
160 |
< |
smallDiag = Hmat[0][0]; |
155 |
< |
if(smallDiag > Hmat[1][1]) smallDiag = Hmat[1][1]; |
156 |
< |
if(smallDiag > Hmat[2][2]) smallDiag = Hmat[2][2]; |
157 |
< |
tol = smallDiag * 1E-6; |
160 |
> |
oldOrtho = orthoRhombic; |
161 |
|
|
162 |
+ |
smallDiag = fabs(Hmat[0][0]); |
163 |
+ |
if(smallDiag > fabs(Hmat[1][1])) smallDiag = fabs(Hmat[1][1]); |
164 |
+ |
if(smallDiag > fabs(Hmat[2][2])) smallDiag = fabs(Hmat[2][2]); |
165 |
+ |
tol = smallDiag * orthoTolerance; |
166 |
+ |
|
167 |
|
orthoRhombic = 1; |
168 |
|
|
169 |
|
for (i = 0; i < 3; i++ ) { |
170 |
|
for (j = 0 ; j < 3; j++) { |
171 |
|
if (i != j) { |
172 |
|
if (orthoRhombic) { |
173 |
< |
if (Hmat[i][j] >= tol) orthoRhombic = 0; |
173 |
> |
if ( fabs(Hmat[i][j]) >= tol) orthoRhombic = 0; |
174 |
|
} |
175 |
|
} |
176 |
|
} |
177 |
|
} |
178 |
+ |
|
179 |
+ |
if( oldOrtho != orthoRhombic ){ |
180 |
+ |
|
181 |
+ |
if( orthoRhombic ){ |
182 |
+ |
sprintf( painCave.errMsg, |
183 |
+ |
"Hmat is switching from Non-Orthorhombic to Orthorhombic Box.\n" |
184 |
+ |
"\tIf this is a bad thing, change the orthoBoxTolerance\n" |
185 |
+ |
"\tvariable ( currently set to %G ).\n", |
186 |
+ |
orthoTolerance); |
187 |
+ |
simError(); |
188 |
+ |
} |
189 |
+ |
else { |
190 |
+ |
sprintf( painCave.errMsg, |
191 |
+ |
"Hmat is switching from Orthorhombic to Non-Orthorhombic Box.\n" |
192 |
+ |
"\tIf this is a bad thing, change the orthoBoxTolerance\n" |
193 |
+ |
"\tvariable ( currently set to %G ).\n", |
194 |
+ |
orthoTolerance); |
195 |
+ |
simError(); |
196 |
+ |
} |
197 |
+ |
} |
198 |
|
} |
199 |
|
|
200 |
|
double SimInfo::matDet3(double a[3][3]) { |
301 |
|
<< "[ " << A[6] << ", " << A[7] << ", " << A[8] << " ]\n"; |
302 |
|
} |
303 |
|
|
304 |
+ |
|
305 |
+ |
void SimInfo::crossProduct3(double a[3],double b[3], double out[3]){ |
306 |
+ |
|
307 |
+ |
out[0] = a[1] * b[2] - a[2] * b[1]; |
308 |
+ |
out[1] = a[2] * b[0] - a[0] * b[2] ; |
309 |
+ |
out[2] = a[0] * b[1] - a[1] * b[0]; |
310 |
+ |
|
311 |
+ |
} |
312 |
+ |
|
313 |
+ |
double SimInfo::dotProduct3(double a[3], double b[3]){ |
314 |
+ |
return a[0]*b[0] + a[1]*b[1]+ a[2]*b[2]; |
315 |
+ |
} |
316 |
+ |
|
317 |
+ |
double SimInfo::length3(double a[3]){ |
318 |
+ |
return sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]); |
319 |
+ |
} |
320 |
+ |
|
321 |
|
void SimInfo::calcBoxL( void ){ |
322 |
|
|
323 |
|
double dx, dy, dz, dsq; |
279 |
– |
int i; |
324 |
|
|
325 |
|
// boxVol = Determinant of Hmat |
326 |
|
|
331 |
|
dx = Hmat[0][0]; dy = Hmat[1][0]; dz = Hmat[2][0]; |
332 |
|
dsq = dx*dx + dy*dy + dz*dz; |
333 |
|
boxL[0] = sqrt( dsq ); |
334 |
< |
maxCutoff = 0.5 * boxL[0]; |
334 |
> |
//maxCutoff = 0.5 * boxL[0]; |
335 |
|
|
336 |
|
// boxLy |
337 |
|
|
338 |
|
dx = Hmat[0][1]; dy = Hmat[1][1]; dz = Hmat[2][1]; |
339 |
|
dsq = dx*dx + dy*dy + dz*dz; |
340 |
|
boxL[1] = sqrt( dsq ); |
341 |
< |
if( (0.5 * boxL[1]) < maxCutoff ) maxCutoff = 0.5 * boxL[1]; |
341 |
> |
//if( (0.5 * boxL[1]) < maxCutoff ) maxCutoff = 0.5 * boxL[1]; |
342 |
|
|
343 |
+ |
|
344 |
|
// boxLz |
345 |
|
|
346 |
|
dx = Hmat[0][2]; dy = Hmat[1][2]; dz = Hmat[2][2]; |
347 |
|
dsq = dx*dx + dy*dy + dz*dz; |
348 |
|
boxL[2] = sqrt( dsq ); |
349 |
< |
if( (0.5 * boxL[2]) < maxCutoff ) maxCutoff = 0.5 * boxL[2]; |
349 |
> |
//if( (0.5 * boxL[2]) < maxCutoff ) maxCutoff = 0.5 * boxL[2]; |
350 |
> |
|
351 |
> |
//calculate the max cutoff |
352 |
> |
maxCutoff = calcMaxCutOff(); |
353 |
|
|
354 |
|
checkCutOffs(); |
355 |
|
|
356 |
|
} |
357 |
|
|
358 |
|
|
359 |
+ |
double SimInfo::calcMaxCutOff(){ |
360 |
+ |
|
361 |
+ |
double ri[3], rj[3], rk[3]; |
362 |
+ |
double rij[3], rjk[3], rki[3]; |
363 |
+ |
double minDist; |
364 |
+ |
|
365 |
+ |
ri[0] = Hmat[0][0]; |
366 |
+ |
ri[1] = Hmat[1][0]; |
367 |
+ |
ri[2] = Hmat[2][0]; |
368 |
+ |
|
369 |
+ |
rj[0] = Hmat[0][1]; |
370 |
+ |
rj[1] = Hmat[1][1]; |
371 |
+ |
rj[2] = Hmat[2][1]; |
372 |
+ |
|
373 |
+ |
rk[0] = Hmat[0][2]; |
374 |
+ |
rk[1] = Hmat[1][2]; |
375 |
+ |
rk[2] = Hmat[2][2]; |
376 |
+ |
|
377 |
+ |
crossProduct3(ri,rj, rij); |
378 |
+ |
distXY = dotProduct3(rk,rij) / length3(rij); |
379 |
+ |
|
380 |
+ |
crossProduct3(rj,rk, rjk); |
381 |
+ |
distYZ = dotProduct3(ri,rjk) / length3(rjk); |
382 |
+ |
|
383 |
+ |
crossProduct3(rk,ri, rki); |
384 |
+ |
distZX = dotProduct3(rj,rki) / length3(rki); |
385 |
+ |
|
386 |
+ |
minDist = min(min(distXY, distYZ), distZX); |
387 |
+ |
return minDist/2; |
388 |
+ |
|
389 |
+ |
} |
390 |
+ |
|
391 |
|
void SimInfo::wrapVector( double thePos[3] ){ |
392 |
|
|
393 |
< |
int i, j, k; |
393 |
> |
int i; |
394 |
|
double scaled[3]; |
395 |
|
|
396 |
|
if( !orthoRhombic ){ |
428 |
|
|
429 |
|
|
430 |
|
int SimInfo::getNDF(){ |
431 |
< |
int ndf_local, ndf; |
431 |
> |
int ndf_local; |
432 |
|
|
433 |
|
ndf_local = 3 * n_atoms + 3 * n_oriented - n_constraints; |
434 |
|
|
438 |
|
ndf = ndf_local; |
439 |
|
#endif |
440 |
|
|
441 |
< |
ndf = ndf - 3; |
441 |
> |
ndf = ndf - 3 - nZconstraints; |
442 |
|
|
443 |
|
return ndf; |
444 |
|
} |
445 |
|
|
446 |
|
int SimInfo::getNDFraw() { |
447 |
< |
int ndfRaw_local, ndfRaw; |
447 |
> |
int ndfRaw_local; |
448 |
|
|
449 |
|
// Raw degrees of freedom that we have to set |
450 |
|
ndfRaw_local = 3 * n_atoms + 3 * n_oriented; |
457 |
|
|
458 |
|
return ndfRaw; |
459 |
|
} |
460 |
< |
|
460 |
> |
|
461 |
> |
int SimInfo::getNDFtranslational() { |
462 |
> |
int ndfTrans_local; |
463 |
> |
|
464 |
> |
ndfTrans_local = 3 * n_atoms - n_constraints; |
465 |
> |
|
466 |
> |
#ifdef IS_MPI |
467 |
> |
MPI_Allreduce(&ndfTrans_local,&ndfTrans,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
468 |
> |
#else |
469 |
> |
ndfTrans = ndfTrans_local; |
470 |
> |
#endif |
471 |
> |
|
472 |
> |
ndfTrans = ndfTrans - 3 - nZconstraints; |
473 |
> |
|
474 |
> |
return ndfTrans; |
475 |
> |
} |
476 |
> |
|
477 |
|
void SimInfo::refreshSim(){ |
478 |
|
|
479 |
|
simtype fInfo; |
483 |
|
|
484 |
|
fInfo.dielect = 0.0; |
485 |
|
|
486 |
< |
if( useDipole ){ |
486 |
> |
if( useDipoles ){ |
487 |
|
if( useReactionField )fInfo.dielect = dielectric; |
488 |
|
} |
489 |
|
|
492 |
|
fInfo.SIM_uses_LJ = useLJ; |
493 |
|
fInfo.SIM_uses_sticky = useSticky; |
494 |
|
//fInfo.SIM_uses_sticky = 0; |
495 |
< |
fInfo.SIM_uses_dipoles = useDipole; |
495 |
> |
fInfo.SIM_uses_charges = useCharges; |
496 |
> |
fInfo.SIM_uses_dipoles = useDipoles; |
497 |
|
//fInfo.SIM_uses_dipoles = 0; |
498 |
|
//fInfo.SIM_uses_RF = useReactionField; |
499 |
|
fInfo.SIM_uses_RF = 0; |
530 |
|
|
531 |
|
this->ndf = this->getNDF(); |
532 |
|
this->ndfRaw = this->getNDFraw(); |
533 |
< |
|
533 |
> |
this->ndfTrans = this->getNDFtranslational(); |
534 |
|
} |
535 |
|
|
536 |
+ |
void SimInfo::setDefaultRcut( double theRcut ){ |
537 |
|
|
538 |
< |
void SimInfo::setRcut( double theRcut ){ |
538 |
> |
haveRcut = 1; |
539 |
> |
rCut = theRcut; |
540 |
|
|
541 |
< |
if( !haveOrigRcut ){ |
443 |
< |
haveOrigRcut = 1; |
444 |
< |
origRcut = theRcut; |
445 |
< |
} |
541 |
> |
( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; |
542 |
|
|
543 |
< |
rCut = theRcut; |
448 |
< |
checkCutOffs(); |
543 |
> |
notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); |
544 |
|
} |
545 |
|
|
546 |
< |
void SimInfo::setEcr( double theEcr ){ |
546 |
> |
void SimInfo::setDefaultEcr( double theEcr ){ |
547 |
|
|
548 |
< |
if( !haveOrigEcr ){ |
454 |
< |
haveOrigEcr = 1; |
455 |
< |
origEcr = theEcr; |
456 |
< |
} |
457 |
< |
|
548 |
> |
haveEcr = 1; |
549 |
|
ecr = theEcr; |
550 |
< |
checkCutOffs(); |
550 |
> |
|
551 |
> |
( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; |
552 |
> |
|
553 |
> |
notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); |
554 |
|
} |
555 |
|
|
556 |
< |
void SimInfo::setEcr( double theEcr, double theEst ){ |
556 |
> |
void SimInfo::setDefaultEcr( double theEcr, double theEst ){ |
557 |
|
|
558 |
|
est = theEst; |
559 |
< |
setEcr( theEcr ); |
559 |
> |
setDefaultEcr( theEcr ); |
560 |
|
} |
561 |
|
|
562 |
|
|
563 |
|
void SimInfo::checkCutOffs( void ){ |
564 |
< |
|
471 |
< |
int cutChanged = 0; |
472 |
< |
|
473 |
< |
|
474 |
< |
|
564 |
> |
|
565 |
|
if( boxIsInit ){ |
566 |
|
|
567 |
|
//we need to check cutOffs against the box |
568 |
< |
|
569 |
< |
if(( maxCutoff > rCut )&&(usePBC)){ |
570 |
< |
if( rCut < origRcut ){ |
571 |
< |
rCut = origRcut; |
572 |
< |
if (rCut > maxCutoff) rCut = maxCutoff; |
573 |
< |
|
574 |
< |
sprintf( painCave.errMsg, |
575 |
< |
"New Box size is setting the long range cutoff radius " |
576 |
< |
"to %lf\n", |
577 |
< |
rCut ); |
578 |
< |
painCave.isFatal = 0; |
579 |
< |
simError(); |
580 |
< |
} |
568 |
> |
|
569 |
> |
if( rCut > maxCutoff ){ |
570 |
> |
sprintf( painCave.errMsg, |
571 |
> |
"Box size is too small for the long range cutoff radius, " |
572 |
> |
"%G, at time %G\n" |
573 |
> |
"\t[ %G %G %G ]\n" |
574 |
> |
"\t[ %G %G %G ]\n" |
575 |
> |
"\t[ %G %G %G ]\n", |
576 |
> |
rCut, currentTime, |
577 |
> |
Hmat[0][0], Hmat[0][1], Hmat[0][2], |
578 |
> |
Hmat[1][0], Hmat[1][1], Hmat[1][2], |
579 |
> |
Hmat[2][0], Hmat[2][1], Hmat[2][2]); |
580 |
> |
painCave.isFatal = 1; |
581 |
> |
simError(); |
582 |
|
} |
583 |
< |
|
584 |
< |
if( maxCutoff > ecr ){ |
585 |
< |
if( ecr < origEcr ){ |
495 |
< |
rCut = origEcr; |
496 |
< |
if (ecr > maxCutoff) ecr = maxCutoff; |
497 |
< |
|
583 |
> |
|
584 |
> |
if( haveEcr ){ |
585 |
> |
if( ecr > maxCutoff ){ |
586 |
|
sprintf( painCave.errMsg, |
587 |
< |
"New Box size is setting the electrostaticCutoffRadius " |
588 |
< |
"to %lf\n", |
589 |
< |
ecr ); |
590 |
< |
painCave.isFatal = 0; |
587 |
> |
"Box size is too small for the electrostatic cutoff radius, " |
588 |
> |
"%G, at time %G\n" |
589 |
> |
"\t[ %G %G %G ]\n" |
590 |
> |
"\t[ %G %G %G ]\n" |
591 |
> |
"\t[ %G %G %G ]\n", |
592 |
> |
ecr, currentTime, |
593 |
> |
Hmat[0][0], Hmat[0][1], Hmat[0][2], |
594 |
> |
Hmat[1][0], Hmat[1][1], Hmat[1][2], |
595 |
> |
Hmat[2][0], Hmat[2][1], Hmat[2][2]); |
596 |
> |
painCave.isFatal = 1; |
597 |
|
simError(); |
598 |
|
} |
599 |
|
} |
600 |
< |
|
601 |
< |
|
602 |
< |
if ((rCut > maxCutoff)&&(usePBC)) { |
603 |
< |
sprintf( painCave.errMsg, |
604 |
< |
"New Box size is setting the long range cutoff radius " |
605 |
< |
"to %lf\n", |
606 |
< |
maxCutoff ); |
513 |
< |
painCave.isFatal = 0; |
514 |
< |
simError(); |
515 |
< |
rCut = maxCutoff; |
516 |
< |
} |
517 |
< |
|
518 |
< |
if( ecr > maxCutoff){ |
519 |
< |
sprintf( painCave.errMsg, |
520 |
< |
"New Box size is setting the electrostaticCutoffRadius " |
521 |
< |
"to %lf\n", |
522 |
< |
maxCutoff ); |
523 |
< |
painCave.isFatal = 0; |
524 |
< |
simError(); |
525 |
< |
ecr = maxCutoff; |
526 |
< |
} |
527 |
< |
|
528 |
< |
|
600 |
> |
} else { |
601 |
> |
// initialize this stuff before using it, OK? |
602 |
> |
sprintf( painCave.errMsg, |
603 |
> |
"Trying to check cutoffs without a box.\n" |
604 |
> |
"\tOOPSE should have better programmers than that.\n" ); |
605 |
> |
painCave.isFatal = 1; |
606 |
> |
simError(); |
607 |
|
} |
530 |
– |
|
531 |
– |
|
532 |
– |
if( (oldEcr != ecr) || ( oldRcut != rCut ) ) cutChanged = 1; |
533 |
– |
|
534 |
– |
// rlist is the 1.0 plus max( rcut, ecr ) |
608 |
|
|
536 |
– |
( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; |
537 |
– |
|
538 |
– |
if( cutChanged ){ |
539 |
– |
|
540 |
– |
notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); |
541 |
– |
} |
542 |
– |
|
543 |
– |
oldEcr = ecr; |
544 |
– |
oldRcut = rCut; |
609 |
|
} |
610 |
|
|
611 |
|
void SimInfo::addProperty(GenericData* prop){ |
655 |
|
return result; |
656 |
|
} |
657 |
|
|
658 |
+ |
double SimInfo::matTrace3(double m[3][3]){ |
659 |
+ |
double trace; |
660 |
+ |
trace = m[0][0] + m[1][1] + m[2][2]; |
661 |
|
|
662 |
+ |
return trace; |
663 |
+ |
} |