--- trunk/OOPSE/libmdtools/SimInfo.cpp 2003/09/25 19:27:15 787 +++ branches/new-templateless/OOPSE/libmdtools/SimInfo.cpp 2003/11/06 18:20:47 852 @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include #include using namespace std; @@ -61,6 +61,8 @@ SimInfo::SimInfo(){ myConfiguration = new SimState(); + properties = new GenericData(); + wrapMeSimInfo( this ); } @@ -68,12 +70,7 @@ SimInfo::~SimInfo(){ SimInfo::~SimInfo(){ delete myConfiguration; - - map::iterator i; - - for(i = properties.begin(); i != properties.end(); i++) - delete (*i).second; - + delete properties; } void SimInfo::setBox(double newBox[3]) { @@ -145,7 +142,8 @@ void SimInfo::calcHmatInv( void ) { } void SimInfo::calcHmatInv( void ) { - + + int oldOrtho; int i,j; double smallDiag; double tol; @@ -155,13 +153,16 @@ void SimInfo::calcHmatInv( void ) { // Check the inverse to make sure it is sane: - matMul3( Hmat, HmatInv, sanity ); + // 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]; + 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 * 1E-6; orthoRhombic = 1; @@ -170,9 +171,25 @@ void SimInfo::calcHmatInv( void ) { 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 ortho tolerance in SimInfo.\n" ); + simError(); + } + else { + sprintf( painCave.errMsg, + "Hmat is switching from Orthorhombic to Non-OrthoRhombic\n" + " If this is a bad thing change the ortho tolerance in SimInfo.\n" ); + simError(); } } } @@ -408,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; @@ -424,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; @@ -439,7 +456,7 @@ int SimInfo::getNDFtranslational() { } int SimInfo::getNDFtranslational() { - int ndfTrans_local, ndfTrans; + int ndfTrans_local; ndfTrans_local = 3 * n_atoms - n_constraints; @@ -514,34 +531,53 @@ void SimInfo::setRcut( double theRcut ){ void SimInfo::setRcut( double theRcut ){ - - if( !haveOrigRcut ){ - haveOrigRcut = 1; - origRcut = theRcut; - } rCut = theRcut; checkCutOffs(); } -void SimInfo::setEcr( double theEcr ){ +void SimInfo::setDefaultRcut( double theRcut ){ - if( !haveOrigEcr ){ - haveOrigEcr = 1; - origEcr = theEcr; - } + haveOrigRcut = 1; + origRcut = theRcut; + rCut = theRcut; + ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; + + notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); +} + +void SimInfo::setEcr( double theEcr ){ + ecr = theEcr; checkCutOffs(); } +void SimInfo::setDefaultEcr( double theEcr ){ + + haveOrigEcr = 1; + origEcr = theEcr; + + ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; + + ecr = theEcr; + + notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); +} + void SimInfo::setEcr( double theEcr, double theEst ){ est = theEst; setEcr( theEcr ); } +void SimInfo::setDefaultEcr( double theEcr, double theEst ){ + est = theEst; + setDefaultEcr( theEcr ); +} + + void SimInfo::checkCutOffs( void ){ int cutChanged = 0; @@ -608,7 +644,6 @@ void SimInfo::checkCutOffs( void ){ ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; if( cutChanged ){ - notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); } @@ -625,53 +660,11 @@ void SimInfo::checkCutOffs( void ){ } -void SimInfo::addProperty(GenericData* prop){ +GenericData* SimInfo::getProperty(char* propName){ - 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; - - } - + return properties->find( propName ); } -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];