Simpatico  v1.10
CosineSqAngle.h
1 #ifndef SIMP_COSINE_SQ_ANGLE_H
2 #define SIMP_COSINE_SQ_ANGLE_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 #include <util/space/Vector.h>
13 #include <util/param/ParamComposite.h> // base class
14 
15 #include <cmath>
16 
17 namespace Util {class Random;}
18 
19 namespace Simp
20 {
21 
22  using namespace Util;
23 
34  class CosineSqAngle : public ParamComposite
35  {
36 
37  public:
38 
42  CosineSqAngle();
43 
47  CosineSqAngle(const CosineSqAngle& other);
48 
53 
54  // Default C++ destructor.
55 
61  void setNAngleType(int nAngleType);
62 
73  void readParameters(std::istream &in);
74 
80  virtual void loadParameters(Serializable::IArchive &ar);
81 
87  virtual void save(Serializable::OArchive &ar);
88 
96  void set(std::string name, int type, double value);
97 
104  double energy(double cosTheta, int type) const;
105 
117  void force(const Vector& R1, const Vector& R2,
118  Vector& F1, Vector& F2, int type) const;
119 
134  double randomAngle(Random *random, double beta, int type) const;
135 
150  double randomCosineAngle(Random *random, double beta, int type) const;
151 
152 
160  double get(std::string name, int type) const;
161 
165  std::string className() const;
166 
167  private:
168 
170  static const int MaxNAngleType = 4;
171 
172  double kappa_[MaxNAngleType];
173  double theta0_[MaxNAngleType];
174  double cosTheta0_[MaxNAngleType];
175  int nAngleType_;
176 
177  };
178 
179  // Inline method definitions
180 
181  /*
182  * Return angle energy.
183  */
184  inline double CosineSqAngle::energy(double cosTheta, int type) const
185  {
186  return ( kappa_[type]
187  *(cosTheta-cosTheta0_[type])
188  *(cosTheta-cosTheta0_[type])*0.5 );
189  }
190 
191  /*
192  * Return:
193  * F1 = d energy / d(R1)
194  * F2 = d energy / d(R2)
195  * for use in MD and stress calculation.
196  */
197  inline
198  void CosineSqAngle::force(const Vector& R1, const Vector& R2,
199  Vector& F1, Vector& F2, int type) const
200  {
201  Vector u1 = R1;
202  Vector u2 = R2;
203  double r1 = R1.abs();
204  double r2 = R2.abs();
205  double cosTheta;
206 
207  u1 /= r1;
208  u2 /= r2;
209  cosTheta = u1.dot(u2);
210 
211  F1.multiply(u1, cosTheta);
212  F1 -= u2;
213  F1 *= kappa_[type]/r1*(cosTheta0_[type]-cosTheta);
214 
215  F2.multiply(u2, cosTheta);
216  F2 -= u1;
217  F2 *= kappa_[type]/r2*(cosTheta0_[type]-cosTheta);
218  }
219 
220 }
221 
222 #endif
A Vector is a Cartesian vector.
Definition: Vector.h:75
void force(const Vector &R1, const Vector &R2, Vector &F1, Vector &F2, int type) const
Compute angle forces.
double dot(const Vector &v) const
Return dot product of this vector and vector v.
Definition: Vector.h:632
double energy(double cosTheta, int type) const
Returns potential energy for one angle.
Vector & multiply(const Vector &v, double s)
Multiply a vector v by a scalar s.
Definition: Vector.h:686
std::string className() const
Return name string "CosineSqAngle" for this evaluator class.
CosineSqAngle()
Default constructor.
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
Saving / output archive for binary ostream.
A three body angle potential, as a function of angle cosine.
Definition: CosineSqAngle.h:34
Utility classes for scientific computation.
Definition: accumulators.mod:1
double randomCosineAngle(Random *random, double beta, int type) const
Return bond angle cosine chosen from equilibrium distribution.
void setNAngleType(int nAngleType)
Set the number of angle types.
void readParameters(std::istream &in)
Read angle interaction parameters from input stream.
CosineSqAngle & operator=(const CosineSqAngle &other)
Assignment.
Saving archive for binary istream.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
double abs() const
Return absolute magnitude of this vector.
Definition: Vector.h:625
Random number generator.
Definition: Random.h:46
An object that can read multiple parameters from file.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
double randomAngle(Random *random, double beta, int type) const
Return bond angle chosen from equilibrium distribution.