ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/integrators/NVT.cpp
(Generate patch)

Comparing trunk/src/integrators/NVT.cpp (file contents):
Revision 665 by tim, Thu Oct 13 22:26:47 2005 UTC vs.
Revision 2071 by gezelter, Sat Mar 7 21:41:51 2015 UTC

# Line 6 | Line 6
6   * redistribute this software in source and binary code form, provided
7   * that the following conditions are met:
8   *
9 < * 1. Acknowledgement of the program authors must be made in any
10 < *    publication of scientific results based in part on use of the
11 < *    program.  An acceptable form of acknowledgement is citation of
12 < *    the article in which the program was described (Matthew
13 < *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 < *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 < *    Parallel Simulation Engine for Molecular Dynamics,"
16 < *    J. Comput. Chem. 26, pp. 252-271 (2005))
17 < *
18 < * 2. Redistributions of source code must retain the above copyright
9 > * 1. Redistributions of source code must retain the above copyright
10   *    notice, this list of conditions and the following disclaimer.
11   *
12 < * 3. Redistributions in binary form must reproduce the above copyright
12 > * 2. Redistributions in binary form must reproduce the above copyright
13   *    notice, this list of conditions and the following disclaimer in the
14   *    documentation and/or other materials provided with the
15   *    distribution.
# Line 37 | Line 28
28   * arising out of the use of or inability to use software, even if the
29   * University of Notre Dame has been advised of the possibility of
30   * such damages.
31 + *
32 + * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your
33 + * research, please cite the appropriate papers when you publish your
34 + * work.  Good starting points are:
35 + *                                                                      
36 + * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).            
37 + * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).          
38 + * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).          
39 + * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010).
40 + * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41   */
42  
43   #include "integrators/NVT.hpp"
44   #include "primitives/Molecule.hpp"
45   #include "utils/simError.h"
46 < #include "utils/OOPSEConstant.hpp"
46 > #include "utils/PhysicalConstants.hpp"
47  
48 < namespace oopse {
48 > namespace OpenMD {
49  
50 <  NVT::NVT(SimInfo* info) : VelocityVerletIntegrator(info), chiTolerance_ (1e-6), maxIterNum_(4) {
50 >  NVT::NVT(SimInfo* info) : VelocityVerletIntegrator(info), maxIterNum_(4),
51 >                            chiTolerance_(1e-6) {
52  
53      Globals* simParams = info_->getSimParams();
54  
55      if (!simParams->getUseIntialExtendedSystemState()) {
56 <      Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
57 <      currSnapshot->setChi(0.0);
56 <      currSnapshot->setIntegralOfChiDt(0.0);
56 >      Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot();
57 >      snap->setThermostat(make_pair(0.0, 0.0));
58      }
59      
60      if (!simParams->haveTargetTemp()) {
61        sprintf(painCave.errMsg, "You can't use the NVT integrator without a targetTemp_!\n");
62        painCave.isFatal = 1;
63 <      painCave.severity = OOPSE_ERROR;
63 >      painCave.severity = OPENMD_ERROR;
64        simError();
65      } else {
66        targetTemp_ = simParams->getTargetTemp();
67      }
68  
69 <    // We must set tauThermostat_.
69 >    // We must set tauThermostat.
70  
71      if (!simParams->haveTauThermostat()) {
72        sprintf(painCave.errMsg, "If you use the constant temperature\n"
73 <              "\tintegrator, you must set tauThermostat_.\n");
73 >              "\tintegrator, you must set tauThermostat.\n");
74  
75 <      painCave.severity = OOPSE_ERROR;
75 >      painCave.severity = OPENMD_ERROR;
76        painCave.isFatal = 1;
77        simError();
78      } else {
79        tauThermostat_ = simParams->getTauThermostat();
80      }
81  
82 <    update();
82 >    updateSizes();
83    }
84  
85 <  void NVT::doUpdate() {
85 >  void NVT::doUpdateSizes() {
86      oldVel_.resize(info_->getNIntegrableObjects());
87 <    oldJi_.resize(info_->getNIntegrableObjects());    
87 >    oldJi_.resize(info_->getNIntegrableObjects());
88    }
89 +
90    void NVT::moveA() {
91      SimInfo::MoleculeIterator i;
92      Molecule::IntegrableObjectIterator  j;
93      Molecule* mol;
94 <    StuntDouble* integrableObject;
94 >    StuntDouble* sd;
95      Vector3d Tb;
96      Vector3d ji;
97 <    double mass;
97 >    RealType mass;
98      Vector3d vel;
99      Vector3d pos;
100      Vector3d frc;
101  
102 <    double chi = currentSnapshot_->getChi();
103 <    double integralOfChidt = currentSnapshot_->getIntegralOfChiDt();
102 <    
102 >    pair<RealType, RealType> thermostat = snap->getThermostat();
103 >
104      // We need the temperature at time = t for the chi update below:
105  
106 <    double instTemp = thermo.getTemperature();
106 >    RealType instTemp = thermo.getTemperature();
107  
108 <    for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) {
109 <      for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
109 <           integrableObject = mol->nextIntegrableObject(j)) {
108 >    for (mol = info_->beginMolecule(i); mol != NULL;
109 >         mol = info_->nextMolecule(i)) {
110  
111 <        vel = integrableObject->getVel();
112 <        pos = integrableObject->getPos();
113 <        frc = integrableObject->getFrc();
111 >      for (sd = mol->beginIntegrableObject(j); sd != NULL;
112 >           sd = mol->nextIntegrableObject(j)) {
113  
114 <        mass = integrableObject->getMass();
114 >        vel = sd->getVel();
115 >        pos = sd->getPos();
116 >        frc = sd->getFrc();
117  
118 <        // velocity half step  (use chi from previous step here):
119 <        //vel[j] += dt2 * ((frc[j] / mass ) * OOPSEConstant::energyConvert - vel[j]*chi);
120 <        vel += dt2 *OOPSEConstant::energyConvert/mass*frc - dt2*chi*vel;
118 >        mass = sd->getMass();
119 >
120 >        // velocity half step (use chi from previous step here):
121 >        vel += dt2 *PhysicalConstants::energyConvert/mass*frc
122 >          - dt2*thermostat.first*vel;
123          
124          // position whole step
122        //pos[j] += dt * vel[j];
125          pos += dt * vel;
126  
127 <        integrableObject->setVel(vel);
128 <        integrableObject->setPos(pos);
127 >        sd->setVel(vel);
128 >        sd->setPos(pos);
129  
130 <        if (integrableObject->isDirectional()) {
130 >        if (sd->isDirectional()) {
131  
132            //convert the torque to body frame
133 <          Tb = integrableObject->lab2Body(integrableObject->getTrq());
133 >          Tb = sd->lab2Body(sd->getTrq());
134  
135            // get the angular momentum, and propagate a half step
136  
137 <          ji = integrableObject->getJ();
137 >          ji = sd->getJ();
138  
139 <          //ji[j] += dt2 * (Tb[j] * OOPSEConstant::energyConvert - ji[j]*chi);
140 <          ji += dt2*OOPSEConstant::energyConvert*Tb - dt2*chi *ji;
139 <          rotAlgo->rotate(integrableObject, ji, dt);
139 >          ji += dt2*PhysicalConstants::energyConvert*Tb
140 >            - dt2*thermostat.first *ji;
141  
142 <          integrableObject->setJ(ji);
142 >          rotAlgo_->rotate(sd, ji, dt);
143 >
144 >          sd->setJ(ji);
145          }
146        }
147  
148      }
149      
150 <    rattle->constraintA();
150 >    flucQ_->moveA();
151 >    rattle_->constraintA();
152  
153      // Finally, evolve chi a half step (just like a velocity) using
154      // temperature at time t, not time t+dt/2
155  
156 <    
157 <    chi += dt2 * (instTemp / targetTemp_ - 1.0) / (tauThermostat_ * tauThermostat_);
158 <    integralOfChidt += chi * dt2;
156 >    thermostat.first += dt2 * (instTemp / targetTemp_ - 1.0)
157 >      / (tauThermostat_ * tauThermostat_);
158 >    thermostat.second += thermostat.first * dt2;
159  
160 <    currentSnapshot_->setChi(chi);
157 <    currentSnapshot_->setIntegralOfChiDt(integralOfChidt);
160 >    snap->setThermostat(thermostat);
161    }
162  
163    void NVT::moveB() {
164      SimInfo::MoleculeIterator i;
165      Molecule::IntegrableObjectIterator  j;
166      Molecule* mol;
167 <    StuntDouble* integrableObject;
167 >    StuntDouble* sd;
168      
169      Vector3d Tb;
170      Vector3d ji;    
171      Vector3d vel;
172      Vector3d frc;
173 <    double mass;
174 <    double instTemp;
173 >    RealType mass;
174 >    RealType instTemp;
175      int index;
176      // Set things up for the iteration:
177  
178 <    double chi = currentSnapshot_->getChi();
179 <    double oldChi = chi;
180 <    double  prevChi;
178 <    double integralOfChidt = currentSnapshot_->getIntegralOfChiDt();
178 >    pair<RealType, RealType> thermostat = snap->getThermostat();
179 >    RealType oldChi = thermostat.first;
180 >    RealType  prevChi;
181  
182      index = 0;
183 <    for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) {
184 <      for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
183 <           integrableObject = mol->nextIntegrableObject(j)) {
184 <        oldVel_[index] = integrableObject->getVel();
185 <        oldJi_[index] = integrableObject->getJ();                
183 >    for (mol = info_->beginMolecule(i); mol != NULL;
184 >         mol = info_->nextMolecule(i)) {
185  
186 +      for (sd = mol->beginIntegrableObject(j); sd != NULL;
187 +           sd = mol->nextIntegrableObject(j)) {
188 +
189 +        oldVel_[index] = sd->getVel();
190 +        
191 +        if (sd->isDirectional())
192 +          oldJi_[index] = sd->getJ();                
193 +        
194          ++index;    
195 <      }
189 <          
195 >      }          
196      }
197  
198      // do the iteration:
# Line 197 | Line 203 | namespace oopse {
203  
204        // evolve chi another half step using the temperature at t + dt/2
205  
206 <      prevChi = chi;
207 <      chi = oldChi + dt2 * (instTemp / targetTemp_ - 1.0) / (tauThermostat_ * tauThermostat_);
206 >      prevChi = thermostat.first;
207 >      thermostat.first = oldChi + dt2 * (instTemp / targetTemp_ - 1.0)
208 >        / (tauThermostat_ * tauThermostat_);
209  
210 <      for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) {
211 <        for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
212 <             integrableObject = mol->nextIntegrableObject(j)) {
210 >      for (mol = info_->beginMolecule(i); mol != NULL;
211 >           mol = info_->nextMolecule(i)) {
212 >        
213 >        for (sd = mol->beginIntegrableObject(j); sd != NULL;
214 >             sd = mol->nextIntegrableObject(j)) {
215  
216 <          frc = integrableObject->getFrc();
217 <          vel = integrableObject->getVel();
216 >          frc = sd->getFrc();
217 >          mass = sd->getMass();
218  
210          mass = integrableObject->getMass();
211
219            // velocity half step
220 <          //for(j = 0; j < 3; j++)
221 <          //    vel[j] = oldVel_[3*i+j] + dt2 * ((frc[j] / mass ) * OOPSEConstant::energyConvert - oldVel_[3*i + j]*chi);
222 <          vel = oldVel_[index] + dt2/mass*OOPSEConstant::energyConvert * frc - dt2*chi*oldVel_[index];
220 >
221 >          vel = oldVel_[index]
222 >            + dt2/mass*PhysicalConstants::energyConvert * frc
223 >            - dt2*thermostat.first*oldVel_[index];
224              
225 <          integrableObject->setVel(vel);
225 >          sd->setVel(vel);
226  
227 <          if (integrableObject->isDirectional()) {
227 >          if (sd->isDirectional()) {
228  
229              // get and convert the torque to body frame
230  
231 <            Tb =  integrableObject->lab2Body(integrableObject->getTrq());
231 >            Tb =  sd->lab2Body(sd->getTrq());
232  
233 <            //for(j = 0; j < 3; j++)
234 <            //    ji[j] = oldJi_[3*i + j] + dt2 * (Tb[j] * OOPSEConstant::energyConvert - oldJi_[3*i+j]*chi);
227 <            ji = oldJi_[index] + dt2*OOPSEConstant::energyConvert*Tb - dt2*chi *oldJi_[index];
233 >            ji = oldJi_[index] + dt2*PhysicalConstants::energyConvert*Tb
234 >              - dt2*thermostat.first *oldJi_[index];
235  
236 <            integrableObject->setJ(ji);
236 >            sd->setJ(ji);
237            }
238  
239  
# Line 234 | Line 241 | namespace oopse {
241          }
242        }
243      
244 +      rattle_->constraintB();
245  
246 <      rattle->constraintB();
239 <
240 <      if (fabs(prevChi - chi) <= chiTolerance_)
246 >      if (fabs(prevChi - thermostat.first) <= chiTolerance_)
247          break;
248  
249      }
250  
251 <    integralOfChidt += dt2 * chi;
251 >    flucQ_->moveB();
252  
253 <    currentSnapshot_->setChi(chi);
254 <    currentSnapshot_->setIntegralOfChiDt(integralOfChidt);
253 >    thermostat.second += dt2 * thermostat.first;
254 >    snap->setThermostat(thermostat);
255    }
256  
257    void NVT::resetIntegrator() {
258 <      currentSnapshot_->setChi(0.0);
253 <      currentSnapshot_->setIntegralOfChiDt(0.0);
258 >    snap->setThermostat(make_pair(0.0, 0.0));
259    }
260    
261 <  double NVT::calcConservedQuantity() {
261 >  RealType NVT::calcConservedQuantity() {
262  
263 <    double chi = currentSnapshot_->getChi();
264 <    double integralOfChidt = currentSnapshot_->getIntegralOfChiDt();
265 <    double conservedQuantity;
266 <    double fkBT;
267 <    double Energy;
268 <    double thermostat_kinetic;
264 <    double thermostat_potential;
263 >    pair<RealType, RealType> thermostat = snap->getThermostat();
264 >    RealType conservedQuantity;
265 >    RealType fkBT;
266 >    RealType Energy;
267 >    RealType thermostat_kinetic;
268 >    RealType thermostat_potential;
269      
270 <    fkBT = info_->getNdf() *OOPSEConstant::kB *targetTemp_;
270 >    fkBT = info_->getNdf() *PhysicalConstants::kB *targetTemp_;
271  
272 <    Energy = thermo.getTotalE();
272 >    Energy = thermo.getTotalEnergy();
273  
274 <    thermostat_kinetic = fkBT * tauThermostat_ * tauThermostat_ * chi * chi / (2.0 * OOPSEConstant::energyConvert);
274 >    thermostat_kinetic = fkBT * tauThermostat_ * tauThermostat_ * thermostat.first * thermostat.first / (2.0 * PhysicalConstants::energyConvert);
275  
276 <    thermostat_potential = fkBT * integralOfChidt / OOPSEConstant::energyConvert;
276 >    thermostat_potential = fkBT * thermostat.second / PhysicalConstants::energyConvert;
277  
278      conservedQuantity = Energy + thermostat_kinetic + thermostat_potential;
279  
# Line 277 | Line 281 | namespace oopse {
281    }
282  
283  
284 < }//end namespace oopse
284 > }//end namespace OpenMD

Comparing trunk/src/integrators/NVT.cpp (property svn:keywords):
Revision 665 by tim, Thu Oct 13 22:26:47 2005 UTC vs.
Revision 2071 by gezelter, Sat Mar 7 21:41:51 2015 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines