Simpatico  v1.10
BendForce.h
1 #ifndef SIMP_BEND_FORCE_H
2 #define SIMP_BEND_FORCE_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 "Bend.h" // base class
12 
13 #include <cmath>
14 
15 namespace Simp
16 {
17 
18  using namespace Util;
19 
33  struct BendForce : public Bend
34  {
35 
36  public:
37 
42 
47 
54  void computeDerivatives(const Vector& b1, const Vector& b2);
55 
56  };
57 
58  // Inline method definitions
59 
60  /*
61  * Calculate cosTheta and unit vectors.
62  */
63  inline
64  void BendForce::computeDerivatives(const Vector& b1, const Vector& b2)
65  {
66  Vector u1, u2;
67 
68  double b1Abs = b1.abs();
69  u1.divide(b1, b1Abs);
70 
71  double b2Abs = b2.abs();
72  u2.divide(b2, b2Abs);
73 
74  cosTheta = u1.dot(u2);
75 
76  Vector t;
77  t.multiply(u1, cosTheta);
78  d1.subtract(u2, t);
79  d1 /= b1Abs;
80 
81  t.multiply(u2, cosTheta);
82  d2.subtract(u1, t);
83  d2 /= b2Abs;
84  }
85 
86 }
87 #endif
Vector d2
Vector of derivatives d2[i] = d(cosTheta)/d(b2[i])
Definition: BendForce.h:46
A BendForce computes derivatives of the angle between two vectors.
Definition: BendForce.h:33
A Vector is a Cartesian vector.
Definition: Vector.h:75
Vector d1
Vector of derivatives d1[i] = d(cosTheta)/d(b1[i])
Definition: BendForce.h:41
Vector & divide(const Vector &v, double s)
Divide vector v by scalar s.
Definition: Vector.h:700
A Bend calculates the angle between two vectors.
Definition: Bend.h:30
double dot(const Vector &v) const
Return dot product of this vector and vector v.
Definition: Vector.h:632
Vector & multiply(const Vector &v, double s)
Multiply a vector v by a scalar s.
Definition: Vector.h:686
Classes used by all simpatico molecular simulations.
void computeDerivatives(const Vector &b1, const Vector &b2)
Compute cosTheta and its derivatives d1 and d2.
Definition: BendForce.h:64
Utility classes for scientific computation.
Definition: accumulators.mod:1
double abs() const
Return absolute magnitude of this vector.
Definition: Vector.h:625
Vector & subtract(const Vector &v1, const Vector &v2)
Subtract vector v2 from v1.
Definition: Vector.h:672
double cosTheta
Cosine of angle between vectors b1 and b2.
Definition: Bend.h:38