NAMD
ComputeFullDirectBase.h
Go to the documentation of this file.
1 
7 /*
8  Function body for calc_fulldirect.
9 */
10 
11 {
14  BigReal *dp1 = data1;
15  BigReal *rp1 = results1;
16  int j_begin = 0;
17  register BigReal electEnergy = 0.;
18  register BigReal virial_xx = 0.;
19  register BigReal virial_xy = 0.;
20  register BigReal virial_xz = 0.;
21  register BigReal virial_yy = 0.;
22  register BigReal virial_yz = 0.;
23  register BigReal virial_zz = 0.;
24 
25 #ifdef FULLDIRECT_PERIODIC
26  Vector a1 = lattice->a();
27  Vector b1(0); if ( lattice->a_p() ) b1 = lattice->a_r();
28  Vector a2 = lattice->b();
29  Vector b2(0); if ( lattice->b_p() ) b2 = lattice->b_r();
30  Vector a3 = lattice->c();
31  Vector b3(0); if ( lattice->c_p() ) b3 = lattice->c_r();
32 #endif
33 
34  for(int i=0; i<n1; ++i)
35  {
36  register BigReal p_i_x = *(dp1++);
37  register BigReal p_i_y = *(dp1++);
38  register BigReal p_i_z = *(dp1++);
39  register BigReal kq_i = coulomb * *(dp1++);
40  register BigReal f_i_x = 0.;
41  register BigReal f_i_y = 0.;
42  register BigReal f_i_z = 0.;
43  if ( selfmode )
44  {
45  ++j_begin; data2 += 4; results2 += 3;
46  }
47  register BigReal *dp2 = data2;
48  register BigReal *rp2 = results2;
49  register int n2c = n2;
50  register int j;
51  for( j = j_begin; j<n2c; ++j)
52  {
53  register BigReal p_ij_x = p_i_x - *(dp2++);
54  register BigReal p_ij_y = p_i_y - *(dp2++);
55  register BigReal p_ij_z = p_i_z - *(dp2++);
56 
57 #ifdef FULLDIRECT_PERIODIC
58  Vector p_ij(p_ij_x,p_ij_y,p_ij_z);
59  p_ij -= ( a1*floor(0.5+b1*p_ij) + a2*floor(0.5+b2*p_ij) + a3*floor(0.5+b3*p_ij) );
60  p_ij_x = p_ij.x;
61  p_ij_y = p_ij.y;
62  p_ij_z = p_ij.z;
63 #endif
64 
65  register BigReal r_1;
66  r_1 = 1./sqrt(p_ij_x * p_ij_x + p_ij_y * p_ij_y + p_ij_z * p_ij_z);
67  register BigReal f = *(dp2++) * kq_i * r_1;
68  electEnergy += f;
69  f *= r_1*r_1;
70  virial_xx += f * p_ij_x * p_ij_x;
71  virial_xy += f * p_ij_x * p_ij_y;
72  virial_xz += f * p_ij_x * p_ij_z;
73  p_ij_x *= f;
74  virial_yy += f * p_ij_y * p_ij_y;
75  virial_yz += f * p_ij_y * p_ij_z;
76  p_ij_y *= f;
77  virial_zz += f * p_ij_z * p_ij_z;
78  p_ij_z *= f;
79  f_i_x += p_ij_x;
80  f_i_y += p_ij_y;
81  f_i_z += p_ij_z;
82  *(rp2++) -= p_ij_x;
83  *(rp2++) -= p_ij_y;
84  *(rp2++) -= p_ij_z;
85  }
86  *(rp1++) += f_i_x;
87  *(rp1++) += f_i_y;
88  *(rp1++) += f_i_z;
89  }
90 
91  virial.xx += virial_xx;
92  virial.xy += virial_xy;
93  virial.xz += virial_xz;
94  virial.yx += virial_xy;
95  virial.yy += virial_yy;
96  virial.yz += virial_yz;
97  virial.zx += virial_xz;
98  virial.zy += virial_yz;
99  virial.zz += virial_zz;
100  return electEnergy;
101 }
102 
register BigReal virial_xy
register BigReal virial_xz
int j_begin
register BigReal virial_yz
Definition: Vector.h:64
register BigReal electEnergy
#define COULOMB
Definition: common.h:44
BigReal * dp1
register const BigReal p_ij_z
register BigReal virial_yy
register BigReal virial_zz
const BigReal coulomb
register const BigReal p_ij_x
register BigReal virial_xx
BigReal * rp1
register const BigReal p_ij_y
double BigReal
Definition: common.h:112