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 
48  Force *forces = r->f[Results::normal];
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
NAMD_HOST_DEVICE Position reverse_transform(Position data, const Transform &t) const
Definition: Lattice.h:143
int32 ComputeID
Definition: NamdTypes.h:278
Lattice & lattice
Definition: Patch.h:127
virtual ~ComputeEField()
Definition: ComputeEField.C:24
NAMD_HOST_DEVICE Tensor outer(const Vector &v1, const Vector &v2)
Definition: Tensor.h:241
virtual void doForce(FullAtom *p, Results *r)
Definition: ComputeEField.C:32
Definition: Vector.h:72
#define ADD_TENSOR_OBJECT(R, RL, D)
Definition: ReductionMgr.h:44
SimParameters * simParameters
Definition: Node.h:181
BigReal & item(int i)
Definition: ReductionMgr.h:313
SubmitReduction * willSubmit(int setID, int size=-1)
Definition: ReductionMgr.C:366
static ReductionMgr * Object(void)
Definition: ReductionMgr.h:279
Flags flags
Definition: Patch.h:128
Charge charge
Definition: NamdTypes.h:78
#define PI
Definition: common.h:92
Force * f[maxNumForces]
Definition: PatchTypes.h:146
NAMD_HOST_DEVICE Vector a_r() const
Definition: Lattice.h:284
NAMD_HOST_DEVICE Vector b_r() const
Definition: Lattice.h:285
NAMD_HOST_DEVICE Vector c_r() const
Definition: Lattice.h:286
#define TWOPI
Definition: common.h:96
#define simParams
Definition: Output.C:129
SubmitReduction * reduction
Definition: ComputeEField.h:22
Definition: Tensor.h:15
#define ADD_VECTOR_OBJECT(R, RL, D)
Definition: ReductionMgr.h:28
ComputeEField(ComputeID c, PatchID pid)
Definition: ComputeEField.C:14
void submit(void)
Definition: ReductionMgr.h:324
int32 PatchID
Definition: NamdTypes.h:277
NAMD_HOST_DEVICE Vector origin() const
Definition: Lattice.h:278
HomePatch * homePatch
double BigReal
Definition: common.h:123
int step
Definition: PatchTypes.h:16