--- trunk/OOPSE/libmdtools/Thermo.cpp 2003/04/03 19:58:24 445 +++ trunk/OOPSE/libmdtools/Thermo.cpp 2003/04/04 01:57:11 454 @@ -4,7 +4,6 @@ using namespace std; #ifdef IS_MPI #include -#include #endif //is_mpi #include "Thermo.hpp" @@ -73,7 +72,8 @@ double Thermo::getKinetic(){ } } #ifdef IS_MPI - MPI::COMM_WORLD.Allreduce(&kinetic,&kinetic_global,1,MPI_DOUBLE,MPI_SUM); + MPI_Allreduce(&kinetic,&kinetic_global,1,MPI_DOUBLE, + MPI_SUM, MPI_COMM_WORLD); kinetic = kinetic_global; #endif //is_mpi @@ -100,17 +100,10 @@ double Thermo::getPotential(){ potential_local += molecules[el].getPotential(); } -#ifdef IS_MPI - /* - std::cerr << "node " << worldRank << ": before LONG RANGE pot = " << entry_plug->lrPot - << "; pot_local = " << potential_local - << "; pot = " << potential << "\n"; - */ -#endif - // Get total potential for entire system from MPI. #ifdef IS_MPI - MPI::COMM_WORLD.Allreduce(&potential_local,&potential,1,MPI_DOUBLE,MPI_SUM); + MPI_Allreduce(&potential_local,&potential,1,MPI_DOUBLE, + MPI_SUM, MPI_COMM_WORLD); #else potential = potential_local; #endif // is_mpi @@ -132,24 +125,45 @@ double Thermo::getTemperature(){ return total; } -double Thermo::getTemperature(){ - - const double kb = 1.9872179E-3; // boltzman's constant in kcal/(mol K) - double temperature; +int Thermo::getNDF(){ int ndf_local, ndf; ndf_local = 3 * entry_plug->n_atoms + 3 * entry_plug->n_oriented - entry_plug->n_constraints; #ifdef IS_MPI - MPI::COMM_WORLD.Allreduce(&ndf_local,&ndf,1,MPI_INT,MPI_SUM); + MPI_Allreduce(&ndf_local,&ndf,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); #else ndf = ndf_local; #endif ndf = ndf - 3; + + return ndf; +} + +int Thermo::getNDFraw() { + int ndfRaw_local, ndfRaw; + + // Raw degrees of freedom that we have to set + ndfRaw_local = 3 * entry_plug->n_atoms + 3 * entry_plug->n_oriented; - temperature = ( 2.0 * this->getKinetic() ) / ( ndf * kb ); +#ifdef IS_MPI + MPI_Allreduce(&ndfRaw_local,&ndfRaw,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); +#else + ndfRaw = ndfRaw_local; +#endif + + return ndfRaw; +} + + +double Thermo::getTemperature(){ + + const double kb = 1.9872179E-3; // boltzman's constant in kcal/(mol K) + double temperature; + + temperature = ( 2.0 * this->getKinetic() ) / ( (double)this->getNDF() * kb ); return temperature; } @@ -187,24 +201,9 @@ void Thermo::velocitize() { n_oriented = entry_plug->n_oriented; n_constraints = entry_plug->n_constraints; - // Raw degrees of freedom that we have to set - ndfRaw_local = 3 * entry_plug->n_atoms + 3 * entry_plug->n_oriented; - - // Degrees of freedom that can contain kinetic energy - ndf_local = 3 * entry_plug->n_atoms + 3 * entry_plug->n_oriented - - entry_plug->n_constraints; + kebar = kb * temperature * (double)this->getNDF() / + ( 2.0 * (double)this->getNDFraw() ); -#ifdef IS_MPI - MPI::COMM_WORLD.Allreduce(&ndf_local,&ndf,1,MPI_INT,MPI_SUM); - MPI::COMM_WORLD.Allreduce(&ndfRaw_local,&ndfRaw,1,MPI_INT,MPI_SUM); -#else - ndfRaw = ndfRaw_local; - ndf = ndf_local; -#endif - ndf = ndf - 3; - - kebar = kb * temperature * (double)ndf / ( 2.0 * (double)ndfRaw ); - for(vr = 0; vr < n_atoms; vr++){ // uses equipartition theory to solve for vbar in angstrom/fs @@ -260,7 +259,7 @@ void Thermo::velocitize() { vbar = sqrt( 2.0 * kebar * dAtom->getIyy() ); jy = vbar * gaussStream->getGaussian(); - + vbar = sqrt( 2.0 * kebar * dAtom->getIzz() ); jz = vbar * gaussStream->getGaussian(); @@ -300,8 +299,8 @@ void Thermo::getCOMVel(double vdrift[3]){ } #ifdef IS_MPI - MPI::COMM_WORLD.Allreduce(&mtot_local,&mtot,1,MPI_DOUBLE,MPI_SUM); - MPI::COMM_WORLD.Allreduce(vdrift_local,vdrift,3,MPI_DOUBLE,MPI_SUM); + MPI_Allreduce(&mtot_local,&mtot,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(vdrift_local,vdrift,3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); #else mtot = mtot_local; for(vd = 0; vd < 3; vd++) {