Remove all unnecessary HAVE_CONFIG_H
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecEw_VdwLJEw_GeomW4W4_c.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS c kernel generator.
37  */
38 #include "config.h"
39
40 #include <math.h>
41
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "nrnb.h"
46
47 /*
48  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwLJEw_GeomW4W4_VF_c
49  * Electrostatics interaction: Ewald
50  * VdW interaction:            LJEwald
51  * Geometry:                   Water4-Water4
52  * Calculate force/pot:        PotentialAndForce
53  */
54 void
55 nb_kernel_ElecEw_VdwLJEw_GeomW4W4_VF_c
56                     (t_nblist                    * gmx_restrict       nlist,
57                      rvec                        * gmx_restrict          xx,
58                      rvec                        * gmx_restrict          ff,
59                      t_forcerec                  * gmx_restrict          fr,
60                      t_mdatoms                   * gmx_restrict     mdatoms,
61                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
62                      t_nrnb                      * gmx_restrict        nrnb)
63 {
64     int              i_shift_offset,i_coord_offset,j_coord_offset;
65     int              j_index_start,j_index_end;
66     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
67     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
68     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
69     real             *shiftvec,*fshift,*x,*f;
70     int              vdwioffset0;
71     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
72     int              vdwioffset1;
73     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
74     int              vdwioffset2;
75     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
76     int              vdwioffset3;
77     real             ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
78     int              vdwjidx0;
79     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
80     int              vdwjidx1;
81     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
82     int              vdwjidx2;
83     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
84     int              vdwjidx3;
85     real             jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
86     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
87     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
88     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
89     real             dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13,cexp1_13,cexp2_13;
90     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
91     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
92     real             dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23,cexp1_23,cexp2_23;
93     real             dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31,cexp1_31,cexp2_31;
94     real             dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32,cexp1_32,cexp2_32;
95     real             dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33,cexp1_33,cexp2_33;
96     real             velec,felec,velecsum,facel,crf,krf,krf2;
97     real             *charge;
98     int              nvdwtype;
99     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
100     int              *vdwtype;
101     real             *vdwparam;
102     real             c6grid_00;
103     real             c6grid_11;
104     real             c6grid_12;
105     real             c6grid_13;
106     real             c6grid_21;
107     real             c6grid_22;
108     real             c6grid_23;
109     real             c6grid_31;
110     real             c6grid_32;
111     real             c6grid_33;
112     real             ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,sh_lj_ewald;
113     real             *vdwgridparam;
114     int              ewitab;
115     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
116     real             *ewtab;
117
118     x                = xx[0];
119     f                = ff[0];
120
121     nri              = nlist->nri;
122     iinr             = nlist->iinr;
123     jindex           = nlist->jindex;
124     jjnr             = nlist->jjnr;
125     shiftidx         = nlist->shift;
126     gid              = nlist->gid;
127     shiftvec         = fr->shift_vec[0];
128     fshift           = fr->fshift[0];
129     facel            = fr->epsfac;
130     charge           = mdatoms->chargeA;
131     nvdwtype         = fr->ntype;
132     vdwparam         = fr->nbfp;
133     vdwtype          = mdatoms->typeA;
134     vdwgridparam     = fr->ljpme_c6grid;
135     ewclj            = fr->ewaldcoeff_lj;
136     sh_lj_ewald      = fr->ic->sh_lj_ewald;
137     ewclj2           = ewclj*ewclj;
138     ewclj6           = ewclj2*ewclj2*ewclj2;
139
140     sh_ewald         = fr->ic->sh_ewald;
141     ewtab            = fr->ic->tabq_coul_FDV0;
142     ewtabscale       = fr->ic->tabq_scale;
143     ewtabhalfspace   = 0.5/ewtabscale;
144
145     /* Setup water-specific parameters */
146     inr              = nlist->iinr[0];
147     iq1              = facel*charge[inr+1];
148     iq2              = facel*charge[inr+2];
149     iq3              = facel*charge[inr+3];
150     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
151
152     jq1              = charge[inr+1];
153     jq2              = charge[inr+2];
154     jq3              = charge[inr+3];
155     vdwjidx0         = 2*vdwtype[inr+0];
156     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
157     c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
158     c6grid_00        = vdwgridparam[vdwioffset0+vdwjidx0];
159     qq11             = iq1*jq1;
160     qq12             = iq1*jq2;
161     qq13             = iq1*jq3;
162     qq21             = iq2*jq1;
163     qq22             = iq2*jq2;
164     qq23             = iq2*jq3;
165     qq31             = iq3*jq1;
166     qq32             = iq3*jq2;
167     qq33             = iq3*jq3;
168
169     outeriter        = 0;
170     inneriter        = 0;
171
172     /* Start outer loop over neighborlists */
173     for(iidx=0; iidx<nri; iidx++)
174     {
175         /* Load shift vector for this list */
176         i_shift_offset   = DIM*shiftidx[iidx];
177         shX              = shiftvec[i_shift_offset+XX];
178         shY              = shiftvec[i_shift_offset+YY];
179         shZ              = shiftvec[i_shift_offset+ZZ];
180
181         /* Load limits for loop over neighbors */
182         j_index_start    = jindex[iidx];
183         j_index_end      = jindex[iidx+1];
184
185         /* Get outer coordinate index */
186         inr              = iinr[iidx];
187         i_coord_offset   = DIM*inr;
188
189         /* Load i particle coords and add shift vector */
190         ix0              = shX + x[i_coord_offset+DIM*0+XX];
191         iy0              = shY + x[i_coord_offset+DIM*0+YY];
192         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
193         ix1              = shX + x[i_coord_offset+DIM*1+XX];
194         iy1              = shY + x[i_coord_offset+DIM*1+YY];
195         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
196         ix2              = shX + x[i_coord_offset+DIM*2+XX];
197         iy2              = shY + x[i_coord_offset+DIM*2+YY];
198         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
199         ix3              = shX + x[i_coord_offset+DIM*3+XX];
200         iy3              = shY + x[i_coord_offset+DIM*3+YY];
201         iz3              = shZ + x[i_coord_offset+DIM*3+ZZ];
202
203         fix0             = 0.0;
204         fiy0             = 0.0;
205         fiz0             = 0.0;
206         fix1             = 0.0;
207         fiy1             = 0.0;
208         fiz1             = 0.0;
209         fix2             = 0.0;
210         fiy2             = 0.0;
211         fiz2             = 0.0;
212         fix3             = 0.0;
213         fiy3             = 0.0;
214         fiz3             = 0.0;
215
216         /* Reset potential sums */
217         velecsum         = 0.0;
218         vvdwsum          = 0.0;
219
220         /* Start inner kernel loop */
221         for(jidx=j_index_start; jidx<j_index_end; jidx++)
222         {
223             /* Get j neighbor index, and coordinate index */
224             jnr              = jjnr[jidx];
225             j_coord_offset   = DIM*jnr;
226
227             /* load j atom coordinates */
228             jx0              = x[j_coord_offset+DIM*0+XX];
229             jy0              = x[j_coord_offset+DIM*0+YY];
230             jz0              = x[j_coord_offset+DIM*0+ZZ];
231             jx1              = x[j_coord_offset+DIM*1+XX];
232             jy1              = x[j_coord_offset+DIM*1+YY];
233             jz1              = x[j_coord_offset+DIM*1+ZZ];
234             jx2              = x[j_coord_offset+DIM*2+XX];
235             jy2              = x[j_coord_offset+DIM*2+YY];
236             jz2              = x[j_coord_offset+DIM*2+ZZ];
237             jx3              = x[j_coord_offset+DIM*3+XX];
238             jy3              = x[j_coord_offset+DIM*3+YY];
239             jz3              = x[j_coord_offset+DIM*3+ZZ];
240
241             /* Calculate displacement vector */
242             dx00             = ix0 - jx0;
243             dy00             = iy0 - jy0;
244             dz00             = iz0 - jz0;
245             dx11             = ix1 - jx1;
246             dy11             = iy1 - jy1;
247             dz11             = iz1 - jz1;
248             dx12             = ix1 - jx2;
249             dy12             = iy1 - jy2;
250             dz12             = iz1 - jz2;
251             dx13             = ix1 - jx3;
252             dy13             = iy1 - jy3;
253             dz13             = iz1 - jz3;
254             dx21             = ix2 - jx1;
255             dy21             = iy2 - jy1;
256             dz21             = iz2 - jz1;
257             dx22             = ix2 - jx2;
258             dy22             = iy2 - jy2;
259             dz22             = iz2 - jz2;
260             dx23             = ix2 - jx3;
261             dy23             = iy2 - jy3;
262             dz23             = iz2 - jz3;
263             dx31             = ix3 - jx1;
264             dy31             = iy3 - jy1;
265             dz31             = iz3 - jz1;
266             dx32             = ix3 - jx2;
267             dy32             = iy3 - jy2;
268             dz32             = iz3 - jz2;
269             dx33             = ix3 - jx3;
270             dy33             = iy3 - jy3;
271             dz33             = iz3 - jz3;
272
273             /* Calculate squared distance and things based on it */
274             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
275             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
276             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
277             rsq13            = dx13*dx13+dy13*dy13+dz13*dz13;
278             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
279             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
280             rsq23            = dx23*dx23+dy23*dy23+dz23*dz23;
281             rsq31            = dx31*dx31+dy31*dy31+dz31*dz31;
282             rsq32            = dx32*dx32+dy32*dy32+dz32*dz32;
283             rsq33            = dx33*dx33+dy33*dy33+dz33*dz33;
284
285             rinv00           = gmx_invsqrt(rsq00);
286             rinv11           = gmx_invsqrt(rsq11);
287             rinv12           = gmx_invsqrt(rsq12);
288             rinv13           = gmx_invsqrt(rsq13);
289             rinv21           = gmx_invsqrt(rsq21);
290             rinv22           = gmx_invsqrt(rsq22);
291             rinv23           = gmx_invsqrt(rsq23);
292             rinv31           = gmx_invsqrt(rsq31);
293             rinv32           = gmx_invsqrt(rsq32);
294             rinv33           = gmx_invsqrt(rsq33);
295
296             rinvsq00         = rinv00*rinv00;
297             rinvsq11         = rinv11*rinv11;
298             rinvsq12         = rinv12*rinv12;
299             rinvsq13         = rinv13*rinv13;
300             rinvsq21         = rinv21*rinv21;
301             rinvsq22         = rinv22*rinv22;
302             rinvsq23         = rinv23*rinv23;
303             rinvsq31         = rinv31*rinv31;
304             rinvsq32         = rinv32*rinv32;
305             rinvsq33         = rinv33*rinv33;
306
307             /**************************
308              * CALCULATE INTERACTIONS *
309              **************************/
310
311             r00              = rsq00*rinv00;
312
313             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
314             ewcljrsq         = ewclj2*rsq00;
315             exponent         = exp(-ewcljrsq);
316             poly             = exponent*(1.0 + ewcljrsq + ewcljrsq*ewcljrsq*0.5);
317             vvdw6            = (c6_00-c6grid_00*(1.0-poly))*rinvsix;
318             vvdw12           = c12_00*rinvsix*rinvsix;
319             vvdw             = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
320             fvdw             = (vvdw12 - vvdw6 - c6grid_00*(1.0/6.0)*exponent*ewclj6)*rinvsq00;
321
322             /* Update potential sums from outer loop */
323             vvdwsum         += vvdw;
324
325             fscal            = fvdw;
326
327             /* Calculate temporary vectorial force */
328             tx               = fscal*dx00;
329             ty               = fscal*dy00;
330             tz               = fscal*dz00;
331
332             /* Update vectorial force */
333             fix0            += tx;
334             fiy0            += ty;
335             fiz0            += tz;
336             f[j_coord_offset+DIM*0+XX] -= tx;
337             f[j_coord_offset+DIM*0+YY] -= ty;
338             f[j_coord_offset+DIM*0+ZZ] -= tz;
339
340             /**************************
341              * CALCULATE INTERACTIONS *
342              **************************/
343
344             r11              = rsq11*rinv11;
345
346             /* EWALD ELECTROSTATICS */
347
348             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
349             ewrt             = r11*ewtabscale;
350             ewitab           = ewrt;
351             eweps            = ewrt-ewitab;
352             ewitab           = 4*ewitab;
353             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
354             velec            = qq11*(rinv11-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
355             felec            = qq11*rinv11*(rinvsq11-felec);
356
357             /* Update potential sums from outer loop */
358             velecsum        += velec;
359
360             fscal            = felec;
361
362             /* Calculate temporary vectorial force */
363             tx               = fscal*dx11;
364             ty               = fscal*dy11;
365             tz               = fscal*dz11;
366
367             /* Update vectorial force */
368             fix1            += tx;
369             fiy1            += ty;
370             fiz1            += tz;
371             f[j_coord_offset+DIM*1+XX] -= tx;
372             f[j_coord_offset+DIM*1+YY] -= ty;
373             f[j_coord_offset+DIM*1+ZZ] -= tz;
374
375             /**************************
376              * CALCULATE INTERACTIONS *
377              **************************/
378
379             r12              = rsq12*rinv12;
380
381             /* EWALD ELECTROSTATICS */
382
383             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
384             ewrt             = r12*ewtabscale;
385             ewitab           = ewrt;
386             eweps            = ewrt-ewitab;
387             ewitab           = 4*ewitab;
388             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
389             velec            = qq12*(rinv12-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
390             felec            = qq12*rinv12*(rinvsq12-felec);
391
392             /* Update potential sums from outer loop */
393             velecsum        += velec;
394
395             fscal            = felec;
396
397             /* Calculate temporary vectorial force */
398             tx               = fscal*dx12;
399             ty               = fscal*dy12;
400             tz               = fscal*dz12;
401
402             /* Update vectorial force */
403             fix1            += tx;
404             fiy1            += ty;
405             fiz1            += tz;
406             f[j_coord_offset+DIM*2+XX] -= tx;
407             f[j_coord_offset+DIM*2+YY] -= ty;
408             f[j_coord_offset+DIM*2+ZZ] -= tz;
409
410             /**************************
411              * CALCULATE INTERACTIONS *
412              **************************/
413
414             r13              = rsq13*rinv13;
415
416             /* EWALD ELECTROSTATICS */
417
418             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
419             ewrt             = r13*ewtabscale;
420             ewitab           = ewrt;
421             eweps            = ewrt-ewitab;
422             ewitab           = 4*ewitab;
423             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
424             velec            = qq13*(rinv13-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
425             felec            = qq13*rinv13*(rinvsq13-felec);
426
427             /* Update potential sums from outer loop */
428             velecsum        += velec;
429
430             fscal            = felec;
431
432             /* Calculate temporary vectorial force */
433             tx               = fscal*dx13;
434             ty               = fscal*dy13;
435             tz               = fscal*dz13;
436
437             /* Update vectorial force */
438             fix1            += tx;
439             fiy1            += ty;
440             fiz1            += tz;
441             f[j_coord_offset+DIM*3+XX] -= tx;
442             f[j_coord_offset+DIM*3+YY] -= ty;
443             f[j_coord_offset+DIM*3+ZZ] -= tz;
444
445             /**************************
446              * CALCULATE INTERACTIONS *
447              **************************/
448
449             r21              = rsq21*rinv21;
450
451             /* EWALD ELECTROSTATICS */
452
453             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
454             ewrt             = r21*ewtabscale;
455             ewitab           = ewrt;
456             eweps            = ewrt-ewitab;
457             ewitab           = 4*ewitab;
458             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
459             velec            = qq21*(rinv21-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
460             felec            = qq21*rinv21*(rinvsq21-felec);
461
462             /* Update potential sums from outer loop */
463             velecsum        += velec;
464
465             fscal            = felec;
466
467             /* Calculate temporary vectorial force */
468             tx               = fscal*dx21;
469             ty               = fscal*dy21;
470             tz               = fscal*dz21;
471
472             /* Update vectorial force */
473             fix2            += tx;
474             fiy2            += ty;
475             fiz2            += tz;
476             f[j_coord_offset+DIM*1+XX] -= tx;
477             f[j_coord_offset+DIM*1+YY] -= ty;
478             f[j_coord_offset+DIM*1+ZZ] -= tz;
479
480             /**************************
481              * CALCULATE INTERACTIONS *
482              **************************/
483
484             r22              = rsq22*rinv22;
485
486             /* EWALD ELECTROSTATICS */
487
488             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
489             ewrt             = r22*ewtabscale;
490             ewitab           = ewrt;
491             eweps            = ewrt-ewitab;
492             ewitab           = 4*ewitab;
493             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
494             velec            = qq22*(rinv22-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
495             felec            = qq22*rinv22*(rinvsq22-felec);
496
497             /* Update potential sums from outer loop */
498             velecsum        += velec;
499
500             fscal            = felec;
501
502             /* Calculate temporary vectorial force */
503             tx               = fscal*dx22;
504             ty               = fscal*dy22;
505             tz               = fscal*dz22;
506
507             /* Update vectorial force */
508             fix2            += tx;
509             fiy2            += ty;
510             fiz2            += tz;
511             f[j_coord_offset+DIM*2+XX] -= tx;
512             f[j_coord_offset+DIM*2+YY] -= ty;
513             f[j_coord_offset+DIM*2+ZZ] -= tz;
514
515             /**************************
516              * CALCULATE INTERACTIONS *
517              **************************/
518
519             r23              = rsq23*rinv23;
520
521             /* EWALD ELECTROSTATICS */
522
523             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
524             ewrt             = r23*ewtabscale;
525             ewitab           = ewrt;
526             eweps            = ewrt-ewitab;
527             ewitab           = 4*ewitab;
528             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
529             velec            = qq23*(rinv23-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
530             felec            = qq23*rinv23*(rinvsq23-felec);
531
532             /* Update potential sums from outer loop */
533             velecsum        += velec;
534
535             fscal            = felec;
536
537             /* Calculate temporary vectorial force */
538             tx               = fscal*dx23;
539             ty               = fscal*dy23;
540             tz               = fscal*dz23;
541
542             /* Update vectorial force */
543             fix2            += tx;
544             fiy2            += ty;
545             fiz2            += tz;
546             f[j_coord_offset+DIM*3+XX] -= tx;
547             f[j_coord_offset+DIM*3+YY] -= ty;
548             f[j_coord_offset+DIM*3+ZZ] -= tz;
549
550             /**************************
551              * CALCULATE INTERACTIONS *
552              **************************/
553
554             r31              = rsq31*rinv31;
555
556             /* EWALD ELECTROSTATICS */
557
558             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
559             ewrt             = r31*ewtabscale;
560             ewitab           = ewrt;
561             eweps            = ewrt-ewitab;
562             ewitab           = 4*ewitab;
563             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
564             velec            = qq31*(rinv31-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
565             felec            = qq31*rinv31*(rinvsq31-felec);
566
567             /* Update potential sums from outer loop */
568             velecsum        += velec;
569
570             fscal            = felec;
571
572             /* Calculate temporary vectorial force */
573             tx               = fscal*dx31;
574             ty               = fscal*dy31;
575             tz               = fscal*dz31;
576
577             /* Update vectorial force */
578             fix3            += tx;
579             fiy3            += ty;
580             fiz3            += tz;
581             f[j_coord_offset+DIM*1+XX] -= tx;
582             f[j_coord_offset+DIM*1+YY] -= ty;
583             f[j_coord_offset+DIM*1+ZZ] -= tz;
584
585             /**************************
586              * CALCULATE INTERACTIONS *
587              **************************/
588
589             r32              = rsq32*rinv32;
590
591             /* EWALD ELECTROSTATICS */
592
593             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
594             ewrt             = r32*ewtabscale;
595             ewitab           = ewrt;
596             eweps            = ewrt-ewitab;
597             ewitab           = 4*ewitab;
598             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
599             velec            = qq32*(rinv32-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
600             felec            = qq32*rinv32*(rinvsq32-felec);
601
602             /* Update potential sums from outer loop */
603             velecsum        += velec;
604
605             fscal            = felec;
606
607             /* Calculate temporary vectorial force */
608             tx               = fscal*dx32;
609             ty               = fscal*dy32;
610             tz               = fscal*dz32;
611
612             /* Update vectorial force */
613             fix3            += tx;
614             fiy3            += ty;
615             fiz3            += tz;
616             f[j_coord_offset+DIM*2+XX] -= tx;
617             f[j_coord_offset+DIM*2+YY] -= ty;
618             f[j_coord_offset+DIM*2+ZZ] -= tz;
619
620             /**************************
621              * CALCULATE INTERACTIONS *
622              **************************/
623
624             r33              = rsq33*rinv33;
625
626             /* EWALD ELECTROSTATICS */
627
628             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
629             ewrt             = r33*ewtabscale;
630             ewitab           = ewrt;
631             eweps            = ewrt-ewitab;
632             ewitab           = 4*ewitab;
633             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
634             velec            = qq33*(rinv33-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
635             felec            = qq33*rinv33*(rinvsq33-felec);
636
637             /* Update potential sums from outer loop */
638             velecsum        += velec;
639
640             fscal            = felec;
641
642             /* Calculate temporary vectorial force */
643             tx               = fscal*dx33;
644             ty               = fscal*dy33;
645             tz               = fscal*dz33;
646
647             /* Update vectorial force */
648             fix3            += tx;
649             fiy3            += ty;
650             fiz3            += tz;
651             f[j_coord_offset+DIM*3+XX] -= tx;
652             f[j_coord_offset+DIM*3+YY] -= ty;
653             f[j_coord_offset+DIM*3+ZZ] -= tz;
654
655             /* Inner loop uses 409 flops */
656         }
657         /* End of innermost loop */
658
659         tx = ty = tz = 0;
660         f[i_coord_offset+DIM*0+XX] += fix0;
661         f[i_coord_offset+DIM*0+YY] += fiy0;
662         f[i_coord_offset+DIM*0+ZZ] += fiz0;
663         tx                         += fix0;
664         ty                         += fiy0;
665         tz                         += fiz0;
666         f[i_coord_offset+DIM*1+XX] += fix1;
667         f[i_coord_offset+DIM*1+YY] += fiy1;
668         f[i_coord_offset+DIM*1+ZZ] += fiz1;
669         tx                         += fix1;
670         ty                         += fiy1;
671         tz                         += fiz1;
672         f[i_coord_offset+DIM*2+XX] += fix2;
673         f[i_coord_offset+DIM*2+YY] += fiy2;
674         f[i_coord_offset+DIM*2+ZZ] += fiz2;
675         tx                         += fix2;
676         ty                         += fiy2;
677         tz                         += fiz2;
678         f[i_coord_offset+DIM*3+XX] += fix3;
679         f[i_coord_offset+DIM*3+YY] += fiy3;
680         f[i_coord_offset+DIM*3+ZZ] += fiz3;
681         tx                         += fix3;
682         ty                         += fiy3;
683         tz                         += fiz3;
684         fshift[i_shift_offset+XX]  += tx;
685         fshift[i_shift_offset+YY]  += ty;
686         fshift[i_shift_offset+ZZ]  += tz;
687
688         ggid                        = gid[iidx];
689         /* Update potential energies */
690         kernel_data->energygrp_elec[ggid] += velecsum;
691         kernel_data->energygrp_vdw[ggid] += vvdwsum;
692
693         /* Increment number of inner iterations */
694         inneriter                  += j_index_end - j_index_start;
695
696         /* Outer loop uses 41 flops */
697     }
698
699     /* Increment number of outer iterations */
700     outeriter        += nri;
701
702     /* Update outer/inner flops */
703
704     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_VF,outeriter*41 + inneriter*409);
705 }
706 /*
707  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwLJEw_GeomW4W4_F_c
708  * Electrostatics interaction: Ewald
709  * VdW interaction:            LJEwald
710  * Geometry:                   Water4-Water4
711  * Calculate force/pot:        Force
712  */
713 void
714 nb_kernel_ElecEw_VdwLJEw_GeomW4W4_F_c
715                     (t_nblist                    * gmx_restrict       nlist,
716                      rvec                        * gmx_restrict          xx,
717                      rvec                        * gmx_restrict          ff,
718                      t_forcerec                  * gmx_restrict          fr,
719                      t_mdatoms                   * gmx_restrict     mdatoms,
720                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
721                      t_nrnb                      * gmx_restrict        nrnb)
722 {
723     int              i_shift_offset,i_coord_offset,j_coord_offset;
724     int              j_index_start,j_index_end;
725     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
726     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
727     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
728     real             *shiftvec,*fshift,*x,*f;
729     int              vdwioffset0;
730     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
731     int              vdwioffset1;
732     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
733     int              vdwioffset2;
734     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
735     int              vdwioffset3;
736     real             ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
737     int              vdwjidx0;
738     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
739     int              vdwjidx1;
740     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
741     int              vdwjidx2;
742     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
743     int              vdwjidx3;
744     real             jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
745     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
746     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
747     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
748     real             dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13,cexp1_13,cexp2_13;
749     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
750     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
751     real             dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23,cexp1_23,cexp2_23;
752     real             dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31,cexp1_31,cexp2_31;
753     real             dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32,cexp1_32,cexp2_32;
754     real             dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33,cexp1_33,cexp2_33;
755     real             velec,felec,velecsum,facel,crf,krf,krf2;
756     real             *charge;
757     int              nvdwtype;
758     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
759     int              *vdwtype;
760     real             *vdwparam;
761     real             c6grid_00;
762     real             c6grid_11;
763     real             c6grid_12;
764     real             c6grid_13;
765     real             c6grid_21;
766     real             c6grid_22;
767     real             c6grid_23;
768     real             c6grid_31;
769     real             c6grid_32;
770     real             c6grid_33;
771     real             ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,sh_lj_ewald;
772     real             *vdwgridparam;
773     int              ewitab;
774     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
775     real             *ewtab;
776
777     x                = xx[0];
778     f                = ff[0];
779
780     nri              = nlist->nri;
781     iinr             = nlist->iinr;
782     jindex           = nlist->jindex;
783     jjnr             = nlist->jjnr;
784     shiftidx         = nlist->shift;
785     gid              = nlist->gid;
786     shiftvec         = fr->shift_vec[0];
787     fshift           = fr->fshift[0];
788     facel            = fr->epsfac;
789     charge           = mdatoms->chargeA;
790     nvdwtype         = fr->ntype;
791     vdwparam         = fr->nbfp;
792     vdwtype          = mdatoms->typeA;
793     vdwgridparam     = fr->ljpme_c6grid;
794     ewclj            = fr->ewaldcoeff_lj;
795     sh_lj_ewald      = fr->ic->sh_lj_ewald;
796     ewclj2           = ewclj*ewclj;
797     ewclj6           = ewclj2*ewclj2*ewclj2;
798
799     sh_ewald         = fr->ic->sh_ewald;
800     ewtab            = fr->ic->tabq_coul_F;
801     ewtabscale       = fr->ic->tabq_scale;
802     ewtabhalfspace   = 0.5/ewtabscale;
803
804     /* Setup water-specific parameters */
805     inr              = nlist->iinr[0];
806     iq1              = facel*charge[inr+1];
807     iq2              = facel*charge[inr+2];
808     iq3              = facel*charge[inr+3];
809     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
810
811     jq1              = charge[inr+1];
812     jq2              = charge[inr+2];
813     jq3              = charge[inr+3];
814     vdwjidx0         = 2*vdwtype[inr+0];
815     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
816     c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
817     c6grid_00        = vdwgridparam[vdwioffset0+vdwjidx0];
818     qq11             = iq1*jq1;
819     qq12             = iq1*jq2;
820     qq13             = iq1*jq3;
821     qq21             = iq2*jq1;
822     qq22             = iq2*jq2;
823     qq23             = iq2*jq3;
824     qq31             = iq3*jq1;
825     qq32             = iq3*jq2;
826     qq33             = iq3*jq3;
827
828     outeriter        = 0;
829     inneriter        = 0;
830
831     /* Start outer loop over neighborlists */
832     for(iidx=0; iidx<nri; iidx++)
833     {
834         /* Load shift vector for this list */
835         i_shift_offset   = DIM*shiftidx[iidx];
836         shX              = shiftvec[i_shift_offset+XX];
837         shY              = shiftvec[i_shift_offset+YY];
838         shZ              = shiftvec[i_shift_offset+ZZ];
839
840         /* Load limits for loop over neighbors */
841         j_index_start    = jindex[iidx];
842         j_index_end      = jindex[iidx+1];
843
844         /* Get outer coordinate index */
845         inr              = iinr[iidx];
846         i_coord_offset   = DIM*inr;
847
848         /* Load i particle coords and add shift vector */
849         ix0              = shX + x[i_coord_offset+DIM*0+XX];
850         iy0              = shY + x[i_coord_offset+DIM*0+YY];
851         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
852         ix1              = shX + x[i_coord_offset+DIM*1+XX];
853         iy1              = shY + x[i_coord_offset+DIM*1+YY];
854         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
855         ix2              = shX + x[i_coord_offset+DIM*2+XX];
856         iy2              = shY + x[i_coord_offset+DIM*2+YY];
857         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
858         ix3              = shX + x[i_coord_offset+DIM*3+XX];
859         iy3              = shY + x[i_coord_offset+DIM*3+YY];
860         iz3              = shZ + x[i_coord_offset+DIM*3+ZZ];
861
862         fix0             = 0.0;
863         fiy0             = 0.0;
864         fiz0             = 0.0;
865         fix1             = 0.0;
866         fiy1             = 0.0;
867         fiz1             = 0.0;
868         fix2             = 0.0;
869         fiy2             = 0.0;
870         fiz2             = 0.0;
871         fix3             = 0.0;
872         fiy3             = 0.0;
873         fiz3             = 0.0;
874
875         /* Start inner kernel loop */
876         for(jidx=j_index_start; jidx<j_index_end; jidx++)
877         {
878             /* Get j neighbor index, and coordinate index */
879             jnr              = jjnr[jidx];
880             j_coord_offset   = DIM*jnr;
881
882             /* load j atom coordinates */
883             jx0              = x[j_coord_offset+DIM*0+XX];
884             jy0              = x[j_coord_offset+DIM*0+YY];
885             jz0              = x[j_coord_offset+DIM*0+ZZ];
886             jx1              = x[j_coord_offset+DIM*1+XX];
887             jy1              = x[j_coord_offset+DIM*1+YY];
888             jz1              = x[j_coord_offset+DIM*1+ZZ];
889             jx2              = x[j_coord_offset+DIM*2+XX];
890             jy2              = x[j_coord_offset+DIM*2+YY];
891             jz2              = x[j_coord_offset+DIM*2+ZZ];
892             jx3              = x[j_coord_offset+DIM*3+XX];
893             jy3              = x[j_coord_offset+DIM*3+YY];
894             jz3              = x[j_coord_offset+DIM*3+ZZ];
895
896             /* Calculate displacement vector */
897             dx00             = ix0 - jx0;
898             dy00             = iy0 - jy0;
899             dz00             = iz0 - jz0;
900             dx11             = ix1 - jx1;
901             dy11             = iy1 - jy1;
902             dz11             = iz1 - jz1;
903             dx12             = ix1 - jx2;
904             dy12             = iy1 - jy2;
905             dz12             = iz1 - jz2;
906             dx13             = ix1 - jx3;
907             dy13             = iy1 - jy3;
908             dz13             = iz1 - jz3;
909             dx21             = ix2 - jx1;
910             dy21             = iy2 - jy1;
911             dz21             = iz2 - jz1;
912             dx22             = ix2 - jx2;
913             dy22             = iy2 - jy2;
914             dz22             = iz2 - jz2;
915             dx23             = ix2 - jx3;
916             dy23             = iy2 - jy3;
917             dz23             = iz2 - jz3;
918             dx31             = ix3 - jx1;
919             dy31             = iy3 - jy1;
920             dz31             = iz3 - jz1;
921             dx32             = ix3 - jx2;
922             dy32             = iy3 - jy2;
923             dz32             = iz3 - jz2;
924             dx33             = ix3 - jx3;
925             dy33             = iy3 - jy3;
926             dz33             = iz3 - jz3;
927
928             /* Calculate squared distance and things based on it */
929             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
930             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
931             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
932             rsq13            = dx13*dx13+dy13*dy13+dz13*dz13;
933             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
934             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
935             rsq23            = dx23*dx23+dy23*dy23+dz23*dz23;
936             rsq31            = dx31*dx31+dy31*dy31+dz31*dz31;
937             rsq32            = dx32*dx32+dy32*dy32+dz32*dz32;
938             rsq33            = dx33*dx33+dy33*dy33+dz33*dz33;
939
940             rinv00           = gmx_invsqrt(rsq00);
941             rinv11           = gmx_invsqrt(rsq11);
942             rinv12           = gmx_invsqrt(rsq12);
943             rinv13           = gmx_invsqrt(rsq13);
944             rinv21           = gmx_invsqrt(rsq21);
945             rinv22           = gmx_invsqrt(rsq22);
946             rinv23           = gmx_invsqrt(rsq23);
947             rinv31           = gmx_invsqrt(rsq31);
948             rinv32           = gmx_invsqrt(rsq32);
949             rinv33           = gmx_invsqrt(rsq33);
950
951             rinvsq00         = rinv00*rinv00;
952             rinvsq11         = rinv11*rinv11;
953             rinvsq12         = rinv12*rinv12;
954             rinvsq13         = rinv13*rinv13;
955             rinvsq21         = rinv21*rinv21;
956             rinvsq22         = rinv22*rinv22;
957             rinvsq23         = rinv23*rinv23;
958             rinvsq31         = rinv31*rinv31;
959             rinvsq32         = rinv32*rinv32;
960             rinvsq33         = rinv33*rinv33;
961
962             /**************************
963              * CALCULATE INTERACTIONS *
964              **************************/
965
966             r00              = rsq00*rinv00;
967
968             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
969             ewcljrsq         = ewclj2*rsq00;
970             exponent         = exp(-ewcljrsq);
971             poly             = exponent*(1.0 + ewcljrsq + ewcljrsq*ewcljrsq*0.5);
972             fvdw             = (((c12_00*rinvsix - c6_00 + c6grid_00*(1.0-poly))*rinvsix) - c6grid_00*(1.0/6.0)*exponent*ewclj6)*rinvsq00;
973
974             fscal            = fvdw;
975
976             /* Calculate temporary vectorial force */
977             tx               = fscal*dx00;
978             ty               = fscal*dy00;
979             tz               = fscal*dz00;
980
981             /* Update vectorial force */
982             fix0            += tx;
983             fiy0            += ty;
984             fiz0            += tz;
985             f[j_coord_offset+DIM*0+XX] -= tx;
986             f[j_coord_offset+DIM*0+YY] -= ty;
987             f[j_coord_offset+DIM*0+ZZ] -= tz;
988
989             /**************************
990              * CALCULATE INTERACTIONS *
991              **************************/
992
993             r11              = rsq11*rinv11;
994
995             /* EWALD ELECTROSTATICS */
996
997             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
998             ewrt             = r11*ewtabscale;
999             ewitab           = ewrt;
1000             eweps            = ewrt-ewitab;
1001             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1002             felec            = qq11*rinv11*(rinvsq11-felec);
1003
1004             fscal            = felec;
1005
1006             /* Calculate temporary vectorial force */
1007             tx               = fscal*dx11;
1008             ty               = fscal*dy11;
1009             tz               = fscal*dz11;
1010
1011             /* Update vectorial force */
1012             fix1            += tx;
1013             fiy1            += ty;
1014             fiz1            += tz;
1015             f[j_coord_offset+DIM*1+XX] -= tx;
1016             f[j_coord_offset+DIM*1+YY] -= ty;
1017             f[j_coord_offset+DIM*1+ZZ] -= tz;
1018
1019             /**************************
1020              * CALCULATE INTERACTIONS *
1021              **************************/
1022
1023             r12              = rsq12*rinv12;
1024
1025             /* EWALD ELECTROSTATICS */
1026
1027             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1028             ewrt             = r12*ewtabscale;
1029             ewitab           = ewrt;
1030             eweps            = ewrt-ewitab;
1031             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1032             felec            = qq12*rinv12*(rinvsq12-felec);
1033
1034             fscal            = felec;
1035
1036             /* Calculate temporary vectorial force */
1037             tx               = fscal*dx12;
1038             ty               = fscal*dy12;
1039             tz               = fscal*dz12;
1040
1041             /* Update vectorial force */
1042             fix1            += tx;
1043             fiy1            += ty;
1044             fiz1            += tz;
1045             f[j_coord_offset+DIM*2+XX] -= tx;
1046             f[j_coord_offset+DIM*2+YY] -= ty;
1047             f[j_coord_offset+DIM*2+ZZ] -= tz;
1048
1049             /**************************
1050              * CALCULATE INTERACTIONS *
1051              **************************/
1052
1053             r13              = rsq13*rinv13;
1054
1055             /* EWALD ELECTROSTATICS */
1056
1057             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1058             ewrt             = r13*ewtabscale;
1059             ewitab           = ewrt;
1060             eweps            = ewrt-ewitab;
1061             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1062             felec            = qq13*rinv13*(rinvsq13-felec);
1063
1064             fscal            = felec;
1065
1066             /* Calculate temporary vectorial force */
1067             tx               = fscal*dx13;
1068             ty               = fscal*dy13;
1069             tz               = fscal*dz13;
1070
1071             /* Update vectorial force */
1072             fix1            += tx;
1073             fiy1            += ty;
1074             fiz1            += tz;
1075             f[j_coord_offset+DIM*3+XX] -= tx;
1076             f[j_coord_offset+DIM*3+YY] -= ty;
1077             f[j_coord_offset+DIM*3+ZZ] -= tz;
1078
1079             /**************************
1080              * CALCULATE INTERACTIONS *
1081              **************************/
1082
1083             r21              = rsq21*rinv21;
1084
1085             /* EWALD ELECTROSTATICS */
1086
1087             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1088             ewrt             = r21*ewtabscale;
1089             ewitab           = ewrt;
1090             eweps            = ewrt-ewitab;
1091             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1092             felec            = qq21*rinv21*(rinvsq21-felec);
1093
1094             fscal            = felec;
1095
1096             /* Calculate temporary vectorial force */
1097             tx               = fscal*dx21;
1098             ty               = fscal*dy21;
1099             tz               = fscal*dz21;
1100
1101             /* Update vectorial force */
1102             fix2            += tx;
1103             fiy2            += ty;
1104             fiz2            += tz;
1105             f[j_coord_offset+DIM*1+XX] -= tx;
1106             f[j_coord_offset+DIM*1+YY] -= ty;
1107             f[j_coord_offset+DIM*1+ZZ] -= tz;
1108
1109             /**************************
1110              * CALCULATE INTERACTIONS *
1111              **************************/
1112
1113             r22              = rsq22*rinv22;
1114
1115             /* EWALD ELECTROSTATICS */
1116
1117             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1118             ewrt             = r22*ewtabscale;
1119             ewitab           = ewrt;
1120             eweps            = ewrt-ewitab;
1121             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1122             felec            = qq22*rinv22*(rinvsq22-felec);
1123
1124             fscal            = felec;
1125
1126             /* Calculate temporary vectorial force */
1127             tx               = fscal*dx22;
1128             ty               = fscal*dy22;
1129             tz               = fscal*dz22;
1130
1131             /* Update vectorial force */
1132             fix2            += tx;
1133             fiy2            += ty;
1134             fiz2            += tz;
1135             f[j_coord_offset+DIM*2+XX] -= tx;
1136             f[j_coord_offset+DIM*2+YY] -= ty;
1137             f[j_coord_offset+DIM*2+ZZ] -= tz;
1138
1139             /**************************
1140              * CALCULATE INTERACTIONS *
1141              **************************/
1142
1143             r23              = rsq23*rinv23;
1144
1145             /* EWALD ELECTROSTATICS */
1146
1147             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1148             ewrt             = r23*ewtabscale;
1149             ewitab           = ewrt;
1150             eweps            = ewrt-ewitab;
1151             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1152             felec            = qq23*rinv23*(rinvsq23-felec);
1153
1154             fscal            = felec;
1155
1156             /* Calculate temporary vectorial force */
1157             tx               = fscal*dx23;
1158             ty               = fscal*dy23;
1159             tz               = fscal*dz23;
1160
1161             /* Update vectorial force */
1162             fix2            += tx;
1163             fiy2            += ty;
1164             fiz2            += tz;
1165             f[j_coord_offset+DIM*3+XX] -= tx;
1166             f[j_coord_offset+DIM*3+YY] -= ty;
1167             f[j_coord_offset+DIM*3+ZZ] -= tz;
1168
1169             /**************************
1170              * CALCULATE INTERACTIONS *
1171              **************************/
1172
1173             r31              = rsq31*rinv31;
1174
1175             /* EWALD ELECTROSTATICS */
1176
1177             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1178             ewrt             = r31*ewtabscale;
1179             ewitab           = ewrt;
1180             eweps            = ewrt-ewitab;
1181             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1182             felec            = qq31*rinv31*(rinvsq31-felec);
1183
1184             fscal            = felec;
1185
1186             /* Calculate temporary vectorial force */
1187             tx               = fscal*dx31;
1188             ty               = fscal*dy31;
1189             tz               = fscal*dz31;
1190
1191             /* Update vectorial force */
1192             fix3            += tx;
1193             fiy3            += ty;
1194             fiz3            += tz;
1195             f[j_coord_offset+DIM*1+XX] -= tx;
1196             f[j_coord_offset+DIM*1+YY] -= ty;
1197             f[j_coord_offset+DIM*1+ZZ] -= tz;
1198
1199             /**************************
1200              * CALCULATE INTERACTIONS *
1201              **************************/
1202
1203             r32              = rsq32*rinv32;
1204
1205             /* EWALD ELECTROSTATICS */
1206
1207             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1208             ewrt             = r32*ewtabscale;
1209             ewitab           = ewrt;
1210             eweps            = ewrt-ewitab;
1211             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1212             felec            = qq32*rinv32*(rinvsq32-felec);
1213
1214             fscal            = felec;
1215
1216             /* Calculate temporary vectorial force */
1217             tx               = fscal*dx32;
1218             ty               = fscal*dy32;
1219             tz               = fscal*dz32;
1220
1221             /* Update vectorial force */
1222             fix3            += tx;
1223             fiy3            += ty;
1224             fiz3            += tz;
1225             f[j_coord_offset+DIM*2+XX] -= tx;
1226             f[j_coord_offset+DIM*2+YY] -= ty;
1227             f[j_coord_offset+DIM*2+ZZ] -= tz;
1228
1229             /**************************
1230              * CALCULATE INTERACTIONS *
1231              **************************/
1232
1233             r33              = rsq33*rinv33;
1234
1235             /* EWALD ELECTROSTATICS */
1236
1237             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1238             ewrt             = r33*ewtabscale;
1239             ewitab           = ewrt;
1240             eweps            = ewrt-ewitab;
1241             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1242             felec            = qq33*rinv33*(rinvsq33-felec);
1243
1244             fscal            = felec;
1245
1246             /* Calculate temporary vectorial force */
1247             tx               = fscal*dx33;
1248             ty               = fscal*dy33;
1249             tz               = fscal*dz33;
1250
1251             /* Update vectorial force */
1252             fix3            += tx;
1253             fiy3            += ty;
1254             fiz3            += tz;
1255             f[j_coord_offset+DIM*3+XX] -= tx;
1256             f[j_coord_offset+DIM*3+YY] -= ty;
1257             f[j_coord_offset+DIM*3+ZZ] -= tz;
1258
1259             /* Inner loop uses 341 flops */
1260         }
1261         /* End of innermost loop */
1262
1263         tx = ty = tz = 0;
1264         f[i_coord_offset+DIM*0+XX] += fix0;
1265         f[i_coord_offset+DIM*0+YY] += fiy0;
1266         f[i_coord_offset+DIM*0+ZZ] += fiz0;
1267         tx                         += fix0;
1268         ty                         += fiy0;
1269         tz                         += fiz0;
1270         f[i_coord_offset+DIM*1+XX] += fix1;
1271         f[i_coord_offset+DIM*1+YY] += fiy1;
1272         f[i_coord_offset+DIM*1+ZZ] += fiz1;
1273         tx                         += fix1;
1274         ty                         += fiy1;
1275         tz                         += fiz1;
1276         f[i_coord_offset+DIM*2+XX] += fix2;
1277         f[i_coord_offset+DIM*2+YY] += fiy2;
1278         f[i_coord_offset+DIM*2+ZZ] += fiz2;
1279         tx                         += fix2;
1280         ty                         += fiy2;
1281         tz                         += fiz2;
1282         f[i_coord_offset+DIM*3+XX] += fix3;
1283         f[i_coord_offset+DIM*3+YY] += fiy3;
1284         f[i_coord_offset+DIM*3+ZZ] += fiz3;
1285         tx                         += fix3;
1286         ty                         += fiy3;
1287         tz                         += fiz3;
1288         fshift[i_shift_offset+XX]  += tx;
1289         fshift[i_shift_offset+YY]  += ty;
1290         fshift[i_shift_offset+ZZ]  += tz;
1291
1292         /* Increment number of inner iterations */
1293         inneriter                  += j_index_end - j_index_start;
1294
1295         /* Outer loop uses 39 flops */
1296     }
1297
1298     /* Increment number of outer iterations */
1299     outeriter        += nri;
1300
1301     /* Update outer/inner flops */
1302
1303     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_F,outeriter*39 + inneriter*341);
1304 }