--- trunk/OOPSE/libmdtools/SimInfo.cpp 2003/09/22 23:07:57 781 +++ trunk/OOPSE/libmdtools/SimInfo.cpp 2003/11/21 20:10:02 874 @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include #include using namespace std; @@ -20,6 +20,9 @@ inline double roundMe( double x ){ return ( x >= 0 ) ? floor( x + 0.5 ) : ceil( x - 0.5 ); } +inline double min( double a, double b ){ + return (a < b ) ? a : b; +} SimInfo* currentInfo; @@ -37,20 +40,18 @@ SimInfo::SimInfo(){ thermalTime = 0.0; currentTime = 0.0; rCut = 0.0; - origRcut = -1.0; ecr = 0.0; - origEcr = -1.0; est = 0.0; - oldEcr = 0.0; - oldRcut = 0.0; - haveOrigRcut = 0; - haveOrigEcr = 0; + haveRcut = 0; + haveEcr = 0; boxIsInit = 0; resetTime = 1e99; - + orthoTolerance = 1E-6; + useInitXSstate = true; + usePBC = 0; useLJ = 0; useSticky = 0; @@ -94,8 +95,7 @@ void SimInfo::setBoxM( double theBox[3][3] ){ void SimInfo::setBoxM( double theBox[3][3] ){ - int i, j, status; - double smallestBoxL, maxCutoff; + int i, j; double FortranHmat[9]; // to preserve compatibility with Fortran the // ordering in the array is as follows: // [ 0 3 6 ] @@ -103,7 +103,6 @@ void SimInfo::setBoxM( double theBox[3][3] ){ // [ 2 5 8 ] double FortranHmatInv[9]; // the inverted Hmat (for Fortran); - if( !boxIsInit ) boxIsInit = 1; for(i=0; i < 3; i++) @@ -147,6 +146,7 @@ void SimInfo::calcHmatInv( void ) { void SimInfo::calcHmatInv( void ) { + int oldOrtho; int i,j; double smallDiag; double tol; @@ -154,28 +154,44 @@ void SimInfo::calcHmatInv( void ) { invertMat3( Hmat, HmatInv ); - // Check the inverse to make sure it is sane: - - matMul3( Hmat, HmatInv, sanity ); - // check to see if Hmat is orthorhombic - smallDiag = Hmat[0][0]; - if(smallDiag > Hmat[1][1]) smallDiag = Hmat[1][1]; - if(smallDiag > Hmat[2][2]) smallDiag = Hmat[2][2]; - tol = smallDiag * 1E-6; + oldOrtho = orthoRhombic; + smallDiag = fabs(Hmat[0][0]); + if(smallDiag > fabs(Hmat[1][1])) smallDiag = fabs(Hmat[1][1]); + if(smallDiag > fabs(Hmat[2][2])) smallDiag = fabs(Hmat[2][2]); + tol = smallDiag * orthoTolerance; + orthoRhombic = 1; for (i = 0; i < 3; i++ ) { for (j = 0 ; j < 3; j++) { if (i != j) { if (orthoRhombic) { - if (Hmat[i][j] >= tol) orthoRhombic = 0; + if ( fabs(Hmat[i][j]) >= tol) orthoRhombic = 0; } } } } + + if( oldOrtho != orthoRhombic ){ + + if( orthoRhombic ){ + sprintf( painCave.errMsg, + "Hmat is switching from Non-Orthorhombic to OrthoRhombic\n" + " If this is a bad thing, change the orthoBoxTolerance( currently %G ).\n", + orthoTolerance); + simError(); + } + else { + sprintf( painCave.errMsg, + "Hmat is switching from Orthorhombic to Non-OrthoRhombic\n" + " If this is a bad thing, change the orthoBoxTolerance( currently %G ).\n", + orthoTolerance); + simError(); + } + } } double SimInfo::matDet3(double a[3][3]) { @@ -302,7 +318,6 @@ void SimInfo::calcBoxL( void ){ void SimInfo::calcBoxL( void ){ double dx, dy, dz, dsq; - int i; // boxVol = Determinant of Hmat @@ -372,7 +387,7 @@ void SimInfo::wrapVector( double thePos[3] ){ void SimInfo::wrapVector( double thePos[3] ){ - int i, j, k; + int i; double scaled[3]; if( !orthoRhombic ){ @@ -410,7 +425,7 @@ int SimInfo::getNDF(){ int SimInfo::getNDF(){ - int ndf_local, ndf; + int ndf_local; ndf_local = 3 * n_atoms + 3 * n_oriented - n_constraints; @@ -426,7 +441,7 @@ int SimInfo::getNDFraw() { } int SimInfo::getNDFraw() { - int ndfRaw_local, ndfRaw; + int ndfRaw_local; // Raw degrees of freedom that we have to set ndfRaw_local = 3 * n_atoms + 3 * n_oriented; @@ -441,7 +456,7 @@ int SimInfo::getNDFtranslational() { } int SimInfo::getNDFtranslational() { - int ndfTrans_local, ndfTrans; + int ndfTrans_local; ndfTrans_local = 3 * n_atoms - n_constraints; @@ -514,109 +529,70 @@ void SimInfo::refreshSim(){ this->ndfTrans = this->getNDFtranslational(); } +void SimInfo::setDefaultRcut( double theRcut ){ -void SimInfo::setRcut( double theRcut ){ + haveRcut = 1; + rCut = theRcut; - if( !haveOrigRcut ){ - haveOrigRcut = 1; - origRcut = theRcut; - } + ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; - rCut = theRcut; - checkCutOffs(); + notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); } -void SimInfo::setEcr( double theEcr ){ +void SimInfo::setDefaultEcr( double theEcr ){ - if( !haveOrigEcr ){ - haveOrigEcr = 1; - origEcr = theEcr; - } - + haveEcr = 1; ecr = theEcr; - checkCutOffs(); + + ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; + + notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); } -void SimInfo::setEcr( double theEcr, double theEst ){ +void SimInfo::setDefaultEcr( double theEcr, double theEst ){ est = theEst; - setEcr( theEcr ); + setDefaultEcr( theEcr ); } void SimInfo::checkCutOffs( void ){ - - int cutChanged = 0; if( boxIsInit ){ //we need to check cutOffs against the box - - //detect the change of rCut - if(( maxCutoff > rCut )&&(usePBC)){ - if( rCut < origRcut ){ - rCut = origRcut; - - if (rCut > maxCutoff) - rCut = maxCutoff; - - sprintf( painCave.errMsg, - "New Box size is setting the long range cutoff radius " - "to %lf at time %lf\n", - rCut, currentTime ); - painCave.isFatal = 0; - simError(); - } - } - else if ((rCut > maxCutoff)&&(usePBC)) { + + if( rCut > maxCutoff ){ sprintf( painCave.errMsg, - "New Box size is setting the long range cutoff radius " - "to %lf at time %lf\n", - maxCutoff, currentTime ); - painCave.isFatal = 0; + "Box size is too small for the long range cutoff radius, " + "%G, at time %G\n" + " [ %G %G %G ]\n" + " [ %G %G %G ]\n" + " [ %G %G %G ]\n", + rCut, currentTime, + Hmat[0][0], Hmat[0][1], Hmat[0][2], + Hmat[1][0], Hmat[1][1], Hmat[1][2], + Hmat[2][0], Hmat[2][1], Hmat[2][2]); + painCave.isFatal = 1; simError(); - rCut = maxCutoff; } - - - //detect the change of ecr - if( maxCutoff > ecr ){ - if( ecr < origEcr ){ - ecr = origEcr; - if (ecr > maxCutoff) ecr = maxCutoff; - - sprintf( painCave.errMsg, - "New Box size is setting the electrostaticCutoffRadius " - "to %lf at time %lf\n", - ecr, currentTime ); - painCave.isFatal = 0; - simError(); + + if( haveEcr ){ + if( ecr > maxCutoff ){ + sprintf( painCave.errMsg, + "Box size is too small for the electrostatic cutoff radius, " + "%G, at time %G\n" + " [ %G %G %G ]\n" + " [ %G %G %G ]\n" + " [ %G %G %G ]\n", + ecr, currentTime, + Hmat[0][0], Hmat[0][1], Hmat[0][2], + Hmat[1][0], Hmat[1][1], Hmat[1][2], + Hmat[2][0], Hmat[2][1], Hmat[2][2]); + painCave.isFatal = 1; + simError(); } } - else if( ecr > maxCutoff){ - sprintf( painCave.errMsg, - "New Box size is setting the electrostaticCutoffRadius " - "to %lf at time %lf\n", - maxCutoff, currentTime ); - painCave.isFatal = 0; - simError(); - ecr = maxCutoff; - } - - if( (oldEcr != ecr) || ( oldRcut != rCut ) ) cutChanged = 1; - - // rlist is the 1.0 plus max( rcut, ecr ) - - ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; - - if( cutChanged ){ - - notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); - } - - oldEcr = ecr; - oldRcut = rCut; - } else { // initialize this stuff before using it, OK? sprintf( painCave.errMsg,