--- trunk/OOPSE/libmdtools/Integrator.cpp 2004/06/01 17:15:43 1212 +++ trunk/OOPSE/libmdtools/Integrator.cpp 2004/08/23 15:11:36 1452 @@ -1,7 +1,8 @@ #include #include #include - +#include "Rattle.hpp" +#include "Roll.hpp" #ifdef IS_MPI #include "mpiSimulation.hpp" #include @@ -32,7 +33,17 @@ template Integrator::Integrator(SimInfo nAtoms = info->n_atoms; integrableObjects = info->integrableObjects; - + + consFramework = new RollFramework(info); + + if(consFramework == NULL){ + sprintf(painCave.errMsg, + "Integrator::Intergrator() Error: Memory allocation error for RattleFramework" ); + painCave.isFatal = 1; + simError(); + } + +/* // check for constraints constrainedA = NULL; @@ -45,10 +56,13 @@ template Integrator::Integrator(SimInfo nConstrained = 0; checkConstraints(); - +*/ } template Integrator::~Integrator(){ + if (consFramework != NULL) + delete consFramework; +/* if (nConstrained){ delete[] constrainedA; delete[] constrainedB; @@ -57,8 +71,10 @@ template Integrator::~Integrator(){ delete[] moved; delete[] oldPos; } +*/ } +/* template void Integrator::checkConstraints(void){ isConstrained = 0; @@ -93,7 +109,7 @@ template void Integrator::checkConstrai if (constrained){ dummy_plug = theArray[j]->get_constraint(); temp_con[nConstrained].set_a(dummy_plug->get_a()); - temp_con[nConstrained].set_b(dummy_plug->get_b()); + temp_con[nConstrained].set_b(Dummy_plug->get_b()); temp_con[nConstrained].set_dsqr(dummy_plug->get_dsqr()); nConstrained++; @@ -151,8 +167,8 @@ template void Integrator::checkConstrai delete[] temp_con; } +*/ - template void Integrator::integrate(void){ double runTime = info->run_time; @@ -183,7 +199,8 @@ template void Integrator::integrate(voi // remove center of mass drift velocity (in case we passed in a configuration // that was drifting tStats->removeCOMdrift(); - + //tStats->removeAngularMomentum(); + // initialize the retraints if necessary if (info->useSolidThermInt && !info->useLiquidThermInt) { myFF->initRestraints(); @@ -192,13 +209,12 @@ template void Integrator::integrate(voi // initialize the forces before the first step calcForce(1, 1); - - if (nConstrained){ - preMove(); - constrainA(); - calcForce(1, 1); - constrainB(); - } + + //execute constraint algorithm to make sure at the very beginning the system is constrained + //consFramework->doPreConstraint(); + //consFramework->doConstrainA(); + //calcForce(1, 1); + //consFramework->doConstrainB(); if (info->setTemp){ thermalize(); @@ -255,8 +271,6 @@ template void Integrator::integrate(voi if (info->getTime() >= currStatus){ statOut->writeStat(info->getTime()); - if (info->useSolidThermInt || info->useLiquidThermInt) - statOut->writeRaw(info->getTime()); calcPot = 0; calcStress = 0; currStatus += statusTime; @@ -296,7 +310,8 @@ template void Integrator::integrateStep startProfile(pro3); #endif //profile - preMove(); + //save old state (position, velocity etc) + consFramework->doPreConstraint(); #ifdef PROFILE endProfile(pro3); @@ -332,6 +347,8 @@ template void Integrator::integrateStep startProfile( pro6 ); #endif //profile + consFramework->doPreConstraint(); + // finish the velocity half step moveB(); @@ -389,12 +406,11 @@ template void Integrator::moveA(void){ this->rotationPropagation( integrableObjects[i], ji ); integrableObjects[i]->setJ(ji); + } } - if (nConstrained){ - constrainA(); - } + consFramework->doConstrainA(); } @@ -433,13 +449,13 @@ template void Integrator::moveB(void){ integrableObjects[i]->setJ(ji); } - } - if (nConstrained){ - constrainB(); } + + consFramework->doConstrainB(); } +/* template void Integrator::preMove(void){ int i, j; double pos[3]; @@ -698,7 +714,7 @@ template void Integrator::constrainB(vo simError(); } } - +*/ template void Integrator::rotationPropagation ( StuntDouble* sd, double ji[3] ){ @@ -852,3 +868,82 @@ template string Integrator::getAddition //return a pointer point to local variable which might cause problem return string(); } + + +template void Integrator::printQuaternion(StuntDouble* sd){ + Mat4x4d S; + double I[3][3]; + Vector4d j4; + Vector3d j; + Vector3d tempJ; + Vector4d qdot; + Vector4d omega4; + Mat4x4d I4; + Quaternion q; + double I0; + Vector4d p_qua; + + if (sd->isDirectional()){ + sd->getQ(q.vec); + sd->getI(I); + sd->getJ(j.vec); + + //omega4[0] = 0.0; + //omega4[1] = j[0]/I[0][0]; + //omega4[2] = j[1]/I[1][1]; + //omega4[3] = j[2]/I[2][2]; + + //S = getS(q); + //qdot = 0.5 * S * omega4; + + //I0 = (qdot[1] * q[1] * I[0][0] + qdot[2] * q[2] * I[1][1] + qdot[3] * q[3] * I[2][2])/(qdot[1] * q[1]+ qdot[2] * q[2] + qdot[3] * q[3]); + + //I4.element[0][0] = I0; + //I4.element[1][1] = I[0][0]; + //I4.element[2][2] = I[1][1]; + //I4.element[3][3] = I[2][2]; + + S = getS(q); + j4[0] = 0.0; + j4[1] = j[0]; + j4[2] = j[1]; + j4[3] = j[2]; + + p_qua = 2 * S * j4; + + j4 = 0.5 * S.transpose() * p_qua; + //cout << "q0^2 + q1^2 + q2^2 + q3^2 = " << q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3] << endl; + //cout << "q0*q0dot + q1*q1dot + q2 *q2dot + q3*q3dot = " <