Simpatico  v1.10
MdCoulombPotential.cpp
1 #ifndef MD_COULOMB_POTENTIAL_CPP
2 #define MD_COULOMB_POTENTIAL_CPP
3 
4 /*
5 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
6 *
7 * Copyright 2010 - 2012, David Morse (morse012@umn.edu)
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include "MdCoulombPotential.h"
12 #include <mcMd/simulation/System.h>
13 #include <mcMd/simulation/Simulation.h>
14 
15 namespace McMd
16 {
17 
18  using namespace Util;
19 
20  /*
21  * Constructor.
22  */
24  : isInitialized_(false),
25  hasWaves_(false)
26  { setClassName("CoulombPotential"); }
27 
28  /*
29  * Destructor (does nothing)
30  */
32  {}
33 
34  /*
35  * Modify an interaction parameter, identified by a string.
36  *
37  * This default implementation throw an Exception, but is
38  * called only if virtual function is not re-implemented by
39  * derived class.
40  */
41  void MdCoulombPotential::set(std::string name, double value)
42  {
43  UTIL_THROW("Unimplemented virtual set method");
44  };
45 
46  /*
47  * Get an interaction parameter value, identified by a string.
48  *
49  * This default implementation throw an Exception, but is
50  * called only if virtual function is not re-implemented by
51  * derived class.
52  */
53  double MdCoulombPotential::get(std::string name) const
54  {
55  UTIL_THROW("Unimplemented virtual get method");
56  return 0.0;
57  };
58 
59  /*
60  * Unset precomputed wavevectors, influence function, energy and stress.
61  */
63  {
64  hasWaves_ = false;
65  unsetEnergy();
66  unsetStress();
67  }
68 
69  /*
70  * Unset k-space energy (does not unset rSpace or waves).
71  */
73  { kSpaceEnergy_.unset(); }
74 
75  /*
76  * Get kspace energy (compute iff necessary).
77  */
79  {
80  if (!kSpaceEnergy_.isSet()) {
81  computeEnergy();
82  }
83  return kSpaceEnergy_.value();
84  }
85 
86  /*
87  * Get rspace energy (compute iff necessary).
88  */
90  { return rSpaceAccumulator_.rSpaceEnergy(); }
91 
92  /*
93  * Get total Coulomb energy (recompute as needed).
94  */
96  {
97  double temp;
98  temp = kSpaceEnergy();
99  temp += rSpaceEnergy();
100  return temp;
101  }
102 
103  /*
104  * Unset k-space stress contribution (does not unset rSpace).
105  */
107  { kSpaceStress_.unset(); }
108 
109  /*
110  * Get k-space stress contribution.
111  */
113  {
114  if (!kSpaceStress_.isSet()) {
115  computeStress();
116  }
117  return kSpaceStress_.value();
118  }
119 
120  /*
121  * Get r-space stress contribution (recompute as needed).
122  */
124  { return rSpaceAccumulator_.rSpaceStress(); }
125 
126  /*
127  * Get total Coulomb stress (recompute as needed).
128  */
130  {
131  Tensor temp;
132  temp = kSpaceStress();
134  return temp;
135  }
136 
137  /*
138  * Get total Coulomb stress (recompute as needed).
139  */
141  {
142  Tensor temp = stress();
143  double value = 0.0;
144  for (int i = 0; i < Dimension; ++i) {
145  value += temp(i, i);
146  }
147  return value/3.0;
148  }
149 
150  /*
151  * Get total Coulomb stress.
152  */
154  {
155  stress = kSpaceStress();
156  stress+= rSpaceAccumulator_.rSpaceStress();
157  }
158 
163  {
164  Tensor temp = stress();
165  for (int i = 0; i < Dimension; ++i) {
166  pressures[i] = temp(i,i);
167  }
168  }
169 
176  {
177  Tensor temp = stress();
178  pressure = 0.0;
179  for (int i = 0; i < Dimension; ++i) {
180  pressure += temp(i, i);
181  }
182  pressure /= 3.0;
183  }
184 
185 }
186 #endif
virtual double get(std::string name) const
Get an interaction parameter value, identified by a string.
const int Dimension
Dimensionality of space.
Definition: Dimension.h:19
Setable< double > kSpaceEnergy_
K-space part of Coulomb energy.
A Vector is a Cartesian vector.
Definition: Vector.h:75
virtual void set(std::string name, double value)
Modify an interaction parameter, identified by a string.
double rSpaceEnergy()
Return short-range r-space part of Coulomb energy.
Tensor rSpaceStress()
Return the r-space stress (compute if necessary).
bool isSet() const
Is this object set (is the value known)?
Definition: Setable.h:124
double rSpaceEnergy()
Return the r-space energy (compute if necessary).
virtual void computeStress()=0
Compute kspace part of Coulomb stress.
A Tensor represents a Cartesian tensor.
Definition: Tensor.h:32
virtual void unsetEnergy()
Unset k-space energy.
Tensor stress()
Get total Coulomb stress.
const T & value() const
Return value (if set).
Definition: Setable.h:132
Setable< Tensor > kSpaceStress_
K-space part of Coulomb stress.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
Tensor kSpaceStress()
Get long-range k-space part of Coulomb stress.
virtual ~MdCoulombPotential()
Destructor (does nothing).
double kSpaceEnergy()
Get long-range k-space part of Coulomb energy.
EwaldRSpaceAccumulator rSpaceAccumulator_
Short-range real space energy and stress contributions.
Utility classes for scientific computation.
Definition: accumulators.mod:1
virtual void computeEnergy()=0
Calculate the long range kspace part of Coulomb energy.
void unset()
Unset the value (mark as unknown).
Definition: Setable.h:116
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
bool hasWaves_
Are waves and k-space potential up to date? Unset if boundary or parameters change.
void setClassName(const char *className)
Set class name string.
double pressure()
Get total Coulomb pressure.
virtual void unsetStress()
Unset k-space stress.
double energy()
Get total Coulomb energy.
void unsetWaves()
Unset all data that depends on the Boundary.
Tensor rSpaceStress()
Return short-range r-space part of Coulomb stress.