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 444 by gezelter, Thu Apr 3 13:43:02 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 148 | Line 168 | void Thermo::velocitize() {
168    double vx, vy, vz;
169    double jx, jy, jz;
170    int i, vr, vd; // velocity randomizer loop counters
171 <  double *vdrift;
171 >  double vdrift[3];
172    double vbar;
173    const double kb = 8.31451e-7; // kb in amu, angstroms, fs, etc.
174    double av2;
175    double kebar;
176 <  int ndf; // number of degrees of freedom
177 <  int ndfRaw; // the raw number of degrees of freedom
176 >  int ndf, ndf_local; // number of degrees of freedom
177 >  int ndfRaw, ndfRaw_local; // the raw number of degrees of freedom
178    int n_atoms;
179    Atom** atoms;
180    DirectionalAtom* dAtom;
# Line 168 | Line 188 | void Thermo::velocitize() {
188    n_oriented    = entry_plug->n_oriented;
189    n_constraints = entry_plug->n_constraints;
190    
191 +  // Raw degrees of freedom that we have to set
192 +  ndfRaw_local = 3 * entry_plug->n_atoms + 3 * entry_plug->n_oriented;
193  
194 <  ndfRaw = 3 * n_atoms + 3 * n_oriented;
195 <  ndf = ndfRaw - n_constraints - 3;
194 >  // Degrees of freedom that can contain kinetic energy
195 >  ndf_local = 3 * entry_plug->n_atoms + 3 * entry_plug->n_oriented
196 >    - entry_plug->n_constraints;
197 >  
198 > #ifdef IS_MPI
199 >  MPI::COMM_WORLD.Allreduce(&ndf_local,&ndf,1,MPI_INT,MPI_SUM);
200 >  MPI::COMM_WORLD.Allreduce(&ndfRaw_local,&ndfRaw,1,MPI_INT,MPI_SUM);
201 > #else
202 >  ndfRaw = ndfRaw_local;
203 >  ndf = ndf_local;
204 > #endif
205 >  ndf = ndf - 3;
206 >
207    kebar = kb * temperature * (double)ndf / ( 2.0 * (double)ndfRaw );
208    
209    for(vr = 0; vr < n_atoms; vr++){
# Line 179 | Line 212 | void Thermo::velocitize() {
212  
213      av2 = 2.0 * kebar / atoms[vr]->getMass();
214      vbar = sqrt( av2 );
215 <
215 >
216   //     vbar = sqrt( 8.31451e-7 * temperature / atoms[vr]->getMass() );
217      
218      // picks random velocities from a gaussian distribution
# Line 196 | Line 229 | void Thermo::velocitize() {
229  
230    // Get the Center of Mass drift velocity.
231  
232 <  vdrift = getCOMVel();
232 >  getCOMVel(vdrift);
233    
234    //  Corrects for the center of mass drift.
235    // sums all the momentum and divides by total mass.
# Line 240 | Line 273 | double* Thermo::getCOMVel(){
273    }
274   }
275  
276 < double* Thermo::getCOMVel(){
276 > void Thermo::getCOMVel(double vdrift[3]){
277  
278    double mtot, mtot_local;
246  double* vdrift;
279    double vdrift_local[3];
280    int vd, n_atoms;
281    Atom** atoms;
282  
251  vdrift = new double[3];
283    // We are very careless here with the distinction between n_atoms and n_local
284    // We should really fix this before someone pokes an eye out.
285  
# Line 271 | Line 302 | double* Thermo::getCOMVel(){
302  
303   #ifdef IS_MPI
304    MPI::COMM_WORLD.Allreduce(&mtot_local,&mtot,1,MPI_DOUBLE,MPI_SUM);
305 <  MPI::COMM_WORLD.Allreduce(&vdrift_local,&vdrift,3,MPI_DOUBLE,MPI_SUM);
305 >  MPI::COMM_WORLD.Allreduce(vdrift_local,vdrift,3,MPI_DOUBLE,MPI_SUM);
306   #else
307    mtot = mtot_local;
308    for(vd = 0; vd < 3; vd++) {
# Line 283 | Line 314 | double* Thermo::getCOMVel(){
314      vdrift[vd] = vdrift[vd] / mtot;
315    }
316    
286  return vdrift;
317   }
318  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines