Simpatico  v1.10
CompensatedPair.h
1 #ifndef SIMP_COMPENSATED_PAIR_H
2 #define SIMP_COMPENSATED_PAIR_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/param/ParamComposite.h>
12 #include <util/param/Begin.h>
13 #include <util/param/End.h>
14 #include <util/global.h>
15 
16 #include <math.h>
17 
18 namespace Simp
19 {
20 
21  using namespace Util;
22 
31  template <class BarePair, class LinkPotential>
33  {
34 
35  public:
36 
41 
43 
51  void readParameters(std::istream &in);
52 
58  void setNAtomType(int nAtomType);
59 
67  void setEpsilon(int i, int j, double epsilon);
68 
77  void set(std::string name, int i, int j, double value);
78 
80 
89  double energy(double rsq, int i, int j) const;
90 
103  double forceOverR(double rsq, int i, int j) const;
104 
108  double cutoffSq(int i, int j) const;
109 
113  double maxPairCutoff() const;
114 
116 
124  double epsilon(int i, int j) const;
125 
133  double get(std::string name, int i, int j) const;
134 
135  private:
136 
138  double maxLinkLength_;
139 
141  double maxLinkLengthSq_;
142 
148  double maxPairCutoff_;
149 
153  double maxPairCutoffSq_;
154 
155  BarePair pair_;
156  LinkPotential link_;
157  double temp_;
158  double mu_;
159  double activity_;
160  double beta_;
161 
165  CompensatedPair(BarePair barePot);
166 
171 
172  };
173 
174 
175  /*
176  * Constructor.
177  */
178  template <class BarePair, class LinkPotential>
180  : maxPairCutoff_(0.0),
181  maxPairCutoffSq_(0.0),
182  temp_(0.0),
183  mu_(0.0),
184  activity_(0.0),
185  beta_(0.0)
186  {
187  std::string name("CompensatedPair");
188  name += "<";
189  name += pair_.className();
190  name += ",";
191  name += link_.className();
192  name += ">";
193  setClassName(name.c_str());
194  }
195 
196  /*
197  * Copy constructor.
198  */
199  template <class BarePair, class LinkPotential>
201  : maxPairCutoff_(0.0),
202  pair_(barePot),
203  temp_(0.0),
204  mu_(0.0),
205  activity_(0.0),
206  beta_(0.0)
207  {}
208 
209  /*
210  * Read potential parameters from file.
211  */
212  template <class BarePair, class LinkPotential>
214  {
215  #if 0
216  std::string label;
217  Begin* beginPtr = 0;
218  End* endPtr = 0;
219 
220  // Read bare pair potential
221  //label = pair_.className();
222  //label += "{";
223  beginPtr = &addBegin(pair_.className().c_str());
224  beginPtr->setIndent(*this);
225  beginPtr->readParameters(in);
226  readParamComposite(in, pair_);
227  endPtr = &addEnd();
228  endPtr->setIndent(*this);
229  endPtr->readParameters(in);
230 
231  // Read bare link potential
232  //label = link_.className();
233  //label += "{";
234  beginPtr = &addBegin(link_.className().c_str());
235  beginPtr->setIndent(*this);
236  beginPtr->readParameters(in);
237  readParamComposite(in, link_);
238  endPtr = &addEnd();
239  endPtr->setIndent(*this);
240  endPtr->readParameters(in);
241  #endif
242 
243  readParamComposite(in, pair_);
244  readParamComposite(in, link_);
245 
246  read<double>(in, "maxLinkLength", maxLinkLength_);
247  read<double>(in, "temperature", temp_);
248  read<double>(in, "mu", mu_);
249 
250  beta_ = 1.0/temp_;
251  activity_ = exp(mu_*beta_);
252 
253  maxLinkLengthSq_ = maxLinkLength_*maxLinkLength_;
254  maxPairCutoff_ = maxLinkLength_;
255  if (pair_.maxPairCutoff() > maxLinkLength_) {
256  maxPairCutoff_ = pair_.maxPairCutoff();
257  }
258  maxPairCutoffSq_ = maxPairCutoff_*maxPairCutoff_;
259  }
260 
261  /*
262  * Set nAtomType
263  */
264  template <class BarePair, class LinkPotential>
266  {
267  pair_.setNAtomType(nAtomType);
268  link_.setNBondType(1);
269  }
270 
271  /*
272  * SetEpsilon
273  */
274  template <class BarePair, class LinkPotential>
276  { pair_.setEpsilon(i, j, epsilon); }
277 
278 
279  /*
280  * Get maximum of pair cutoff distance, for all atom type pairs.
281  */
282  template <class BarePair, class LinkPotential>
284  { return maxPairCutoff_; }
285 
286 
287  /*
288  * Calculate interaction energy for a pair, as function of squared distance.
289  */
290  template <class BarePair, class LinkPotential>
291  inline double CompensatedPair<BarePair, LinkPotential>::energy(double rsq, int i, int j) const
292  {
293  double total = pair_.energy(rsq, i, j);
294  if (rsq < maxLinkLengthSq_) {
295  total += activity_ * temp_ * exp(-beta_ * link_.energy(rsq, 0));
296  }
297  return total;
298  }
299 
300 
301  /*
302  * Calculate force/distance for a pair as function of squared distance.
303  */
304  template <class BarePair, class LinkPotential>
305  inline double
307  {
308  double total = 0.0;
309  if (rsq < pair_.cutoffSq(i, j)) {
310  total += pair_.forceOverR(rsq, i, j);
311  }
312  if (rsq < maxLinkLengthSq_) {
313  total -= activity_ * exp(-beta_ * link_.energy(rsq, 0)) * link_.forceOverR(rsq, 0);
314  }
315  return total;
316  }
317 
318  /*
319  * Get square of maximum pair cutoff distance.
320  */
321  template <class BarePair, class LinkPotential>
322  inline
324  { return maxPairCutoffSq_; }
325 
326  /*
327  * Modify a parameter, identified by a string.
328  */
329  template <class BarePair, class LinkPotential>
331  ::set(std::string name, int i, int j, double value)
332  {
333  if (name == "epsilon") {
334  pair_.setEpsilon(i, j, value);
335  } else {
336  UTIL_THROW("Unrecognized parameter name");
337  }
338  }
339 
340  /*
341  * Get a parameter value, identified by a string.
342  */
343  template <class BarePair, class LinkPotential>
345  ::get(std::string name, int i, int j) const
346  {
347  double value = 0.0;
348  if (name == "epsilon") {
349  value = pair_.epsilon(i, j);
350  } else {
351  UTIL_THROW("Unrecognized parameter name");
352  }
353  return value;
354  }
355 
356 }
357 #endif
End bracket of a ParamComposite parameter block.
Definition: End.h:24
CompensatedPair()
Constructor.
double energy(double rsq, int i, int j) const
Returns interaction energy for a single pair of particles.
void setEpsilon(int i, int j, double epsilon)
Set LJ interaction energy for a specific pair of Atom types.
double cutoffSq(int i, int j) const
Get cutoff for pair potential, for a particular type pair.
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
void setNAtomType(int nAtomType)
Set nAtomType value.
End & addEnd()
Add a closing bracket.
Compensated pair potential for transient gel.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
Utility classes for scientific computation.
Definition: accumulators.mod:1
Begin & addBegin(const char *label)
Add a Begin object representing a class name and bracket.
void readParameters(std::istream &in)
Read epsilon and sigma, initialize other variables.
void setIndent(const ParamComponent &parent, bool next=true)
Set indent level.
void setClassName(const char *className)
Set class name string.
void readParamComposite(std::istream &in, ParamComposite &child, bool next=true)
Add and read a required child ParamComposite.
double epsilon(int i, int j) const
Get LJ interaction energy for a specific pair of Atom types.
An object that can read multiple parameters from file.
double maxPairCutoff() const
Get maximum of pair cutoff distance, for all atom type pairs.
Beginning line of a composite parameter block.
Definition: Begin.h:24
double forceOverR(double rsq, int i, int j) const
Returns ratio of scalar pair interaction force to pair separation.