--- trunk/OOPSE/libmdtools/ConstraintAlgorithm.cpp 2004/06/03 21:51:55 1232 +++ trunk/OOPSE/libmdtools/ConstraintAlgorithm.cpp 2004/08/23 15:11:36 1452 @@ -2,14 +2,16 @@ #include "ConstraintPair.hpp" #include "SimInfo.hpp" #include "ConstraintManager.hpp" +#include "simError.h" +#include "Vector3d.hpp" //////////////////////////////////////////////////////////////////////////////// //Implementation of ConstraintAlgorithm //////////////////////////////////////////////////////////////////////////////// ConstraintAlgorithm::ConstraintAlgorithm(SimInfo* rhs){ info = rhs; - cpIter = info->consMan->creatPairIterator(); - ceIter = info->consMan->creatElementIterator(); + cpIter = info->consMan->createPairIterator(); + ceIter = info->consMan->createElementIterator(); } ConstraintAlgorithm::~ConstraintAlgorithm(){ @@ -27,7 +29,7 @@ void ConstraintAlgorithm::doConstrain(){ } void ConstraintAlgorithm::doConstrain(){ - const int maxConsIteration = 30; + const int maxConsIteration = 20; bool done; int iteration; int maxIteration; @@ -36,7 +38,7 @@ void ConstraintAlgorithm::doConstrain(){ ConstraintPair* consPair; int exeStatus; - + error = false; for(ceIter->first(); !ceIter->isEnd(); ceIter->next()){ consElem = ceIter->currentItem(); @@ -61,8 +63,13 @@ void ConstraintAlgorithm::doConstrain(){ exeStatus = doConstrainPair(consPair); switch(exeStatus){ + case consExceedMaxIter: + //cerr << "ConstraintAlgorithm::doConstrain() Error: can not constrain the bond within maximum iteration" << endl; + error = true; + case consFail: - cerr << "ConstraintAlgorithm::doConstrain() Error: Constraint Fail" << endl; + //cerr << "ConstraintAlgorithm::doConstrain() Error: Constraint Fail" << endl; + error = true; break; case consSuccess: //constrain the pair by moving two elements @@ -76,13 +83,16 @@ void ConstraintAlgorithm::doConstrain(){ case consPairHandlerFail: //can not found call back functor for constraint pair cerr << "ConstraintAlgorithm::doConstrain() Error: can not found callback functor for constraint pair " << endl; + error = true; break; case consElemHandlerFail: //can not found callback functor for constraint element cerr << "ConstraintAlgorithm::doConstrain() Error: can not found callback functor for constraint element " << endl; + error = true; break; default: cerr << "ConstraintAlgorithm::doConstrain() Error: unrecognized status" << endl; + error = true; break; } }//end for(iter->first()) @@ -95,7 +105,15 @@ void ConstraintAlgorithm::doConstrain(){ iteration++; }//end while - + + //if (!done){ + // error = true; + // sprintf(painCave.errMsg, + // "Constraint failure in constrainB, too many iterations: %d\n", + // iteration); + // painCave.isFatal = 1; + // simError(); + //} } @@ -103,7 +121,8 @@ int ConstraintAlgorithm::doConstrainPair(ConstraintPai map::iterator foundResult; CallbackFunctor* functor; - foundResult = callbackMap.find(typeid(consPair)); + //typeid must operate on deferenced, otherwise it will return the type_info of base class + foundResult = callbackMap.find(TypeInfo(typeid(*consPair))); if (foundResult != callbackMap.end()){ functor = foundResult->second; return (*functor)(consPair); @@ -141,17 +160,21 @@ ConsAlgoFramework::ConsAlgoFramework(SimInfo* rhs){ //Implementation of ConsAlgoFramework //////////////////////////////////////////////////////////////////////////////// ConsAlgoFramework::ConsAlgoFramework(SimInfo* rhs){ - ceIter = rhs->consMan->creatElementIterator(); + ceIter = rhs->consMan->createElementIterator(); } ConsAlgoFramework::~ConsAlgoFramework(){ delete ceIter; } + void ConsAlgoFramework::doPreConstraint(){ ConstraintElement* consElem; + Vector3d zeroVector(0.0, 0.0, 0.0); for(ceIter->first(); !ceIter->isEnd(); ceIter->next()){ consElem = ceIter->currentItem(); consElem->saveOldState(); - } -} + consElem->setConsForce(zeroVector); + consElem->setConsTorque(zeroVector); + } +}