ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Thermo.cpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/Thermo.cpp (file contents):
Revision 401 by chuckv, Tue Mar 25 22:54:16 2003 UTC vs.
Revision 445 by gezelter, Thu Apr 3 19:58:24 2003 UTC

# Line 10 | Line 10 | using namespace std;
10   #include "Thermo.hpp"
11   #include "SRI.hpp"
12   #include "Integrator.hpp"
13 + #include "simError.h"
14 +
15 + #ifdef IS_MPI
16   #define __C
17 < //#include "mpiSimulation.hpp"
17 > #include "mpiSimulation.hpp"
18 > #endif // is_mpi
19  
20 +
21   #define BASE_SEED 123456789
22  
23   Thermo::Thermo( SimInfo* the_entry_plug ) {
# Line 82 | Line 87 | double Thermo::getPotential(){
87    double potential_local;
88    double potential;
89    int el, nSRI;
90 <  SRI** sris;
90 >  Molecule* molecules;
91  
92 <  sris = entry_plug->sr_interactions;
92 >  molecules = entry_plug->molecules;
93    nSRI = entry_plug->n_SRI;
94  
95    potential_local = 0.0;
96 +  potential = 0.0;
97    potential_local += entry_plug->lrPot;
98  
99 <  for( el=0; el<nSRI; el++ ){    
100 <    potential_local += sris[el]->get_potential();
99 >  for( el=0; el<entry_plug->n_mol; el++ ){    
100 >    potential_local += molecules[el].getPotential();
101    }
102  
103 + #ifdef IS_MPI
104 +  /*
105 +  std::cerr << "node " << worldRank << ": before LONG RANGE pot = " << entry_plug->lrPot
106 +            << "; pot_local = " << potential_local
107 +            << "; pot = " << potential << "\n";
108 +  */
109 + #endif
110 +
111    // Get total potential for entire system from MPI.
112   #ifdef IS_MPI
113    MPI::COMM_WORLD.Allreduce(&potential_local,&potential,1,MPI_DOUBLE,MPI_SUM);
# Line 101 | Line 115 | double Thermo::getPotential(){
115    potential = potential_local;
116   #endif // is_mpi
117  
118 + #ifdef IS_MPI
119 +  /*
120 +  std::cerr << "node " << worldRank << ": after pot = " << potential << "\n";
121 +  */
122 + #endif
123 +
124    return potential;
125   }
126  
# Line 134 | Line 154 | double Thermo::getPressure(){
154   }
155  
156   double Thermo::getPressure(){
157 <
158 < //  const double conv_Pa_atm = 9.901E-6; // convert Pa -> atm
159 < // const double conv_internal_Pa = 1.661E-7; //convert amu/(fs^2 A) -> Pa
140 < //  const double conv_A_m = 1.0E-10; //convert A -> m
157 >  // returns pressure in units amu*fs^-2*Ang^-1
158 >  // routine derived via viral theorem description in:
159 >  // Paci, E. and Marchi, M. J.Phys.Chem. 1996, 100, 4314-4322
160  
161    return 0.0;
162   }
# Line 148 | Line 167 | void Thermo::velocitize() {
167    double vx, vy, vz;
168    double jx, jy, jz;
169    int i, vr, vd; // velocity randomizer loop counters
170 <  double *vdrift;
170 >  double vdrift[3];
171    double vbar;
172    const double kb = 8.31451e-7; // kb in amu, angstroms, fs, etc.
173    double av2;
174    double kebar;
175 <  int ndf; // number of degrees of freedom
176 <  int ndfRaw; // the raw number of degrees of freedom
175 >  int ndf, ndf_local; // number of degrees of freedom
176 >  int ndfRaw, ndfRaw_local; // the raw number of degrees of freedom
177    int n_atoms;
178    Atom** atoms;
179    DirectionalAtom* dAtom;
# Line 168 | Line 187 | void Thermo::velocitize() {
187    n_oriented    = entry_plug->n_oriented;
188    n_constraints = entry_plug->n_constraints;
189    
190 +  // Raw degrees of freedom that we have to set
191 +  ndfRaw_local = 3 * entry_plug->n_atoms + 3 * entry_plug->n_oriented;
192  
193 <  ndfRaw = 3 * n_atoms + 3 * n_oriented;
194 <  ndf = ndfRaw - n_constraints - 3;
193 >  // Degrees of freedom that can contain kinetic energy
194 >  ndf_local = 3 * entry_plug->n_atoms + 3 * entry_plug->n_oriented
195 >    - entry_plug->n_constraints;
196 >  
197 > #ifdef IS_MPI
198 >  MPI::COMM_WORLD.Allreduce(&ndf_local,&ndf,1,MPI_INT,MPI_SUM);
199 >  MPI::COMM_WORLD.Allreduce(&ndfRaw_local,&ndfRaw,1,MPI_INT,MPI_SUM);
200 > #else
201 >  ndfRaw = ndfRaw_local;
202 >  ndf = ndf_local;
203 > #endif
204 >  ndf = ndf - 3;
205 >
206    kebar = kb * temperature * (double)ndf / ( 2.0 * (double)ndfRaw );
207    
208    for(vr = 0; vr < n_atoms; vr++){
# Line 179 | Line 211 | void Thermo::velocitize() {
211  
212      av2 = 2.0 * kebar / atoms[vr]->getMass();
213      vbar = sqrt( av2 );
214 <
214 >
215   //     vbar = sqrt( 8.31451e-7 * temperature / atoms[vr]->getMass() );
216      
217      // picks random velocities from a gaussian distribution
# Line 196 | Line 228 | void Thermo::velocitize() {
228  
229    // Get the Center of Mass drift velocity.
230  
231 <  vdrift = getCOMVel();
231 >  getCOMVel(vdrift);
232    
233    //  Corrects for the center of mass drift.
234    // sums all the momentum and divides by total mass.
# Line 240 | Line 272 | double* Thermo::getCOMVel(){
272    }
273   }
274  
275 < double* Thermo::getCOMVel(){
275 > void Thermo::getCOMVel(double vdrift[3]){
276  
277    double mtot, mtot_local;
246  double* vdrift;
278    double vdrift_local[3];
279    int vd, n_atoms;
280    Atom** atoms;
281  
251  vdrift = new double[3];
282    // We are very careless here with the distinction between n_atoms and n_local
283    // We should really fix this before someone pokes an eye out.
284  
# Line 271 | Line 301 | double* Thermo::getCOMVel(){
301  
302   #ifdef IS_MPI
303    MPI::COMM_WORLD.Allreduce(&mtot_local,&mtot,1,MPI_DOUBLE,MPI_SUM);
304 <  MPI::COMM_WORLD.Allreduce(&vdrift_local,&vdrift,3,MPI_DOUBLE,MPI_SUM);
304 >  MPI::COMM_WORLD.Allreduce(vdrift_local,vdrift,3,MPI_DOUBLE,MPI_SUM);
305   #else
306    mtot = mtot_local;
307    for(vd = 0; vd < 3; vd++) {
# Line 283 | Line 313 | double* Thermo::getCOMVel(){
313      vdrift[vd] = vdrift[vd] / mtot;
314    }
315    
286  return vdrift;
316   }
317  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines