8 #include "NphIntegrator.h" 9 #include <mcMd/mdSimulation/MdSystem.h> 10 #include <mcMd/simulation/Simulation.h> 11 #include <mcMd/potentials/pair/MdPairPotential.h> 12 #include <mcMd/chemistry/Molecule.h> 13 #include <mcMd/chemistry/Atom.h> 14 #include <simp/ensembles/EnergyEnsemble.h> 15 #include <simp/ensembles/BoundaryEnsemble.h> 16 #include <simp/boundary/Boundary.h> 17 #include <util/space/Vector.h> 18 #include <util/archives/Serializable_includes.h> 19 #include <util/crystal/LatticeSystem.h> 51 read<double>(in,
"dt",
dt_);
52 read<double>(in,
"W", W_);
53 read<LatticeSystem>(in,
"mode", mode_);
65 loadParameter<double>(ar,
"dt",
dt_);
66 loadParameter<double>(ar,
"W", W_);
67 loadParameter<LatticeSystem>(ar,
"mode", mode_);
92 int nAtomType = prefactors_.
capacity();
93 for (
int i = 0; i < nAtomType; ++i) {
95 prefactors_[i] = 0.5*
dt_/mass;
105 int iSpecies, nSpecies;
154 double volume = lengths[0]*lengths[1]*lengths[2];
159 if (mode_ == Orthorhombic) {
160 double Vdthalf = 1.0/2.0 * volume *
dt_;
161 eta_[0] += Vdthalf/lengths[0] * (currP_[0] - extP);
162 eta_[1] += Vdthalf/lengths[1] * (currP_[1] - extP);
163 eta_[2] += Vdthalf/lengths[2] * (currP_[2] - extP);
164 }
else if (mode_ == Tetragonal) {
165 double Vdthalf = 1.0/2.0* volume *
dt_;
166 eta_[0] += Vdthalf/lengths[0]*(currP_[0] - extP);
167 eta_[1] += Vdthalf/lengths[1]*(currP_[1] + currP_[2] - 2.0*extP);
168 }
else if (mode_ == Cubic) {
169 eta_[0] += 1.0/2.0*
dt_*(1.0/3.0*(currP_[0]+currP_[1]+currP_[2]) - extP);
177 Vector lengthsOld = lengths;
179 double volumeFinal = 0.0;
181 double dthalfoverW = 1.0/2.0*
dt_/W_;
183 if (mode_ == Orthorhombic) {
184 lengths[0] += dthalfoverW*eta_[0];
185 lengths[1] += dthalfoverW*eta_[1];
186 lengths[2] += dthalfoverW*eta_[2];
187 lengthsFinal[0] = lengths[0] + dthalfoverW*eta_[0];
188 lengthsFinal[1] = lengths[1] + dthalfoverW*eta_[1];
189 lengthsFinal[2] = lengths[2] + dthalfoverW*eta_[2];
190 volumeFinal = lengthsFinal[0]*lengthsFinal[1]*lengthsFinal[2];
191 }
else if (mode_ == Tetragonal) {
192 lengths[0] += dthalfoverW*eta_[0];
193 lengths[1] += (1.0/2.0)*dthalfoverW*eta_[1];
194 lengths[2] = lengths[1];
195 lengthsFinal[0] = lengths[0] + dthalfoverW*eta_[0];
196 lengthsFinal[1] = lengths[1] + (1.0/2.0)*dthalfoverW*eta_[1];
197 lengthsFinal[2] = lengthsFinal[1];
198 volumeFinal = lengthsFinal[0]*lengthsFinal[1]*lengthsFinal[2];
199 }
else if (mode_ == Cubic) {
200 volume += dthalfoverW*eta_[0];
201 lengths[0] = pow(volume,1.0/3.0);
202 lengths[1] = lengths[0];
203 lengths[2] = lengths[0];
204 volumeFinal = volume + dthalfoverW*eta_[0];
205 lengthsFinal[0] = pow(volumeFinal,1./3.);
206 lengthsFinal[1] = lengthsFinal[0];
207 lengthsFinal[2] = lengthsFinal[0];
216 Vector vtmp, dr, rtmp, dv;
217 Vector lengthsFac, dtLengthsFac2;
219 for (
int i=0; i<3; i++) {
220 lengthsFac[i] = lengthsFinal[i]/lengthsOld[i];
221 dtLengthsFac2[i] =
dt_ * lengthsOld[i]*lengthsOld[i]/lengths[i]/lengths[i];
224 for (iSpecies=0; iSpecies < nSpecies; ++iSpecies) {
226 for ( ; molIter.
notEnd(); ++molIter) {
227 for (ia=0; ia < molIter->nAtom(); ++ia) {
228 atomPtr = &molIter->atom(ia);
229 prefactor = prefactors_[atomPtr->
typeId()];
234 dr[0] = vtmp[0] * dtLengthsFac2[0];
235 dr[1] = vtmp[1] * dtLengthsFac2[1];
236 dr[2] = vtmp[2] * dtLengthsFac2[2];
240 rtmp[0] *= lengthsFac[0];
241 rtmp[1] *= lengthsFac[1];
242 rtmp[2] *= lengthsFac[2];
246 vtmp[0] /= lengthsFac[0];
247 vtmp[1] /= lengthsFac[1];
248 vtmp[2] /= lengthsFac[2];
258 if (!
system().pairPotential().isPairListCurrent()) {
273 for (iSpecies=0; iSpecies < nSpecies; ++iSpecies) {
275 for ( ; molIter.
notEnd(); ++molIter)
277 for (ia=0; ia < molIter->nAtom(); ++ia) {
278 atomPtr = &molIter->atom(ia);
279 prefactor = prefactors_[atomPtr->
typeId()];
291 if (mode_ == Orthorhombic) {
292 double Vdthalf = 1.0/2.0 * volumeFinal *
dt_;
293 eta_[0] += Vdthalf/lengthsFinal[0] * (currP_[0] - extP);
294 eta_[1] += Vdthalf/lengthsFinal[1] * (currP_[1] - extP);
295 eta_[2] += Vdthalf/lengthsFinal[2] * (currP_[2] - extP);
296 }
else if (mode_ == Tetragonal) {
297 double Vdthalf = 1.0/2.0 * volumeFinal *
dt_;
298 eta_[0] += Vdthalf/lengthsFinal[0]*(currP_[0] - extP);
299 eta_[1] += Vdthalf/lengthsFinal[1]*(currP_[1] + currP_[2] - 2.0*extP);
300 }
else if (mode_ == Cubic) {
301 eta_[0] += 1.0/2.0*
dt_*(1.0/3.0*(currP_[0]+currP_[1]+currP_[2]) - extP);
305 if (!
system().pairPotential().isPairListCurrent()) {
330 double barostat_energy = 0.0;
331 if (mode_ == Orthorhombic)
332 barostat_energy = (eta_[0]*eta_[0]+eta_[1]*eta_[1]+eta_[2]*eta_[2]) / 2.0 / W_;
333 else if (mode_ == Tetragonal)
334 barostat_energy = (eta_[0]*eta_[0]+eta_[1]*eta_[1]/2.0) / 2.0 / W_;
335 else if (mode_ == Cubic)
336 barostat_energy = eta_[0]*eta_[0]/2.0/W_;
338 return barostat_energy;
Vector & zero()
Set all elements of a 3D vector to zero.
A Vector is a Cartesian vector.
virtual void setup()
Setup private variables before main loop.
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 pressure() const
Get the target pressure.
Signal & positionSignal()
Signal to indicate change in atomic positions.
Vector & force()
Get atomic force Vector by reference.
void setOrthorhombic(const Vector &lengths)
Set unit cell dimensions for orthorhombic boundary.
const Vector & lengths() const
Get Vector of unit cell lengths by const reference.
Vector & multiply(const Vector &v, double s)
Multiply a vector v by a scalar s.
virtual double barostatEnergy()
Get the barostat energy.
virtual void step()
Take a complete NVE MD integration step.
BoundaryEnsemble & boundaryEnsemble() const
Get the BoundaryEnsemble by reference.
Classes used by all simpatico molecular simulations.
Simulation & simulation()
Get parent Simulation by reference.
void computeStress(T &stress) const
Compute total pressure (T=double), xyz pressures (T=Vector) or stress (T=Tensor). ...
virtual LatticeSystem mode() const
Get the integrator mode.
Abstract base for molecular dynamics integrators.
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.
virtual double barostatMass() const
Get the barostat mass.
int typeId() const
Get type index for this Atom.
MdSystem & system()
Get parent MdSystem by reference.
virtual void readParameters(std::istream &in)
Read parameters from file and initialize this MdSystem.
void notify(const T &t)
Notify all observers.
virtual void loadParameters(Serializable::IArchive &ar)
Load the internal state to an archive.
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.
void serializeEnum(Archive &ar, T &data, const unsigned int version=0)
Serialize an enumeration value.
virtual void save(Serializable::OArchive &ar)
Save the internal state to an archive.
virtual void setEta(unsigned int index, double eta)
Get the barostat momentum.
Forward iterator for a PArray.
double dt_
Integrator time step.
Signal & velocitySignal()
Signal to indicate change in atomic velocities.
Boundary & boundary() const
Get the Boundary by reference.
Saving archive for binary istream.
LatticeSystem
Enumeration of the 7 possible Bravais lattice systems.
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 setClassName(const char *className)
Set class name string.
NphIntegrator(MdSystem &system)
Constructor.
A System for Molecular Dynamics simulation.
int capacity() const
Return allocated size.
void allocate(int capacity)
Allocate the underlying C array.
const Vector & position() const
Get the position Vector by const reference.
int nAtomType() const
Get the number of atom types.
virtual ~NphIntegrator()
Destructor.