ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-4/src/integrators/NVT.cpp
Revision: 1927
Committed: Wed Jan 12 17:14:35 2005 UTC (21 years, 4 months ago) by tim
File size: 9263 byte(s)
Log Message:
change license

File Contents

# User Rev Content
1 tim 1927 /*
2     * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3     *
4     * The University of Notre Dame grants you ("Licensee") a
5     * non-exclusive, royalty free, license to use, modify and
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
19     * notice, this list of conditions and the following disclaimer.
20     *
21     * 3. Redistributions in binary form must reproduce the above copyright
22     * notice, this list of conditions and the following disclaimer in the
23     * documentation and/or other materials provided with the
24     * distribution.
25     *
26     * This software is provided "AS IS," without a warranty of any
27     * kind. All express or implied conditions, representations and
28     * warranties, including any implied warranty of merchantability,
29     * fitness for a particular purpose or non-infringement, are hereby
30     * excluded. The University of Notre Dame and its licensors shall not
31     * be liable for any damages suffered by licensee as a result of
32     * using, modifying or distributing the software or its
33     * derivatives. In no event will the University of Notre Dame or its
34     * licensors be liable for any lost revenue, profit or data, or for
35     * direct, indirect, special, consequential, incidental or punitive
36     * damages, however caused and regardless of the theory of liability,
37     * arising out of the use of or inability to use software, even if the
38     * University of Notre Dame has been advised of the possibility of
39     * such damages.
40     */
41    
42 tim 1821 #include "integrators/NVT.hpp"
43     #include "primitives/Molecule.hpp"
44     #include "utils/simError.h"
45     #include "utils/OOPSEConstant.hpp"
46 tim 1837
47 tim 1765 namespace oopse {
48 tim 1762
49 tim 1774 NVT::NVT(SimInfo* info) : VelocityVerletIntegrator(info), chiTolerance_ (1e-6) {
50 tim 1762
51 tim 1841 Globals* simParams = info_->getSimParams();
52 tim 1762
53 tim 1841 if (simParams->getUseInitXSstate()) {
54 tim 1774 Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
55     currSnapshot->setChi(0.0);
56     currSnapshot->setIntegralOfChiDt(0.0);
57     }
58    
59 tim 1841 if (!simParams->haveTargetTemp()) {
60 tim 1774 sprintf(painCave.errMsg, "You can't use the NVT integrator without a targetTemp_!\n");
61     painCave.isFatal = 1;
62     painCave.severity = OOPSE_ERROR;
63     simError();
64     } else {
65 tim 1841 targetTemp_ = simParams->getTargetTemp();
66 tim 1774 }
67 tim 1762
68 tim 1774 // We must set tauThermostat_.
69 tim 1762
70 tim 1841 if (!simParams->haveTauThermostat()) {
71 tim 1774 sprintf(painCave.errMsg, "If you use the constant temperature\n"
72     "\tintegrator, you must set tauThermostat_.\n");
73 tim 1762
74 tim 1774 painCave.severity = OOPSE_ERROR;
75     painCave.isFatal = 1;
76     simError();
77     } else {
78 tim 1841 tauThermostat_ = simParams->getTauThermostat();
79 tim 1762 }
80    
81 tim 1774 update();
82 tim 1762 }
83    
84 tim 1867 void NVT::doUpdate() {
85 tim 1774 oldVel_.resize(info_->getNIntegrableObjects());
86     oldJi_.resize(info_->getNIntegrableObjects());
87     }
88 tim 1765 void NVT::moveA() {
89 tim 1821 SimInfo::MoleculeIterator i;
90     Molecule::IntegrableObjectIterator j;
91 tim 1765 Molecule* mol;
92     StuntDouble* integrableObject;
93 tim 1762 Vector3d Tb;
94     Vector3d ji;
95     double mass;
96     Vector3d vel;
97     Vector3d pos;
98     Vector3d frc;
99    
100 tim 1867 double chi = currentSnapshot_->getChi();
101     double integralOfChidt = currentSnapshot_->getIntegralOfChiDt();
102 tim 1821
103 tim 1762 // We need the temperature at time = t for the chi update below:
104    
105 tim 1821 double instTemp = thermo.getTemperature();
106 tim 1762
107 tim 1765 for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) {
108     for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
109     integrableObject = mol->nextIntegrableObject(j)) {
110 tim 1762
111 tim 1765 vel = integrableObject->getVel();
112     pos = integrableObject->getPos();
113     frc = integrableObject->getFrc();
114 tim 1762
115 tim 1765 mass = integrableObject->getMass();
116 tim 1762
117 tim 1765 // velocity half step (use chi from previous step here):
118 tim 1821 //vel[j] += dt2 * ((frc[j] / mass ) * OOPSEConstant::energyConvert - vel[j]*chi);
119 tim 1852 vel += dt2 *OOPSEConstant::energyConvert/mass*frc - dt2*chi*vel;
120 tim 1765
121     // position whole step
122     //pos[j] += dt * vel[j];
123 tim 1774 pos += dt * vel;
124 tim 1762
125 tim 1765 integrableObject->setVel(vel);
126     integrableObject->setPos(pos);
127 tim 1762
128 tim 1765 if (integrableObject->isDirectional()) {
129 tim 1762
130 tim 1871 //convert the torque to body frame
131     Tb = integrableObject->lab2Body(integrableObject->getTrq());
132 tim 1762
133     // get the angular momentum, and propagate a half step
134    
135 tim 1765 ji = integrableObject->getJ();
136 tim 1762
137 tim 1821 //ji[j] += dt2 * (Tb[j] * OOPSEConstant::energyConvert - ji[j]*chi);
138     ji += dt2*OOPSEConstant::energyConvert*Tb - dt2*chi *ji;
139     rotAlgo->rotate(integrableObject, ji, dt);
140 tim 1762
141 tim 1765 integrableObject->setJ(ji);
142 tim 1762 }
143     }
144    
145 tim 1765 }
146    
147 tim 1901 rattle->constraintA();
148 tim 1762
149     // Finally, evolve chi a half step (just like a velocity) using
150     // temperature at time t, not time t+dt/2
151    
152 tim 1765
153 tim 1774 chi += dt2 * (instTemp / targetTemp_ - 1.0) / (tauThermostat_ * tauThermostat_);
154     integralOfChidt += chi * dt2;
155 tim 1762
156 tim 1867 currentSnapshot_->setChi(chi);
157     currentSnapshot_->setIntegralOfChiDt(integralOfChidt);
158 tim 1762 }
159    
160 tim 1765 void NVT::moveB() {
161 tim 1821 SimInfo::MoleculeIterator i;
162     Molecule::IntegrableObjectIterator j;
163 tim 1765 Molecule* mol;
164     StuntDouble* integrableObject;
165    
166     Vector3d Tb;
167     Vector3d ji;
168     Vector3d vel;
169     Vector3d frc;
170 tim 1762 double mass;
171     double instTemp;
172 tim 1765 int index;
173 tim 1762 // Set things up for the iteration:
174    
175 tim 1867 double chi = currentSnapshot_->getChi();
176 tim 1821 double oldChi = chi;
177     double prevChi;
178 tim 1867 double integralOfChidt = currentSnapshot_->getIntegralOfChiDt();
179 tim 1762
180 tim 1765 index = 0;
181     for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) {
182     for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
183     integrableObject = mol->nextIntegrableObject(j)) {
184     oldVel_[index] = integrableObject->getVel();
185     oldJi_[index] = integrableObject->getJ();
186 tim 1868
187     ++index;
188 tim 1762 }
189 tim 1868
190 tim 1762 }
191    
192     // do the iteration:
193    
194 tim 1765 for(int k = 0; k < maxIterNum_; k++) {
195     index = 0;
196 tim 1821 instTemp = thermo.getTemperature();
197 tim 1762
198     // evolve chi another half step using the temperature at t + dt/2
199    
200     prevChi = chi;
201 tim 1774 chi = oldChi + dt2 * (instTemp / targetTemp_ - 1.0) / (tauThermostat_ * tauThermostat_);
202 tim 1762
203 tim 1765 for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) {
204     for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
205     integrableObject = mol->nextIntegrableObject(j)) {
206 tim 1762
207 tim 1765 frc = integrableObject->getFrc();
208     vel = integrableObject->getVel();
209 tim 1762
210 tim 1765 mass = integrableObject->getMass();
211 tim 1762
212 tim 1765 // velocity half step
213     //for(j = 0; j < 3; j++)
214 tim 1821 // vel[j] = oldVel_[3*i+j] + dt2 * ((frc[j] / mass ) * OOPSEConstant::energyConvert - oldVel_[3*i + j]*chi);
215     vel = oldVel_[index] + dt2/mass*OOPSEConstant::energyConvert * frc - dt2*chi*oldVel_[index];
216 tim 1765
217     integrableObject->setVel(vel);
218 tim 1762
219 tim 1765 if (integrableObject->isDirectional()) {
220 tim 1762
221 tim 1765 // get and convert the torque to body frame
222 tim 1762
223 tim 1871 Tb = integrableObject->lab2Body(integrableObject->getTrq());
224 tim 1762
225 tim 1765 //for(j = 0; j < 3; j++)
226 tim 1821 // ji[j] = oldJi_[3*i + j] + dt2 * (Tb[j] * OOPSEConstant::energyConvert - oldJi_[3*i+j]*chi);
227 tim 1868 ji = oldJi_[index] + dt2*OOPSEConstant::energyConvert*Tb - dt2*chi *oldJi_[index];
228 tim 1762
229 tim 1765 integrableObject->setJ(ji);
230     }
231 tim 1852
232    
233     ++index;
234 tim 1762 }
235     }
236 tim 1765
237 tim 1762
238 tim 1901 rattle->constraintB();
239 tim 1762
240 tim 1821 if (fabs(prevChi - chi) <= chiTolerance_)
241 tim 1762 break;
242 tim 1765
243 tim 1762 }
244    
245 tim 1774 integralOfChidt += dt2 * chi;
246 tim 1762
247 tim 1867 currentSnapshot_->setChi(chi);
248     currentSnapshot_->setIntegralOfChiDt(integralOfChidt);
249 tim 1762 }
250    
251    
252 tim 1774 double NVT::calcConservedQuantity() {
253 tim 1867
254     double chi = currentSnapshot_->getChi();
255     double integralOfChidt = currentSnapshot_->getIntegralOfChiDt();
256 tim 1762 double conservedQuantity;
257     double fkBT;
258     double Energy;
259     double thermostat_kinetic;
260     double thermostat_potential;
261 tim 1821
262     fkBT = info_->getNdf() *OOPSEConstant::kB *targetTemp_;
263 tim 1762
264 tim 1821 Energy = thermo.getTotalE();
265 tim 1762
266 tim 1821 thermostat_kinetic = fkBT * tauThermostat_ * tauThermostat_ * chi * chi / (2.0 * OOPSEConstant::energyConvert);
267 tim 1762
268 tim 1821 thermostat_potential = fkBT * integralOfChidt / OOPSEConstant::energyConvert;
269 tim 1762
270     conservedQuantity = Energy + thermostat_kinetic + thermostat_potential;
271    
272     return conservedQuantity;
273     }
274    
275    
276 tim 1765 }//end namespace oopse