Simpatico  v1.10
BennettsMethod.h
1 #ifdef MCMD_PERTURB
2 #ifdef UTIL_MPI
3 #ifndef MCMD_BENNETTS_METHOD_H
4 #define MCMD_BENNETTS_METHOD_H
5 
6 /*
7 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
8 *
9 * Copyright 2010, The Regents of the University of Minnesota
10 * Distributed under the terms of the GNU General Public License.
11 */
12 
13 #include <mcMd/analyzers/SystemAnalyzer.h> // base class template
14 #include <mcMd/simulation/System.h> // base template parameter
15 #include <util/accumulators/Average.h> // member
16 #ifdef UTIL_MPI
17 #include <util/containers/DArray.h>
18 #include <util/mpi/MpiSendRecv.h>
19 #include <util/mpi/MpiLogger.h>
20 #endif
21 #include <mcMd/simulation/Simulation.h>
22 #include <util/space/Vector.h> // Util namespace
23 #include <util/global.h>
24 #include <util/param/ParamComposite.h>
25 
26 #include <fstream>
27 #include <cstdio>
28 
29 namespace McMd
30 {
31 
32  using namespace Util;
33 
39  class BennettsMethod : public SystemAnalyzer<System>
40  {
41 
42  public:
43 
49  BennettsMethod(System& system);
50 
56  virtual void readParameters(std::istream& in);
57 
63  virtual void loadParameters(Serializable::IArchive& ar);
64 
70  virtual void save(Serializable::OArchive& ar);
71 
75  template <class Archive>
76  void serialize(Archive& ar, const unsigned int version);
77 
81  virtual void setup();
82 
83  /*
84  * Evaluate Fermi functions and add to accumulators.
85  *
86  * \param iStep step counter
87  */
88  virtual void sample(long iStep);
89 
93  virtual void output();
94 
95  protected:
96 
98  double shift_;
99 
101  double lowerShift_;
102 
103  #ifdef UTIL_MPI
104  // Values of shift constants for all replicas.
105  DArray<double> shifts_;
106  #endif
107 
108  private:
109 
111  static const int TagDerivative[2];
112 
114  static const int TagFermi[2];
115 
117  MPI::Intracomm* communicatorPtr_;
118 
120  int myId_;
121 
123  int nProcs_;
124 
126  int lowerId_;
127 
129  int upperId_;
130 
132  int nParameter_;
133 
135  DArray<double> myParam_;
136 
138  DArray<double> lowerParam_;
139 
141  DArray<double> upperParam_;
142 
144  int nSamplePerBlock_;
145 
147  Average myAccumulator_;
148 
150  Average upperAccumulator_;
151 
153  double myArg_;
154 
156  double lowerArg_;
157 
159  double myFermi_;
160 
162  double lowerFermi_;
163 
165  double upperFermi_;
166 
168  std::ofstream outputFile_;
169 
171  long interval_;
172 
174  bool isInitialized_;
175 
180  virtual void analyze();
181  };
182 
183  /*
184  * Serialize to/from an archive.
185  */
186  template <class Archive>
187  void BennettsMethod::serialize(Archive& ar, const unsigned int version)
188  {
189  Analyzer::serialize(ar, version);
190  ar & nSamplePerBlock_;
191  #ifdef UTIL_MPI
192  if (hasIoCommunicator()) {
193  ar & shifts_;
194  } else {
195  ar & shift_;
196  }
197  #else
198  ar & shift_;
199  #endif
200  ar & myAccumulator_;
201  ar & upperAccumulator_;
202 
203  // Set in constructor
204  //ar & myId_;
205  //ar & nProcs_;
206  //ar & lowerId_;
207  //ar & upperId_;
208  //ar & nParameter_;
209  // ar & myParam_;
210 
211  ar & lowerParam_;
212  ar & upperParam_;
213  ar & myArg_;
214  ar & lowerArg_;
215  ar & myFermi_;
216  ar & lowerFermi_;
217  ar & upperFermi_;
218  }
219 
220 
221 }
222 #endif // ifndef BENNETTS_METHOD_H
223 #endif // ifdef UTIL_MPI
224 #endif // ifdef UTIL_PERTURB
Calculates the average and variance of a sampled property.
Definition: Average.h:43
double shift_
Value of shift constant for associated system.
A set of interacting Molecules enclosed by a Boundary.
Definition: System.h:115
File containing preprocessor macros for error handling.
void serialize(Archive &ar, PairSelector &selector, const unsigned int version)
Serialize a PairSelector.
Definition: PairSelector.h:167
Saving / output archive for binary ostream.
double lowerShift_
Value of shift constant for lower replica system.
void serialize(Archive &ar, const unsigned int version)
Serialize to/from an archive.
Utility classes for scientific computation.
Definition: accumulators.mod:1
Template for Analyzer associated with one System.
Saving archive for binary istream.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
Bennett&#39;s method estimates free energy difference between two states.
This file contains templates for global functions send<T>, recv<T> and bcast<T>.
void serialize(Archive &ar, const unsigned int version)
Serialize to/from an archive.