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

Comparing trunk/OOPSE/libmdtools/NVT.cpp (file contents):
Revision 778 by mmeineke, Fri Sep 19 20:00:27 2003 UTC vs.
Revision 855 by mmeineke, Thu Nov 6 22:01:37 2003 UTC

# Line 1 | Line 1
1 + #include <math.h>
2 +
3   #include "Atom.hpp"
4   #include "SRI.hpp"
5   #include "AbstractClasses.hpp"
# Line 6 | Line 8
8   #include "Thermo.hpp"
9   #include "ReadWrite.hpp"
10   #include "Integrator.hpp"
11 < #include "simError.h"
11 > #include "simError.h"
12  
13  
14   // Basic thermostating via Hoover, Phys.Rev.A, 1985, Vol. 31 (5) 1695-1697
# Line 14 | Line 16 | template<typename T> NVT<T>::NVT ( SimInfo *theInfo, F
16   template<typename T> NVT<T>::NVT ( SimInfo *theInfo, ForceFields* the_ff):
17    T( theInfo, the_ff )
18   {
19 +  GenericData* data;
20 +  DoubleData * chiValue;
21 +  DoubleData * integralOfChidtValue;
22 +
23 +  chiValue = NULL;
24 +  integralOfChidtValue = NULL;
25 +
26    chi = 0.0;
27    have_tau_thermostat = 0;
28    have_target_temp = 0;
29    have_chi_tolerance = 0;
30    integralOfChidt = 0.0;
31  
32 +
33 +  if( theInfo->useInitXSstate ){
34 +
35 +    // retrieve chi and integralOfChidt from simInfo
36 +    data = info->getProperty(CHIVALUE_ID);
37 +    if(data){
38 +      chiValue = dynamic_cast<DoubleData*>(data);
39 +    }
40 +    
41 +    data = info->getProperty(INTEGRALOFCHIDT_ID);
42 +    if(data){
43 +      integralOfChidtValue = dynamic_cast<DoubleData*>(data);
44 +    }
45 +    
46 +    // chi and integralOfChidt should appear by pair
47 +    if(chiValue && integralOfChidtValue){
48 +      chi = chiValue->getData();
49 +      integralOfChidt = integralOfChidtValue->getData();
50 +    }
51 +  }
52 +
53    oldVel = new double[3*nAtoms];
54    oldJi = new double[3*nAtoms];
55   }
# Line 30 | Line 60 | template<typename T> void NVT<T>::moveA() {
60   }
61  
62   template<typename T> void NVT<T>::moveA() {
63 <  
63 >
64    int i, j;
65    DirectionalAtom* dAtom;
66    double Tb[3], ji[3];
# Line 42 | Line 72 | template<typename T> void NVT<T>::moveA() {
72    // We need the temperature at time = t for the chi update below:
73  
74    instTemp = tStats->getTemperature();
75 <  
75 >
76    for( i=0; i<nAtoms; i++ ){
77  
78      atoms[i]->getVel( vel );
# Line 60 | Line 90 | template<typename T> void NVT<T>::moveA() {
90  
91      atoms[i]->setVel( vel );
92      atoms[i]->setPos( pos );
93 <  
93 >
94      if( atoms[i]->isDirectional() ){
95  
96        dAtom = (DirectionalAtom *)atoms[i];
97 <          
97 >
98        // get and convert the torque to body frame
99 <      
99 >
100        dAtom->getTrq( Tb );
101        dAtom->lab2Body( Tb );
102 <      
102 >
103        // get the angular momentum, and propagate a half step
104  
105        dAtom->getJ( ji );
106  
107 <      for (j=0; j < 3; j++)
107 >      for (j=0; j < 3; j++)
108          ji[j] += dt2 * (Tb[j] * eConvert - ji[j]*chi);
109 <      
109 >
110        this->rotationPropagation( dAtom, ji );
111 <      
111 >
112        dAtom->setJ( ji );
113 <    }    
113 >    }
114    }
115 <  
115 >
116    if (nConstrained){
117      constrainA();
118    }
119  
120 <  // Finally, evolve chi a half step (just like a velocity) using
120 >  // Finally, evolve chi a half step (just like a velocity) using
121    // temperature at time t, not time t+dt/2
122  
123    chi += dt2 * ( instTemp / targetTemp - 1.0) / (tauThermostat*tauThermostat);
# Line 130 | Line 160 | template<typename T> void NVT<T>::moveB( void ){
160    // do the iteration:
161  
162    for (k=0; k < 4; k++) {
163 <    
163 >
164      instTemp = tStats->getTemperature();
165  
166      // evolve chi another half step using the temperature at t + dt/2
167  
168      prevChi = chi;
169 <    chi = oldChi + dt2 * ( instTemp / targetTemp - 1.0) /
169 >    chi = oldChi + dt2 * ( instTemp / targetTemp - 1.0) /
170        (tauThermostat*tauThermostat);
171 <  
171 >
172      for( i=0; i<nAtoms; i++ ){
173  
174        atoms[i]->getFrc( frc );
175        atoms[i]->getVel(vel);
176 <      
176 >
177        mass = atoms[i]->getMass();
178 <      
178 >
179        // velocity half step
180 <      for (j=0; j < 3; j++)
180 >      for (j=0; j < 3; j++)
181          vel[j] = oldVel[3*i+j] + dt2 * ((frc[j] / mass ) * eConvert - oldVel[3*i + j]*chi);
182 <      
182 >
183        atoms[i]->setVel( vel );
184 <      
184 >
185        if( atoms[i]->isDirectional() ){
186 <        
186 >
187          dAtom = (DirectionalAtom *)atoms[i];
188 <        
189 <        // get and convert the torque to body frame      
190 <        
188 >
189 >        // get and convert the torque to body frame
190 >
191          dAtom->getTrq( Tb );
192 <        dAtom->lab2Body( Tb );      
193 <            
194 <        for (j=0; j < 3; j++)
192 >        dAtom->lab2Body( Tb );
193 >
194 >        for (j=0; j < 3; j++)
195            ji[j] = oldJi[3*i + j] + dt2 * (Tb[j] * eConvert - oldJi[3*i+j]*chi);
196 <      
196 >
197          dAtom->setJ( ji );
198        }
199      }
# Line 174 | Line 204 | template<typename T> void NVT<T>::moveB( void ){
204  
205      if (fabs(prevChi - chi) <= chiTolerance) break;
206    }
207 <  
207 >
208    integralOfChidt += dt2*chi;
209   }
210  
211   template<typename T> void NVT<T>::resetIntegrator( void ){
212 <  
212 >
213    chi = 0.0;
214    integralOfChidt = 0.0;
215   }
# Line 189 | Line 219 | template<typename T> int NVT<T>::readyCheck() {
219    //check parent's readyCheck() first
220    if (T::readyCheck() == -1)
221      return -1;
222 <  
223 <  // First check to see if we have a target temperature.
224 <  // Not having one is fatal.
225 <  
222 >
223 >  // First check to see if we have a target temperature.
224 >  // Not having one is fatal.
225 >
226    if (!have_target_temp) {
227      sprintf( painCave.errMsg,
228               "NVT error: You can't use the NVT integrator without a targetTemp!\n"
# Line 201 | Line 231 | template<typename T> int NVT<T>::readyCheck() {
231      simError();
232      return -1;
233    }
234 <  
234 >
235    // We must set tauThermostat.
236 <  
236 >
237    if (!have_tau_thermostat) {
238      sprintf( painCave.errMsg,
239               "NVT error: If you use the constant temperature\n"
# Line 211 | Line 241 | template<typename T> int NVT<T>::readyCheck() {
241      painCave.isFatal = 1;
242      simError();
243      return -1;
244 <  }    
244 >  }
245  
246    if (!have_chi_tolerance) {
247      sprintf( painCave.errMsg,
# Line 220 | Line 250 | template<typename T> int NVT<T>::readyCheck() {
250      have_chi_tolerance = 1;
251      painCave.isFatal = 0;
252      simError();
253 <  }    
253 >  }
254  
255 <  return 1;    
255 >  return 1;
256  
257   }
258  
# Line 234 | Line 264 | template<typename T> double NVT<T>::getConservedQuanti
264    double thermostat_kinetic;
265    double thermostat_potential;
266  
267 <  fkBT = (double)(info->getNDF()    ) * kB * targetTemp;
268 <
267 >  fkBT = (double)(info->getNDF()    ) * kB * targetTemp;
268 >
269    Energy = tStats->getTotalE();
270  
271 <  thermostat_kinetic = fkBT* tauThermostat * tauThermostat * chi * chi /
271 >  thermostat_kinetic = fkBT* tauThermostat * tauThermostat * chi * chi /
272      (2.0 * eConvert);
273  
274    thermostat_potential = fkBT * integralOfChidt / eConvert;
275  
276    conservedQuantity = Energy + thermostat_kinetic + thermostat_potential;
247  
248  cerr << info->getTime() << "\t" << Energy << "\t" << thermostat_kinetic <<
249      "\t" << thermostat_potential << "\t" << conservedQuantity << endl;
277  
278 <  return conservedQuantity;
278 >  return conservedQuantity;
279   }
280 +
281 + template<typename T> string NVT<T>::getAdditionalParameters(void){
282 +  string parameters;
283 +  const int BUFFERSIZE = 2000; // size of the read buffer
284 +  char buffer[BUFFERSIZE];
285 +
286 +  sprintf(buffer,"\t%G\t%G;", chi, integralOfChidt);
287 +  parameters += buffer;
288 +
289 +  return parameters;
290 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines