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 |
|
|
40 |
|
thermalTime = 0.0; |
41 |
|
currentTime = 0.0; |
42 |
|
rCut = 0.0; |
40 |
– |
origRcut = -1.0; |
43 |
|
ecr = 0.0; |
42 |
– |
origEcr = -1.0; |
44 |
|
est = 0.0; |
44 |
– |
oldEcr = 0.0; |
45 |
– |
oldRcut = 0.0; |
45 |
|
|
46 |
< |
haveOrigRcut = 0; |
47 |
< |
haveOrigEcr = 0; |
46 |
> |
haveRcut = 0; |
47 |
> |
haveEcr = 0; |
48 |
|
boxIsInit = 0; |
49 |
|
|
50 |
|
resetTime = 1e99; |
52 |
– |
|
51 |
|
|
52 |
+ |
orthoTolerance = 1E-6; |
53 |
+ |
useInitXSstate = true; |
54 |
+ |
|
55 |
|
usePBC = 0; |
56 |
|
useLJ = 0; |
57 |
|
useSticky = 0; |
103 |
|
// [ 2 5 8 ] |
104 |
|
double FortranHmatInv[9]; // the inverted Hmat (for Fortran); |
105 |
|
|
105 |
– |
|
106 |
|
if( !boxIsInit ) boxIsInit = 1; |
107 |
|
|
108 |
|
for(i=0; i < 3; i++) |
146 |
|
|
147 |
|
void SimInfo::calcHmatInv( void ) { |
148 |
|
|
149 |
+ |
int oldOrtho; |
150 |
|
int i,j; |
151 |
|
double smallDiag; |
152 |
|
double tol; |
154 |
|
|
155 |
|
invertMat3( Hmat, HmatInv ); |
156 |
|
|
156 |
– |
// Check the inverse to make sure it is sane: |
157 |
– |
|
158 |
– |
matMul3( Hmat, HmatInv, sanity ); |
159 |
– |
|
157 |
|
// check to see if Hmat is orthorhombic |
158 |
|
|
159 |
< |
smallDiag = Hmat[0][0]; |
163 |
< |
if(smallDiag > Hmat[1][1]) smallDiag = Hmat[1][1]; |
164 |
< |
if(smallDiag > Hmat[2][2]) smallDiag = Hmat[2][2]; |
165 |
< |
tol = smallDiag * 1E-6; |
159 |
> |
oldOrtho = orthoRhombic; |
160 |
|
|
161 |
+ |
smallDiag = fabs(Hmat[0][0]); |
162 |
+ |
if(smallDiag > fabs(Hmat[1][1])) smallDiag = fabs(Hmat[1][1]); |
163 |
+ |
if(smallDiag > fabs(Hmat[2][2])) smallDiag = fabs(Hmat[2][2]); |
164 |
+ |
tol = smallDiag * orthoTolerance; |
165 |
+ |
|
166 |
|
orthoRhombic = 1; |
167 |
|
|
168 |
|
for (i = 0; i < 3; i++ ) { |
169 |
|
for (j = 0 ; j < 3; j++) { |
170 |
|
if (i != j) { |
171 |
|
if (orthoRhombic) { |
172 |
< |
if (Hmat[i][j] >= tol) orthoRhombic = 0; |
172 |
> |
if ( fabs(Hmat[i][j]) >= tol) orthoRhombic = 0; |
173 |
|
} |
174 |
|
} |
175 |
|
} |
176 |
|
} |
177 |
+ |
|
178 |
+ |
if( oldOrtho != orthoRhombic ){ |
179 |
+ |
|
180 |
+ |
if( orthoRhombic ){ |
181 |
+ |
sprintf( painCave.errMsg, |
182 |
+ |
"Hmat is switching from Non-Orthorhombic to OrthoRhombic\n" |
183 |
+ |
" If this is a bad thing, change the orthoBoxTolerance( currently %G ).\n", |
184 |
+ |
orthoTolerance); |
185 |
+ |
simError(); |
186 |
+ |
} |
187 |
+ |
else { |
188 |
+ |
sprintf( painCave.errMsg, |
189 |
+ |
"Hmat is switching from Orthorhombic to Non-OrthoRhombic\n" |
190 |
+ |
" If this is a bad thing, change the orthoBoxTolerance( currently %G ).\n", |
191 |
+ |
orthoTolerance); |
192 |
+ |
simError(); |
193 |
+ |
} |
194 |
+ |
} |
195 |
|
} |
196 |
|
|
197 |
|
double SimInfo::matDet3(double a[3][3]) { |
529 |
|
this->ndfTrans = this->getNDFtranslational(); |
530 |
|
} |
531 |
|
|
532 |
+ |
void SimInfo::setDefaultRcut( double theRcut ){ |
533 |
|
|
534 |
< |
void SimInfo::setRcut( double theRcut ){ |
534 |
> |
haveRcut = 1; |
535 |
> |
rCut = theRcut; |
536 |
|
|
537 |
< |
if( !haveOrigRcut ){ |
519 |
< |
haveOrigRcut = 1; |
520 |
< |
origRcut = theRcut; |
521 |
< |
} |
537 |
> |
( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; |
538 |
|
|
539 |
< |
rCut = theRcut; |
524 |
< |
checkCutOffs(); |
539 |
> |
notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); |
540 |
|
} |
541 |
|
|
542 |
< |
void SimInfo::setEcr( double theEcr ){ |
542 |
> |
void SimInfo::setDefaultEcr( double theEcr ){ |
543 |
|
|
544 |
< |
if( !haveOrigEcr ){ |
545 |
< |
haveOrigEcr = 1; |
546 |
< |
origEcr = theEcr; |
532 |
< |
} |
544 |
> |
haveEcr = 1; |
545 |
> |
|
546 |
> |
( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; |
547 |
|
|
548 |
|
ecr = theEcr; |
549 |
< |
checkCutOffs(); |
549 |
> |
|
550 |
> |
notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); |
551 |
|
} |
552 |
|
|
553 |
< |
void SimInfo::setEcr( double theEcr, double theEst ){ |
553 |
> |
void SimInfo::setDefaultEcr( double theEcr, double theEst ){ |
554 |
|
|
555 |
|
est = theEst; |
556 |
< |
setEcr( theEcr ); |
556 |
> |
setDefaultEcr( theEcr ); |
557 |
|
} |
558 |
|
|
559 |
|
|
560 |
|
void SimInfo::checkCutOffs( void ){ |
546 |
– |
|
547 |
– |
int cutChanged = 0; |
561 |
|
|
562 |
|
if( boxIsInit ){ |
563 |
|
|
564 |
|
//we need to check cutOffs against the box |
565 |
< |
|
566 |
< |
//detect the change of rCut |
554 |
< |
if(( maxCutoff > rCut )&&(usePBC)){ |
555 |
< |
if( rCut < origRcut ){ |
556 |
< |
rCut = origRcut; |
557 |
< |
|
558 |
< |
if (rCut > maxCutoff) |
559 |
< |
rCut = maxCutoff; |
560 |
< |
|
561 |
< |
sprintf( painCave.errMsg, |
562 |
< |
"New Box size is setting the long range cutoff radius " |
563 |
< |
"to %lf at time %lf\n", |
564 |
< |
rCut, currentTime ); |
565 |
< |
painCave.isFatal = 0; |
566 |
< |
simError(); |
567 |
< |
} |
568 |
< |
} |
569 |
< |
else if ((rCut > maxCutoff)&&(usePBC)) { |
565 |
> |
|
566 |
> |
if( rCut > maxCutoff ){ |
567 |
|
sprintf( painCave.errMsg, |
568 |
< |
"New Box size is setting the long range cutoff radius " |
569 |
< |
"to %lf at time %lf\n", |
570 |
< |
maxCutoff, currentTime ); |
571 |
< |
painCave.isFatal = 0; |
568 |
> |
"Box size is too small for the long range cutoff radius, " |
569 |
> |
"%lf, at time %lf\n", |
570 |
> |
rCut, currentTime ); |
571 |
> |
painCave.isFatal = 1; |
572 |
|
simError(); |
576 |
– |
rCut = maxCutoff; |
573 |
|
} |
574 |
< |
|
575 |
< |
|
576 |
< |
//detect the change of ecr |
577 |
< |
if( maxCutoff > ecr ){ |
578 |
< |
if( ecr < origEcr ){ |
579 |
< |
ecr = origEcr; |
580 |
< |
if (ecr > maxCutoff) ecr = maxCutoff; |
581 |
< |
|
582 |
< |
sprintf( painCave.errMsg, |
587 |
< |
"New Box size is setting the electrostaticCutoffRadius " |
588 |
< |
"to %lf at time %lf\n", |
589 |
< |
ecr, currentTime ); |
590 |
< |
painCave.isFatal = 0; |
591 |
< |
simError(); |
574 |
> |
|
575 |
> |
if( haveEcr ){ |
576 |
> |
if( ecr > maxCutoff ){ |
577 |
> |
sprintf( painCave.errMsg, |
578 |
> |
"Box size is too small for the electrostatic cutoff radius, " |
579 |
> |
"%lf, at time %lf\n", |
580 |
> |
ecr, currentTime ); |
581 |
> |
painCave.isFatal = 1; |
582 |
> |
simError(); |
583 |
|
} |
584 |
|
} |
594 |
– |
else if( ecr > maxCutoff){ |
595 |
– |
sprintf( painCave.errMsg, |
596 |
– |
"New Box size is setting the electrostaticCutoffRadius " |
597 |
– |
"to %lf at time %lf\n", |
598 |
– |
maxCutoff, currentTime ); |
599 |
– |
painCave.isFatal = 0; |
600 |
– |
simError(); |
601 |
– |
ecr = maxCutoff; |
602 |
– |
} |
603 |
– |
|
604 |
– |
if( (oldEcr != ecr) || ( oldRcut != rCut ) ) cutChanged = 1; |
605 |
– |
|
606 |
– |
// rlist is the 1.0 plus max( rcut, ecr ) |
607 |
– |
|
608 |
– |
( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; |
609 |
– |
|
610 |
– |
if( cutChanged ){ |
611 |
– |
|
612 |
– |
notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); |
613 |
– |
} |
614 |
– |
|
615 |
– |
oldEcr = ecr; |
616 |
– |
oldRcut = rCut; |
617 |
– |
|
585 |
|
} else { |
586 |
|
// initialize this stuff before using it, OK? |
587 |
|
sprintf( painCave.errMsg, |