54#include "brains/ForceModifier.hpp"
55#include "nonbonded/NonBondedInteraction.hpp"
57#include "types/FixedChargeAdapter.hpp"
58#include "types/FluctuatingChargeAdapter.hpp"
59#include "types/MultipoleAdapter.hpp"
60#include "utils/Constants.hpp"
64 UniformField::UniformField(
SimInfo* info) :
65 ForceModifier {info}, initialized {false}, doUniformField {false},
66 doParticlePot {false} {
67 simParams = info_->getSimParams();
70 void UniformField::initialize() {
71 std::vector<RealType> ef;
73 if (simParams->haveElectricField()) {
74 doUniformField =
true;
75 ef = simParams->getElectricField();
77 if (simParams->haveUniformField()) {
78 doUniformField =
true;
79 ef = simParams->getUniformField();
82 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
83 "UniformField: Incorrect number of parameters specified.\n"
84 "\tthere should be 3 parameters, but %zu were specified.\n",
93 int storageLayout_ = info_->getSnapshotManager()->getAtomStorageLayout();
94 if (storageLayout_ & DataStorage::dslParticlePot) doParticlePot =
true;
98 void UniformField::modifyForces() {
99 if (!initialized) initialize();
101 SimInfo::MoleculeIterator i;
102 Molecule::AtomIterator j;
106 potVec longRangePotential(0.0);
118 if (doUniformField) {
122 for (mol = info_->beginMolecule(i); mol != NULL;
123 mol = info_->nextMolecule(i)) {
124 for (atom = mol->beginAtom(j); atom != NULL; atom = mol->nextAtom(j)) {
128 atype = atom->getAtomType();
134 info_->getSnapshotManager()->getCurrentSnapshot()->wrapVector(r);
136 atom->addElectricField(EF * Constants::chargeFieldConvert);
138 FixedChargeAdapter fca = FixedChargeAdapter(atype);
139 if (fca.isFixedCharge()) {
144 FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atype);
145 if (fqa.isFluctuatingCharge()) {
147 C += atom->getFlucQPos();
148 atom->addFlucQFrc(
dot(r, EF) * Constants::chargeFieldConvert);
152 f = EF * C * Constants::chargeFieldConvert;
156 if (doParticlePot) { atom->addParticlePot(U); }
160 MultipoleAdapter ma = MultipoleAdapter(atype);
162 D = atom->getDipole() * Constants::dipoleFieldConvert;
169 if (doParticlePot) { atom->addParticlePot(U); }
176 MPI_Allreduce(MPI_IN_PLACE, &fPot, 1, MPI_REALTYPE, MPI_SUM,
180 Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot();
181 longRangePotential = snap->getLongRangePotentials();
183 snap->setLongRangePotentials(longRangePotential);
Abstract class for external ForceModifier classes.
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.
Vector3< Real > cross(const Vector3< Real > &v1, const Vector3< Real > &v2)
Returns the cross product of two Vectors.
Real dot(const DynamicVector< Real > &v1, const DynamicVector< Real > &v2)
Returns the dot product of two DynamicVectors.
@ ELECTROSTATIC_FAMILY
Coulombic and point-multipole interactions.