ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/flucq/FluctuatingChargeNVT.cpp
Revision: 2071
Committed: Sat Mar 7 21:41:51 2015 UTC (10 years, 4 months ago) by gezelter
File size: 7883 byte(s)
Log Message:
Reducing the number of warnings when using g++ to compile.

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

Properties

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