NAMD
ComputeEField.C
Go to the documentation of this file.
1 
7 #include "InfoStream.h"
8 #include "ComputeEField.h"
9 #include "Node.h"
10 #include "SimParameters.h"
11 #include "HomePatch.h"
12 
13 
15  : ComputeHomePatch(c,pid)
16 {
17 
19 
20 }
21 /* END OF FUNCTION ComputeEField */
22 
23 
25 
26 {
27  delete reduction;
28 }
29 /* END OF FUNCTION ~ComputeEField */
30 
31 
33 
35  Vector eField = simParams->eField;
36  // Calculate the angular frequency in 1/fs.
37  BigReal omega = TWOPI * simParams->eFieldFreq / 1000.;
38  BigReal phi = PI/180.* simParams->eFieldPhase;
39  BigReal t = patch->flags.step * simParams->dt;
40  Vector eField1 = cos(omega * t - phi) * eField;
41 
42  const int normalized = simParams->eFieldNormalized;
43  if ( normalized ) {
45  eField1 = Vector(l.a_r()*eField1, l.b_r()*eField1, l.c_r()*eField1);
46  }
47 
49  BigReal energy = 0;
50  Force extForce = 0.;
51  Tensor extVirial;
52 
53  // Loop through and check each atom
54  for (int i=0; i<numAtoms; i++) {
55  Force force = p[i].charge * eField1;
56  forces[i] += force;
58  p[i].position, p[i].transform );
59  energy -= force * (vpos - homePatch->lattice.origin());
60  if ( ! normalized ) {
61  extForce += force;
62  extVirial += outer(force,vpos);
63  }
64  }
65 
67  if ( ! normalized ) {
68  ADD_VECTOR_OBJECT(reduction,REDUCTION_EXT_FORCE_NORMAL,extForce);
69  ADD_TENSOR_OBJECT(reduction,REDUCTION_VIRIAL_NORMAL,extVirial);
70  }
71  reduction->submit();
72 
73 }
74 /* END OF FUNCTION force */
static Node * Object()
Definition: Node.h:86
Vector a_r() const
Definition: Lattice.h:268
int ComputeID
Definition: NamdTypes.h:183
Lattice & lattice
Definition: Patch.h:126
virtual ~ComputeEField()
Definition: ComputeEField.C:24
virtual void doForce(FullAtom *p, Results *r)
Definition: ComputeEField.C:32
Definition: Vector.h:64
BigReal eFieldFreq
#define ADD_TENSOR_OBJECT(R, RL, D)
Definition: ReductionMgr.h:43
SimParameters * simParameters
Definition: Node.h:178
Vector c_r() const
Definition: Lattice.h:270
static __thread float4 * forces
BigReal & item(int i)
Definition: ReductionMgr.h:312
SubmitReduction * willSubmit(int setID, int size=-1)
Definition: ReductionMgr.C:365
static ReductionMgr * Object(void)
Definition: ReductionMgr.h:278
Vector origin() const
Definition: Lattice.h:262
Vector b_r() const
Definition: Lattice.h:269
Flags flags
Definition: Patch.h:127
BigReal eFieldPhase
Charge charge
Definition: NamdTypes.h:54
#define PI
Definition: common.h:81
Force * f[maxNumForces]
Definition: PatchTypes.h:67
int PatchID
Definition: NamdTypes.h:182
Tensor outer(const Vector &v1, const Vector &v2)
Definition: Tensor.h:241
#define TWOPI
Definition: common.h:85
#define simParams
Definition: Output.C:127
SubmitReduction * reduction
Definition: ComputeEField.h:22
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
ComputeEField(ComputeID c, PatchID pid)
Definition: ComputeEField.C:14
void submit(void)
Definition: ReductionMgr.h:323
HomePatch * homePatch
double BigReal
Definition: common.h:112
int step
Definition: PatchTypes.h:16