Simpatico  v1.10
LinearPerturbation.h
1 #ifndef MCMD_LINEAR_PERTURBATION_H
2 #define MCMD_LINEAR_PERTURBATION_H
3 
4 /*
5 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include "Perturbation.h"
12 
13 namespace McMd
14 {
15 
28  template <class SystemType>
30  {
31 
32  public:
33 
37 
49  LinearPerturbation(SystemType& system, int size, int rank);
50 
54  virtual ~LinearPerturbation();
55 
59  virtual double difference(DArray<double> iPartnerParameter) const;
60 
64  SystemType& system() const;
65 
66  private:
67 
69  SystemType* systemPtr_;
70 
71  };
72 
73  // Methods
74 
75  /*
76  * Constructor.
77  */
78  template <class SystemType>
80  ::LinearPerturbation(SystemType& system, int size, int rank)
81  : Perturbation(size, rank),
82  systemPtr_(&system)
83  {}
84 
85  template <class SystemType>
87  {}
88 
89  /*
90  * Returns the difference W(partner) - W(current).
91  */
92  template <class SystemType>
94  {
95  int nParameters = getNParameters();
96  double difference = 0.0;
97  for (int i = 0; i < nParameters; ++i) {
98  difference += (iPartnerParameter[i] - parameter(i)) * derivative(i);
99  }
100  return difference;
101  }
102 
103  /*
104  * Return associated System by reference.
105  */
106  template <class SystemType>
107  inline SystemType& LinearPerturbation<SystemType>::system() const
108  { return *systemPtr_; }
109 
110 }
111 
112 #endif // ifndef LINEAR_PERTURBATION_H
virtual ~LinearPerturbation()
Destructor.
LinearPerturbation(SystemType &system, int size, int rank)
Constructor.
A Perturbation that is a linear function of a parameter.
virtual double derivative(int i) const =0
Get derivative of the Boltzmann weight W(X,p) with respect to the perturbation parameter p[i] of inde...
double parameter(int i, int id)
Get parameter i of system id.
int getNParameters() const
Gets the number of parameters per system.
SystemType & system() const
Get the associated System by reference.
Model of parameter dependence in a free energy perturbation theory.
Definition: Perturbation.h:39
virtual double difference(DArray< double > iPartnerParameter) const
Returns the difference W(partner) - W(current).
Single-processor Monte Carlo (MC) and molecular dynamics (MD).