48#include "FluctuatingChargeDamped.hpp"
51#include "utils/Constants.hpp"
52#include "utils/simError.h"
56 FluctuatingChargeDamped::FluctuatingChargeDamped(
SimInfo* info) :
58 snap(info->getSnapshotManager()->getCurrentSnapshot()) {}
60 void FluctuatingChargeDamped::initialize() {
61 FluctuatingChargePropagator::initialize();
63 if (info_->getSimParams()->haveDt()) {
64 dt_ = info_->getSimParams()->getDt();
67 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
68 "FluctuatingChargeDamped Error: dt is not set\n");
73 if (!fqParams_->haveDragCoefficient()) {
74 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
75 "If you use the FluctuatingChargeDamped\n"
76 "\tpropagator, you must set flucQ dragCoefficient .\n");
78 painCave.severity = OPENMD_ERROR;
82 drag_ = fqParams_->getDragCoefficient();
87 void FluctuatingChargeDamped::moveA() {
88 if (!hasFlucQ_)
return;
90 SimInfo::MoleculeIterator i;
91 Molecule::FluctuatingChargeIterator j;
94 RealType cvel, cpos, cfrc, cmass;
96 for (mol = info_->beginMolecule(i); mol != NULL;
97 mol = info_->nextMolecule(i)) {
98 for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
99 atom = mol->nextFluctuatingCharge(j)) {
100 cvel = atom->getFlucQVel();
101 cpos = atom->getFlucQPos();
102 cfrc = atom->getFlucQFrc();
103 cmass = atom->getChargeMass();
106 cvel += dt2_ * cfrc / cmass;
110 atom->setFlucQVel(cvel);
111 atom->setFlucQPos(cpos);
116 void FluctuatingChargeDamped::applyConstraints() {
117 if (!hasFlucQ_)
return;
119 SimInfo::MoleculeIterator i;
120 Molecule::FluctuatingChargeIterator j;
123 RealType cvel, cfrc, cmass, frictionForce;
124 RealType velStep, oldFF;
126 for (mol = info_->beginMolecule(i); mol != NULL;
127 mol = info_->nextMolecule(i)) {
128 for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
129 atom = mol->nextFluctuatingCharge(j)) {
137 cvel = atom->getFlucQVel();
142 cfrc = atom->getFlucQFrc();
143 cmass = atom->getChargeMass();
144 velStep = cvel + dt2_ * cfrc / cmass;
150 for (
int k = 0; k < maxIterNum_; k++) {
151 oldFF = frictionForce;
152 frictionForce = -drag_ * velStep;
155 velStep = cvel + dt2_ * (cfrc + frictionForce) / cmass;
159 if (fabs(frictionForce - oldFF) <= forceTolerance_)
162 atom->addFlucQFrc(frictionForce);
165 fqConstraints_->applyConstraints();
168 void FluctuatingChargeDamped::moveB() {
169 if (!hasFlucQ_)
return;
170 SimInfo::MoleculeIterator i;
171 Molecule::FluctuatingChargeIterator j;
174 RealType cfrc, cvel, cmass;
176 for (mol = info_->beginMolecule(i); mol != NULL;
177 mol = info_->nextMolecule(i)) {
178 for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
179 atom = mol->nextFluctuatingCharge(j)) {
180 cvel = atom->getFlucQVel();
181 cfrc = atom->getFlucQFrc();
182 cmass = atom->getChargeMass();
185 cvel += (dt2_ * cfrc) / cmass;
187 atom->setFlucQVel(cvel);
192 void FluctuatingChargeDamped::updateSizes() {}
194 RealType FluctuatingChargeDamped::calcConservedQuantity() {
return 0.0; }
abstract class for propagating fluctuating charge variables
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.