ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/flucq/FluctuatingChargeLangevin.cpp
Revision: 1768
Committed: Sat Jul 7 03:59:27 2012 UTC (12 years, 10 months ago) by gezelter
File size: 7619 byte(s)
Log Message:
Fixed a bug in the FluctuatingChargeLangevin propagator, updated some samples.

File Contents

# User Rev Content
1 gezelter 1766 /*
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. Redistributions of source code must retain the above copyright
10     * notice, this list of conditions and the following disclaimer.
11     *
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.
16     *
17     * This software is provided "AS IS," without a warranty of any
18     * kind. All express or implied conditions, representations and
19     * warranties, including any implied warranty of merchantability,
20     * fitness for a particular purpose or non-infringement, are hereby
21     * excluded. The University of Notre Dame and its licensors shall not
22     * be liable for any damages suffered by licensee as a result of
23     * using, modifying or distributing the software or its
24     * derivatives. In no event will the University of Notre Dame or its
25     * licensors be liable for any lost revenue, profit or data, or for
26     * direct, indirect, special, consequential, incidental or punitive
27     * damages, however caused and regardless of the theory of liability,
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, 24107 (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 "FluctuatingChargeLangevin.hpp"
44     #include "primitives/Molecule.hpp"
45     #include "utils/simError.h"
46     #include "utils/PhysicalConstants.hpp"
47    
48    
49     namespace OpenMD {
50    
51     FluctuatingChargeLangevin::FluctuatingChargeLangevin(SimInfo* info) :
52     FluctuatingChargePropagator(info), maxIterNum_(4),
53     forceTolerance_(1e-6),
54     snap(info->getSnapshotManager()->getCurrentSnapshot()) {
55     }
56    
57     void FluctuatingChargeLangevin::initialize() {
58     FluctuatingChargePropagator::initialize();
59     if (hasFlucQ_) {
60     if (info_->getSimParams()->haveDt()) {
61     dt_ = info_->getSimParams()->getDt();
62     dt2_ = dt_ * 0.5;
63     } else {
64     sprintf(painCave.errMsg,
65     "FluctuatingChargeLangevin Error: dt is not set\n");
66     painCave.isFatal = 1;
67     simError();
68     }
69    
70     if (!fqParams_->haveTargetTemp()) {
71     sprintf(painCave.errMsg, "You can't use the FluctuatingChargeLangevin "
72     "propagator without a flucQ.targetTemp!\n");
73     painCave.isFatal = 1;
74     painCave.severity = OPENMD_ERROR;
75     simError();
76     } else {
77     targetTemp_ = fqParams_->getTargetTemp();
78     }
79    
80     // We must set tauThermostat.
81    
82     if (!fqParams_->haveDragCoefficient()) {
83     sprintf(painCave.errMsg, "If you use the FluctuatingChargeLangevin\n"
84     "\tpropagator, you must set flucQ.dragCoefficient .\n");
85    
86     painCave.severity = OPENMD_ERROR;
87     painCave.isFatal = 1;
88     simError();
89     } else {
90     drag_ = fqParams_->getDragCoefficient();
91     }
92     }
93    
94     variance_ = 2.0 * PhysicalConstants::kb * targetTemp_ * drag_ / dt_;
95     }
96    
97    
98     void FluctuatingChargeLangevin::moveA() {
99    
100     if (!hasFlucQ_) return;
101    
102     SimInfo::MoleculeIterator i;
103     Molecule::FluctuatingChargeIterator j;
104     Molecule* mol;
105     Atom* atom;
106     RealType cvel, cpos, cfrc, cmass;
107    
108     for (mol = info_->beginMolecule(i); mol != NULL;
109     mol = info_->nextMolecule(i)) {
110     for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
111     atom = mol->nextFluctuatingCharge(j)) {
112    
113     cvel = atom->getFlucQVel();
114     cpos = atom->getFlucQPos();
115     cfrc = atom->getFlucQFrc();
116     cmass = atom->getChargeMass();
117    
118     // velocity half step
119     cvel += dt2_ * cfrc / cmass;
120     // position whole step
121     cpos += dt_ * cvel;
122    
123     atom->setFlucQVel(cvel);
124     atom->setFlucQPos(cpos);
125     }
126     }
127     }
128    
129     void FluctuatingChargeLangevin::applyConstraints() {
130 gezelter 1768
131     if (!hasFlucQ_) return;
132    
133 gezelter 1766 SimInfo::MoleculeIterator i;
134     Molecule::FluctuatingChargeIterator j;
135     Molecule* mol;
136     Atom* atom;
137 gezelter 1767 RealType cvel, cpos, cfrc, cmass, randomForce, frictionForce;
138 gezelter 1766 RealType velStep, oldFF; // used to test for convergence
139    
140     for (mol = info_->beginMolecule(i); mol != NULL;
141     mol = info_->nextMolecule(i)) {
142     for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
143     atom = mol->nextFluctuatingCharge(j)) {
144    
145     cvel = atom->getFlucQVel();
146     cpos = atom->getFlucQPos();
147     cfrc = atom->getFlucQFrc();
148     cmass = atom->getChargeMass();
149    
150     randomForce = randNumGen_.randNorm(0, variance_ );
151     atom->addFlucQFrc(randomForce);
152    
153     // What remains contains velocity explicitly, but the velocity
154     // required is at the full step: v(t + h), while we have
155     // initially the velocity at the half step: v(t + h/2). We
156     // need to iterate to converge the friction force vector.
157    
158     // this is the velocity at the half-step:
159    
160     cvel = atom->getFlucQVel();
161    
162     // estimate velocity at full-step using everything but
163     // friction forces:
164    
165     cfrc = atom->getFlucQFrc();
166     velStep = cvel + dt2_ * cfrc / cmass;
167    
168     frictionForce = 0.0;
169     //iteration starts here:
170    
171     for (int k = 0; k < maxIterNum_; k++) {
172    
173     oldFF = frictionForce;
174     frictionForce = -drag_ * velStep;
175     // re-estimate velocities at full-step using friction forces:
176    
177     velStep = cvel + dt2_ * (cfrc + frictionForce) / cmass;
178    
179     // check for convergence
180    
181     if (fabs(frictionForce - oldFF) <= forceTolerance_)
182     break; // iteration ends here
183     }
184     //cerr << "rand = " << randomForce << " fric = " << frictionForce << "\n";
185     atom->addFlucQFrc(frictionForce);
186     }
187     }
188     fqConstraints_->applyConstraints();
189     }
190    
191     void FluctuatingChargeLangevin::moveB() {
192     if (!hasFlucQ_) return;
193     SimInfo::MoleculeIterator i;
194     Molecule::FluctuatingChargeIterator j;
195     Molecule* mol;
196     Atom* atom;
197     RealType cfrc, cvel, cmass;
198    
199     for (mol = info_->beginMolecule(i); mol != NULL;
200     mol = info_->nextMolecule(i)) {
201     for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
202     atom = mol->nextFluctuatingCharge(j)) {
203    
204     cvel =atom->getFlucQVel();
205     cfrc = atom->getFlucQFrc();
206     cmass = atom->getChargeMass();
207    
208     // velocity half step
209     cvel += (dt2_ * cfrc) / cmass;
210    
211     atom->setFlucQVel(cvel);
212     }
213     }
214     }
215    
216     void FluctuatingChargeLangevin::updateSizes() { }
217    
218     RealType FluctuatingChargeLangevin::calcConservedQuantity() {
219     return 0.0;
220     }
221     }

Properties

Name Value
svn:eol-style native
svn:executable *