8 #include "NvtDpdVvIntegrator.h" 9 #include <mcMd/mdSimulation/MdSystem.h> 10 #include <mcMd/simulation/Simulation.h> 11 #include <mcMd/potentials/pair/MdPairPotential.h> 12 #include <mcMd/neighbor/PairList.h> 13 #include <mcMd/neighbor/PairIterator.h> 14 #include <mcMd/chemistry/Molecule.h> 15 #include <mcMd/chemistry/Atom.h> 16 #include <simp/ensembles/EnergyEnsemble.h> 17 #include <simp/boundary/Boundary.h> 18 #include <util/archives/Serializable_includes.h> 19 #include <util/space/Vector.h> 21 #define MCMD_DPD_TYPE 0 41 pairListPtr_(&system.pairPotential().pairList()),
43 boundaryPtr_(&system.boundary()),
44 randomPtr_(&system.simulation().random()),
45 energyEnsemblePtr_(&system.energyEnsemble()),
46 atomCapacity_(system.simulation().atomCapacity()),
54 UTIL_THROW(
"System energy ensemble is not isothermal");
74 UTIL_THROW(
"NvtDpdVvIntegrator already initialized");
77 read<double>(in,
"dt",
dt_);
78 read<double>(in,
"cutoff", cutoff_);
81 UTIL_THROW(
"Error: Dpd pair cutoff > maxCutoff of pair potential");
84 read<double>(in,
"gamma", gamma_);
87 dissipativeForces_.allocate(atomCapacity_);
88 randomForces_.allocate(atomCapacity_);
91 isInitialized_ =
true;
100 if (isInitialized_) {
101 UTIL_THROW(
"NvtDpdVvIntegrator already initialized");
104 loadParameter<double>(ar,
"dt",
dt_);
105 loadParameter<double>(ar,
"cutoff", cutoff_);
108 UTIL_THROW(
"Error: Dpd pair cutoff > maxCutoff of pair potential");
111 loadParameter<double>(ar,
"gamma", gamma_);
117 ar & dissipativeForces_;
120 isInitialized_ =
true;
136 ar & dissipativeForces_;
145 if (!isInitialized_) {
146 UTIL_THROW(
"Object must be initialized before use");
152 for (
int i = 0; i < nAtomType; ++i) {
154 dtMinvFactors_[i] = 0.5*
dt_/mass;
158 sigma_ = sqrt(2.0*gamma_*temperature_/
dt_);
159 cutoffSq_ = cutoff_*cutoff_;
167 computeDpdForces(
true);
177 void NvtDpdVvIntegrator::computeDpdForces(
bool computeRandom)
193 for (i=0; i < atomCapacity_; ++i) {
194 dissipativeForces_[i].zero();
197 for (i=0; i < atomCapacity_; ++i) {
198 randomForces_[i].zero();
203 for (pairListPtr_->
begin(iter); iter.
notEnd(); ++iter) {
204 iter.
getPair(atom0Ptr, atom1Ptr);
207 if (rsq < cutoffSq_) {
211 #if MCMD_DPD_TYPE == 0 214 #if MCMD_DPD_TYPE == 1 215 wr = 1.0 - (r/cutoff_);
217 #if MCMD_DPD_TYPE == 2 218 wr = 1.0 - rsq/cutoffSq_;
223 fr = sigma_*wr*randomPtr_->
gaussian();
225 randomForces_[atom0Ptr->
id()] += f;
226 randomForces_[atom1Ptr->
id()] -= f;
231 fd = -gamma_*wr*wr*dv.
dot(e);
233 dissipativeForces_[atom0Ptr->
id()] += f;
234 dissipativeForces_[atom1Ptr->
id()] -= f;
253 int iSpecies, nSpecies, atomId;
259 for (iSpecies=0; iSpecies < nSpecies; ++iSpecies) {
260 for (
system().begin(iSpecies, molIter); molIter.
notEnd(); ++molIter)
262 for (molIter->begin(atomIter); atomIter.
notEnd(); ++atomIter) {
263 atomId = atomIter->id();
266 f.
add(atomIter->force(), dissipativeForces_[atomId]);
267 f += randomForces_[atomId];
270 dv.
multiply(f, dtMinvFactors_[atomIter->typeId()]);
271 atomIter->velocity() += dv;
274 atomIter->position() += dr;
284 if (!
system().pairPotential().isPairListCurrent()) {
294 computeDpdForces(
true);
297 for (iSpecies=0; iSpecies < nSpecies; ++iSpecies) {
299 for ( ; molIter.
notEnd(); ++molIter) {
300 for (molIter->begin(atomIter); atomIter.
notEnd(); ++atomIter) {
301 atomId = atomIter->id();
304 f.
add(atomIter->force(), dissipativeForces_[atomId]);
305 f += randomForces_[atomId];
308 dv.
multiply(f, dtMinvFactors_[atomIter->typeId()]);
309 atomIter->velocity() += dv;
317 computeDpdForces(
false);
virtual void save(Serializable::OArchive &ar)
Save the internal state to an archive.
A Vector is a Cartesian vector.
virtual double maxPairCutoff() const =0
Return maximum cutoff distance.
void calculateForces()
Compute all forces in this System.
void begin(int speciesId, MoleculeIterator &iterator)
Initialize an iterator for molecules of one species in this System.
Vector & add(const Vector &v1, const Vector &v2)
Add vectors v1 and v2.
Vector & velocity()
Get atomic velocity Vector by reference.
double distanceSq(const Vector &r1, const Vector &r2) const
Return square distance between positions r1 and r2.
bool notEnd() const
Is the current pointer not at the end of the array?
Signal & positionSignal()
Signal to indicate change in atomic positions.
virtual void step()
Take a complete integration step.
double dot(const Vector &v) const
Return dot product of this vector and vector v.
Vector & multiply(const Vector &v, double s)
Multiply a vector v by a scalar s.
EnergyEnsemble & energyEnsemble() const
Get the EnergyEnsemble by reference.
Classes used by all simpatico molecular simulations.
Simulation & simulation()
Get parent Simulation by reference.
void getPair(Atom *&atom1Ptr, Atom *&atom2Ptr) const
Get pointers for current pair of Atoms.
Abstract base for molecular dynamics integrators.
virtual void loadParameters(Serializable::IArchive &ar)
Load the internal state to an archive.
Saving / output archive for binary ostream.
MdPairPotential & pairPotential() const
Return MdPairPotential by reference.
const AtomType & atomType(int i) const
Get a single AtomType object by const reference.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
bool isIsothermal() const
Is this an Isothermal ensemble?
MdSystem & system()
Get parent MdSystem by reference.
void notify(const T &t)
Notify all observers.
A point particle within a Molecule.
bool notEnd() const
Is the current pointer not at the end of the PArray?
Utility classes for scientific computation.
double gaussian(void)
Return a Gaussian random number with zero average and unit variance.
int id() const
Get global index for this Atom within the Simulation.
Forward iterator for an Array or a C array.
Forward iterator for a PArray.
Iterator for pairs in a PairList.
double dt_
Integrator time step.
void begin(PairIterator &iterator) const
Initialize a PairIterator.
Signal & velocitySignal()
Signal to indicate change in atomic velocities.
Saving archive for binary istream.
double mass() const
Get the mass.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
int nSpecies() const
Get the number of Species in this Simulation.
void buildPairList()
Build the internal PairList.
void clearPairListStatistics()
Clear all statistical accumulators stored in PairList.
virtual void setup()
Setup private variables before main loop.
Vector & subtract(const Vector &v1, const Vector &v2)
Subtract vector v2 from v1.
void setClassName(const char *className)
Set class name string.
bool notEnd() const
Return true if not at end of PairList.
A System for Molecular Dynamics simulation.
void allocate(int capacity)
Allocate the underlying C array.
double temperature() const
Return the temperature.
const Vector & position() const
Get the position Vector by const reference.
int nAtomType() const
Get the number of atom types.
NvtDpdVvIntegrator(MdSystem &system)
Constructor.
virtual ~NvtDpdVvIntegrator()
Destructor.
virtual void readParameters(std::istream &in)
Read parameters from file and initialize this MdSystem.