Simpatico  v1.10
HarmonicL0Bond.h
1 #ifndef SIMP_HARMONIC_L0_BOND_H
2 #define SIMP_HARMONIC_L0_BOND_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/global.h>
12 
13 #include <util/param/ParamComposite.h> // base class
14 #include <util/random/Random.h> // Util namespace
15 
16 #include <cmath>
17 
18 namespace Simp
19 {
20 
21  using namespace Util;
22 
32  {
33 
34  public:
35 
40 
44  HarmonicL0Bond(const HarmonicL0Bond& other);
45 
46  // Default destructor.
47 
52 
58  void setNBondType(int nBondType);
59 
70  void readParameters(std::istream &in);
71 
77  virtual void loadParameters(Serializable::IArchive &ar);
78 
84  virtual void save(Serializable::OArchive &ar);
85 
92  double energy(double rSq, int type) const;
93 
103  double forceOverR(double rSq, int type) const;
104 
118  double randomBondLength(Random *random, double beta, int type) const;
119 
127  void set(std::string name, int type, double value);
128 
135  double get(std::string name, int type) const;
136 
140  double kappa(int type) const;
141 
142  private:
143 
145  static const int MaxNBondType = 2;
146 
147  double kappa_[MaxNBondType];
148  int nBondType_;
149 
150  };
151 
152  // Inline method definitions
153 
154  /*
155  * Return bond spring constant
156  */
157  inline double HarmonicL0Bond::kappa(int type) const
158  {
159  assert(type >= 0);
160  assert(type < nBondType_);
161  return kappa_[type];
162  }
163 
164  /*
165  * Return interaction energy for one bond
166  */
167  inline double HarmonicL0Bond::energy(double rSq, int type) const
168  { return 0.5*kappa_[type]*rSq; }
169 
170  /*
171  * Return force / distance for one bond, for use in MD
172  */
173  inline
174  double HarmonicL0Bond::forceOverR(double rSq, int type) const
175  { return -kappa_[type]; }
176 
177 }
178 #endif
void setNBondType(int nBondType)
Set the number of bond types.
double forceOverR(double rSq, int type) const
Returns force/distance for one bond, for use in MD.
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
HarmonicL0Bond & operator=(const HarmonicL0Bond &other)
Assignment.
Saving / output archive for binary ostream.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
A harmonic bond potential with zero rest length.
double energy(double rSq, int type) const
Returns potential energy for one bond.
Utility classes for scientific computation.
Definition: accumulators.mod:1
double kappa(int type) const
Returns bond spring constant.
HarmonicL0Bond()
Constructor.
double randomBondLength(Random *random, double beta, int type) const
Return bond length chosen from equilibrium distribution.
Saving archive for binary istream.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
Random number generator.
Definition: Random.h:46
void readParameters(std::istream &in)
Read bond interaction parameters from input stream.
An object that can read multiple parameters from file.