| 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 |
jmichalk |
1735 |
// velocity half step |
| 127 |
|
|
cvel += dt2_ * cfrc / cmass - dt2_*chi*cvel; |
| 128 |
gezelter |
1716 |
// position whole step |
| 129 |
|
|
cpos += dt_ * cvel; |
| 130 |
jmichalk |
1735 |
|
| 131 |
gezelter |
1716 |
atom->setFlucQVel(cvel); |
| 132 |
|
|
atom->setFlucQPos(cpos); |
| 133 |
|
|
} |
| 134 |
|
|
} |
| 135 |
|
|
|
| 136 |
|
|
chi += dt2_ * (instTemp / targetTemp_ - 1.0) / |
| 137 |
|
|
(tauThermostat_ * tauThermostat_); |
| 138 |
|
|
|
| 139 |
|
|
integralOfChidt += chi * dt2_; |
| 140 |
gezelter |
1764 |
snap->setElectronicThermostat(make_pair(chi, integralOfChidt)); |
| 141 |
gezelter |
1716 |
} |
| 142 |
|
|
|
| 143 |
|
|
void FluctuatingChargeNVT::updateSizes() { |
| 144 |
|
|
oldVel_.resize(info_->getNFluctuatingCharges()); |
| 145 |
|
|
} |
| 146 |
|
|
|
| 147 |
|
|
void FluctuatingChargeNVT::moveB() { |
| 148 |
|
|
if (!hasFlucQ_) return; |
| 149 |
|
|
SimInfo::MoleculeIterator i; |
| 150 |
|
|
Molecule::FluctuatingChargeIterator j; |
| 151 |
|
|
Molecule* mol; |
| 152 |
|
|
Atom* atom; |
| 153 |
|
|
RealType instTemp; |
| 154 |
gezelter |
1764 |
pair<RealType, RealType> thermostat = snap->getElectronicThermostat(); |
| 155 |
|
|
RealType chi = thermostat.first; |
| 156 |
gezelter |
1716 |
RealType oldChi = chi; |
| 157 |
|
|
RealType prevChi; |
| 158 |
gezelter |
1764 |
RealType integralOfChidt = thermostat.second; |
| 159 |
gezelter |
1716 |
int index; |
| 160 |
|
|
RealType cfrc, cvel, cmass; |
| 161 |
|
|
|
| 162 |
|
|
index = 0; |
| 163 |
|
|
for (mol = info_->beginMolecule(i); mol != NULL; |
| 164 |
|
|
mol = info_->nextMolecule(i)) { |
| 165 |
|
|
for (atom = mol->beginFluctuatingCharge(j); atom != NULL; |
| 166 |
|
|
atom = mol->nextFluctuatingCharge(j)) { |
| 167 |
|
|
|
| 168 |
|
|
oldVel_[index] = atom->getFlucQVel(); |
| 169 |
|
|
++index; |
| 170 |
|
|
} |
| 171 |
|
|
} |
| 172 |
|
|
|
| 173 |
|
|
// do the iteration: |
| 174 |
|
|
|
| 175 |
|
|
for(int k = 0; k < maxIterNum_; k++) { |
| 176 |
|
|
index = 0; |
| 177 |
|
|
instTemp = thermo.getElectronicTemperature(); |
| 178 |
|
|
// evolve chi another half step using the temperature at t + dt/2 |
| 179 |
|
|
prevChi = chi; |
| 180 |
|
|
chi = oldChi + dt2_ * (instTemp / targetTemp_ - 1.0) / |
| 181 |
|
|
(tauThermostat_ * tauThermostat_); |
| 182 |
|
|
|
| 183 |
|
|
for (mol = info_->beginMolecule(i); mol != NULL; |
| 184 |
|
|
mol = info_->nextMolecule(i)) { |
| 185 |
|
|
for (atom = mol->beginFluctuatingCharge(j); atom != NULL; |
| 186 |
|
|
atom = mol->nextFluctuatingCharge(j)) { |
| 187 |
|
|
|
| 188 |
|
|
cfrc = atom->getFlucQFrc(); |
| 189 |
|
|
cvel =atom->getFlucQVel(); |
| 190 |
|
|
cmass = atom->getChargeMass(); |
| 191 |
|
|
|
| 192 |
|
|
// velocity half step |
| 193 |
jmichalk |
1735 |
cvel = oldVel_[index] + dt2_ * cfrc / cmass - dt2_*chi*oldVel_[index]; |
| 194 |
gezelter |
1716 |
atom->setFlucQVel(cvel); |
| 195 |
|
|
++index; |
| 196 |
|
|
} |
| 197 |
|
|
} |
| 198 |
|
|
if (fabs(prevChi - chi) <= chiTolerance_) |
| 199 |
|
|
break; |
| 200 |
|
|
} |
| 201 |
|
|
integralOfChidt += dt2_ * chi; |
| 202 |
gezelter |
1764 |
snap->setElectronicThermostat(make_pair(chi, integralOfChidt)); |
| 203 |
gezelter |
1716 |
} |
| 204 |
|
|
|
| 205 |
|
|
void FluctuatingChargeNVT::resetPropagator() { |
| 206 |
|
|
if (!hasFlucQ_) return; |
| 207 |
gezelter |
1764 |
snap->setElectronicThermostat(make_pair(0.0, 0.0)); |
| 208 |
gezelter |
1716 |
} |
| 209 |
|
|
|
| 210 |
|
|
RealType FluctuatingChargeNVT::calcConservedQuantity() { |
| 211 |
|
|
if (!hasFlucQ_) return 0.0; |
| 212 |
gezelter |
1764 |
pair<RealType, RealType> thermostat = snap->getElectronicThermostat(); |
| 213 |
|
|
RealType chi = thermostat.first; |
| 214 |
|
|
RealType integralOfChidt = thermostat.second; |
| 215 |
gezelter |
1716 |
RealType fkBT = info_->getNFluctuatingCharges() * |
| 216 |
|
|
PhysicalConstants::kB *targetTemp_; |
| 217 |
|
|
|
| 218 |
|
|
RealType thermostat_kinetic = fkBT * tauThermostat_ * tauThermostat_ * |
| 219 |
|
|
chi * chi / (2.0 * PhysicalConstants::energyConvert); |
| 220 |
|
|
|
| 221 |
|
|
RealType thermostat_potential = fkBT * integralOfChidt / |
| 222 |
|
|
PhysicalConstants::energyConvert; |
| 223 |
|
|
|
| 224 |
|
|
return thermostat_kinetic + thermostat_potential; |
| 225 |
|
|
} |
| 226 |
|
|
} |