Simpatico  v1.10
NveIntegrator.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "NveIntegrator.h"
9 #include <ddMd/simulation/Simulation.h>
10 #include <ddMd/storage/AtomStorage.h>
11 #include <ddMd/storage/AtomIterator.h>
12 #include <ddMd/communicate/Exchanger.h>
13 #include <ddMd/potentials/pair/PairPotential.h>
14 #include <util/space/Vector.h>
15 #include <util/global.h>
16 
17 #include <iostream>
18 
19 namespace DdMd
20 {
21  using namespace Util;
22 
23  /*
24  * Constructor.
25  */
27  : TwoStepIntegrator(simulation)
28  { setClassName("NveIntegrator"); }
29 
30  /*
31  * Destructor.
32  */
34  {}
35 
36  /*
37  * Read time step dt.
38  */
39  void NveIntegrator::readParameters(std::istream& in)
40  {
41  read<double>(in, "dt", dt_);
43 
44  int nAtomType = simulation().nAtomType();
45  if (!prefactors_.isAllocated()) {
46  prefactors_.allocate(nAtomType);
47  }
48  }
49 
54  {
55  loadParameter<double>(ar, "dt", dt_);
57 
58  int nAtomType = simulation().nAtomType();
59  if (!prefactors_.isAllocated()) {
60  prefactors_.allocate(nAtomType);
61  }
62  // Note: Values of prefactors_ calculated in setup()
63  }
64 
65  /*
66  * Save internal state to an archive.
67  */
69  {
70  ar << dt_;
71  Integrator::save(ar);
72  }
73 
74  /*
75  * Setup at beginning of run, before entering main loop.
76  */
78  {
79 
80  // Initialize state and clear statistics on first usage.
81  if (!isSetup()) {
82  clear();
83  setIsSetup();
84  }
85 
86  // Exchange atoms, build pair list, compute forces.
87  setupAtoms();
88 
89  // Set prefactors for acceleration
90  double dtHalf = 0.5*dt_;
91  double mass;
92  int nAtomType = prefactors_.capacity();
93  for (int i = 0; i < nAtomType; ++i) {
94  mass = simulation().atomType(i).mass();
95  prefactors_[i] = dtHalf/mass;
96  }
97  }
98 
99  /*
100  * First half of velocity-Verlet update.
101  */
103  {
104  Vector dv;
105  Vector dr;
106  double prefactor; // = 0.5*dt/mass
107  AtomIterator atomIter;
108 
109  // 1st half of velocity Verlet.
110  atomStorage().begin(atomIter);
111  for ( ; atomIter.notEnd(); ++atomIter) {
112  prefactor = prefactors_[atomIter->typeId()];
113 
114  dv.multiply(atomIter->force(), prefactor);
115  atomIter->velocity() += dv;
116 
117  dr.multiply(atomIter->velocity(), dt_);
118  atomIter->position() += dr;
119  }
120  }
121 
122  /*
123  * Second half of velocity-Verlet update.
124  */
126  {
127  Vector dv;
128  double prefactor; // = 0.5*dt/mass
129  AtomIterator atomIter;
130 
131  // 2nd half of velocity Verlet
132  atomStorage().begin(atomIter);
133  for ( ; atomIter.notEnd(); ++atomIter) {
134  prefactor = prefactors_[atomIter->typeId()];
135  dv.multiply(atomIter->force(), prefactor);
136  atomIter->velocity() += dv;
137  }
138 
139  // Notify observers of change in velocity
141  }
142 
143 }
void loadParameters(Serializable::IArchive &ar)
Load saveInterval and saveFileName from restart archive.
Definition: Integrator.cpp:83
virtual void integrateStep2()
Execute second step of two-step integrator.
~NveIntegrator()
Destructor.
Signal & velocitySignal()
Signal to indicate change in atomic velocities.
A Vector is a Cartesian vector.
Definition: Vector.h:75
Vector & multiply(const Vector &v, double s)
Multiply a vector v by a scalar s.
Definition: Vector.h:686
void readParameters(std::istream &in)
Read saveInterval and saveFileName.
Definition: Integrator.cpp:65
void setIsSetup()
Mark the integrator as having been setup at least once.
Definition: Integrator.h:240
double mass() const
Get the mass.
File containing preprocessor macros for error handling.
Parallel domain decomposition (DD) MD simulation.
Main object for a domain-decomposition MD simulation.
AtomType & atomType(int i)
Get an AtomType descriptor by reference.
virtual void integrateStep1()
Execute first step of two-step integrator.
Saving / output archive for binary ostream.
void setupAtoms()
Setup state of atoms just before integration.
Definition: Integrator.cpp:118
void setup()
Setup state just before main loop.
void notify(const T &t)
Notify all observers.
Definition: Signal.cpp:22
bool notEnd() const
Is the current pointer not at the end of the PArray?
Utility classes for scientific computation.
Definition: accumulators.mod:1
void readParameters(std::istream &in)
Read required parameters.
bool isAllocated() const
Return true if the DArray has been allocated, false otherwise.
Definition: DArray.h:222
bool isSetup() const
Has the setup() method been called at least once previously?
Definition: Integrator.h:234
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
AtomStorage & atomStorage()
Get the AtomStorage.
void save(Serializable::OArchive &ar)
Save saveInterval and saveFileName from restart archive.
Definition: Integrator.cpp:105
Simulation & simulation()
Get the parent simulation.
int nAtomType()
Get maximum number of atom types.
Saving archive for binary istream.
A two-step velocity-Verlet style integrator.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
void setClassName(const char *className)
Set class name string.
int nAtomType()
Get maximum number of atom types.
int capacity() const
Return allocated size.
Definition: Array.h:153
void allocate(int capacity)
Allocate the underlying C array.
Definition: DArray.h:191
Iterator for all atoms owned by an AtomStorage.
Definition: AtomIterator.h:24
NveIntegrator(Simulation &simulation)
Constructor.
virtual void clear()
Set integrator to initial state and clears all statistics.
Definition: Integrator.cpp:539
void begin(AtomIterator &iterator)
Set iterator to beginning of the set of atoms.