Simpatico  v1.10
Potential.h
1 #ifndef DDMD_POTENTIAL_H
2 #define DDMD_POTENTIAL_H
3 
4 #include <util/param/ParamComposite.h> // base class
5 #include <util/misc/Setable.h> // template for members
6 #include <util/space/Tensor.h> // parameter for member
7 
8 /*
9 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
10 *
11 * Copyright 2010 - 2017, The Regents of the University of Minnesota
12 * Distributed under the terms of the GNU General Public License.
13 */
14 
15 namespace DdMd
16 {
17 
18  using namespace Util;
19 
28  class Potential : public ParamComposite
29  {
30 
31  public:
32 
36  Potential();
37 
41  virtual ~Potential();
42 
48  void setReverseUpdateFlag(bool reverseUpdateFlag);
49 
53  bool reverseUpdateFlag() const;
54 
56 
57 
61  virtual void computeForces() = 0;
62 
70  #ifdef UTIL_MPI
71  virtual void computeEnergy(MPI::Intracomm& communicator) = 0;
72  #else
73  virtual void computeEnergy() = 0;
74  #endif
75 
82  double energy() const;
83 
89  void unsetEnergy();
90 
94  bool isEnergySet() const;
95 
103  #ifdef UTIL_MPI
104  virtual void computeStress(MPI::Intracomm& communicator)
105  #else
106  virtual void computeStress()
107  #endif
108  {}
109 
117  #ifdef UTIL_MPI
118  virtual void computeForcesAndStress(MPI::Intracomm& communicator);
119  #else
120  virtual void computeForcesAndStress();
121  #endif
122 
129  Tensor stress() const;
130 
137  double pressure() const;
138 
144  void unsetStress();
145 
149  bool isStressSet() const;
150 
151  #ifdef UTIL_MPI
152 
160  virtual bool isValid(MPI::Intracomm& communicator) const;
161  #endif
162 
164 
165  protected:
166 
170  void setEnergy(double energy);
171 
175  void setStress(const Tensor& stress);
176 
184  void incrementPairStress(const Vector& f, const Vector& dr,
185  Tensor& stress) const;
186 
195  #ifdef UTIL_MPI
196  void reduceEnergy(double localEnergy, MPI::Intracomm& communicator);
197  #else
198  void reduceEnergy();
199  #endif
200 
209  #ifdef UTIL_MPI
210  void reduceStress(Tensor& localStress, MPI::Intracomm& communicator);
211  #else
212  void reduceStress();
213  #endif
214 
215  private:
216 
218  Setable<Tensor> stress_;
219 
221  Setable<double> energy_;
222 
224  bool reverseUpdateFlag_;
225 
226  };
227 
228  inline bool Potential::reverseUpdateFlag() const
229  { return reverseUpdateFlag_; }
230 
231  /*
232  * Add a pair contribution to the virial tensor (protected).
233  */
234  inline void
236  Tensor& stress) const
237  {
238  int i, j;
239  for (i = 0; i < Dimension; ++i) {
240  for (j = 0; j < Dimension; ++j) {
241  stress(i, j) += f[i]*dr[j];
242  }
243  }
244  }
245 
246 }
247 #endif
const int Dimension
Dimensionality of space.
Definition: Dimension.h:19
A Vector is a Cartesian vector.
Definition: Vector.h:75
Template for a value that can be set or declared null (i.e., unknown).
Definition: Setable.h:38
virtual void computeStress(MPI::Intracomm &communicator)
Compute stress on all processors.
Definition: Potential.h:104
Parallel domain decomposition (DD) MD simulation.
A Tensor represents a Cartesian tensor.
Definition: Tensor.h:32
A Potential represents a potential energy contribution.
Definition: Potential.h:28
Utility classes for scientific computation.
Definition: accumulators.mod:1
void incrementPairStress(const Vector &f, const Vector &dr, Tensor &stress) const
Add a pair contribution to the stress tensor.
Definition: Potential.h:235
bool reverseUpdateFlag() const
Get flag to identify if reverse communication is enabled.
Definition: Potential.h:228
An object that can read multiple parameters from file.