NAMD
Public Member Functions | Public Attributes | List of all members
ComputeRestraints Class Reference

#include <ComputeRestraints.h>

Inheritance diagram for ComputeRestraints:
ComputeHomePatch Compute

Public Member Functions

 ComputeRestraints (ComputeID c, PatchID pid)
 
virtual ~ComputeRestraints ()
 
virtual void doForce (FullAtom *p, Results *r)
 
- Public Member Functions inherited from ComputeHomePatch
 ComputeHomePatch (ComputeID c, PatchID pid)
 
virtual ~ComputeHomePatch ()
 
virtual void initialize ()
 
virtual void atomUpdate ()
 
virtual void doWork ()
 
- Public Member Functions inherited from Compute
 Compute (ComputeID)
 
int type ()
 
virtual ~Compute ()
 
void setNumPatches (int n)
 
int getNumPatches ()
 
virtual void patchReady (PatchID, int doneMigration, int seq)
 
virtual int noWork ()
 
virtual void finishPatch (int)
 
int sequence (void)
 
int priority (void)
 
int getGBISPhase (void)
 
virtual void gbisP2PatchReady (PatchID, int seq)
 
virtual void gbisP3PatchReady (PatchID, int seq)
 

Public Attributes

SubmitReductionreduction
 
- Public Attributes inherited from Compute
const ComputeID cid
 
LDObjHandle ldObjHandle
 
LocalWorkMsg *const localWorkMsg
 

Additional Inherited Members

- Protected Member Functions inherited from Compute
void enqueueWork ()
 
- Protected Attributes inherited from ComputeHomePatch
int numAtoms
 
Patchpatch
 
HomePatchhomePatch
 
- Protected Attributes inherited from Compute
int computeType
 
int basePriority
 
int gbisPhase
 
int gbisPhasePriority [3]
 

Detailed Description

Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by The Board of Trustees of the University of Illinois. All rights reserved.

Definition at line 13 of file ComputeRestraints.h.

Constructor & Destructor Documentation

◆ ComputeRestraints()

ComputeRestraints::ComputeRestraints ( ComputeID  c,
PatchID  pid 
)

Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by The Board of Trustees of the University of Illinois. All rights reserved.

Definition at line 20 of file ComputeRestraints.C.

References Node::Object(), ReductionMgr::Object(), reduction, REDUCTIONS_BASIC, Node::simParameters, simParams, and ReductionMgr::willSubmit().

21  : ComputeHomePatch(c,pid)
22 {
24 
26 
27  // Get parameters from the SimParameters object
28  consExp = simParams->constraintExp;
29 
30  //****** BEGIN selective restraints (X,Y,Z) changes
31  consSelectOn = simParams->selectConstraintsOn;
32  if (consSelectOn) {
33  consSelectX = simParams->constrXOn;
34  consSelectY = simParams->constrYOn;
35  consSelectZ = simParams->constrZOn;
36  }
37  //****** END selective restraints (X,Y,Z) changes
38 
39  //****** BEGIN moving constraints changes
40  consMoveOn = simParams->movingConstraintsOn;
41  if (consMoveOn) {
42  moveVel = simParams->movingConsVel;
43  }
44  //****** END moving constraints changes
45  //****** BEGIN rotating constraints changes
46  consRotOn = simParams->rotConstraintsOn;
47  if (consRotOn) {
48  rotVel = simParams->rotConsVel;
49  rotAxis = simParams->rotConsAxis;
50  rotPivot = simParams->rotConsPivot;
51  }
52  //****** END rotating constraints changes
53 
54 }
static Node * Object()
Definition: Node.h:86
SimParameters * simParameters
Definition: Node.h:181
SubmitReduction * willSubmit(int setID, int size=-1)
Definition: ReductionMgr.C:366
static ReductionMgr * Object(void)
Definition: ReductionMgr.h:279
SubmitReduction * reduction
#define simParams
Definition: Output.C:129
ComputeHomePatch(ComputeID c, PatchID pid)

◆ ~ComputeRestraints()

ComputeRestraints::~ComputeRestraints ( )
virtual

Definition at line 65 of file ComputeRestraints.C.

References reduction.

67 {
68  delete reduction;
69 }
SubmitReduction * reduction

Member Function Documentation

◆ doForce()

void ComputeRestraints::doForce ( FullAtom p,
Results r 
)
virtual

Implements ComputeHomePatch.

Definition at line 77 of file ComputeRestraints.C.

References ADD_TENSOR_OBJECT, ADD_VECTOR_OBJECT, Lattice::delta(), Results::f, FullAtom::fixedPosition, Patch::flags, Molecule::get_cons_params(), CompAtomExt::id, Molecule::is_atom_constrained(), SubmitReduction::item(), Patch::lattice, Vector::length(), mat_multiply_vec(), Node::molecule, Results::normal, ComputeHomePatch::numAtoms, Node::Object(), outer(), ComputeHomePatch::patch, reduction, REDUCTION_BC_ENERGY, Node::simParameters, simParams, Flags::step, SubmitReduction::submit(), vec_rotation_matrix(), and Vector::x.

