ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/flucq/FluctuatingChargeNVT.cpp
Revision: 1766
Committed: Thu Jul 5 17:08:25 2012 UTC (12 years, 10 months ago) by gezelter
File size: 8048 byte(s)
Log Message:
Added Fluctuating Charge Langevin propagator, and made it the default
fixed some errors on the one-center slater coulomb integrals, and some
parameters in PhysicalConstants.


File Contents

# User Rev Content
1 gezelter 1716 /*
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 "FluctuatingChargeNVT.hpp"
44     #include "primitives/Molecule.hpp"
45     #include "utils/simError.h"
46     #include "utils/PhysicalConstants.hpp"
47    
48 gezelter 1761
49 gezelter 1716 namespace OpenMD {
50    
51 gezelter 1760 FluctuatingChargeNVT::FluctuatingChargeNVT(SimInfo* info) :
52     FluctuatingChargePropagator(info), chiTolerance_ (1e-6),
53 gezelter 1761 maxIterNum_(4), thermo(info),
54 gezelter 1764 snap(info->getSnapshotManager()->getCurrentSnapshot()) {
55 gezelter 1761 }
56    
57     void FluctuatingChargeNVT::initialize() {
58     FluctuatingChargePropagator::initialize();
59     if (hasFlucQ_) {
60 gezelter 1739 if (info_->getSimParams()->haveDt()) {
61     dt_ = info_->getSimParams()->getDt();
62     dt2_ = dt_ * 0.5;
63     } else {
64     sprintf(painCave.errMsg,
65     "FluctuatingChargeNVT Error: dt is not set\n");
66     painCave.isFatal = 1;
67     simError();
68     }
69    
70     if (!info_->getSimParams()->getUseIntialExtendedSystemState()) {
71 gezelter 1764 snap->setElectronicThermostat(make_pair(0.0, 0.0));
72 gezelter 1739 }
73    
74     if (!fqParams_->haveTargetTemp()) {
75     sprintf(painCave.errMsg, "You can't use the FluctuatingChargeNVT "
76     "propagator without a flucQ.targetTemp!\n");
77     painCave.isFatal = 1;
78     painCave.severity = OPENMD_ERROR;
79     simError();
80     } else {
81     targetTemp_ = fqParams_->getTargetTemp();
82     }
83    
84     // We must set tauThermostat.
85    
86     if (!fqParams_->haveTauThermostat()) {
87     sprintf(painCave.errMsg, "If you use the FluctuatingChargeNVT\n"
88     "\tpropagator, you must set flucQ.tauThermostat .\n");
89 gezelter 1716
90 gezelter 1739 painCave.severity = OPENMD_ERROR;
91     painCave.isFatal = 1;
92     simError();
93     } else {
94     tauThermostat_ = fqParams_->getTauThermostat();
95 gezelter 1716 }
96 gezelter 1761 updateSizes();
97 gezelter 1739 }
98 gezelter 1716 }
99    
100    
101     void FluctuatingChargeNVT::moveA() {
102    
103     if (!hasFlucQ_) return;
104    
105     SimInfo::MoleculeIterator i;
106     Molecule::FluctuatingChargeIterator j;
107     Molecule* mol;
108     Atom* atom;
109     RealType cvel, cpos, cfrc, cmass;
110    
111 gezelter 1764 pair<RealType, RealType> thermostat = snap->getElectronicThermostat();
112     RealType chi = thermostat.first;
113     RealType integralOfChidt = thermostat.second;
114 gezelter 1716 RealType instTemp = thermo.getElectronicTemperature();
115    
116     for (mol = info_->beginMolecule(i); mol != NULL;
117     mol = info_->nextMolecule(i)) {
118     for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
119     atom = mol->nextFluctuatingCharge(j)) {
120    
121     cvel = atom->getFlucQVel();
122     cpos = atom->getFlucQPos();
123     cfrc = atom->getFlucQFrc();
124 gezelter 1761 cmass = atom->getChargeMass();
125    
126 gezelter 1766 cerr << cpos << "\t" << cvel << "\t" << cfrc << "\t" << instTemp << "\t" <<chi << "\t" << integralOfChidt << "\n";
127 jmichalk 1735 // velocity half step
128     cvel += dt2_ * cfrc / cmass - dt2_*chi*cvel;
129 gezelter 1716 // position whole step
130     cpos += dt_ * cvel;
131 jmichalk 1735
132 gezelter 1716 atom->setFlucQVel(cvel);
133     atom->setFlucQPos(cpos);
134     }
135     }
136    
137     chi += dt2_ * (instTemp / targetTemp_ - 1.0) /
138     (tauThermostat_ * tauThermostat_);
139    
140     integralOfChidt += chi * dt2_;
141 gezelter 1764 snap->setElectronicThermostat(make_pair(chi, integralOfChidt));
142 gezelter 1716 }
143    
144     void FluctuatingChargeNVT::updateSizes() {
145     oldVel_.resize(info_->getNFluctuatingCharges());
146     }
147    
148     void FluctuatingChargeNVT::moveB() {
149     if (!hasFlucQ_) return;
150     SimInfo::MoleculeIterator i;
151     Molecule::FluctuatingChargeIterator j;
152     Molecule* mol;
153     Atom* atom;
154     RealType instTemp;
155 gezelter 1764 pair<RealType, RealType> thermostat = snap->getElectronicThermostat();
156     RealType chi = thermostat.first;
157 gezelter 1716 RealType oldChi = chi;
158     RealType prevChi;
159 gezelter 1764 RealType integralOfChidt = thermostat.second;
160 gezelter 1716 int index;
161     RealType cfrc, cvel, cmass;
162    
163     index = 0;
164     for (mol = info_->beginMolecule(i); mol != NULL;
165     mol = info_->nextMolecule(i)) {
166     for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
167     atom = mol->nextFluctuatingCharge(j)) {
168    
169     oldVel_[index] = atom->getFlucQVel();
170     ++index;
171     }
172     }
173    
174     // do the iteration:
175    
176     for(int k = 0; k < maxIterNum_; k++) {
177     index = 0;
178     instTemp = thermo.getElectronicTemperature();
179     // evolve chi another half step using the temperature at t + dt/2
180     prevChi = chi;
181     chi = oldChi + dt2_ * (instTemp / targetTemp_ - 1.0) /
182     (tauThermostat_ * tauThermostat_);
183    
184     for (mol = info_->beginMolecule(i); mol != NULL;
185     mol = info_->nextMolecule(i)) {
186     for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
187     atom = mol->nextFluctuatingCharge(j)) {
188    
189     cfrc = atom->getFlucQFrc();
190     cvel =atom->getFlucQVel();
191     cmass = atom->getChargeMass();
192    
193     // velocity half step
194 jmichalk 1735 cvel = oldVel_[index] + dt2_ * cfrc / cmass - dt2_*chi*oldVel_[index];
195 gezelter 1716 atom->setFlucQVel(cvel);
196     ++index;
197     }
198     }
199     if (fabs(prevChi - chi) <= chiTolerance_)
200     break;
201     }
202     integralOfChidt += dt2_ * chi;
203 gezelter 1764 snap->setElectronicThermostat(make_pair(chi, integralOfChidt));
204 gezelter 1716 }
205    
206     void FluctuatingChargeNVT::resetPropagator() {
207     if (!hasFlucQ_) return;
208 gezelter 1764 snap->setElectronicThermostat(make_pair(0.0, 0.0));
209 gezelter 1716 }
210    
211     RealType FluctuatingChargeNVT::calcConservedQuantity() {
212     if (!hasFlucQ_) return 0.0;
213 gezelter 1764 pair<RealType, RealType> thermostat = snap->getElectronicThermostat();
214     RealType chi = thermostat.first;
215     RealType integralOfChidt = thermostat.second;
216 gezelter 1716 RealType fkBT = info_->getNFluctuatingCharges() *
217     PhysicalConstants::kB *targetTemp_;
218    
219     RealType thermostat_kinetic = fkBT * tauThermostat_ * tauThermostat_ *
220     chi * chi / (2.0 * PhysicalConstants::energyConvert);
221    
222     RealType thermostat_potential = fkBT * integralOfChidt /
223     PhysicalConstants::energyConvert;
224    
225     return thermostat_kinetic + thermostat_potential;
226     }
227     }

Properties

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