--- trunk/OOPSE/libmdtools/SimInfo.cpp 2003/07/21 16:23:57 642 +++ trunk/OOPSE/libmdtools/SimInfo.cpp 2003/09/16 20:02:11 767 @@ -26,16 +26,20 @@ 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; @@ -54,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; @@ -292,6 +310,8 @@ void SimInfo::calcBoxL( void ){ dsq = dx*dx + dy*dy + dz*dz; boxL[2] = sqrt( dsq ); if( (0.5 * boxL[2]) < maxCutoff ) maxCutoff = 0.5 * boxL[2]; + + checkCutOffs(); } @@ -346,7 +366,7 @@ int SimInfo::getNDF(){ ndf = ndf_local; #endif - ndf = ndf - 3; + ndf = ndf - 3 - nZconstraints; return ndf; } @@ -365,7 +385,23 @@ int SimInfo::getNDFraw() { return ndfRaw; } - + +int SimInfo::getNDFtranslational() { + int ndfTrans_local, ndfTrans; + + ndfTrans_local = 3 * n_atoms - n_constraints; + +#ifdef IS_MPI + MPI_Allreduce(&ndfTrans_local,&ndfTrans,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); +#else + ndfTrans = ndfTrans_local; +#endif + + ndfTrans = ndfTrans - 3 - nZconstraints; + + return ndfTrans; +} + void SimInfo::refreshSim(){ simtype fInfo; @@ -421,7 +457,7 @@ void SimInfo::refreshSim(){ this->ndf = this->getNDF(); this->ndfRaw = this->getNDFraw(); - + this->ndfTrans = this->getNDFtranslational(); } @@ -458,11 +494,13 @@ void SimInfo::checkCutOffs( void ){ int cutChanged = 0; + + if( boxIsInit ){ //we need to check cutOffs against the box - - if( maxCutoff > rCut ){ + + if(( maxCutoff > rCut )&&(usePBC)){ if( rCut < origRcut ){ rCut = origRcut; if (rCut > maxCutoff) rCut = maxCutoff; @@ -478,7 +516,7 @@ void SimInfo::checkCutOffs( void ){ if( maxCutoff > ecr ){ if( ecr < origEcr ){ - rCut = origEcr; + ecr = origEcr; if (ecr > maxCutoff) ecr = maxCutoff; sprintf( painCave.errMsg, @@ -491,7 +529,7 @@ void SimInfo::checkCutOffs( void ){ } - if (rCut > maxCutoff) { + if ((rCut > maxCutoff)&&(usePBC)) { sprintf( painCave.errMsg, "New Box size is setting the long range cutoff radius " "to %lf\n", @@ -511,21 +549,81 @@ void SimInfo::checkCutOffs( void ){ ecr = maxCutoff; } - - } - + + if( (oldEcr != ecr) || ( oldRcut != rCut ) ) cutChanged = 1; - 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 ){ + // rlist is the 1.0 plus max( rcut, ecr ) - notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); + ( 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, + "Trying to check cutoffs without a box. Be smarter.\n" ); + painCave.isFatal = 1; + simError(); } - 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; +} + +double SimInfo::matTrace3(double m[3][3]){ + double trace; + trace = m[0][0] + m[1][1] + m[2][2]; + + return trace; +}