Simpatico  v1.10
StressAutoCorrelation.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include <ddMd/analyzers/stress/StressAutoCorrelation.h>
9 #include <ddMd/analyzers/AutoCorrAnalyzer.tpp>
10 
11 #include <sstream>
12 
13 namespace DdMd
14 {
15 
16  using namespace Util;
17 
18  /*
19  * Constructor.
20  */
22  : AutoCorrAnalyzer<Tensor, double>(simulation)
23  { setClassName("StressAutoCorrelation"); }
24 
25 
26  /*
27  * Sample the stress tensor.
28  */
30  {
31  Simulation& sim = simulation();
32  sim.computeVirialStress();
34  }
35 
36  /*
37  * Sample the stress tensor.
38  */
40  {
41  Tensor virial = simulation().virialStress();
42  Tensor kinetic = simulation().kineticStress();
43  Tensor stress;
44  stress.add(virial, kinetic);
45 
46  // Remove trace
47  double pressure = 0.0;
48  int i, j;
49  for (i = 0; i < Dimension; ++i) {
50  pressure += stress(i,i);
51  }
52  pressure = pressure/double(Dimension);
53  for (i = 0; i < Dimension; ++i) {
54  stress(i,i) -= pressure;
55  }
56 
57  double factor = sqrt(simulation().boundary().volume()/10.0);
58  for (i = 0; i < Dimension; ++i) {
59  for (j = 0; j < Dimension; ++j) {
60  stress(i,j) *= factor;
61  }
62  }
63 
64  return stress;
65  }
66 
67 }
virtual void computeData()
Compute Data value, call on all processors.
StressAutoCorrelation(Simulation &simulation)
Constructor.
const int Dimension
Dimensionality of space.
Definition: Dimension.h:19
Simulation & simulation()
Get the parent Simulation by reference.
Compute an autocorrelation function for a sequence of Data values.
virtual Tensor data()
Get current Data value, call only on master.
Parallel domain decomposition (DD) MD simulation.
Main object for a domain-decomposition MD simulation.
A Tensor represents a Cartesian tensor.
Definition: Tensor.h:32
Tensor & add(const Tensor &t1, const Tensor &t2)
Add tensors t1 and t2.
Definition: Tensor.h:567
Utility classes for scientific computation.
Definition: accumulators.mod:1
Tensor kineticStress() const
Return total kinetic stress.
void computeVirialStress()
Calculate and store all virial stress contributions.
void setClassName(const char *className)
Set class name string.
Tensor virialStress() const
Return total virial stress.
void computeKineticStress()
Calculate and store kinetic stress.