| 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; |
| 95 |
|
|
| 96 |
|
void SimInfo::setBoxM( double theBox[3][3] ){ |
| 97 |
|
|
| 98 |
< |
int i, j, status; |
| 98 |
< |
double smallestBoxL, maxCutoff; |
| 98 |
> |
int i, j; |
| 99 |
|
double FortranHmat[9]; // to preserve compatibility with Fortran the |
| 100 |
|
// ordering in the array is as follows: |
| 101 |
|
// [ 0 3 6 ] |
| 103 |
|
// [ 2 5 8 ] |
| 104 |
|
double FortranHmatInv[9]; // the inverted Hmat (for Fortran); |
| 105 |
|
|
| 106 |
– |
|
| 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 |
|
|
| 157 |
– |
// Check the inverse to make sure it is sane: |
| 158 |
– |
|
| 159 |
– |
matMul3( Hmat, HmatInv, sanity ); |
| 160 |
– |
|
| 157 |
|
// check to see if Hmat is orthorhombic |
| 158 |
|
|
| 159 |
< |
smallDiag = Hmat[0][0]; |
| 164 |
< |
if(smallDiag > Hmat[1][1]) smallDiag = Hmat[1][1]; |
| 165 |
< |
if(smallDiag > Hmat[2][2]) smallDiag = Hmat[2][2]; |
| 166 |
< |
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]) { |
| 318 |
|
void SimInfo::calcBoxL( void ){ |
| 319 |
|
|
| 320 |
|
double dx, dy, dz, dsq; |
| 305 |
– |
int i; |
| 321 |
|
|
| 322 |
|
// boxVol = Determinant of Hmat |
| 323 |
|
|
| 387 |
|
|
| 388 |
|
void SimInfo::wrapVector( double thePos[3] ){ |
| 389 |
|
|
| 390 |
< |
int i, j, k; |
| 390 |
> |
int i; |
| 391 |
|
double scaled[3]; |
| 392 |
|
|
| 393 |
|
if( !orthoRhombic ){ |
| 425 |
|
|
| 426 |
|
|
| 427 |
|
int SimInfo::getNDF(){ |
| 428 |
< |
int ndf_local, ndf; |
| 428 |
> |
int ndf_local; |
| 429 |
|
|
| 430 |
|
ndf_local = 3 * n_atoms + 3 * n_oriented - n_constraints; |
| 431 |
|
|
| 441 |
|
} |
| 442 |
|
|
| 443 |
|
int SimInfo::getNDFraw() { |
| 444 |
< |
int ndfRaw_local, ndfRaw; |
| 444 |
> |
int ndfRaw_local; |
| 445 |
|
|
| 446 |
|
// Raw degrees of freedom that we have to set |
| 447 |
|
ndfRaw_local = 3 * n_atoms + 3 * n_oriented; |
| 456 |
|
} |
| 457 |
|
|
| 458 |
|
int SimInfo::getNDFtranslational() { |
| 459 |
< |
int ndfTrans_local, ndfTrans; |
| 459 |
> |
int ndfTrans_local; |
| 460 |
|
|
| 461 |
|
ndfTrans_local = 3 * n_atoms - n_constraints; |
| 462 |
|
|
| 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 ){ |
| 521 |
< |
haveOrigRcut = 1; |
| 522 |
< |
origRcut = theRcut; |
| 523 |
< |
} |
| 537 |
> |
( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; |
| 538 |
|
|
| 539 |
< |
rCut = theRcut; |
| 526 |
< |
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 ){ |
| 532 |
< |
haveOrigEcr = 1; |
| 533 |
< |
origEcr = theEcr; |
| 534 |
< |
} |
| 535 |
< |
|
| 544 |
> |
haveEcr = 1; |
| 545 |
|
ecr = theEcr; |
| 546 |
< |
checkCutOffs(); |
| 546 |
> |
|
| 547 |
> |
( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; |
| 548 |
> |
|
| 549 |
> |
notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); |
| 550 |
|
} |
| 551 |
|
|
| 552 |
< |
void SimInfo::setEcr( double theEcr, double theEst ){ |
| 552 |
> |
void SimInfo::setDefaultEcr( double theEcr, double theEst ){ |
| 553 |
|
|
| 554 |
|
est = theEst; |
| 555 |
< |
setEcr( theEcr ); |
| 555 |
> |
setDefaultEcr( theEcr ); |
| 556 |
|
} |
| 557 |
|
|
| 558 |
|
|
| 559 |
|
void SimInfo::checkCutOffs( void ){ |
| 548 |
– |
|
| 549 |
– |
int cutChanged = 0; |
| 560 |
|
|
| 561 |
|
if( boxIsInit ){ |
| 562 |
|
|
| 563 |
|
//we need to check cutOffs against the box |
| 564 |
< |
|
| 565 |
< |
//detect the change of rCut |
| 556 |
< |
if(( maxCutoff > rCut )&&(usePBC)){ |
| 557 |
< |
if( rCut < origRcut ){ |
| 558 |
< |
rCut = origRcut; |
| 559 |
< |
|
| 560 |
< |
if (rCut > maxCutoff) |
| 561 |
< |
rCut = maxCutoff; |
| 562 |
< |
|
| 563 |
< |
sprintf( painCave.errMsg, |
| 564 |
< |
"New Box size is setting the long range cutoff radius " |
| 565 |
< |
"to %lf at time %lf\n", |
| 566 |
< |
rCut, currentTime ); |
| 567 |
< |
painCave.isFatal = 0; |
| 568 |
< |
simError(); |
| 569 |
< |
} |
| 570 |
< |
} |
| 571 |
< |
else if ((rCut > maxCutoff)&&(usePBC)) { |
| 564 |
> |
|
| 565 |
> |
if( rCut > maxCutoff ){ |
| 566 |
|
sprintf( painCave.errMsg, |
| 567 |
< |
"New Box size is setting the long range cutoff radius " |
| 568 |
< |
"to %lf at time %lf\n", |
| 569 |
< |
maxCutoff, currentTime ); |
| 570 |
< |
painCave.isFatal = 0; |
| 567 |
> |
"Box size is too small for the long range cutoff radius, " |
| 568 |
> |
"%lf, at time %lf\n", |
| 569 |
> |
rCut, currentTime ); |
| 570 |
> |
painCave.isFatal = 1; |
| 571 |
|
simError(); |
| 578 |
– |
rCut = maxCutoff; |
| 572 |
|
} |
| 573 |
< |
|
| 574 |
< |
|
| 575 |
< |
//detect the change of ecr |
| 576 |
< |
if( maxCutoff > ecr ){ |
| 577 |
< |
if( ecr < origEcr ){ |
| 578 |
< |
ecr = origEcr; |
| 579 |
< |
if (ecr > maxCutoff) ecr = maxCutoff; |
| 580 |
< |
|
| 581 |
< |
sprintf( painCave.errMsg, |
| 589 |
< |
"New Box size is setting the electrostaticCutoffRadius " |
| 590 |
< |
"to %lf at time %lf\n", |
| 591 |
< |
ecr, currentTime ); |
| 592 |
< |
painCave.isFatal = 0; |
| 593 |
< |
simError(); |
| 573 |
> |
|
| 574 |
> |
if( haveEcr ){ |
| 575 |
> |
if( ecr > maxCutoff ){ |
| 576 |
> |
sprintf( painCave.errMsg, |
| 577 |
> |
"Box size is too small for the electrostatic cutoff radius, " |
| 578 |
> |
"%lf, at time %lf\n", |
| 579 |
> |
ecr, currentTime ); |
| 580 |
> |
painCave.isFatal = 1; |
| 581 |
> |
simError(); |
| 582 |
|
} |
| 583 |
|
} |
| 596 |
– |
else if( ecr > maxCutoff){ |
| 597 |
– |
sprintf( painCave.errMsg, |
| 598 |
– |
"New Box size is setting the electrostaticCutoffRadius " |
| 599 |
– |
"to %lf at time %lf\n", |
| 600 |
– |
maxCutoff, currentTime ); |
| 601 |
– |
painCave.isFatal = 0; |
| 602 |
– |
simError(); |
| 603 |
– |
ecr = maxCutoff; |
| 604 |
– |
} |
| 605 |
– |
|
| 606 |
– |
if( (oldEcr != ecr) || ( oldRcut != rCut ) ) cutChanged = 1; |
| 607 |
– |
|
| 608 |
– |
// rlist is the 1.0 plus max( rcut, ecr ) |
| 609 |
– |
|
| 610 |
– |
( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; |
| 611 |
– |
|
| 612 |
– |
if( cutChanged ){ |
| 613 |
– |
|
| 614 |
– |
notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); |
| 615 |
– |
} |
| 616 |
– |
|
| 617 |
– |
oldEcr = ecr; |
| 618 |
– |
oldRcut = rCut; |
| 619 |
– |
|
| 584 |
|
} else { |
| 585 |
|
// initialize this stuff before using it, OK? |
| 586 |
|
sprintf( painCave.errMsg, |