Simpatico  v1.10
stress.h
1 #ifndef MCMD_STRESS_H
2 #define MCMD_STRESS_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 <util/space/Vector.h> // member template
12 #include <util/space/Tensor.h> // member template
13 
14 namespace McMd
15 {
16 
17  using namespace Util;
18 
19  /*
20  * The functions defined in this file are used by function
21  * templates that compute the isotropic pressure (double), the
22  * x-y-z diagonal stress components (Vector), or the full
23  * stress tensor (Tensor) using a common template.
24  *
25  * The overloaded incrementPairStress correctly takes care of the
26  * addition of the contribution from the force between a pair of
27  * particles to either a double precision pressure or to a Vector
28  * or Tensor of stress components.
29  *
30  * The overloaded normalizeStress function divides the trace of
31  * the stress tensor by 3.0 (the dimensionality of space) when
32  * called with a double precision argument, representing a scalar
33  * pressure, but does nothing when called with a Vector or Tensor
34  * argument.
35  */
36 
37  /*
38  * Add a a pair contribution to isotropic pressure.
39  */
40  inline
41  void incrementPairStress(const Vector& f, const Vector& dr,
42  double& pressure)
43  { pressure += f.dot(dr); }
44 
45  /*
46  * Add a a pair contribution to x, y, and z stress components.
47  */
48  inline
49  void incrementPairStress(const Vector& f, const Vector& dr,
50  Vector& stress)
51  {
52  for (int i = 0; i < Dimension; ++i) {
53  stress[i] += f[i]*dr[i];
54  }
55  }
56 
57  /*
58  * Add a pair contribution to the stress tensor.
59  */
60  inline
61  void incrementPairStress(const Vector& f, const Vector& dr,
62  Tensor& stress)
63  {
64  int i, j;
65  for (i = 0; i < Dimension; ++i) {
66  for (j = 0; j < Dimension; ++j) {
67  stress(i, j) += f[i]*dr[j];
68  }
69  }
70  }
71 
72  /*
73  * Divide trace of stress by three to obtain pressure.
74  */
75  inline void normalizeStress(double& pressure)
76  { pressure /= 3.0; }
77 
78  /*
79  * Do nothing
80  */
81  inline void normalizeStress(Vector& stress)
82  { }
83 
84  /*
85  * Do nothing
86  */
87  inline void normalizeStress(Tensor& stress)
88  { }
89 
90 }
91 #endif
const int Dimension
Dimensionality of space.
Definition: Dimension.h:19
A Vector is a Cartesian vector.
Definition: Vector.h:75
double dot(const Vector &v) const
Return dot product of this vector and vector v.
Definition: Vector.h:632
A Tensor represents a Cartesian tensor.
Definition: Tensor.h:32
Utility classes for scientific computation.
Definition: accumulators.mod:1
Single-processor Monte Carlo (MC) and molecular dynamics (MD).