--- trunk/OOPSE/libmdtools/SimInfo.cpp 2003/07/16 02:11:02 621 +++ trunk/OOPSE/libmdtools/SimInfo.cpp 2003/07/16 21:30:56 626 @@ -36,7 +36,15 @@ SimInfo::SimInfo(){ rCut = 0.0; ecr = 0.0; est = 0.0; + oldEcr = 0.0; + oldRcut = 0.0; + haveOrigRcut = 0; + haveOrigEcr = 0; + boxIsInit = 0; + + + usePBC = 0; useLJ = 0; useSticky = 0; @@ -75,16 +83,12 @@ 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++) for (j=0; j < 3; j++) Hmat[i][j] = theBox[i][j]; - // cerr - // << "setting Hmat ->\n" - // << "[ " << Hmat[0][0] << ", " << Hmat[0][1] << ", " << Hmat[0][2] << " ]\n" - // << "[ " << Hmat[1][0] << ", " << Hmat[1][1] << ", " << Hmat[1][2] << " ]\n" - // << "[ " << Hmat[2][0] << ", " << Hmat[2][1] << ", " << Hmat[2][2] << " ]\n"; - calcBoxL(); calcHmatInv(); @@ -97,44 +101,6 @@ void SimInfo::setBoxM( double theBox[3][3] ){ setFortranBoxSize(FortranHmat, FortranHmatInv, &orthoRhombic); - smallestBoxL = boxL[0]; - if (boxL[1] < smallestBoxL) smallestBoxL = boxL[1]; - if (boxL[2] > smallestBoxL) smallestBoxL = boxL[2]; - - maxCutoff = smallestBoxL / 2.0; - - if (rList > maxCutoff) { - sprintf( painCave.errMsg, - "New Box size is forcing neighborlist radius down to %lf\n", - maxCutoff ); - painCave.isFatal = 0; - simError(); - rList = maxCutoff; - - if (rCut > (rList - 1.0)) { - sprintf( painCave.errMsg, - "New Box size is forcing LJ cutoff radius down to %lf\n", - rList - 1.0 ); - painCave.isFatal = 0; - simError(); - rCut = rList - 1.0; - } - - if( ecr > (rList - 1.0) ){ - sprintf( painCave.errMsg, - "New Box size is forcing electrostaticCutoffRadius " - "down to %lf\n" - "electrostaticSkinThickness is now %lf\n", - rList - 1.0, 0.05*(rList-1.0) ); - painCave.isFatal = 0; - simError(); - ecr = maxCutoff; - est = 0.05 * ecr; - } - - // At least one of the radii changed, so we need a refresh: - refreshSim(); - } } @@ -310,19 +276,22 @@ void SimInfo::calcBoxL( void ){ dx = Hmat[0][0]; dy = Hmat[1][0]; dz = Hmat[2][0]; dsq = dx*dx + dy*dy + dz*dz; boxL[0] = sqrt( dsq ); + maxCutoff = 0.5 * boxL[0]; // boxLy dx = Hmat[0][1]; dy = Hmat[1][1]; dz = Hmat[2][1]; dsq = dx*dx + dy*dy + dz*dz; boxL[1] = sqrt( dsq ); + if( (0.5 * boxL[1]) < maxCutoff ) maxCutoff = 0.5 * boxL[1]; // boxLz dx = Hmat[0][2]; dy = Hmat[1][2]; dz = Hmat[2][2]; dsq = dx*dx + dy*dy + dz*dz; boxL[2] = sqrt( dsq ); - + if( (0.5 * boxL[2]) < maxCutoff ) maxCutoff = 0.5 * boxL[2]; + } @@ -402,17 +371,10 @@ void SimInfo::refreshSim(){ int isError; int n_global; int* excl; - - fInfo.rrf = 0.0; - fInfo.rt = 0.0; - fInfo.dielect = 0.0; - fInfo.rlist = rList; - fInfo.rcut = rCut; + fInfo.dielect = 0.0; if( useDipole ){ - fInfo.rrf = ecr; - fInfo.rt = ecr - est; if( useReactionField )fInfo.dielect = dielectric; } @@ -461,3 +423,108 @@ void SimInfo::refreshSim(){ } + +void SimInfo::setRcut( double theRcut ){ + + if( !haveOrigRcut ){ + haveOrigRcut = 1; + origRcut = theRcut; + } + + rCut = theRcut; + checkCutOffs(); +} + +void SimInfo::setEcr( double theEcr ){ + + if( !haveOrigEcr ){ + haveOrigEcr = 1; + origEcr = theEcr; + } + + ecr = theEcr; + checkCutOffs(); +} + +void SimInfo::setEcr( double theEcr, double theEst ){ + + est = theEst; + setEcr( theEcr ); +} + + +void SimInfo::checkCutOffs( void ){ + + int cutChanged = 0; + + if( boxIsInit ){ + + //we need to check cutOffs against the box + + if( maxCutoff > rCut ){ + 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\n", + rCut ); + painCave.isFatal = 0; + simError(); + } + } + + if( maxCutoff > ecr ){ + if( ecr < origEcr ){ + rCut = origEcr; + if (ecr > maxCutoff) ecr = maxCutoff; + + sprintf( painCave.errMsg, + "New Box size is setting the electrostaticCutoffRadius " + "to %lf\n", + ecr ); + painCave.isFatal = 0; + simError(); + } + } + + + if (rCut > maxCutoff) { + sprintf( painCave.errMsg, + "New Box size is setting the long range cutoff radius " + "to %lf\n", + maxCutoff ); + painCave.isFatal = 0; + simError(); + rCut = maxCutoff; + } + + if( ecr > maxCutoff){ + sprintf( painCave.errMsg, + "New Box size is setting the electrostaticCutoffRadius " + "to %lf\n", + maxCutoff ); + 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; +}