--- trunk/OOPSE/libmdtools/Thermo.cpp 2003/04/03 20:21:54 447 +++ trunk/OOPSE/libmdtools/Thermo.cpp 2003/07/10 22:15:53 590 @@ -129,29 +129,104 @@ double Thermo::getTemperature(){ const double kb = 1.9872179E-3; // boltzman's constant in kcal/(mol K) double temperature; - int ndf_local, ndf; - ndf_local = 3 * entry_plug->n_atoms + 3 * entry_plug->n_oriented - - entry_plug->n_constraints; + temperature = ( 2.0 * this->getKinetic() ) / ((double)entry_plug->ndf * kb ); + return temperature; +} -#ifdef IS_MPI - MPI_Allreduce(&ndf_local,&ndf,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); -#else - ndf = ndf_local; -#endif +double Thermo::getEnthalpy() { - ndf = ndf - 3; + const double e_convert = 4.184E-4; // convert kcal/mol -> (amu A^2)/fs^2 + double u, p, v; + double press[3][3]; + + u = this->getTotalE(); + + this->getPressureTensor(press); + p = (press[0][0] + press[1][1] + press[2][2]) / 3.0; + + v = this->getVolume(); + + return (u + (p*v)/e_convert); +} + +double Thermo::getVolume() { + + return entry_plug->boxVol; +} + +double Thermo::getPressure() { + + // Relies on the calculation of the full molecular pressure tensor - temperature = ( 2.0 * this->getKinetic() ) / ( ndf * kb ); - return temperature; + const double p_convert = 1.63882576e8; + double press[3][3]; + double pressure; + + this->getPressureTensor(press); + + pressure = p_convert * (press[0][0] + press[1][1] + press[2][2]) / 3.0; + + return pressure; } -double Thermo::getPressure(){ - // returns pressure in units amu*fs^-2*Ang^-1 + +void Thermo::getPressureTensor(double press[3][3]){ + // returns pressure tensor in units amu*fs^-2*Ang^-1 // routine derived via viral theorem description in: // Paci, E. and Marchi, M. J.Phys.Chem. 1996, 100, 4314-4322 - return 0.0; + const double e_convert = 4.184e-4; + + double molmass, volume; + double vcom[3]; + double p_local[9], p_global[9]; + int i, j, k, l, 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: + for (i=0; i < 9; i++) { + p_local[i] = 0.0; + p_global[i] = 0.0; + } + + for (i=0; i < nMols; i++) { + molmass = molecules[i].getCOMvel(vcom); + + p_local[0] += molmass * (vcom[0] * vcom[0]); + p_local[1] += molmass * (vcom[0] * vcom[1]); + p_local[2] += molmass * (vcom[0] * vcom[2]); + p_local[3] += molmass * (vcom[1] * vcom[0]); + p_local[4] += molmass * (vcom[1] * vcom[1]); + p_local[5] += molmass * (vcom[1] * vcom[2]); + p_local[6] += molmass * (vcom[2] * vcom[0]); + p_local[7] += molmass * (vcom[2] * vcom[1]); + p_local[8] += molmass * (vcom[2] * vcom[2]); + } + + // Get total for entire system from MPI. + +#ifdef IS_MPI + MPI_Allreduce(p_local,p_global,9,MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); +#else + for (i=0; i<9; i++) { + p_global[i] = p_local[i]; + } +#endif // is_mpi + + volume = entry_plug->boxVol; + + for(i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + k = 3*i + j; + l = 3*j + i; + press[i][j] = (p_global[k] - entry_plug->tau[l]*e_convert) / volume; + } + } } void Thermo::velocitize() { @@ -165,8 +240,6 @@ void Thermo::velocitize() { const double kb = 8.31451e-7; // kb in amu, angstroms, fs, etc. double av2; double kebar; - int ndf, ndf_local; // number of degrees of freedom - int ndfRaw, ndfRaw_local; // the raw number of degrees of freedom int n_atoms; Atom** atoms; DirectionalAtom* dAtom; @@ -180,24 +253,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)entry_plug->ndf / + ( 2.0 * (double)entry_plug->ndfRaw ); -#ifdef IS_MPI - MPI_Allreduce(&ndf_local,&ndf,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); - MPI_Allreduce(&ndfRaw_local,&ndfRaw,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); -#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 @@ -253,7 +311,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();