| 45 |
|
#include "utils/simError.h" |
| 46 |
|
#include "utils/PhysicalConstants.hpp" |
| 47 |
|
|
| 48 |
+ |
|
| 49 |
|
namespace OpenMD { |
| 50 |
|
|
| 51 |
|
FluctuatingChargeNVT::FluctuatingChargeNVT(SimInfo* info) : |
| 52 |
|
FluctuatingChargePropagator(info), chiTolerance_ (1e-6), |
| 53 |
< |
maxIterNum_(4), thermo(info), |
| 54 |
< |
currentSnapshot_(info->getSnapshotManager()->getCurrentSnapshot()) { |
| 55 |
< |
|
| 56 |
< |
if (hasFlucQ_) { |
| 53 |
> |
maxIterNum_(4), thermo(info), |
| 54 |
> |
currentSnapshot_(info->getSnapshotManager()->getCurrentSnapshot()) { |
| 55 |
> |
} |
| 56 |
> |
|
| 57 |
> |
void FluctuatingChargeNVT::initialize() { |
| 58 |
> |
FluctuatingChargePropagator::initialize(); |
| 59 |
> |
if (hasFlucQ_) { |
| 60 |
|
if (info_->getSimParams()->haveDt()) { |
| 61 |
|
dt_ = info_->getSimParams()->getDt(); |
| 62 |
|
dt2_ = dt_ * 0.5; |
| 94 |
|
} else { |
| 95 |
|
tauThermostat_ = fqParams_->getTauThermostat(); |
| 96 |
|
} |
| 97 |
< |
updateSizes(); |
| 97 |
> |
updateSizes(); |
| 98 |
|
} |
| 99 |
|
} |
| 100 |
|
|
| 97 |
– |
void FluctuatingChargeNVT::initialize() { |
| 98 |
– |
FluctuatingChargePropagator::initialize(); |
| 99 |
– |
} |
| 101 |
|
|
| 101 |
– |
|
| 102 |
|
void FluctuatingChargeNVT::moveA() { |
| 103 |
|
|
| 104 |
|
if (!hasFlucQ_) return; |
| 113 |
|
RealType integralOfChidt = currentSnapshot_->getIntegralOfChiElectronicDt(); |
| 114 |
|
RealType instTemp = thermo.getElectronicTemperature(); |
| 115 |
|
|
| 116 |
– |
|
| 116 |
|
for (mol = info_->beginMolecule(i); mol != NULL; |
| 117 |
|
mol = info_->nextMolecule(i)) { |
| 118 |
|
for (atom = mol->beginFluctuatingCharge(j); atom != NULL; |
| 121 |
|
cvel = atom->getFlucQVel(); |
| 122 |
|
cpos = atom->getFlucQPos(); |
| 123 |
|
cfrc = atom->getFlucQFrc(); |
| 124 |
< |
cmass = atom->getChargeMass(); |
| 125 |
< |
|
| 127 |
< |
cerr << atom->getType() << "\n"; |
| 128 |
< |
cerr << "Before\n"; |
| 129 |
< |
cerr << "cvel: " << cvel << "\tcpos: " << cpos << "\tcfrc: " << cfrc << "\tcmass: " << cmass << "\n"; |
| 130 |
< |
|
| 124 |
> |
cmass = atom->getChargeMass(); |
| 125 |
> |
|
| 126 |
|
// velocity half step |
| 127 |
|
cvel += dt2_ * cfrc / cmass - dt2_*chi*cvel; |
| 128 |
|
// position whole step |
| 129 |
|
cpos += dt_ * cvel; |
| 130 |
|
|
| 136 |
– |
cerr << "After\n"; |
| 137 |
– |
cerr << "cvel: " << cvel << "\tcpos: " << cpos << "\n\n"; |
| 138 |
– |
|
| 131 |
|
atom->setFlucQVel(cvel); |
| 132 |
|
atom->setFlucQPos(cpos); |
| 133 |
|
} |
| 137 |
|
(tauThermostat_ * tauThermostat_); |
| 138 |
|
|
| 139 |
|
integralOfChidt += chi * dt2_; |
| 148 |
– |
cerr << "Move A instTemp: " << instTemp << "\n"; |
| 140 |
|
currentSnapshot_->setChiElectronic(chi); |
| 141 |
|
currentSnapshot_->setIntegralOfChiElectronicDt(integralOfChidt); |
| 142 |
|
|
| 143 |
|
} |
| 144 |
|
|
| 145 |
|
void FluctuatingChargeNVT::updateSizes() { |
| 155 |
– |
if (!hasFlucQ_) return; |
| 146 |
|
oldVel_.resize(info_->getNFluctuatingCharges()); |
| 147 |
|
} |
| 148 |
|
|
| 176 |
|
for(int k = 0; k < maxIterNum_; k++) { |
| 177 |
|
index = 0; |
| 178 |
|
instTemp = thermo.getElectronicTemperature(); |
| 189 |
– |
cerr << "MoveB instTemp: " << instTemp << "\n"; |
| 179 |
|
// evolve chi another half step using the temperature at t + dt/2 |
| 180 |
|
prevChi = chi; |
| 181 |
|
chi = oldChi + dt2_ * (instTemp / targetTemp_ - 1.0) / |
| 192 |
|
|
| 193 |
|
// velocity half step |
| 194 |
|
cvel = oldVel_[index] + dt2_ * cfrc / cmass - dt2_*chi*oldVel_[index]; |
| 206 |
– |
|
| 195 |
|
atom->setFlucQVel(cvel); |
| 196 |
|
++index; |
| 197 |
|
} |