--- trunk/OOPSE/libmdtools/Integrator.cpp 2003/12/22 21:27:04 892 +++ trunk/OOPSE/libmdtools/Integrator.cpp 2004/06/04 03:15:31 1234 @@ -1,7 +1,7 @@ #include #include #include - +#include "Rattle.hpp" #ifdef IS_MPI #include "mpiSimulation.hpp" #include @@ -31,7 +31,18 @@ template Integrator::Integrator(SimInfo } nAtoms = info->n_atoms; + integrableObjects = info->integrableObjects; + rattle = new RattleFramework(info); + + if(rattle == NULL){ + sprintf(painCave.errMsg, + "Integrator::Intergrator() Error: Memory allocation error for RattleFramework" ); + painCave.isFatal = 1; + simError(); + } + +/* // check for constraints constrainedA = NULL; @@ -44,9 +55,13 @@ template Integrator::Integrator(SimInfo nConstrained = 0; checkConstraints(); +*/ } template Integrator::~Integrator(){ + if (rattle != NULL) + delete rattle; +/* if (nConstrained){ delete[] constrainedA; delete[] constrainedB; @@ -55,8 +70,10 @@ template Integrator::~Integrator(){ delete[] moved; delete[] oldPos; } +*/ } +/* template void Integrator::checkConstraints(void){ isConstrained = 0; @@ -68,7 +85,8 @@ template void Integrator::checkConstrai SRI** theArray; for (int i = 0; i < nMols; i++){ - theArray = (SRI * *) molecules[i].getMyBonds(); + + theArray = (SRI * *) molecules[i].getMyBonds(); for (int j = 0; j < molecules[i].getNBonds(); j++){ constrained = theArray[j]->is_constrained(); @@ -114,6 +132,7 @@ template void Integrator::checkConstrai } } + if (nConstrained > 0){ isConstrained = 1; @@ -135,7 +154,7 @@ template void Integrator::checkConstrai } - // save oldAtoms to check for lode balanceing later on. + // save oldAtoms to check for lode balancing later on. oldAtoms = nAtoms; @@ -147,8 +166,8 @@ template void Integrator::checkConstrai delete[] temp_con; } +*/ - template void Integrator::integrate(void){ double runTime = info->run_time; @@ -157,7 +176,7 @@ template void Integrator::integrate(voi double thermalTime = info->thermalTime; double resetTime = info->resetTime; - + double difference; double currSample; double currThermal; double currStatus; @@ -176,16 +195,24 @@ template void Integrator::integrate(voi readyCheck(); + // remove center of mass drift velocity (in case we passed in a configuration + // that was drifting + tStats->removeCOMdrift(); + + // initialize the retraints if necessary + if (info->useSolidThermInt && !info->useLiquidThermInt) { + myFF->initRestraints(); + } + // 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 + rattle->doPreConstraint(); + rattle->doRattleA(); + calcForce(1, 1); + rattle->doRattleB(); if (info->setTemp){ thermalize(); @@ -207,8 +234,9 @@ template void Integrator::integrate(voi MPIcheckPoint(); #endif // is_mpi - while (info->getTime() < runTime){ - if ((info->getTime() + dt) >= currStatus){ + while (info->getTime() < runTime && !stopIntegrator()){ + difference = info->getTime() + dt - currStatus; + if (difference > 0 || fabs(difference) < 1e-4 ){ calcPot = 1; calcStress = 1; } @@ -263,10 +291,11 @@ template void Integrator::integrate(voi #endif // is_mpi } + // dump out a file containing the omega values for the final configuration + if (info->useSolidThermInt && !info->useLiquidThermInt) + myFF->dumpzAngle(); + - // write the last frame - dumpOut->writeDump(info->getTime()); - delete dumpOut; delete statOut; } @@ -279,7 +308,8 @@ template void Integrator::integrateStep startProfile(pro3); #endif //profile - preMove(); + //save old state (position, velocity etc) + rattle->doPreConstraint(); #ifdef PROFILE endProfile(pro3); @@ -301,9 +331,7 @@ template void Integrator::integrateStep MPIcheckPoint(); #endif // is_mpi - // calc forces - calcForce(calcPot, calcStress); #ifdef IS_MPI @@ -333,19 +361,20 @@ template void Integrator::moveA(void){ template void Integrator::moveA(void){ - int i, j; + size_t i, j; DirectionalAtom* dAtom; double Tb[3], ji[3]; double vel[3], pos[3], frc[3]; double mass; + double omega; + + for (i = 0; i < integrableObjects.size() ; i++){ + integrableObjects[i]->getVel(vel); + integrableObjects[i]->getPos(pos); + integrableObjects[i]->getFrc(frc); + + mass = integrableObjects[i]->getMass(); - for (i = 0; i < nAtoms; i++){ - atoms[i]->getVel(vel); - atoms[i]->getPos(pos); - atoms[i]->getFrc(frc); - - mass = atoms[i]->getMass(); - for (j = 0; j < 3; j++){ // velocity half step vel[j] += (dt2 * frc[j] / mass) * eConvert; @@ -353,80 +382,74 @@ template void Integrator::moveA(void){ pos[j] += dt * vel[j]; } - atoms[i]->setVel(vel); - atoms[i]->setPos(pos); + integrableObjects[i]->setVel(vel); + integrableObjects[i]->setPos(pos); - if (atoms[i]->isDirectional()){ - dAtom = (DirectionalAtom *) atoms[i]; + if (integrableObjects[i]->isDirectional()){ // get and convert the torque to body frame - dAtom->getTrq(Tb); - dAtom->lab2Body(Tb); + integrableObjects[i]->getTrq(Tb); + integrableObjects[i]->lab2Body(Tb); // get the angular momentum, and propagate a half step - dAtom->getJ(ji); + integrableObjects[i]->getJ(ji); for (j = 0; j < 3; j++) ji[j] += (dt2 * Tb[j]) * eConvert; - this->rotationPropagation( dAtom, ji ); + this->rotationPropagation( integrableObjects[i], ji ); - dAtom->setJ(ji); + integrableObjects[i]->setJ(ji); } } - if (nConstrained){ - constrainA(); - } + rattle->doRattleA(); } template void Integrator::moveB(void){ int i, j; - DirectionalAtom* dAtom; double Tb[3], ji[3]; double vel[3], frc[3]; double mass; - for (i = 0; i < nAtoms; i++){ - atoms[i]->getVel(vel); - atoms[i]->getFrc(frc); + for (i = 0; i < integrableObjects.size(); i++){ + integrableObjects[i]->getVel(vel); + integrableObjects[i]->getFrc(frc); - mass = atoms[i]->getMass(); + mass = integrableObjects[i]->getMass(); // velocity half step for (j = 0; j < 3; j++) vel[j] += (dt2 * frc[j] / mass) * eConvert; - atoms[i]->setVel(vel); + integrableObjects[i]->setVel(vel); - if (atoms[i]->isDirectional()){ - dAtom = (DirectionalAtom *) atoms[i]; + if (integrableObjects[i]->isDirectional()){ // get and convert the torque to body frame - dAtom->getTrq(Tb); - dAtom->lab2Body(Tb); + integrableObjects[i]->getTrq(Tb); + integrableObjects[i]->lab2Body(Tb); // get the angular momentum, and propagate a half step - dAtom->getJ(ji); + integrableObjects[i]->getJ(ji); for (j = 0; j < 3; j++) ji[j] += (dt2 * Tb[j]) * eConvert; - dAtom->setJ(ji); + integrableObjects[i]->setJ(ji); } } - if (nConstrained){ - constrainB(); - } + rattle->doRattleB(); } +/* template void Integrator::preMove(void){ int i, j; double pos[3]; @@ -685,40 +708,58 @@ template void Integrator::constrainB(vo simError(); } } - +*/ template void Integrator::rotationPropagation -( DirectionalAtom* dAtom, double ji[3] ){ +( StuntDouble* sd, double ji[3] ){ double angle; double A[3][3], I[3][3]; + int i, j, k; // use the angular velocities to propagate the rotation matrix a // full time step - dAtom->getA(A); - dAtom->getI(I); - - // rotate about the x-axis - angle = dt2 * ji[0] / I[0][0]; - this->rotate( 1, 2, angle, ji, A ); + sd->getA(A); + sd->getI(I); - // rotate about the y-axis - angle = dt2 * ji[1] / I[1][1]; - this->rotate( 2, 0, angle, ji, A ); - - // rotate about the z-axis - angle = dt * ji[2] / I[2][2]; - this->rotate( 0, 1, angle, ji, A); + if (sd->isLinear()) { + i = sd->linearAxis(); + j = (i+1)%3; + k = (i+2)%3; + + angle = dt2 * ji[j] / I[j][j]; + this->rotate( k, i, angle, ji, A ); - // rotate about the y-axis - angle = dt2 * ji[1] / I[1][1]; - this->rotate( 2, 0, angle, ji, A ); + angle = dt * ji[k] / I[k][k]; + this->rotate( i, j, angle, ji, A); - // rotate about the x-axis - angle = dt2 * ji[0] / I[0][0]; - this->rotate( 1, 2, angle, ji, A ); + angle = dt2 * ji[j] / I[j][j]; + this->rotate( k, i, angle, ji, A ); - dAtom->setA( A ); + } else { + // rotate about the x-axis + angle = dt2 * ji[0] / I[0][0]; + this->rotate( 1, 2, angle, ji, A ); + + // rotate about the y-axis + angle = dt2 * ji[1] / I[1][1]; + this->rotate( 2, 0, angle, ji, A ); + + // rotate about the z-axis + angle = dt * ji[2] / I[2][2]; + sd->addZangle(angle); + this->rotate( 0, 1, angle, ji, A); + + // rotate about the y-axis + angle = dt2 * ji[1] / I[1][1]; + this->rotate( 2, 0, angle, ji, A ); + + // rotate about the x-axis + angle = dt2 * ji[0] / I[0][0]; + this->rotate( 1, 2, angle, ji, A ); + + } + sd->setA( A ); } template void Integrator::rotate(int axes1, int axes2,