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; |
42 |
|
rCut = 0.0; |
43 |
|
ecr = 0.0; |
44 |
|
est = 0.0; |
41 |
– |
oldEcr = 0.0; |
42 |
– |
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 |
+ |
has_minimizer = false; |
67 |
+ |
the_minimizer =NULL; |
68 |
+ |
|
69 |
|
wrapMeSimInfo( this ); |
70 |
|
} |
71 |
|
|
99 |
|
|
100 |
|
void SimInfo::setBoxM( double theBox[3][3] ){ |
101 |
|
|
102 |
< |
int i, j, status; |
94 |
< |
double smallestBoxL, maxCutoff; |
102 |
> |
int i, j; |
103 |
|
double FortranHmat[9]; // to preserve compatibility with Fortran the |
104 |
|
// ordering in the array is as follows: |
105 |
|
// [ 0 3 6 ] |
107 |
|
// [ 2 5 8 ] |
108 |
|
double FortranHmatInv[9]; // the inverted Hmat (for Fortran); |
109 |
|
|
102 |
– |
|
110 |
|
if( !boxIsInit ) boxIsInit = 1; |
111 |
|
|
112 |
|
for(i=0; i < 3; i++) |
150 |
|
|
151 |
|
void SimInfo::calcHmatInv( void ) { |
152 |
|
|
153 |
+ |
int oldOrtho; |
154 |
|
int i,j; |
155 |
|
double smallDiag; |
156 |
|
double tol; |
158 |
|
|
159 |
|
invertMat3( Hmat, HmatInv ); |
160 |
|
|
153 |
– |
// Check the inverse to make sure it is sane: |
154 |
– |
|
155 |
– |
matMul3( Hmat, HmatInv, sanity ); |
156 |
– |
|
161 |
|
// check to see if Hmat is orthorhombic |
162 |
|
|
163 |
< |
smallDiag = Hmat[0][0]; |
160 |
< |
if(smallDiag > Hmat[1][1]) smallDiag = Hmat[1][1]; |
161 |
< |
if(smallDiag > Hmat[2][2]) smallDiag = Hmat[2][2]; |
162 |
< |
tol = smallDiag * 1E-6; |
163 |
> |
oldOrtho = orthoRhombic; |
164 |
|
|
165 |
+ |
smallDiag = fabs(Hmat[0][0]); |
166 |
+ |
if(smallDiag > fabs(Hmat[1][1])) smallDiag = fabs(Hmat[1][1]); |
167 |
+ |
if(smallDiag > fabs(Hmat[2][2])) smallDiag = fabs(Hmat[2][2]); |
168 |
+ |
tol = smallDiag * orthoTolerance; |
169 |
+ |
|
170 |
|
orthoRhombic = 1; |
171 |
|
|
172 |
|
for (i = 0; i < 3; i++ ) { |
173 |
|
for (j = 0 ; j < 3; j++) { |
174 |
|
if (i != j) { |
175 |
|
if (orthoRhombic) { |
176 |
< |
if (Hmat[i][j] >= tol) orthoRhombic = 0; |
176 |
> |
if ( fabs(Hmat[i][j]) >= tol) orthoRhombic = 0; |
177 |
|
} |
178 |
|
} |
179 |
|
} |
180 |
|
} |
181 |
+ |
|
182 |
+ |
if( oldOrtho != orthoRhombic ){ |
183 |
+ |
|
184 |
+ |
if( orthoRhombic ){ |
185 |
+ |
sprintf( painCave.errMsg, |
186 |
+ |
"Hmat is switching from Non-Orthorhombic to Orthorhombic Box.\n" |
187 |
+ |
"\tIf this is a bad thing, change the orthoBoxTolerance\n" |
188 |
+ |
"\tvariable ( currently set to %G ).\n", |
189 |
+ |
orthoTolerance); |
190 |
+ |
simError(); |
191 |
+ |
} |
192 |
+ |
else { |
193 |
+ |
sprintf( painCave.errMsg, |
194 |
+ |
"Hmat is switching from Orthorhombic to Non-Orthorhombic Box.\n" |
195 |
+ |
"\tIf this is a bad thing, change the orthoBoxTolerance\n" |
196 |
+ |
"\tvariable ( currently set to %G ).\n", |
197 |
+ |
orthoTolerance); |
198 |
+ |
simError(); |
199 |
+ |
} |
200 |
+ |
} |
201 |
|
} |
202 |
|
|
203 |
|
double SimInfo::matDet3(double a[3][3]) { |
304 |
|
<< "[ " << A[6] << ", " << A[7] << ", " << A[8] << " ]\n"; |
305 |
|
} |
306 |
|
|
307 |
+ |
|
308 |
+ |
void SimInfo::crossProduct3(double a[3],double b[3], double out[3]){ |
309 |
+ |
|
310 |
+ |
out[0] = a[1] * b[2] - a[2] * b[1]; |
311 |
+ |
out[1] = a[2] * b[0] - a[0] * b[2] ; |
312 |
+ |
out[2] = a[0] * b[1] - a[1] * b[0]; |
313 |
+ |
|
314 |
+ |
} |
315 |
+ |
|
316 |
+ |
double SimInfo::dotProduct3(double a[3], double b[3]){ |
317 |
+ |
return a[0]*b[0] + a[1]*b[1]+ a[2]*b[2]; |
318 |
+ |
} |
319 |
+ |
|
320 |
+ |
double SimInfo::length3(double a[3]){ |
321 |
+ |
return sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]); |
322 |
+ |
} |
323 |
+ |
|
324 |
|
void SimInfo::calcBoxL( void ){ |
325 |
|
|
326 |
|
double dx, dy, dz, dsq; |
284 |
– |
int i; |
327 |
|
|
328 |
|
// boxVol = Determinant of Hmat |
329 |
|
|
334 |
|
dx = Hmat[0][0]; dy = Hmat[1][0]; dz = Hmat[2][0]; |
335 |
|
dsq = dx*dx + dy*dy + dz*dz; |
336 |
|
boxL[0] = sqrt( dsq ); |
337 |
< |
maxCutoff = 0.5 * boxL[0]; |
337 |
> |
//maxCutoff = 0.5 * boxL[0]; |
338 |
|
|
339 |
|
// boxLy |
340 |
|
|
341 |
|
dx = Hmat[0][1]; dy = Hmat[1][1]; dz = Hmat[2][1]; |
342 |
|
dsq = dx*dx + dy*dy + dz*dz; |
343 |
|
boxL[1] = sqrt( dsq ); |
344 |
< |
if( (0.5 * boxL[1]) < maxCutoff ) maxCutoff = 0.5 * boxL[1]; |
344 |
> |
//if( (0.5 * boxL[1]) < maxCutoff ) maxCutoff = 0.5 * boxL[1]; |
345 |
|
|
346 |
+ |
|
347 |
|
// boxLz |
348 |
|
|
349 |
|
dx = Hmat[0][2]; dy = Hmat[1][2]; dz = Hmat[2][2]; |
350 |
|
dsq = dx*dx + dy*dy + dz*dz; |
351 |
|
boxL[2] = sqrt( dsq ); |
352 |
< |
if( (0.5 * boxL[2]) < maxCutoff ) maxCutoff = 0.5 * boxL[2]; |
352 |
> |
//if( (0.5 * boxL[2]) < maxCutoff ) maxCutoff = 0.5 * boxL[2]; |
353 |
> |
|
354 |
> |
//calculate the max cutoff |
355 |
> |
maxCutoff = calcMaxCutOff(); |
356 |
|
|
357 |
|
checkCutOffs(); |
358 |
|
|
359 |
|
} |
360 |
|
|
361 |
|
|
362 |
+ |
double SimInfo::calcMaxCutOff(){ |
363 |
+ |
|
364 |
+ |
double ri[3], rj[3], rk[3]; |
365 |
+ |
double rij[3], rjk[3], rki[3]; |
366 |
+ |
double minDist; |
367 |
+ |
|
368 |
+ |
ri[0] = Hmat[0][0]; |
369 |
+ |
ri[1] = Hmat[1][0]; |
370 |
+ |
ri[2] = Hmat[2][0]; |
371 |
+ |
|
372 |
+ |
rj[0] = Hmat[0][1]; |
373 |
+ |
rj[1] = Hmat[1][1]; |
374 |
+ |
rj[2] = Hmat[2][1]; |
375 |
+ |
|
376 |
+ |
rk[0] = Hmat[0][2]; |
377 |
+ |
rk[1] = Hmat[1][2]; |
378 |
+ |
rk[2] = Hmat[2][2]; |
379 |
+ |
|
380 |
+ |
crossProduct3(ri,rj, rij); |
381 |
+ |
distXY = dotProduct3(rk,rij) / length3(rij); |
382 |
+ |
|
383 |
+ |
crossProduct3(rj,rk, rjk); |
384 |
+ |
distYZ = dotProduct3(ri,rjk) / length3(rjk); |
385 |
+ |
|
386 |
+ |
crossProduct3(rk,ri, rki); |
387 |
+ |
distZX = dotProduct3(rj,rki) / length3(rki); |
388 |
+ |
|
389 |
+ |
minDist = min(min(distXY, distYZ), distZX); |
390 |
+ |
return minDist/2; |
391 |
+ |
|
392 |
+ |
} |
393 |
+ |
|
394 |
|
void SimInfo::wrapVector( double thePos[3] ){ |
395 |
|
|
396 |
< |
int i, j, k; |
396 |
> |
int i; |
397 |
|
double scaled[3]; |
398 |
|
|
399 |
|
if( !orthoRhombic ){ |
431 |
|
|
432 |
|
|
433 |
|
int SimInfo::getNDF(){ |
434 |
< |
int ndf_local, ndf; |
434 |
> |
int ndf_local; |
435 |
|
|
436 |
|
ndf_local = 3 * n_atoms + 3 * n_oriented - n_constraints; |
437 |
|
|
447 |
|
} |
448 |
|
|
449 |
|
int SimInfo::getNDFraw() { |
450 |
< |
int ndfRaw_local, ndfRaw; |
450 |
> |
int ndfRaw_local; |
451 |
|
|
452 |
|
// Raw degrees of freedom that we have to set |
453 |
|
ndfRaw_local = 3 * n_atoms + 3 * n_oriented; |
460 |
|
|
461 |
|
return ndfRaw; |
462 |
|
} |
463 |
< |
|
463 |
> |
|
464 |
> |
int SimInfo::getNDFtranslational() { |
465 |
> |
int ndfTrans_local; |
466 |
> |
|
467 |
> |
ndfTrans_local = 3 * n_atoms - n_constraints; |
468 |
> |
|
469 |
> |
#ifdef IS_MPI |
470 |
> |
MPI_Allreduce(&ndfTrans_local,&ndfTrans,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
471 |
> |
#else |
472 |
> |
ndfTrans = ndfTrans_local; |
473 |
> |
#endif |
474 |
> |
|
475 |
> |
ndfTrans = ndfTrans - 3 - nZconstraints; |
476 |
> |
|
477 |
> |
return ndfTrans; |
478 |
> |
} |
479 |
> |
|
480 |
|
void SimInfo::refreshSim(){ |
481 |
|
|
482 |
|
simtype fInfo; |
486 |
|
|
487 |
|
fInfo.dielect = 0.0; |
488 |
|
|
489 |
< |
if( useDipole ){ |
489 |
> |
if( useDipoles ){ |
490 |
|
if( useReactionField )fInfo.dielect = dielectric; |
491 |
|
} |
492 |
|
|
495 |
|
fInfo.SIM_uses_LJ = useLJ; |
496 |
|
fInfo.SIM_uses_sticky = useSticky; |
497 |
|
//fInfo.SIM_uses_sticky = 0; |
498 |
< |
fInfo.SIM_uses_dipoles = useDipole; |
498 |
> |
fInfo.SIM_uses_charges = useCharges; |
499 |
> |
fInfo.SIM_uses_dipoles = useDipoles; |
500 |
|
//fInfo.SIM_uses_dipoles = 0; |
501 |
< |
//fInfo.SIM_uses_RF = useReactionField; |
502 |
< |
fInfo.SIM_uses_RF = 0; |
501 |
> |
fInfo.SIM_uses_RF = useReactionField; |
502 |
> |
//fInfo.SIM_uses_RF = 0; |
503 |
|
fInfo.SIM_uses_GB = useGB; |
504 |
|
fInfo.SIM_uses_EAM = useEAM; |
505 |
|
|
533 |
|
|
534 |
|
this->ndf = this->getNDF(); |
535 |
|
this->ndfRaw = this->getNDFraw(); |
536 |
< |
|
536 |
> |
this->ndfTrans = this->getNDFtranslational(); |
537 |
|
} |
538 |
|
|
539 |
+ |
void SimInfo::setDefaultRcut( double theRcut ){ |
540 |
|
|
541 |
< |
void SimInfo::setRcut( double theRcut ){ |
541 |
> |
haveRcut = 1; |
542 |
> |
rCut = theRcut; |
543 |
|
|
544 |
< |
if( !haveOrigRcut ){ |
448 |
< |
haveOrigRcut = 1; |
449 |
< |
origRcut = theRcut; |
450 |
< |
} |
544 |
> |
( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; |
545 |
|
|
546 |
< |
rCut = theRcut; |
453 |
< |
checkCutOffs(); |
546 |
> |
notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); |
547 |
|
} |
548 |
|
|
549 |
< |
void SimInfo::setEcr( double theEcr ){ |
549 |
> |
void SimInfo::setDefaultEcr( double theEcr ){ |
550 |
|
|
551 |
< |
if( !haveOrigEcr ){ |
459 |
< |
haveOrigEcr = 1; |
460 |
< |
origEcr = theEcr; |
461 |
< |
} |
462 |
< |
|
551 |
> |
haveEcr = 1; |
552 |
|
ecr = theEcr; |
553 |
< |
checkCutOffs(); |
553 |
> |
|
554 |
> |
( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; |
555 |
> |
|
556 |
> |
notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); |
557 |
|
} |
558 |
|
|
559 |
< |
void SimInfo::setEcr( double theEcr, double theEst ){ |
559 |
> |
void SimInfo::setDefaultEcr( double theEcr, double theEst ){ |
560 |
|
|
561 |
|
est = theEst; |
562 |
< |
setEcr( theEcr ); |
562 |
> |
setDefaultEcr( theEcr ); |
563 |
|
} |
564 |
|
|
565 |
|
|
566 |
|
void SimInfo::checkCutOffs( void ){ |
567 |
< |
|
476 |
< |
int cutChanged = 0; |
477 |
< |
|
478 |
< |
|
479 |
< |
|
567 |
> |
|
568 |
|
if( boxIsInit ){ |
569 |
|
|
570 |
|
//we need to check cutOffs against the box |
571 |
< |
|
572 |
< |
if(( maxCutoff > rCut )&&(usePBC)){ |
573 |
< |
if( rCut < origRcut ){ |
574 |
< |
rCut = origRcut; |
575 |
< |
if (rCut > maxCutoff) rCut = maxCutoff; |
576 |
< |
|
577 |
< |
sprintf( painCave.errMsg, |
578 |
< |
"New Box size is setting the long range cutoff radius " |
579 |
< |
"to %lf\n", |
580 |
< |
rCut ); |
581 |
< |
painCave.isFatal = 0; |
582 |
< |
simError(); |
583 |
< |
} |
571 |
> |
|
572 |
> |
if( rCut > maxCutoff ){ |
573 |
> |
sprintf( painCave.errMsg, |
574 |
> |
"Box size is too small for the long range cutoff radius, " |
575 |
> |
"%G, at time %G\n" |
576 |
> |
"\t[ %G %G %G ]\n" |
577 |
> |
"\t[ %G %G %G ]\n" |
578 |
> |
"\t[ %G %G %G ]\n", |
579 |
> |
rCut, currentTime, |
580 |
> |
Hmat[0][0], Hmat[0][1], Hmat[0][2], |
581 |
> |
Hmat[1][0], Hmat[1][1], Hmat[1][2], |
582 |
> |
Hmat[2][0], Hmat[2][1], Hmat[2][2]); |
583 |
> |
painCave.isFatal = 1; |
584 |
> |
simError(); |
585 |
|
} |
586 |
< |
|
587 |
< |
if( maxCutoff > ecr ){ |
588 |
< |
if( ecr < origEcr ){ |
500 |
< |
rCut = origEcr; |
501 |
< |
if (ecr > maxCutoff) ecr = maxCutoff; |
502 |
< |
|
586 |
> |
|
587 |
> |
if( haveEcr ){ |
588 |
> |
if( ecr > maxCutoff ){ |
589 |
|
sprintf( painCave.errMsg, |
590 |
< |
"New Box size is setting the electrostaticCutoffRadius " |
591 |
< |
"to %lf\n", |
592 |
< |
ecr ); |
593 |
< |
painCave.isFatal = 0; |
590 |
> |
"Box size is too small for the electrostatic cutoff radius, " |
591 |
> |
"%G, at time %G\n" |
592 |
> |
"\t[ %G %G %G ]\n" |
593 |
> |
"\t[ %G %G %G ]\n" |
594 |
> |
"\t[ %G %G %G ]\n", |
595 |
> |
ecr, currentTime, |
596 |
> |
Hmat[0][0], Hmat[0][1], Hmat[0][2], |
597 |
> |
Hmat[1][0], Hmat[1][1], Hmat[1][2], |
598 |
> |
Hmat[2][0], Hmat[2][1], Hmat[2][2]); |
599 |
> |
painCave.isFatal = 1; |
600 |
|
simError(); |
601 |
|
} |
602 |
|
} |
603 |
< |
|
604 |
< |
|
605 |
< |
if ((rCut > maxCutoff)&&(usePBC)) { |
606 |
< |
sprintf( painCave.errMsg, |
607 |
< |
"New Box size is setting the long range cutoff radius " |
608 |
< |
"to %lf\n", |
609 |
< |
maxCutoff ); |
518 |
< |
painCave.isFatal = 0; |
519 |
< |
simError(); |
520 |
< |
rCut = maxCutoff; |
521 |
< |
} |
522 |
< |
|
523 |
< |
if( ecr > maxCutoff){ |
524 |
< |
sprintf( painCave.errMsg, |
525 |
< |
"New Box size is setting the electrostaticCutoffRadius " |
526 |
< |
"to %lf\n", |
527 |
< |
maxCutoff ); |
528 |
< |
painCave.isFatal = 0; |
529 |
< |
simError(); |
530 |
< |
ecr = maxCutoff; |
531 |
< |
} |
532 |
< |
|
533 |
< |
|
603 |
> |
} else { |
604 |
> |
// initialize this stuff before using it, OK? |
605 |
> |
sprintf( painCave.errMsg, |
606 |
> |
"Trying to check cutoffs without a box.\n" |
607 |
> |
"\tOOPSE should have better programmers than that.\n" ); |
608 |
> |
painCave.isFatal = 1; |
609 |
> |
simError(); |
610 |
|
} |
535 |
– |
|
536 |
– |
|
537 |
– |
if( (oldEcr != ecr) || ( oldRcut != rCut ) ) cutChanged = 1; |
538 |
– |
|
539 |
– |
// rlist is the 1.0 plus max( rcut, ecr ) |
611 |
|
|
541 |
– |
( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; |
542 |
– |
|
543 |
– |
if( cutChanged ){ |
544 |
– |
|
545 |
– |
notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); |
546 |
– |
} |
547 |
– |
|
548 |
– |
oldEcr = ecr; |
549 |
– |
oldRcut = rCut; |
612 |
|
} |
613 |
|
|
614 |
|
void SimInfo::addProperty(GenericData* prop){ |
658 |
|
return result; |
659 |
|
} |
660 |
|
|
661 |
+ |
double SimInfo::matTrace3(double m[3][3]){ |
662 |
+ |
double trace; |
663 |
+ |
trace = m[0][0] + m[1][1] + m[2][2]; |
664 |
|
|
665 |
+ |
return trace; |
666 |
+ |
} |