--- trunk/OOPSE/libmdtools/NPTim.cpp 2003/07/14 15:04:55 596 +++ trunk/OOPSE/libmdtools/NPTim.cpp 2003/07/15 03:08:00 604 @@ -1,5 +1,6 @@ #include #include "Atom.hpp" +#include "Molecule.hpp" #include "SRI.hpp" #include "AbstractClasses.hpp" #include "SimInfo.hpp" @@ -36,22 +37,22 @@ void NPTim::moveA() { void NPTim::moveA() { - int i,j,k; - int nInMol, aMatIndex; + int i, j; DirectionalAtom* dAtom; - Atom** theAtoms; - Molecule** myMols; - double Tb[3]; - double ji[3]; - double rc[3]; - double mass; - double rx, ry, rz, vx, vy, vz, fx, fy, fz; + double Tb[3], ji[3]; + double A[3][3], I[3][3]; + double angle, mass; + double vel[3], pos[3], frc[3]; + + double rj[3]; double instaTemp, instaPress, instaVol; double tt2, tb2; - double angle; + int nInMol; + double rc[3]; + nMols = info->n_mol; - myMols = info->molecules; + myMolecules = info->molecules; tt2 = tauThermostat * tauThermostat; tb2 = tauBarostat * tauBarostat; @@ -68,10 +69,10 @@ void NPTim::moveA() { for( i = 0; i < nMols; i++) { - myMols[i].getCOM(rc); + myMolecules[i].getCOM(rc); - nInMol = myMols[i]->getNAtoms(); - theAtoms = myMols[i]->getMyAtoms(); + nInMol = myMolecules[i].getNAtoms(); + myAtoms = myMolecules[i].getMyAtoms(); // find the minimum image coordinates of the molecular centers of mass: @@ -79,94 +80,69 @@ void NPTim::moveA() { for (j = 0; j < nInMol; j++) { - if(theAtoms[j] != NULL) { + if(myAtoms[j] != NULL) { - aMatIndex = 9 * theAtoms[j]->getIndex(); - - mass = theAtoms[j]->getMass(); - - vx = theAtoms[j]->get_vx(); - vy = theAtoms[j]->get_vy(); - vz = theAtoms[j]->get_vz(); - - fx = theAtoms[j]->getFx(); - fy = theAtoms[j]->getFy(); - fz = theAtoms[j]->getFz(); + myAtoms[i]->getVel( vel ); + myAtoms[i]->getPos( pos ); + myAtoms[i]->getFrc( frc ); - rx = theAtoms[j]->getX(); - ry = theAtoms[j]->getY(); - rz = theAtoms[j]->getZ(); + mass = myAtoms[i]->getMass(); - // velocity half step + for (j=0; j < 3; j++) + vel[j] += dt2 * ((frc[j] / mass ) * eConvert - vel[j]*(chi+eta)); - vx += dt2 * ((fx / mass)*eConvert - vx*(chi+eta)); - vy += dt2 * ((fy / mass)*eConvert - vy*(chi+eta)); - vz += dt2 * ((fz / mass)*eConvert - vz*(chi+eta)); + myAtoms[i]->setVel( vel ); - // position whole step + for (j = 0; j < 3; j++) + pos[j] += dt * (vel[j] + eta*rc[j]); - rx += dt*(vx + eta*rc[0]); - ry += dt*(vy + eta*rc[1]); - rz += dt*(vz + eta*rc[2]); - - theAtoms[j]->set_vx(vx); - theAtoms[j]->set_vy(vy); - theAtoms[j]->set_vz(vz); + atoms[i]->setPos( pos ); - theAtoms[j]->setX(rx); - theAtoms[j]->setY(ry); - theAtoms[j]->setZ(rz); + if( myAtoms[j]->isDirectional() ){ - if( theAtoms[j]->isDirectional() ){ - - dAtom = (DirectionalAtom *)theAtoms[j]; + dAtom = (DirectionalAtom *)myAtoms[j]; // get and convert the torque to body frame - - Tb[0] = dAtom->getTx(); - Tb[1] = dAtom->getTy(); - Tb[2] = dAtom->getTz(); - + + dAtom->getTrq( Tb ); dAtom->lab2Body( Tb ); - + // get the angular momentum, and propagate a half step - ji[0] = dAtom->getJx(); - ji[1] = dAtom->getJy(); - ji[2] = dAtom->getJz(); + dAtom->getJ( ji ); + + for (j=0; j < 3; j++) + ji[j] += dt2 * (Tb[j] * eConvert - ji[j]*chi); - ji[0] += dt2 * (Tb[0] * eConvert - ji[0]*chi); - ji[1] += dt2 * (Tb[1] * eConvert - ji[1]*chi); - ji[2] += dt2 * (Tb[2] * eConvert - ji[2]*chi); - // 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] / dAtom->getIxx(); - this->rotate( 1, 2, angle, ji, &Amat[aMatIndex] ); + angle = dt2 * ji[0] / I[0][0]; + this->rotate( 1, 2, angle, ji, A ); // rotate about the y-axis - angle = dt2 * ji[1] / dAtom->getIyy(); - this->rotate( 2, 0, angle, ji, &Amat[aMatIndex] ); + angle = dt2 * ji[1] / I[1][1]; + this->rotate( 2, 0, angle, ji, A ); // rotate about the z-axis - angle = dt * ji[2] / dAtom->getIzz(); - this->rotate( 0, 1, angle, ji, &Amat[aMatIndex] ); + angle = dt * ji[2] / I[2][2]; + this->rotate( 0, 1, angle, ji, A); // rotate about the y-axis - angle = dt2 * ji[1] / dAtom->getIyy(); - this->rotate( 2, 0, angle, ji, &Amat[aMatIndex] ); + angle = dt2 * ji[1] / I[1][1]; + this->rotate( 2, 0, angle, ji, A ); // rotate about the x-axis - angle = dt2 * ji[0] / dAtom->getIxx(); - this->rotate( 1, 2, angle, ji, &Amat[aMatIndex] ); + angle = dt2 * ji[0] / I[0][0]; + this->rotate( 1, 2, angle, ji, A ); - dAtom->setJx( ji[0] ); - dAtom->setJy( ji[1] ); - dAtom->setJz( ji[2] ); - } - + dAtom->setJ( ji ); + dAtom->setA( A ); + } } } } @@ -178,15 +154,16 @@ void NPTi::moveB( void ){ info->scaleBox(exp(dt*eta)); } -void NPTi::moveB( void ){ - int i,j,k; - int atomIndex; +void NPTim::moveB( void ){ + int i, j; DirectionalAtom* dAtom; - double Tb[3]; - double ji[3]; + double Tb[3], ji[3]; + double vel[3], frc[3]; + double mass; + double instaTemp, instaPress, instaVol; double tt2, tb2; - + tt2 = tauThermostat * tauThermostat; tb2 = tauBarostat * tauBarostat; @@ -199,52 +176,47 @@ void NPTi::moveB( void ){ (p_convert*NkBT*tb2)); for( i=0; igetVel( vel ); + atoms[i]->getFrc( frc ); + + mass = atoms[i]->getMass(); + // velocity half step - for( j=atomIndex; j<(atomIndex+3); j++ ) - for( j=atomIndex; j<(atomIndex+3); j++ ) - vel[j] += dt2 * ((frc[j]/atoms[i]->getMass())*eConvert - - vel[j]*(chi+eta)); + for (j=0; j < 3; j++) + vel[j] += dt2 * ((frc[j] / mass ) * eConvert - vel[j]*(chi+eta)); + atoms[i]->setVel( vel ); + if( atoms[i]->isDirectional() ){ dAtom = (DirectionalAtom *)atoms[i]; - // get and convert the torque to body frame + // get and convert the torque to body frame - Tb[0] = dAtom->getTx(); - Tb[1] = dAtom->getTy(); - Tb[2] = dAtom->getTz(); - + dAtom->getTrq( Tb ); dAtom->lab2Body( Tb ); - // get the angular momentum, and complete the angular momentum - // half step + // get the angular momentum, and propagate a half step - ji[0] = dAtom->getJx(); - ji[1] = dAtom->getJy(); - ji[2] = dAtom->getJz(); + dAtom->getJ( ji ); - ji[0] += dt2 * (Tb[0] * eConvert - ji[0]*chi); - ji[1] += dt2 * (Tb[1] * eConvert - ji[1]*chi); - ji[2] += dt2 * (Tb[2] * eConvert - ji[2]*chi); + for (j=0; j < 3; j++) + ji[j] += dt2 * (Tb[j] * eConvert - ji[j]*chi); - dAtom->setJx( ji[0] ); - dAtom->setJy( ji[1] ); - dAtom->setJz( ji[2] ); + dAtom->setJ( ji ); } } } -int NPTi::readyCheck() { +int NPTim::readyCheck() { // First check to see if we have a target temperature. // Not having one is fatal. if (!have_target_temp) { sprintf( painCave.errMsg, - "NPTi error: You can't use the NPTi integrator\n" + "NPTim error: You can't use the NPTim integrator\n" " without a targetTemp!\n" ); painCave.isFatal = 1; @@ -254,7 +226,7 @@ int NPTi::readyCheck() { if (!have_target_pressure) { sprintf( painCave.errMsg, - "NPTi error: You can't use the NPTi integrator\n" + "NPTim error: You can't use the NPTim integrator\n" " without a targetPressure!\n" ); painCave.isFatal = 1; @@ -266,7 +238,7 @@ int NPTi::readyCheck() { if (!have_tau_thermostat) { sprintf( painCave.errMsg, - "NPTi error: If you use the NPTi\n" + "NPTim error: If you use the NPTim\n" " integrator, you must set tauThermostat.\n"); painCave.isFatal = 1; simError(); @@ -277,7 +249,7 @@ int NPTi::readyCheck() { if (!have_tau_barostat) { sprintf( painCave.errMsg, - "NPTi error: If you use the NPTi\n" + "NPTim error: If you use the NPTim\n" " integrator, you must set tauBarostat.\n"); painCave.isFatal = 1; simError();