--- trunk/OOPSE/libmdtools/Integrator.cpp 2003/06/19 19:21:23 558 +++ trunk/OOPSE/libmdtools/Integrator.cpp 2003/06/20 20:29:36 561 @@ -1,5 +1,6 @@ #include #include +#include #ifdef IS_MPI #include "mpiSimulation.hpp" @@ -10,7 +11,7 @@ Integrator::Integrator( SimInfo* theInfo, ForceFields* #include "simError.h" -Integrator::Integrator( SimInfo* theInfo, ForceFields* the_ff ){ +Integrator::Integrator( SimInfo *theInfo, ForceFields* the_ff ){ info = theInfo; myFF = the_ff; @@ -33,7 +34,7 @@ Integrator::Integrator( SimInfo* theInfo, ForceFields* constrainedDsqr = NULL; moving = NULL; moved = NULL; - prePos = NULL; + oldPos = NULL; nConstrained = 0; @@ -48,8 +49,7 @@ Integrator::~Integrator() { delete[] constrainedDsqr; delete[] moving; delete[] moved; - delete[] prePos; -k + delete[] oldPos; } } @@ -147,7 +147,7 @@ void Integrator::checkConstraints( void ){ moving = new int[nAtoms]; moved = new int[nAtoms]; - prePos = new double[nAtoms*3]; + oldPos = new double[nAtoms*3]; } delete[] temp_con; @@ -157,24 +157,7 @@ void Integrator::integrate( void ){ void Integrator::integrate( void ){ int i, j; // loop counters - double kE = 0.0; // the kinetic energy - double rot_kE; - double trans_kE; - int tl; // the time loop conter - double dt2; // half the dt - double vx, vy, vz; // the velocities - double vx2, vy2, vz2; // the square of the velocities - double rx, ry, rz; // the postitions - - double ji[3]; // the body frame angular momentum - double jx2, jy2, jz2; // the square of the angular momentums - double Tb[3]; // torque in the body frame - double angle; // the angle through which to rotate the rotation matrix - double A[3][3]; // the rotation matrix - double press[9]; - - double dt = info->dt; double runTime = info->run_time; double sampleTime = info->sampleTime; double statusTime = info->statusTime; @@ -188,12 +171,16 @@ void Integrator::integrate( void ){ int calcPot, calcStress; int isError; + + tStats = new Thermo( info ); - e_out = new StatWriter( info ); - dump_out = new DumpWriter( info ); + statOut = new StatWriter( info ); + dumpOut = new DumpWriter( info ); - Atom** atoms = info->atoms; + atoms = info->atoms; DirectionalAtom* dAtom; + + dt = info->dt; dt2 = 0.5 * dt; // initialize the forces before the first step @@ -205,8 +192,8 @@ void Integrator::integrate( void ){ tStats->velocitize(); } - dump_out->writeDump( 0.0 ); - e_out->writeStat( 0.0 ); + dumpOut->writeDump( 0.0 ); + statOut->writeStat( 0.0 ); calcPot = 0; calcStress = 0; @@ -215,13 +202,29 @@ void Integrator::integrate( void ){ currStatus = statusTime; currTime = 0.0;; + + readyCheck(); + +#ifdef IS_MPI + strcpy( checkPointMsg, + "The integrator is ready to go." ); + MPIcheckPoint(); +#endif // is_mpi + + + pos = Atom::getPosArray(); + vel = Atom::getVelArray(); + frc = Atom::getFrcArray(); + trq = Atom::getTrqArray(); + Amat = Atom::getAmatArray(); + while( currTime < runTime ){ if( (currTime+dt) >= currStatus ){ calcPot = 1; calcStress = 1; } - + integrateStep( calcPot, calcStress ); currTime += dt; @@ -234,29 +237,38 @@ void Integrator::integrate( void ){ } if( currTime >= currSample ){ - dump_out->writeDump( currTime ); + dumpOut->writeDump( currTime ); currSample += sampleTime; } if( currTime >= currStatus ){ - e_out->writeStat( time * dt ); + statOut->writeStat( currTime ); calcPot = 0; calcStress = 0; currStatus += statusTime; } + +#ifdef IS_MPI + strcpy( checkPointMsg, + "successfully took a time step." ); + MPIcheckPoint(); +#endif // is_mpi + } - dump_out->writeFinal(); + dumpOut->writeFinal(); - delete dump_out; - delete e_out; + delete dumpOut; + delete statOut; } void Integrator::integrateStep( int calcPot, int calcStress ){ + + // Position full step, and velocity half step - //preMove(); + preMove(); moveA(); if( nConstrained ) constrainA(); @@ -279,6 +291,7 @@ void Integrator::moveA( void ){ DirectionalAtom* dAtom; double Tb[3]; double ji[3]; + double angle; for( i=0; igetIxx(); - this->rotate( 1, 2, angle, ji, &aMat[aMatIndex] ); + this->rotate( 1, 2, angle, ji, &Amat[aMatIndex] ); // rotate about the y-axis angle = dt2 * ji[1] / dAtom->getIyy(); - this->rotate( 2, 0, angle, ji, &aMat[aMatIndex] ); + this->rotate( 2, 0, angle, ji, &Amat[aMatIndex] ); // rotate about the z-axis angle = dt * ji[2] / dAtom->getIzz(); - this->rotate( 0, 1, angle, ji, &aMat[aMatIndex] ); + this->rotate( 0, 1, angle, ji, &Amat[aMatIndex] ); // rotate about the y-axis angle = dt2 * ji[1] / dAtom->getIyy(); - this->rotate( 2, 0, angle, ji, &aMat[aMatIndex] ); + this->rotate( 2, 0, angle, ji, &Amat[aMatIndex] ); // rotate about the x-axis angle = dt2 * ji[0] / dAtom->getIxx(); - this->rotate( 1, 2, angle, ji, &aMat[aMatIndex] ); + this->rotate( 1, 2, angle, ji, &Amat[aMatIndex] ); dAtom->setJx( ji[0] ); dAtom->setJy( ji[1] ); @@ -375,10 +388,6 @@ void Integrator::moveB( void ){ ji[0] = dAtom->getJx() + ( dt2 * Tb[0] ) * eConvert; ji[1] = dAtom->getJy() + ( dt2 * Tb[1] ) * eConvert; ji[2] = dAtom->getJz() + ( dt2 * Tb[2] ) * eConvert; - - jx2 = ji[0] * ji[0]; - jy2 = ji[1] * ji[1]; - jz2 = ji[2] * ji[2]; dAtom->setJx( ji[0] ); dAtom->setJy( ji[1] ); @@ -392,21 +401,22 @@ void Integrator::preMove( void ){ int i; if( nConstrained ){ - if( oldAtoms != nAtoms ){ + +// if( oldAtoms != nAtoms ){ - // save oldAtoms to check for lode balanceing later on. +// // save oldAtoms to check for lode balanceing later on. - oldAtoms = nAtoms; +// oldAtoms = nAtoms; - delete[] moving; - delete[] moved; - delete[] oldPos; +// delete[] moving; +// delete[] moved; +// delete[] oldPos; - moving = new int[nAtoms]; - moved = new int[nAtoms]; +// moving = new int[nAtoms]; +// moved = new int[nAtoms]; - oldPos = new double[nAtoms*3]; - } +// oldPos = new double[nAtoms*3]; +// } for(i=0; i<(nAtoms*3); i++) oldPos[i] = pos[i]; } @@ -421,6 +431,7 @@ void Integrator::constrainA(){ int a, b; double rma, rmb; double dx, dy, dz; + double rpab; double rabsq, pabsq, rpabsq; double diffsq; double gab; @@ -453,14 +464,14 @@ void Integrator::constrainA(){ //periodic boundary condition pxab = pxab - info->box_x * copysign(1, pxab) - * int(pxab / info->box_x + 0.5); + * int( fabs(pxab) / info->box_x + 0.5); pyab = pyab - info->box_y * copysign(1, pyab) - * int(pyab / info->box_y + 0.5); + * int( fabs(pyab) / info->box_y + 0.5); pzab = pzab - info->box_z * copysign(1, pzab) - * int(pzab / info->box_z + 0.5); + * int( fabs(pzab) / info->box_z + 0.5); pabsq = pxab * pxab + pyab * pyab + pzab * pzab; - rabsq = constraintedDsqr[i]; + rabsq = constrainedDsqr[i]; diffsq = pabsq - rabsq; // the original rattle code from alan tidesley @@ -470,11 +481,11 @@ void Integrator::constrainA(){ rzab = oldPos[3*a+2] - oldPos[3*b+2]; rxab = rxab - info->box_x * copysign(1, rxab) - * int(rxab / info->box_x + 0.5); + * int( fabs(rxab) / info->box_x + 0.5); ryab = ryab - info->box_y * copysign(1, ryab) - * int(ryab / info->box_y + 0.5); + * int( fabs(ryab) / info->box_y + 0.5); rzab = rzab - info->box_z * copysign(1, rzab) - * int(rzab / info->box_z + 0.5); + * int( fabs(rzab) / info->box_z + 0.5); rpab = rxab * pxab + ryab * pyab + rzab * pzab; rpabsq = rpab * rpab; @@ -538,9 +549,9 @@ void Integrator::constrainA(){ if( !done ){ - sprintf( painCae.errMsg, + sprintf( painCave.errMsg, "Constraint failure in constrainA, too many iterations: %d\n", - iterations ); + iteration ); painCave.isFatal = 1; simError(); } @@ -561,12 +572,13 @@ void Integrator::constrainB( void ){ double gab; int iteration; - for(i=0; ibox_x * copysign(1, rxab) - * int(rxab / info->box_x + 0.5); + * int( fabs(rxab) / info->box_x + 0.5); ryab = ryab - info->box_y * copysign(1, ryab) - * int(ryab / info->box_y + 0.5); + * int( fabs(ryab) / info->box_y + 0.5); rzab = rzab - info->box_z * copysign(1, rzab) - * int(rzab / info->box_z + 0.5); + * int( fabs(rzab) / info->box_z + 0.5); rma = 1.0 / atoms[a]->getMass(); rmb = 1.0 / atoms[b]->getMass(); rvab = rxab * vxab + ryab * vyab + rzab * vzab; - gab = -rvab / ( ( rma + rmb ) * constraintsDsqr[i] ); + gab = -rvab / ( ( rma + rmb ) * constrainedDsqr[i] ); if (fabs(gab) > tol) { @@ -630,9 +642,9 @@ void Integrator::constrainB( void ){ if( !done ){ - sprintf( painCae.errMsg, + sprintf( painCave.errMsg, "Constraint failure in constrainB, too many iterations: %d\n", - iterations ); + iteration ); painCave.isFatal = 1; simError(); } @@ -646,7 +658,7 @@ void Integrator::rotate( int axes1, int axes2, double void Integrator::rotate( int axes1, int axes2, double angle, double ji[3], - double A[3][3] ){ + double A[9] ){ int i,j,k; double sinAngle; @@ -662,7 +674,7 @@ void Integrator::rotate( int axes1, int axes2, double for(i=0; i<3; i++){ for(j=0; j<3; j++){ - tempA[j][i] = A[i][j]; + tempA[j][i] = A[3*i + j]; } } @@ -713,15 +725,15 @@ void Integrator::rotate( int axes1, int axes2, double // A[][] = A[][] * transpose(rot[][]) - // NOte for as yet unknown reason, we are setting the performing the + // NOte for as yet unknown reason, we are performing the // calculation as: // transpose(A[][]) = transpose(A[][]) * transpose(rot[][]) for(i=0; i<3; i++){ for(j=0; j<3; j++){ - A[j][i] = 0.0; + A[3*j + i] = 0.0; for(k=0; k<3; k++){ - A[j][i] += tempA[i][k] * rot[j][k]; + A[3*j + i] += tempA[i][k] * rot[j][k]; } } }