NAMD
ComputeConsForce.C
Go to the documentation of this file.
1 
2 #include "InfoStream.h"
3 #include "SimParameters.h"
4 #include "ComputeConsForce.h"
5 #include "Molecule.h"
6 #include "Node.h"
7 #include "HomePatch.h"
8 
10 // compute constant force
12  : ComputeHomePatch(c,pid)
13 {
15 }
16 
18 {
19  delete reduction;
20 }
21 
23 { int localID,forceID;
24  Molecule *molecule = Node::Object()->molecule;
26  int32 *index = molecule->consForceIndexes; // Indexes into the force array
27  Vector *cf = molecule->consForce; // Force array
29  Force extForce = 0.;
30  Tensor extVirial;
31 
32  for (localID=0; localID<numAtoms; ++localID) {
33  // When the index is -1, it means there's no constant force on this atom
34  if ((forceID=index[p[localID].id]) != -1) {
35  Vector sf = scaling * cf[forceID];
36  forces[localID] += sf;
37  extForce += sf;
39  p[localID].position, p[localID].transform );
40  extVirial += outer(sf,vpos);
41  }
42  }
43 
44  ADD_VECTOR_OBJECT(reduction,REDUCTION_EXT_FORCE_NORMAL,extForce);
45  ADD_TENSOR_OBJECT(reduction,REDUCTION_VIRIAL_NORMAL,extVirial);
46  reduction->submit();
47 }
48 
50 // compute "constant" torque
52  : ComputeHomePatch(c,pid)
53 {
55 }
56 
58 {
59  delete reduction;
60 }
61 
63 { int localID,torqueID;
64  Molecule *molecule = Node::Object()->molecule;
66 
67  int32 *index = molecule->consTorqueIndexes; // Indexes into the torque array
69  Force extForce = 0.;
70  Tensor extVirial;
71  const BigReal consTorqueGlobVal = simParams->consTorqueGlobVal;
72  BigReal consTorqueVal;
73  Vector consTorqueAxis, consTorquePivot;
74  Vector atomRadius;
75  Vector torque;
76 
77  for (localID=0; localID<numAtoms; ++localID) {
78  // When the index is -1, it means there's no constant torque on this atom
79  if ((torqueID=index[p[localID].id]) != -1) {
80  // compute the torqueing force and add it to the net force
81  molecule->get_constorque_params(consTorqueVal, consTorqueAxis, consTorquePivot, p[localID].id);
82  consTorqueAxis /= consTorqueAxis.length();
83  atomRadius = p[localID].position - consTorquePivot;
84  torque = cross(consTorqueAxis, atomRadius) * consTorqueVal * consTorqueGlobVal;
85  forces[localID] += torque;
86  extForce += torque;
88  p[localID].position, p[localID].transform );
89  extVirial += outer(torque,vpos);
90  }
91  }
92 
93  ADD_VECTOR_OBJECT(reduction,REDUCTION_EXT_FORCE_NORMAL,extForce);
94  ADD_TENSOR_OBJECT(reduction,REDUCTION_VIRIAL_NORMAL,extVirial);
95  reduction->submit();
96 }
static Node * Object()
Definition: Node.h:86
virtual void doForce(FullAtom *, Results *)
short int32
Definition: dumpdcd.c:24
int ComputeID
Definition: NamdTypes.h:183
Lattice & lattice
Definition: Patch.h:126
Definition: Vector.h:64
#define ADD_TENSOR_OBJECT(R, RL, D)
Definition: ReductionMgr.h:43
SimParameters * simParameters
Definition: Node.h:178
static __thread float4 * forces
__device__ __forceinline__ float3 cross(const float3 v1, const float3 v2)
Position position
Definition: NamdTypes.h:53
SubmitReduction * willSubmit(int setID, int size=-1)
Definition: ReductionMgr.C:365
ComputeConsTorque(ComputeID, PatchID)
static ReductionMgr * Object(void)
Definition: ReductionMgr.h:278
BigReal length(void) const
Definition: Vector.h:169
virtual void doForce(FullAtom *, Results *)
void get_constorque_params(BigReal &v, Vector &a, Vector &p, int atomnum) const
Definition: Molecule.h:1336
int32 * consTorqueIndexes
Definition: Molecule.h:615
virtual ~ComputeConsForce()
Force * f[maxNumForces]
Definition: PatchTypes.h:67
ComputeConsForce(ComputeID, PatchID)
int PatchID
Definition: NamdTypes.h:182
Tensor outer(const Vector &v1, const Vector &v2)
Definition: Tensor.h:241
BigReal consTorqueGlobVal
#define simParams
Definition: Output.C:127
int32 * consForceIndexes
Definition: Molecule.h:612
Position reverse_transform(Position data, const Transform &t) const
Definition: Lattice.h:138
Definition: Tensor.h:15
#define ADD_VECTOR_OBJECT(R, RL, D)
Definition: ReductionMgr.h:27
Vector * consForce
Definition: Molecule.h:613
virtual ~ComputeConsTorque()
void submit(void)
Definition: ReductionMgr.h:323
Molecule * molecule
Definition: Node.h:176
HomePatch * homePatch
double BigReal
Definition: common.h:114
BigReal consForceScaling