--- trunk/OOPSE/libmdtools/SimInfo.cpp 2003/07/10 22:15:53 590 +++ trunk/OOPSE/libmdtools/SimInfo.cpp 2003/08/15 19:24:13 699 @@ -26,15 +26,30 @@ SimInfo::SimInfo(){ SimInfo::SimInfo(){ excludes = NULL; n_constraints = 0; + nZconstraints = 0; n_oriented = 0; n_dipoles = 0; ndf = 0; ndfRaw = 0; + nZconstraints = 0; the_integrator = NULL; setTemp = 0; 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; + boxIsInit = 0; + + + usePBC = 0; useLJ = 0; useSticky = 0; @@ -43,9 +58,23 @@ SimInfo::SimInfo(){ useGB = 0; useEAM = 0; + myConfiguration = new SimState(); + wrapMeSimInfo( this ); } + +SimInfo::~SimInfo(){ + + delete myConfiguration; + + map::iterator i; + + for(i = properties.begin(); i != properties.end(); i++) + delete (*i).second; + +} + void SimInfo::setBox(double newBox[3]) { int i, j; @@ -73,16 +102,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(); @@ -95,49 +120,6 @@ void SimInfo::setBoxM( double theBox[3][3] ){ setFortranBoxSize(FortranHmat, FortranHmatInv, &orthoRhombic); - smallestBoxL = boxLx; - if (boxLy < smallestBoxL) smallestBoxL = boxLy; - if (boxLz < smallestBoxL) smallestBoxL = boxLz; - - 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; - - sprintf( painCave.errMsg, - "New Box size is forcing cutoff radius down to %lf\n", - maxCutoff - 1.0 ); - painCave.isFatal = 0; - simError(); - - rCut = rList - 1.0; - - // list radius changed so we have to refresh the simulation structure. - refreshSim(); - } - - if (rCut > maxCutoff) { - sprintf( painCave.errMsg, - "New Box size is forcing cutoff radius down to %lf\n", - maxCutoff ); - painCave.isFatal = 0; - simError(); - - status = 0; - LJ_new_rcut(&rCut, &status); - if (status != 0) { - sprintf( painCave.errMsg, - "Error in recomputing LJ shifts based on new rcut\n"); - painCave.isFatal = 1; - simError(); - } - } } @@ -153,7 +135,7 @@ void SimInfo::scaleBox(double scale) { double theBox[3][3]; int i, j; - cerr << "Scaling box by " << scale << "\n"; + // cerr << "Scaling box by " << scale << "\n"; for(i=0; i<3; i++) for (j=0; j<3; j++) theBox[i][j] = Hmat[i][j]*scale; @@ -266,7 +248,39 @@ void SimInfo::matVecMul3(double m[3][3], double inVec[ outVec[1] = m[1][0]*a0 + m[1][1]*a1 + m[1][2]*a2; outVec[2] = m[2][0]*a0 + m[2][1]*a1 + m[2][2]*a2; } + +void SimInfo::transposeMat3(double in[3][3], double out[3][3]) { + double temp[3][3]; + int i, j; + + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + temp[j][i] = in[i][j]; + } + } + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + out[i][j] = temp[i][j]; + } + } +} +void SimInfo::printMat3(double A[3][3] ){ + + std::cerr + << "[ " << A[0][0] << ", " << A[0][1] << ", " << A[0][2] << " ]\n" + << "[ " << A[1][0] << ", " << A[1][1] << ", " << A[1][2] << " ]\n" + << "[ " << A[2][0] << ", " << A[2][1] << ", " << A[2][2] << " ]\n"; +} + +void SimInfo::printMat9(double A[9] ){ + + std::cerr + << "[ " << A[0] << ", " << A[1] << ", " << A[2] << " ]\n" + << "[ " << A[3] << ", " << A[4] << ", " << A[5] << " ]\n" + << "[ " << A[6] << ", " << A[7] << ", " << A[8] << " ]\n"; +} + void SimInfo::calcBoxL( void ){ double dx, dy, dz, dsq; @@ -280,20 +294,25 @@ void SimInfo::calcBoxL( void ){ dx = Hmat[0][0]; dy = Hmat[1][0]; dz = Hmat[2][0]; dsq = dx*dx + dy*dy + dz*dz; - boxLx = sqrt( dsq ); + 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; - boxLy = sqrt( dsq ); + 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; - boxLz = sqrt( dsq ); + boxL[2] = sqrt( dsq ); + if( (0.5 * boxL[2]) < maxCutoff ) maxCutoff = 0.5 * boxL[2]; + checkCutOffs(); + } @@ -347,7 +366,7 @@ int SimInfo::getNDF(){ ndf = ndf_local; #endif - ndf = ndf - 3; + ndf = ndf - 3 - nZconstraints; return ndf; } @@ -373,17 +392,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; - if( useDipole ){ - fInfo.rrf = ecr; - fInfo.rt = ecr - est; if( useReactionField )fInfo.dielect = dielectric; } @@ -429,6 +441,162 @@ void SimInfo::refreshSim(){ this->ndf = this->getNDF(); this->ndfRaw = this->getNDFraw(); + +} + + +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 )&&(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\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)&&(usePBC)) { + 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; +} + +void SimInfo::addProperty(GenericData* prop){ + + map::iterator result; + result = properties.find(prop->getID()); + + //we can't simply use properties[prop->getID()] = prop, + //it will cause memory leak if we already contain a propery which has the same name of prop + + if(result != properties.end()){ + + delete (*result).second; + (*result).second = prop; + + } + else{ + + properties[prop->getID()] = prop; + + } + +} + +GenericData* SimInfo::getProperty(const string& propName){ + + map::iterator result; + + //string lowerCaseName = (); + + result = properties.find(propName); + + if(result != properties.end()) + return (*result).second; + else + return NULL; +} + +vector SimInfo::getProperties(){ + + vector result; + map::iterator i; + + for(i = properties.begin(); i != properties.end(); i++) + result.push_back((*i).second); + + return result; +} + +