Simpatico  v1.10
ReplicaMove.h
1 #ifdef UTIL_MPI
2 #ifndef MCMD_REPLICA_MOVE_H
3 #define MCMD_REPLICA_MOVE_H
4 
5 
6 /*
7 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
8 *
9 * Copyright 2010 - 2017, The Regents of the University of Minnesota.
10 * Gibbs sampler algorithm implemented by Jens Glaser, March 2012.
11 *
12 * Distributed under the terms of the GNU General Public License.
13 */
14 
15 #include <util/param/ParamComposite.h> // base class
16 #include <util/space/Vector.h> // Util namespace
17 #include <util/misc/Notifier.h> // Util namespace
18 #include <util/containers/DArray.h>
19 #include <util/containers/Pair.h>
20 #include <util/global.h>
21 
22 #include <fstream>
23 
24 namespace McMd
25 {
26 
27  using namespace Util;
28 
29  class System;
30 
34  typedef Pair<int> sendRecvPair;
35 
36 
63  class ReplicaMove : public ParamComposite,
64  public Notifier<sendRecvPair>
65  {
66 
67  public:
68 
72  ReplicaMove(System& system);
73 
77  virtual ~ReplicaMove();
78 
92  virtual void readParameters(std::istream& in);
93 
99  virtual void loadParameters(Serializable::IArchive& ar);
100 
106  virtual void save(Serializable::OArchive& ar);
107 
111  virtual bool move();
112 
116  long interval() const;
117 
123  bool isAtInterval(long counter) const;
124 
131  void notifyObservers(sendRecvPair partners);
132 
136  long nAttempt();
137 
141  long nAccept();
142 
143  protected:
144 
148  System& system();
149 
150  private:
151 
153  System* systemPtr_;
154 
156  MPI::Intracomm* communicatorPtr_;
157 
159  int myId_;
160 
162  int nProcs_;
163 
165  std::ofstream outputFile_;
166 
168  int nParameters_;
169 
171  long interval_;
172 
174  int nSampling_;
175 
177  Vector *ptPositionPtr_;
178 
180  Vector *myPositionPtr_;
181 
183  long swapAttempt_;
184 
186  long swapAccept_;
187 
188  };
189  // Inline methods
190 
191  /*
192  * Return interval value.
193  */
194  inline long ReplicaMove::interval() const
195  { return interval_; }
196 
197  /*
198  * Return true iff counter is a multiple of the interval.
199  */
200  inline bool ReplicaMove::isAtInterval(long counter) const
201  { return (counter%interval_ == 0); }
202 
203  /*
204  * Number of attempts in given direction.
205  */
206  inline long ReplicaMove::nAttempt()
207  { return swapAttempt_; }
208 
209  /*
210  * Number of accepted moves in given direction.
211  */
212  inline long ReplicaMove::nAccept()
213  { return swapAccept_; }
214 
215  /*
216  * Return reference to parent System.
217  */
219  {
220  assert(systemPtr_);
221  return *systemPtr_;
222  }
223 
224 }
225 #endif
226 #endif // ifdef UTIL_MPI
A Vector is a Cartesian vector.
Definition: Vector.h:75
Replica exchange Monte Carlo move using Gibbs sampling.
Definition: ReplicaMove.h:63
long nAccept()
Number of accepted swaps.
Definition: ReplicaMove.h:212
A set of interacting Molecules enclosed by a Boundary.
Definition: System.h:115
File containing preprocessor macros for error handling.
long nAttempt()
Number of swap attempts.
Definition: ReplicaMove.h:206
Saving / output archive for binary ostream.
long interval() const
Get interval (number of steps between successives attempts).
Definition: ReplicaMove.h:194
Pair< int > sendRecvPair
A pair of receiving and sending partner ranks.
Definition: ReplicaMove.h:29
Utility classes for scientific computation.
Definition: accumulators.mod:1
Abstract template for a notifier (or subject) in the Observer design pattern.
Definition: Notifier.h:41
Saving archive for binary istream.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
bool isAtInterval(long counter) const
Return true iff counter is a multiple of the interval.
Definition: ReplicaMove.h:200
An object that can read multiple parameters from file.
System & system()
Return the associated system by reference.
Definition: ReplicaMove.h:218