ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/flucq/FluctuatingChargeLangevin.cpp
Revision: 1850
Committed: Wed Feb 20 15:39:39 2013 UTC (12 years, 3 months ago) by gezelter
File size: 7578 byte(s)
Log Message:
Fixed a widespread typo in the license 

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 gezelter 1850 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
39 gezelter 1766 * [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 1826 RealType cvel, 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     cfrc = atom->getFlucQFrc();
147     cmass = atom->getChargeMass();
148    
149     randomForce = randNumGen_.randNorm(0, variance_ );
150     atom->addFlucQFrc(randomForce);
151    
152     // What remains contains velocity explicitly, but the velocity
153     // required is at the full step: v(t + h), while we have
154     // initially the velocity at the half step: v(t + h/2). We
155     // need to iterate to converge the friction force vector.
156    
157     // this is the velocity at the half-step:
158    
159     cvel = atom->getFlucQVel();
160    
161     // estimate velocity at full-step using everything but
162     // friction forces:
163    
164     cfrc = atom->getFlucQFrc();
165     velStep = cvel + dt2_ * cfrc / cmass;
166    
167     frictionForce = 0.0;
168     //iteration starts here:
169    
170     for (int k = 0; k < maxIterNum_; k++) {
171    
172     oldFF = frictionForce;
173     frictionForce = -drag_ * velStep;
174     // re-estimate velocities at full-step using friction forces:
175    
176     velStep = cvel + dt2_ * (cfrc + frictionForce) / cmass;
177    
178     // check for convergence
179    
180     if (fabs(frictionForce - oldFF) <= forceTolerance_)
181     break; // iteration ends here
182     }
183     //cerr << "rand = " << randomForce << " fric = " << frictionForce << "\n";
184     atom->addFlucQFrc(frictionForce);
185     }
186     }
187     fqConstraints_->applyConstraints();
188     }
189    
190     void FluctuatingChargeLangevin::moveB() {
191     if (!hasFlucQ_) return;
192     SimInfo::MoleculeIterator i;
193     Molecule::FluctuatingChargeIterator j;
194     Molecule* mol;
195     Atom* atom;
196     RealType cfrc, cvel, cmass;
197    
198     for (mol = info_->beginMolecule(i); mol != NULL;
199     mol = info_->nextMolecule(i)) {
200     for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
201     atom = mol->nextFluctuatingCharge(j)) {
202    
203     cvel =atom->getFlucQVel();
204     cfrc = atom->getFlucQFrc();
205     cmass = atom->getChargeMass();
206    
207     // velocity half step
208     cvel += (dt2_ * cfrc) / cmass;
209    
210     atom->setFlucQVel(cvel);
211     }
212     }
213     }
214    
215     void FluctuatingChargeLangevin::updateSizes() { }
216    
217     RealType FluctuatingChargeLangevin::calcConservedQuantity() {
218     return 0.0;
219     }
220     }

Properties

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