78 {
79  Molecule *molecule = Node::Object()->molecule;
80  Real k; // Force constant
82  BigReal scaling = simParams->constraintScaling;
83  Vector refPos; // Reference position
84  BigReal r, r2; // r=distance between atom position and the
85  // reference position, r2 = r^2
86  Vector Rij; // vector between current position and reference pos
87  BigReal value; // Current calculated value
88 
89  // aliases to work with old code
90  Force *f = res->f[Results::normal];
91  BigReal energy = 0;
92  BigReal m[9];
93  Tensor virial;
94  Vector netForce = 0;
95 
96  // BEGIN moving and rotating constraint changes ******
97 
98  // This version only allows one atom to be moved
99  // and only ALL ref positions to be rotated
100 
101  int currentTime = patch->flags.step;
102  if (consRotOn) {
103  vec_rotation_matrix(rotVel * currentTime, rotAxis, m);
104  }
105 
106  // END moving and rotating constraint changes ******
107 
108 
109  if (scaling != 0.) for (int localID=0; localID<numAtoms; ++localID)
110  {
111  if (molecule->is_atom_constrained(p[localID].id))
112  {
113 #ifndef MEM_OPT_VERSION
114  molecule->get_cons_params(k, refPos, p[localID].id);
115 #else
116  k = 1.0;
117  refPos = p[localID].fixedPosition;
118 #endif
119 
120  k *= scaling;
121 
122  // BEGIN moving and rotating constraint changes ******
123 
124  if (consMoveOn) {
125  refPos += currentTime * moveVel;
126  }
127  else if(consRotOn) {
128  refPos = mat_multiply_vec(refPos - rotPivot, m) + rotPivot;
129  }
130 
131  // END moving and rotating constraint changes *******
132 
133  if (simParams->sphericalConstraintsOn) {
134  BigReal refRad = (refPos - simParams->sphericalConstrCenter).length();
135  Vector relPos = patch->lattice.delta(p[localID].position, simParams->sphericalConstrCenter);
136  refPos = simParams->sphericalConstrCenter + relPos * (refRad/relPos.length());
137  }
138 
139  Rij = patch->lattice.delta(refPos,p[localID].position);
140  Vector vpos = refPos - Rij;
141 
142  //****** BEGIN selective restraints (X,Y,Z) changes
143  if (consSelectOn) { // check which components we want to restrain:
144  if (!consSelectX) {Rij.x=0.0;} // by setting the appropriate
145  if (!consSelectY) {Rij.y=0.0;} // Cartesian component to zero
146  if (!consSelectZ) {Rij.z=0.0;} // we will avoid a restoring force
147  } // along that component, and the
148  // energy will also be correct
149  //****** END selective restraints (X,Y,Z) changes
150 
151 
152  // Calculate the distance and the distance squared
153  r2 = Rij.length2();
154  r = sqrt(r2);
155 
156 
157  // Only calculate the energy and the force if the distance is
158  // non-zero. Otherwise, you could end up dividing by 0, which
159  // is bad
160  if (r>0.0)
161  {
162  value=k;
163 
164  // Loop through and multiple k by r consExp times.
165  // i.e. calculate kr^e
166  // I know, I could use pow(), but I don't trust it.
167  for (int k=0; k<consExp; ++k)
168  {
169  value *= r;
170  }
171 
172  // Add to the energy total
173  energy += value;
174 
175 
176 
177  // Now calculate the force, which is ekr^(e-1). Also, divide
178  // by another factor of r to normalize the vector before we
179  // multiple it by the magnitude
180  value *= consExp;
181  value /= r2;
182 
183  Rij *= value;
184  //iout << iINFO << "restraining force" << Rij << "\n";
185 
186  f[localID] += Rij;
187  netForce += Rij;
188  virial += outer(Rij,vpos);
189  }
190  }
191 
192  }
193 
194  reduction->item(REDUCTION_BC_ENERGY) += energy;
195  ADD_TENSOR_OBJECT(reduction,REDUCTION_VIRIAL_NORMAL,virial);
196  ADD_VECTOR_OBJECT(reduction,REDUCTION_EXT_FORCE_NORMAL,netForce);
197  reduction->submit();
198 
199 }
static Node * Object()
Definition: Node.h:86
Position fixedPosition
Definition: NamdTypes.h:202
Lattice & lattice
Definition: Patch.h:127
NAMD_HOST_DEVICE Tensor outer(const Vector &v1, const Vector &v2)
Definition: Tensor.h:241
Definition: Vector.h:72
#define ADD_TENSOR_OBJECT(R, RL, D)
Definition: ReductionMgr.h:44
SimParameters * simParameters
Definition: Node.h:181
float Real
Definition: common.h:118
BigReal & item(int i)
Definition: ReductionMgr.h:313
void vec_rotation_matrix(BigReal angle, Vector v, BigReal m[])
Definition: NamdOneTools.C:132
Molecule stores the structural information for the system.
Definition: Molecule.h:175
Flags flags
Definition: Patch.h:128
SubmitReduction * reduction
NAMD_HOST_DEVICE BigReal length(void) const
Definition: Vector.h:202
Vector mat_multiply_vec(const Vector &v, BigReal m[])
Definition: NamdOneTools.C:232
void get_cons_params(Real &k, Vector &refPos, int atomnum) const
Definition: Molecule.h:1349
BigReal x
Definition: Vector.h:74
#define simParams
Definition: Output.C:129
Definition: Tensor.h:15
#define ADD_VECTOR_OBJECT(R, RL, D)
Definition: ReductionMgr.h:28
void submit(void)
Definition: ReductionMgr.h:324
Bool is_atom_constrained(int atomnum) const
Definition: Molecule.h:1265
Molecule * molecule
Definition: Node.h:179
double BigReal
Definition: common.h:123
NAMD_HOST_DEVICE Vector delta(const Position &pos1, const Position &pos2) const
Definition: Lattice.h:149
int step
Definition: PatchTypes.h:16

Member Data Documentation

◆ reduction

SubmitReduction* ComputeRestraints::reduction

Definition at line 39 of file ComputeRestraints.h.

Referenced by ComputeRestraints(), doForce(), and ~ComputeRestraints().


The documentation for this class was generated from the following files: