48#include "brains/Velocitizer.hpp"
53#include "brains/Thermo.hpp"
54#include "flucq/FluctuatingChargeConstraints.hpp"
58#include "types/FluctuatingChargeAdapter.hpp"
59#include "utils/Constants.hpp"
60#include "utils/RandNumGen.hpp"
64 Velocitizer::Velocitizer(
SimInfo* info) :
65 info_(info), thermo_(info), globals_(info->getSimParams()),
66 randNumGen_(info->getRandomNumberGenerator()) {}
69 SimInfo::MoleculeIterator mi;
70 Molecule::IntegrableObjectIterator ioi;
75 for (mol = info_->beginMolecule(mi); mol != NULL;
76 mol = info_->nextMolecule(mi)) {
77 for (sd = mol->beginIntegrableObject(ioi); sd != NULL;
78 sd = mol->nextIntegrableObject(ioi)) {
93 info_->getSnapshotManager()->getCurrentSnapshot()->clearDerivedProperties();
113 SimInfo::MoleculeIterator mi;
114 Molecule::IntegrableObjectIterator ioi;
118 std::normal_distribution<RealType> normalDistribution {0.0, 1.0};
120 kebar = Constants::kB * temperature * info_->getNdfRaw() /
121 (2.0 * info_->getNdf());
122 for (mol = info_->beginMolecule(mi); mol != NULL;
123 mol = info_->nextMolecule(mi)) {
124 for (sd = mol->beginIntegrableObject(ioi); sd != NULL;
125 sd = mol->nextIntegrableObject(ioi)) {
128 av2 = 2.0 * kebar / sd->
getMass();
134 for (
int k = 0; k < 3; k++) {
135 v[k] = vbar * normalDistribution(*randNumGen_);
148 jbar = sqrt(2.0 * kebar * I(m, m));
149 j[m] = jbar * normalDistribution(*randNumGen_);
150 jbar = sqrt(2.0 * kebar * I(n, n));
151 j[n] = jbar * normalDistribution(*randNumGen_);
153 for (
int k = 0; k < 3; k++) {
154 jbar = sqrt(2.0 * kebar * I(k, k));
155 j[k] = jbar * normalDistribution(*randNumGen_);
166 info_->getSnapshotManager()->getCurrentSnapshot()->clearDerivedProperties();
181 SimInfo::MoleculeIterator mi;
182 Molecule::IntegrableObjectIterator ioi;
188 std::normal_distribution<RealType> normalDistribution {0.0, 1.0};
190 Globals* simParams = info_->getSimParams();
191 fqParams = simParams->getFluctuatingChargeParameters();
194 fqConstraints->setConstrainRegions(fqParams->getConstrainRegions());
198 ->getNumberOfFlucQConstraints();
199 int dfRaw = fqConstraints->getNumberOfFlucQAtoms();
200 int dfActual = dfRaw - nConstrain;
201 kebar = dfRaw * Constants::kb * temperature / (2 * dfActual);
203 for (mol = info_->beginMolecule(mi); mol != NULL;
204 mol = info_->nextMolecule(mi)) {
205 for (sd = mol->beginIntegrableObject(ioi); sd != NULL;
206 sd = mol->nextIntegrableObject(ioi)) {
208 Atom* atom =
static_cast<Atom*
>(sd);
211 if (fqa.isFluctuatingCharge()) {
214 aw2 = 2.0 * kebar / atom->getChargeMass();
219 atom->
setFlucQVel(wbar * normalDistribution(*randNumGen_));
227 vector<Atom*> atomList;
230 for (
size_t i = 0; i < atomList.size(); ++i) {
231 Atom* atom = atomList[i];
234 if (fqa.isFluctuatingCharge()) {
236 aw2 = 2.0 * kebar / atom->getChargeMass();
240 atom->
setFlucQVel(wbar * normalDistribution(*randNumGen_));
246 fqConstraints->applyConstraintsOnChargeVelocities();
251 Vector3d vdrift = thermo_.getComVel();
253 SimInfo::MoleculeIterator mi;
254 Molecule::IntegrableObjectIterator ioi;
260 for (mol = info_->beginMolecule(mi); mol != NULL;
261 mol = info_->nextMolecule(mi)) {
262 for (sd = mol->beginIntegrableObject(ioi); sd != NULL;
263 sd = mol->nextIntegrableObject(ioi)) {
270 info_->getSnapshotManager()->getCurrentSnapshot()->clearDerivedProperties();
278 thermo_.getComAll(com, vdrift);
280 Mat3x3d inertiaTensor;
281 Vector3d angularMomentum;
284 thermo_.getInertiaTensor(inertiaTensor, angularMomentum);
287 inertiaTensor = inertiaTensor.
inverse();
288 omega = inertiaTensor * angularMomentum;
290 SimInfo::MoleculeIterator mi;
291 Molecule::IntegrableObjectIterator ioi;
299 for (mol = info_->beginMolecule(mi); mol != NULL;
300 mol = info_->nextMolecule(mi)) {
301 for (sd = mol->beginIntegrableObject(ioi); sd != NULL;
302 sd = mol->nextIntegrableObject(ioi)) {
303 tempComPos = sd->
getPos() - com;
310 info_->getSnapshotManager()->getCurrentSnapshot()->clearDerivedProperties();
AtomType * getAtomType()
Returns the AtomType of this Atom.
AtomType is what OpenMD looks to for unchanging data about an atom.
std::vector< Atom * > getAtoms()
Returns the atoms of this rigid body.
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
SquareMatrix3< Real > inverse() const
Sets the value of this matrix to the inverse of itself.
"Don't move, or you're dead! Stand up! Captain, we've got them!"
void setFlucQVel(RealType cvel)
Sets the current charge velocity of this stuntDouble.
Vector3d getVel()
Returns the current velocity of this stuntDouble.
int linearAxis()
Returns the linear axis of the rigidbody, atom and directional atom will always return -1.
RealType getMass()
Returns the mass of this stuntDouble.
virtual Mat3x3d getI()=0
Returns the inertia tensor of this stuntDouble.
bool isLinear()
Tests the if this stuntDouble is a linear rigidbody.
Vector3d getPos()
Returns the current position of this stuntDouble.
void setVel(const Vector3d &vel)
Sets the current velocity of this stuntDouble.
bool isRigidBody()
Tests if this stuntDouble is a rigid body.
Vector3d getJ()
Returns the current angular momentum of this stuntDouble (body -fixed).
bool isAtom()
Tests if this stuntDouble is an atom.
bool isDirectional()
Tests if this stuntDouble is a directional one.
void setJ(const Vector3d &angMom)
Sets the current angular momentum of this stuntDouble (body-fixed).
void randomize(RealType ct)
Resamples velocities and angular momenta Resamples velocities and angular momenta from a Maxwell-Bolt...
void randomizeChargeVelocity(RealType ct)
Resamples charge velocities Resamples charge velocities from a Maxwell-Boltzmann distribution.
void removeComDrift()
Removes Center of Mass Drift Velocity Removes the center of mass drift velocity (required for accurat...
void scale(RealType lambda)
Scales velocities and angular momenta by a scaling factor Rescales velocity (and angular momenta) by ...
void removeAngularDrift()
Removes Center of Mass Angular momentum Removes the center of mass angular momentum (particularly use...
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.