Simpatico  v1.10
DpdMove.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 "DpdMove.h"
9 #include <mcMd/mcSimulation/McSystem.h>
10 #include <mcMd/mdSimulation/MdSystem.h>
11 #include <mcMd/mdIntegrators/MdIntegrator.h>
12 #ifndef SIMP_NOPAIR
13 #include <mcMd/potentials/pair/MdPairPotential.h>
14 #include <mcMd/potentials/pair/McPairPotential.h>
15 #endif
16 
17 namespace McMd
18 {
19 
20  using namespace Util;
21 
22  /*
23  * Constructor
24  */
26  SystemMove(system),
27  mdSystemPtr_(0),
28  nStep_(0)
29  {
30  setClassName("DpdMove");
31  mdSystemPtr_ = new MdSystem(system);
32  }
33 
34  /*
35  * Destructor.
36  */
38  {
39  if (mdSystemPtr_) {
40  delete mdSystemPtr_;
41  }
42  }
43 
44  /*
45  * Read probability, nStep, and MdSystem parameters.
46  */
47  void DpdMove::readParameters(std::istream& in)
48  {
49  readProbability(in);
50  read<int>(in, "nStep", nStep_);
51  readParamComposite(in, *mdSystemPtr_);
52  }
53 
54  /*
55  * Load internal state from an archive.
56  */
58  {
60  loadParameter<int>(ar, "nStep", nStep_);
61  loadParamComposite(ar, *mdSystemPtr_);
62  }
63 
64  /*
65  * Save internal state to an archive.
66  */
68  {
69  McMove::save(ar);
70  ar << nStep_;
71  mdSystemPtr_->saveParameters(ar);
72  }
73 
74  /*
75  * Setup before simulation run.
76  */
78  { mdSystemPtr_->mdIntegrator().setup(); }
79 
80  /*
81  * Generate, attempt and accept or reject a Hybrid MD/MC move.
82  */
84  {
85  // Increment counter for attempted moves
87 
88  // Calculate conservative forces
89  #ifndef SIMP_NOPAIR
90  mdSystemPtr_->pairPotential().buildPairList();
91  #endif
92  mdSystemPtr_->calculateForces();
93 
94  // Run a short DPD MD simulation
95  for (int iStep = 0; iStep < nStep_; ++iStep) {
96  mdSystemPtr_->mdIntegrator().step();
97  }
98 
99  #ifndef SIMP_NOPAIR
100  // Rebuild the McSystem cellList using the new positions.
102  #endif
103 
104  // Increment counter for the number of accepted moves.
106  return true;
107 
108  }
109 
110 }
A System for use in a Markov chain Monte Carlo simulation.
Definition: McSystem.h:52
void buildCellList()
Build the CellList with current configuration.
void calculateForces()
Compute all forces in this System.
Definition: MdSystem.cpp:857
void incrementNAttempt()
Increment the number of attempted moves.
Definition: McMove.h:191
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
Definition: McMove.cpp:58
void loadParamComposite(Serializable::IArchive &ar, ParamComposite &child, bool next=true)
Add and load a required child ParamComposite.
bool move()
Generate, attempt and accept or reject a move.
Definition: DpdMove.cpp:83
MdIntegrator & mdIntegrator()
Return the MdIntegrator by reference.
Definition: MdSystem.h:660
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
Definition: McMove.cpp:48
virtual void setup()
Initialize internal state, if any.
Definition: MdIntegrator.h:53
virtual void save(Serializable::OArchive &ar)
Save state to an archive.
Definition: DpdMove.cpp:67
Saving / output archive for binary ostream.
MdPairPotential & pairPotential() const
Return MdPairPotential by reference.
Definition: MdSystem.h:520
McSystem & system()
Get parent McSystem.
Definition: SystemMove.h:82
void incrementNAccept()
Increment the number of accepted moves.
Definition: McMove.h:197
virtual void loadParameters(Serializable::IArchive &ar)
Load state from an archive.
Definition: DpdMove.cpp:57
virtual void setup()
Initialize before a run.
Definition: DpdMove.cpp:77
Utility classes for scientific computation.
Definition: accumulators.mod:1
An McMove that acts on one McSystem.
Definition: SystemMove.h:28
~DpdMove()
Destructor.
Definition: DpdMove.cpp:37
McPairPotential & pairPotential() const
Return the McPairPotential by reference.
Definition: McSystem.h:388
Saving archive for binary istream.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
void buildPairList()
Build the internal PairList.
void readProbability(std::istream &in)
Read the probability from file.
Definition: McMove.cpp:42
void setClassName(const char *className)
Set class name string.
void readParamComposite(std::istream &in, ParamComposite &child, bool next=true)
Add and read a required child ParamComposite.
A System for Molecular Dynamics simulation.
Definition: MdSystem.h:68
virtual void step()=0
Take a complete MD integration step.
virtual void readParameters(std::istream &in)
Read nStep, dt, skin, maxNPair from file.
Definition: DpdMove.cpp:47
DpdMove(McSystem &system)
Constructor.
Definition: DpdMove.cpp:25
virtual void saveParameters(Serializable::OArchive &ar)
Save parameters to an archive, without configuration.
Definition: MdSystem.cpp:582