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 ( 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 SimParameters::constraintExp, SimParameters::constrXOn, SimParameters::constrYOn, SimParameters::constrZOn, SimParameters::movingConstraintsOn, SimParameters::movingConsVel, Node::Object(), ReductionMgr::Object(), reduction, REDUCTIONS_BASIC, SimParameters::rotConsAxis, SimParameters::rotConsPivot, SimParameters::rotConstraintsOn, SimParameters::rotConsVel, SimParameters::selectConstraintsOn, 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
zVector rotConsAxis
SimParameters * simParameters
Definition: Node.h:178
Bool selectConstraintsOn
Bool movingConstraintsOn
SubmitReduction * willSubmit(int setID, int size=-1)
Definition: ReductionMgr.C:365
zVector rotConsPivot
static ReductionMgr * Object(void)
Definition: ReductionMgr.h:278
BigReal rotConsVel
SubmitReduction * reduction
#define simParams
Definition: Output.C:127
ComputeHomePatch(ComputeID c, PatchID pid)
zVector movingConsVel
ComputeRestraints::~ComputeRestraints ( )
virtual

Definition at line 65 of file ComputeRestraints.C.

References reduction.

67 {
68  delete reduction;
69 }
SubmitReduction * reduction

Member Function Documentation

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, SimParameters::constraintScaling, 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, SimParameters::sphericalConstraintsOn, SimParameters::sphericalConstrCenter, 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  // Only calculate the energy and the force if the distance is
157  // non-zero. Otherwise, you could end up dividing by 0, which
158  // is bad
159  if (r>0.0)
160  {
161  value=k;
162 
163  // Loop through and multiple k by r consExp times.
164  // i.e. calculate kr^e
165  // I know, I could use pow(), but I don't trust it.
166  for (int k=0; k<consExp; ++k)
167  {
168  value *= r;
169  }
170 
171  // Add to the energy total
172  energy += value;
173 
174  // Now calculate the force, which is ekr^(e-1). Also, divide
175  // by another factor of r to normalize the vector before we
176  // multiple it by the magnitude
177  value *= consExp;
178  value /= r2;
179 
180  Rij *= value;
181  //iout << iINFO << "restraining force" << Rij << "\n";
182 
183  f[localID] += Rij;
184  netForce += Rij;
185  virial += outer(Rij,vpos);
186  }
187  }
188  }
189 
190  reduction->item(REDUCTION_BC_ENERGY) += energy;
191  ADD_TENSOR_OBJECT(reduction,REDUCTION_VIRIAL_NORMAL,virial);
192  ADD_VECTOR_OBJECT(reduction,REDUCTION_EXT_FORCE_NORMAL,netForce);
193  reduction->submit();
194 
195 }
static Node * Object()
Definition: Node.h:86
Position fixedPosition
Definition: NamdTypes.h:102
Lattice & lattice
Definition: Patch.h:126
zVector sphericalConstrCenter
Definition: Vector.h:64
#define ADD_TENSOR_OBJECT(R, RL, D)
Definition: ReductionMgr.h:43
SimParameters * simParameters
Definition: Node.h:178
BigReal constraintScaling
float Real
Definition: common.h:109
BigReal & item(int i)
Definition: ReductionMgr.h:312
void vec_rotation_matrix(BigReal angle, Vector v, BigReal m[])
Definition: NamdOneTools.C:132
BigReal length(void) const
Definition: Vector.h:169
Bool sphericalConstraintsOn
Flags flags
Definition: Patch.h:127
SubmitReduction * reduction
Vector mat_multiply_vec(const Vector &v, BigReal m[])
Definition: NamdOneTools.C:232
Vector delta(const Position &pos1, const Position &pos2) const
Definition: Lattice.h:144
BigReal x
Definition: Vector.h:66
Tensor outer(const Vector &v1, const Vector &v2)
Definition: Tensor.h:241
Bool is_atom_constrained(int atomnum) const
Definition: Molecule.h:1201
void get_cons_params(Real &k, Vector &refPos, int atomnum) const
Definition: Molecule.h:1266
#define simParams
Definition: Output.C:127
Definition: Tensor.h:15
#define ADD_VECTOR_OBJECT(R, RL, D)
Definition: ReductionMgr.h:27
void submit(void)
Definition: ReductionMgr.h:323
Molecule * molecule
Definition: Node.h:176
double BigReal
Definition: common.h:114
int step
Definition: PatchTypes.h:16

Member Data Documentation

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: