--- trunk/OOPSE/libmdtools/Thermo.cpp 2003/04/04 19:47:19 458 +++ trunk/OOPSE/libmdtools/Thermo.cpp 2003/04/07 16:56:38 468 @@ -139,7 +139,39 @@ double Thermo::getPressure(){ // routine derived via viral theorem description in: // Paci, E. and Marchi, M. J.Phys.Chem. 1996, 100, 4314-4322 - return 0.0; + const double convert = 4.184e-4; + double mtot; + double vcom[3]; + double p_local, p_sum, p_mol, virial; + double theBox[3]; + double* tau; + int i, nMols; + Molecule* molecules; + + nMols = entry_plug->n_mol; + molecules = entry_plug->molecules; + tau = entry_plug->tau; + + // use velocities of molecular centers of mass and molecular masses: + p_local = 0.0; + for (i=0; i < nMols; i++) { + molecules[i].getCOMvel(mtot, vcom); + p_local += mtot* (vcom[0]*vcom[0] + vcom[1]*vcom[1] + vcom[2]*vcom[2]); + } + + // Get total for entire system from MPI. +#ifdef IS_MPI + MPI_Allreduce(&p_local,&p_sum,1,MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); +#else + p_sum = p_local; +#endif // is_mpi + + virial = tau[0] + tau[4] + tau[8]; + entry_plug->getBox(theBox); + + p_mol = (p_sum - virial*convert) / (3.0 * theBox[0] * theBox[1]* theBox[2]); + + return p_mol; } void Thermo::velocitize() {