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