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 837 by tim, Wed Oct 29 00:19:10 2003 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines