| 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), maxIterNum_(4), |
| 53 |
< |
thermo(info), |
| 54 |
< |
currentSnapshot_(info->getSnapshotManager()->getCurrentSnapshot()) { |
| 54 |
< |
|
| 55 |
< |
if (info_->usesFluctuatingCharges()) { |
| 56 |
< |
if (info_->getNFluctuatingCharges() > 0) { |
| 57 |
< |
|
| 58 |
< |
hasFlucQ_ = true; |
| 59 |
< |
Globals* simParams = info_->getSimParams(); |
| 60 |
< |
|
| 61 |
< |
if (simParams->haveDt()) { |
| 62 |
< |
dt_ = simParams->getDt(); |
| 63 |
< |
dt2_ = dt_ * 0.5; |
| 64 |
< |
} else { |
| 65 |
< |
sprintf(painCave.errMsg, |
| 66 |
< |
"FluctuatingChargeNVT Error: dt is not set\n"); |
| 67 |
< |
painCave.isFatal = 1; |
| 68 |
< |
simError(); |
| 69 |
< |
} |
| 70 |
< |
|
| 71 |
< |
if (!simParams->getUseIntialExtendedSystemState()) { |
| 72 |
< |
currentSnapshot_->setChiElectronic(0.0); |
| 73 |
< |
currentSnapshot_->setIntegralOfChiElectronicDt(0.0); |
| 74 |
< |
} |
| 75 |
< |
|
| 76 |
< |
if (!simParams->haveFlucQTargetTemp()) { |
| 77 |
< |
sprintf(painCave.errMsg, "You can't use the FluctuatingChargeNVT " |
| 78 |
< |
"propagator without a flucQ.targetTemp!\n"); |
| 79 |
< |
painCave.isFatal = 1; |
| 80 |
< |
painCave.severity = OPENMD_ERROR; |
| 81 |
< |
simError(); |
| 82 |
< |
} else { |
| 83 |
< |
targetTemp_ = simParams->getFlucQTargetTemp(); |
| 84 |
< |
} |
| 85 |
< |
|
| 86 |
< |
// We must set tauThermostat. |
| 87 |
< |
|
| 88 |
< |
if (!simParams->haveFlucQtauThermostat()) { |
| 89 |
< |
sprintf(painCave.errMsg, "If you use the FluctuatingChargeNVT\n" |
| 90 |
< |
"\tpropagator, you must set flucQ.tauThermostat .\n"); |
| 91 |
< |
|
| 92 |
< |
painCave.severity = OPENMD_ERROR; |
| 93 |
< |
painCave.isFatal = 1; |
| 94 |
< |
simError(); |
| 95 |
< |
} else { |
| 96 |
< |
tauThermostat_ = simParams->getFlucQtauThermostat(); |
| 97 |
< |
} |
| 98 |
< |
updateSizes(); |
| 99 |
< |
} |
| 100 |
< |
} |
| 52 |
> |
FluctuatingChargePropagator(info), chiTolerance_ (1e-6), |
| 53 |
> |
maxIterNum_(4), thermo(info), |
| 54 |
> |
currentSnapshot_(info->getSnapshotManager()->getCurrentSnapshot()) { |
| 55 |
|
} |
| 56 |
|
|
| 57 |
|
void FluctuatingChargeNVT::initialize() { |
| 58 |
< |
|
| 59 |
< |
if (!hasFlucQ_) return; |
| 60 |
< |
|
| 61 |
< |
SimInfo::MoleculeIterator i; |
| 62 |
< |
Molecule::FluctuatingChargeIterator j; |
| 63 |
< |
Molecule* mol; |
| 64 |
< |
Atom* atom; |
| 65 |
< |
|
| 66 |
< |
for (mol = info_->beginMolecule(i); mol != NULL; |
| 67 |
< |
mol = info_->nextMolecule(i)) { |
| 114 |
< |
for (atom = mol->beginFluctuatingCharge(j); atom != NULL; |
| 115 |
< |
atom = mol->nextFluctuatingCharge(j)) { |
| 116 |
< |
atom->setFlucQPos(0.0); |
| 117 |
< |
atom->setFlucQVel(0.0); |
| 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 |
> |
"FluctuatingChargeNVT Error: dt is not set\n"); |
| 66 |
> |
painCave.isFatal = 1; |
| 67 |
> |
simError(); |
| 68 |
|
} |
| 69 |
+ |
|
| 70 |
+ |
if (!info_->getSimParams()->getUseIntialExtendedSystemState()) { |
| 71 |
+ |
currentSnapshot_->setChiElectronic(0.0); |
| 72 |
+ |
currentSnapshot_->setIntegralOfChiElectronicDt(0.0); |
| 73 |
+ |
} |
| 74 |
+ |
|
| 75 |
+ |
if (!fqParams_->haveTargetTemp()) { |
| 76 |
+ |
sprintf(painCave.errMsg, "You can't use the FluctuatingChargeNVT " |
| 77 |
+ |
"propagator without a flucQ.targetTemp!\n"); |
| 78 |
+ |
painCave.isFatal = 1; |
| 79 |
+ |
painCave.severity = OPENMD_ERROR; |
| 80 |
+ |
simError(); |
| 81 |
+ |
} else { |
| 82 |
+ |
targetTemp_ = fqParams_->getTargetTemp(); |
| 83 |
+ |
} |
| 84 |
+ |
|
| 85 |
+ |
// We must set tauThermostat. |
| 86 |
+ |
|
| 87 |
+ |
if (!fqParams_->haveTauThermostat()) { |
| 88 |
+ |
sprintf(painCave.errMsg, "If you use the FluctuatingChargeNVT\n" |
| 89 |
+ |
"\tpropagator, you must set flucQ.tauThermostat .\n"); |
| 90 |
+ |
|
| 91 |
+ |
painCave.severity = OPENMD_ERROR; |
| 92 |
+ |
painCave.isFatal = 1; |
| 93 |
+ |
simError(); |
| 94 |
+ |
} else { |
| 95 |
+ |
tauThermostat_ = fqParams_->getTauThermostat(); |
| 96 |
+ |
} |
| 97 |
+ |
updateSizes(); |
| 98 |
|
} |
| 120 |
– |
|
| 121 |
– |
cerr << "Yeah, you should probably implement this\n"; |
| 99 |
|
} |
| 100 |
|
|
| 101 |
+ |
|
| 102 |
|
void FluctuatingChargeNVT::moveA() { |
| 103 |
|
|
| 104 |
|
if (!hasFlucQ_) return; |
| 113 |
|
RealType integralOfChidt = currentSnapshot_->getIntegralOfChiElectronicDt(); |
| 114 |
|
RealType instTemp = thermo.getElectronicTemperature(); |
| 115 |
|
|
| 138 |
– |
cerr << "why are we here?\n"; |
| 139 |
– |
|
| 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 |
< |
|
| 126 |
< |
// velocity half step |
| 127 |
< |
cvel += dt2_ *PhysicalConstants::energyConvert/cmass*cfrc - dt2_*chi*cvel; |
| 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 |
< |
|
| 130 |
> |
|
| 131 |
|
atom->setFlucQVel(cvel); |
| 132 |
|
atom->setFlucQPos(cpos); |
| 133 |
|
} |
| 143 |
|
} |
| 144 |
|
|
| 145 |
|
void FluctuatingChargeNVT::updateSizes() { |
| 170 |
– |
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(); |
| 204 |
– |
|
| 179 |
|
// evolve chi another half step using the temperature at t + dt/2 |
| 180 |
|
prevChi = chi; |
| 181 |
|
chi = oldChi + dt2_ * (instTemp / targetTemp_ - 1.0) / |
| 191 |
|
cmass = atom->getChargeMass(); |
| 192 |
|
|
| 193 |
|
// velocity half step |
| 194 |
< |
cvel = oldVel_[index] + dt2_/cmass*PhysicalConstants::energyConvert * cfrc - dt2_*chi*oldVel_[index]; |
| 221 |
< |
|
| 194 |
> |
cvel = oldVel_[index] + dt2_ * cfrc / cmass - dt2_*chi*oldVel_[index]; |
| 195 |
|
atom->setFlucQVel(cvel); |
| 196 |
|
++index; |
| 197 |
|
} |