4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Copyright (c) 1991-2001, University of Groningen, The Netherlands
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * If you want to redistribute modifications, please consider that
18 * scientific software is very special. Version control is crucial -
19 * bugs must be traceable. We will be happy to consider code for
20 * inclusion in the official distribution, but derived work must not
21 * be called official GROMACS. Details are found in the README & COPYING
22 * files - if they are missing, get the official version at www.gromacs.org.
24 * To help us fund GROMACS development, we humbly ask that you cite
25 * the papers on the package - you can find them in the top README file.
27 * For more info, check our website at http://www.gromacs.org
30 * GROup of MAchos and Cynical Suckers
32 static char *SRCID_psgather_c
= "$Id$";
36 #include "shift_util.h"
38 real
ps_gather_inner(int JCXYZ
[],real WXYZ
[],int ixw
[],int iyw
[],int izw
[],
39 real c1x
,real c1y
,real c1z
,real c2x
,real c2y
,real c2z
,
40 real qi
,rvec f
,real
***ptr
)
42 real pi
,fX
,fY
,fZ
,weight
;
43 int jxyz
,m
,jcx
,jcy
,jcz
;
51 /* Now loop over 27 surrounding vectors */
52 for(jxyz
=m
=0; (jxyz
< 27); jxyz
++,m
+=3) {
62 /* Electrostatic Potential ! */
63 pi
+= weight
* ptr
[jcx0
][jcy0
][jcz0
];
66 fX
+= weight
* ((c1x
*(ptr
[ixw
[jcx
-1]] [jcy0
] [jcz0
] -
67 ptr
[ixw
[jcx
+1]] [jcy0
] [jcz0
] )) +
68 (c2x
*(ptr
[ixw
[jcx
-2]] [jcy0
] [jcz0
] -
69 ptr
[ixw
[jcx
+2]] [jcy0
] [jcz0
] )));
70 fY
+= weight
* ((c1y
*(ptr
[jcx0
] [iyw
[jcy
-1]] [jcz0
] -
71 ptr
[jcx0
] [iyw
[jcy
+1]] [jcz0
] )) +
72 (c2y
*(ptr
[jcx0
] [iyw
[jcy
-2]] [jcz0
] -
73 ptr
[jcx0
] [iyw
[jcy
+2]] [jcz0
] )));
74 fZ
+= weight
* ((c1z
*(ptr
[jcx0
] [jcy0
] [izw
[jcz
-1]] -
75 ptr
[jcx0
] [jcy0
] [izw
[jcz
+1]] )) +
76 (c2z
*(ptr
[jcx0
] [jcy0
] [izw
[jcz
-2]] -
77 ptr
[jcx0
] [jcy0
] [izw
[jcz
+2]] )));
86 real
ps_gather_f(FILE *log
,bool bVerbose
,
87 int natoms
,rvec x
[],rvec f
[],real charge
[],rvec box
,
88 real pot
[],t_PSgrid
*grid
,rvec beta
,t_nrnb
*nrnb
)
90 static bool bFirst
=TRUE
;
91 static int *nnx
,*nny
,*nnz
;
99 real c1x
,c1y
,c1z
,c2x
,c2y
,c2z
;
100 int ixw
[7],iyw
[7],izw
[7];
105 unpack_PSgrid(grid
,&nx
,&ny
,&nz
,&ptr
);
107 calc_invh_h(box
,nx
,ny
,nz
,invh
,h
);
109 for(m
=0; (m
<DIM
); m
++) {
110 c1
[m
] = (beta
[m
]/2.0)*invh
[m
];
111 c2
[m
] = ((1.0-beta
[m
])/4.0)*invh
[m
];
121 fprintf(log
,"Gathering Forces using Triangle Shaped on %dx%dx%d grid\n",
123 fprintf(log
,"beta = %10g,%10g,%10g\n",beta
[XX
],beta
[YY
],beta
[ZZ
]);
124 fprintf(log
,"c1 = %10g,%10g,%10g\n",c1
[XX
],c1
[YY
],c1
[ZZ
]);
125 fprintf(log
,"c2 = %10g,%10g,%10g\n",c2
[XX
],c2
[YY
],c2
[ZZ
]);
126 fprintf(log
,"invh = %10g,%10g,%10g\n",invh
[XX
],invh
[YY
],invh
[ZZ
]);
128 calc_nxyz(nx
,ny
,nz
,&nnx
,&nny
,&nnz
);
130 for(i
=0; (i
<27); i
++) {
131 JCXYZ
[3*i
] = 2 + (i
/9);
132 JCXYZ
[3*i
+1] = 2 + (i
/3) % 3;
133 JCXYZ
[3*i
+2] = 2 + (i
% 3);
140 for(i
=0; (i
<natoms
); i
++) {
141 /* Each charge is spread over the nearest 27 grid cells,
142 * thus we loop over -1..1 in X,Y and Z direction
143 * We apply the TSC (triangle shaped charge)
144 * see Luty et. al, JCP 103 (1995) 3014
147 calc_weights(i
,nx
,ny
,nz
,x
[i
],box
,invh
,ixyz
,WXYZ
);
149 for(ll
=llim2
; (ll
<=ulim2
); ll
++) {
150 ixw
[ll
-llim2
] = nnx
[ixyz
[XX
]+ll
+nx
];
151 iyw
[ll
-llim2
] = nny
[ixyz
[YY
]+ll
+ny
];
152 izw
[ll
-llim2
] = nnz
[ixyz
[ZZ
]+ll
+nz
];
156 pi
= ps_gather_inner(JCXYZ
,WXYZ
,ixw
,iyw
,izw
,
157 c1x
,c1y
,c1z
,c2x
,c2y
,c2z
,
164 inc_nrnb(nrnb
,eNR_GATHERF
,27*natoms
);
165 inc_nrnb(nrnb
,eNR_WEIGHTS
,3*natoms
);