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

Comparing trunk/mdtools/md_code/Thermo.cpp (file contents):
Revision 117 by mmeineke, Tue Sep 24 22:10:55 2002 UTC vs.
Revision 261 by chuckv, Mon Feb 3 21:15:59 2003 UTC

# Line 1 | Line 1
1   #include <cmath>
2 + #include <iostream>
3 + using namespace std;
4  
5 + #ifdef IS_MPI
6 + #include <mpi.h>
7 + #include <mpi++.h>
8 + #endif //is_mpi
9 +
10   #include "Thermo.hpp"
11   #include "SRI.hpp"
12   #include "LRI.hpp"
13   #include "Integrator.hpp"
14  
15 + #define BASE_SEED 123456789
16  
17 + Thermo::Thermo( SimInfo* the_entry_plug ) {
18 +  entry_plug = the_entry_plug;
19 +  int baseSeed = BASE_SEED;
20 +  
21 +  gaussStream = new gaussianSPRNG( baseSeed );
22 + }
23 +
24 + Thermo::~Thermo(){
25 +  delete gaussStream;
26 + }
27 +
28   double Thermo::getKinetic(){
29  
30    const double e_convert = 4.184E-4; // convert kcal/mol -> (amu A^2)/fs^2
# Line 17 | Line 36 | double Thermo::getKinetic(){
36    DirectionalAtom *dAtom;
37  
38    int n_atoms;
39 +  double kinetic_global;
40    Atom** atoms;
41 +
42    
43    n_atoms = entry_plug->n_atoms;
44    atoms = entry_plug->atoms;
45  
46    kinetic = 0.0;
47 +  kinetic_global = 0.0;
48    for( kl=0; kl < n_atoms; kl++ ){
49  
50      vx2 = atoms[kl]->get_vx() * atoms[kl]->get_vx();
# Line 44 | Line 66 | double Thermo::getKinetic(){
66          + (jz2 / dAtom->getIzz());
67      }
68    }
69 <  
69 > #ifdef IS_MPI
70 >  MPI::COMM_WORLD.Allreduce(&kinetic,&kinetic_global,1,MPI_DOUBLE,MPI_SUM);
71 >  kinetic = kinetic_global;
72 > #endif //is_mpi
73 >
74    kinetic = kinetic * 0.5 / e_convert;
75  
76    return kinetic;
# Line 53 | Line 79 | double Thermo::getPotential(){
79   double Thermo::getPotential(){
80    
81    double potential;
82 +  double potential_global;
83    int el, nSRI;
84    SRI** sris;
85  
# Line 60 | Line 87 | double Thermo::getPotential(){
87    nSRI = entry_plug->n_SRI;
88  
89    potential = 0.0;
90 +  potential_global = 0.0;
91 +  potential += entry_plug->lrPot;
92  
64  potential += entry_plug->longRange->get_potential();;
65
93    // std::cerr << "long range potential: " << potential << "\n";
67
94    for( el=0; el<nSRI; el++ ){
95      
96      potential += sris[el]->get_potential();
97    }
98  
99 +  // Get total potential for entire system from MPI.
100 + #ifdef IS_MPI
101 +  MPI::COMM_WORLD.Allreduce(&potential,&potential_global,1,MPI_DOUBLE,MPI_SUM);
102 +  potential = potential_global;
103 + #endif // is_mpi
104 +
105    return potential;
106   }
107  
# Line 145 | Line 177 | void Thermo::velocitize() {
177      
178      // picks random velocities from a gaussian distribution
179      // centered on vbar
180 <    
180 > #ifndef USE_SPRNG
181 >    /* If we are using mpi, we need to use the SPRNG random
182 >       generator. The non drand48 generator will just repeat
183 >       the same numbers for every node creating a non-gaussian
184 >       distribution for the simulation. drand48 is fine for the
185 >       single processor version of the code, but SPRNG should
186 >       still be preferred for consistency.
187 >    */
188 >
189 > #ifdef IS_MPI
190 > #error "SPRNG random number generator must be used for MPI"
191 > #else
192 >    // warning "Using drand48 for random number generation"
193 > #endif  // is_mpi
194 >
195      x = drand48();
196      y = drand48();
197      vx = vbar * sqrt( -2.0 * log(x)) * cos(2 * M_PI * y);
# Line 157 | Line 203 | void Thermo::velocitize() {
203      x = drand48();
204      y = drand48();
205      vz = vbar * sqrt( -2.0 * log(x)) * cos(2 * M_PI * y);
206 <    
206 >
207 > #endif // use_spring
208 >
209 > #ifdef USE_SPRNG
210 >    vx = vbar * gaussStream->getGaussian();
211 >    vy = vbar * gaussStream->getGaussian();
212 >    vz = vbar * gaussStream->getGaussian();
213 > #endif // use_spring
214 >
215      atoms[vr]->set_vx( vx );
216      atoms[vr]->set_vy( vy );
217      atoms[vr]->set_vz( vz );
# Line 205 | Line 259 | void Thermo::velocitize() {
259        if( atoms[i]->isDirectional() ){
260          
261          dAtom = (DirectionalAtom *)atoms[i];
262 +
263 + #ifndef USE_SPRNG
264 +
265 + #ifdef IS_MPI
266 + #error "SPRNG random number generator must be used for MPI"
267 + #else  // is_mpi
268 +        //warning "Using drand48 for random number generation"
269 + #endif   // is_MPI
270          
271          vbar = sqrt( 2.0 * kebar * dAtom->getIxx() );
272          x = drand48();
# Line 220 | Line 282 | void Thermo::velocitize() {
282          x = drand48();
283          y = drand48();
284          jz = vbar * sqrt( -2.0 * log(x)) * cos(2 * M_PI * y);
285 +
286 + #else //use_sprng
287 +
288 +        vbar = sqrt( 2.0 * kebar * dAtom->getIxx() );
289 +        jx = vbar * gaussStream->getGaussian();
290 +
291 +        vbar = sqrt( 2.0 * kebar * dAtom->getIyy() );
292 +        jy = vbar * gaussStream->getGaussian();
293 +
294 +        vbar = sqrt( 2.0 * kebar * dAtom->getIzz() );
295 +        jz = vbar * gaussStream->getGaussian();
296 + #endif //use_sprng
297          
298          dAtom->setJx( jx );
299          dAtom->setJy( jy );

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines