45#include "FluctuatingChargeLangevin.hpp"
50#include "utils/Constants.hpp"
51#include "utils/simError.h"
55 FluctuatingChargeLangevin::FluctuatingChargeLangevin(
SimInfo* info) :
57 snap_(info->getSnapshotManager()->getCurrentSnapshot()),
58 randNumGen_(info->getRandomNumberGenerator()) {}
60 void FluctuatingChargeLangevin::initialize() {
61 FluctuatingChargePropagator::initialize();
63 if (info_->getSimParams()->haveDt()) {
64 dt_ = info_->getSimParams()->getDt();
67 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
68 "FluctuatingChargeLangevin Error: dt is not set\n");
73 if (!fqParams_->haveTargetTemp()) {
74 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
75 "You can't use the FluctuatingChargeLangevin "
76 "propagator without a flucQ.targetTemp!\n");
78 painCave.severity = OPENMD_ERROR;
81 targetTemp_ = fqParams_->getTargetTemp();
86 if (!fqParams_->haveDragCoefficient()) {
87 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
88 "If you use the FluctuatingChargeLangevin\n"
89 "\tpropagator, you must set flucQ.dragCoefficient .\n");
91 painCave.severity = OPENMD_ERROR;
95 drag_ = fqParams_->getDragCoefficient();
100 std::sqrt(2.0 * Constants::kb * targetTemp_ * drag_ / dt_);
102 forceDistribution_ = std::normal_distribution<RealType>(0.0, stdDev);
105 void FluctuatingChargeLangevin::moveA() {
106 if (!hasFlucQ_)
return;
108 SimInfo::MoleculeIterator i;
109 Molecule::FluctuatingChargeIterator j;
112 RealType cvel, cpos, cfrc, cmass;
116 for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
117 atom = mol->nextFluctuatingCharge(j)) {
121 cmass = atom->getChargeMass();
124 cvel += dt2_ * cfrc / cmass;
134 void FluctuatingChargeLangevin::applyConstraints() {
135 if (!hasFlucQ_)
return;
137 SimInfo::MoleculeIterator i;
138 Molecule::FluctuatingChargeIterator j;
141 RealType cvel, cfrc, cmass, randomForce, frictionForce;
142 RealType velStep, oldFF;
146 for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
147 atom = mol->nextFluctuatingCharge(j)) {
148 randomForce = forceDistribution_(*randNumGen_);
164 cmass = atom->getChargeMass();
165 velStep = cvel + dt2_ * cfrc / cmass;
171 for (
int k = 0; k < maxIterNum_; k++) {
172 oldFF = frictionForce;
173 frictionForce = -drag_ * velStep;
176 velStep = cvel + dt2_ * (cfrc + frictionForce) / cmass;
180 if (fabs(frictionForce - oldFF) <= forceTolerance_)
186 fqConstraints_->applyConstraints();
189 void FluctuatingChargeLangevin::moveB() {
190 if (!hasFlucQ_)
return;
191 SimInfo::MoleculeIterator i;
192 Molecule::FluctuatingChargeIterator j;
195 RealType cfrc, cvel, cmass;
199 for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
200 atom = mol->nextFluctuatingCharge(j)) {
203 cmass = atom->getChargeMass();
206 cvel += (dt2_ * cfrc) / cmass;
abstract class for propagating fluctuating charge variables
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Molecule * beginMolecule(MoleculeIterator &i)
Returns the first molecule in this SimInfo and intialize the iterator.
Molecule * nextMolecule(MoleculeIterator &i)
Returns the next avaliable Molecule based on the iterator.
void setFlucQVel(RealType cvel)
Sets the current charge velocity of this stuntDouble.
void addFlucQFrc(RealType cfrc)
Adds charge force into the current charge force of this stuntDouble.
void setFlucQPos(RealType charge)
Sets the current fluctuating charge of this stuntDouble.
RealType getFlucQFrc()
Returns the current charge force of this stuntDouble.
RealType getFlucQPos()
Returns the current fluctuating charge of this stuntDouble.
RealType getFlucQVel()
Returns the current charge velocity of this stuntDouble.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.