--- trunk/OOPSE/libmdtools/Thermo.cpp 2003/08/20 22:23:34 708 +++ trunk/OOPSE/libmdtools/Thermo.cpp 2003/09/15 16:52:02 763 @@ -123,7 +123,7 @@ double Thermo::getTemperature(){ double Thermo::getTemperature(){ - const double kb = 1.9872179E-3; // boltzman's constant in kcal/(mol K) + const double kb = 1.9872156E-3; // boltzman's constant in kcal/(mol K) double temperature; temperature = ( 2.0 * this->getKinetic() ) / ((double)info->ndf * kb ); @@ -166,7 +166,52 @@ double Thermo::getPressure() { return pressure; } +double Thermo::getPressureX() { + // Relies on the calculation of the full molecular pressure tensor + + const double p_convert = 1.63882576e8; + double press[3][3]; + double pressureX; + + this->getPressureTensor(press); + + pressureX = p_convert * press[0][0]; + + return pressureX; +} + +double Thermo::getPressureY() { + + // Relies on the calculation of the full molecular pressure tensor + + const double p_convert = 1.63882576e8; + double press[3][3]; + double pressureY; + + this->getPressureTensor(press); + + pressureY = p_convert * press[1][1]; + + return pressureY; +} + +double Thermo::getPressureZ() { + + // Relies on the calculation of the full molecular pressure tensor + + const double p_convert = 1.63882576e8; + double press[3][3]; + double pressureZ; + + this->getPressureTensor(press); + + pressureZ = p_convert * press[2][2]; + + return pressureZ; +} + + void Thermo::getPressureTensor(double press[3][3]){ // returns pressure tensor in units amu*fs^-2*Ang^-1 // routine derived via viral theorem description in: @@ -248,8 +293,8 @@ void Thermo::velocitize() { n_oriented = info->n_oriented; n_constraints = info->n_constraints; - kebar = kb * temperature * (double)info->ndf / - ( 2.0 * (double)info->ndfRaw ); + kebar = kb * temperature * (double)info->ndfRaw / + ( 2.0 * (double)info->ndf ); for(vr = 0; vr < n_atoms; vr++){ @@ -355,3 +400,47 @@ void Thermo::getCOMVel(double vdrift[3]){ } +void Thermo::getCOM(double COM[3]){ + + double mtot, mtot_local; + double aPos[3], amass; + double COM_local[3]; + int i, n_atoms, j; + Atom** atoms; + + // We are very careless here with the distinction between n_atoms and n_local + // We should really fix this before someone pokes an eye out. + + n_atoms = info->n_atoms; + atoms = info->atoms; + + mtot_local = 0.0; + COM_local[0] = 0.0; + COM_local[1] = 0.0; + COM_local[2] = 0.0; + + for(i = 0; i < n_atoms; i++){ + + amass = atoms[i]->getMass(); + atoms[i]->getPos( aPos ); + + for(j = 0; j < 3; j++) + COM_local[j] += aPos[j] * amass; + + mtot_local += amass; + } + +#ifdef IS_MPI + MPI_Allreduce(&mtot_local,&mtot,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(COM_local,COM,3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); +#else + mtot = mtot_local; + for(i = 0; i < 3; i++) { + COM[i] = COM_local[i]; + } +#endif + + for (i = 0; i < 3; i++) { + COM[i] = COM[i] / mtot; + } +}