Merge 'release-4-6' into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecCSTab_VdwCSTab_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_VdwCSTab_GeomW4W4_VF_c
35  * Electrostatics interaction: CubicSplineTable
36  * VdW interaction:            CubicSplineTable
37  * Geometry:                   Water4-Water4
38  * Calculate force/pot:        PotentialAndForce
39  */
40 void
41 nb_kernel_ElecCSTab_VdwCSTab_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_vdw->data;
110     vftabscale       = kernel_data->table_elec_vdw->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             rinv00           = gmx_invsqrt(rsq00);
252             rinv11           = gmx_invsqrt(rsq11);
253             rinv12           = gmx_invsqrt(rsq12);
254             rinv13           = gmx_invsqrt(rsq13);
255             rinv21           = gmx_invsqrt(rsq21);
256             rinv22           = gmx_invsqrt(rsq22);
257             rinv23           = gmx_invsqrt(rsq23);
258             rinv31           = gmx_invsqrt(rsq31);
259             rinv32           = gmx_invsqrt(rsq32);
260             rinv33           = gmx_invsqrt(rsq33);
261
262             /**************************
263              * CALCULATE INTERACTIONS *
264              **************************/
265
266             r00              = rsq00*rinv00;
267
268             /* Calculate table index by multiplying r with table scale and truncate to integer */
269             rt               = r00*vftabscale;
270             vfitab           = rt;
271             vfeps            = rt-vfitab;
272             vfitab           = 3*4*vfitab;
273
274             /* CUBIC SPLINE TABLE DISPERSION */
275             vfitab          += 4;
276             Y                = vftab[vfitab];
277             F                = vftab[vfitab+1];
278             Geps             = vfeps*vftab[vfitab+2];
279             Heps2            = vfeps*vfeps*vftab[vfitab+3];
280             Fp               = F+Geps+Heps2;
281             VV               = Y+vfeps*Fp;
282             vvdw6            = c6_00*VV;
283             FF               = Fp+Geps+2.0*Heps2;
284             fvdw6            = c6_00*FF;
285
286             /* CUBIC SPLINE TABLE REPULSION */
287             Y                = vftab[vfitab+4];
288             F                = vftab[vfitab+5];
289             Geps             = vfeps*vftab[vfitab+6];
290             Heps2            = vfeps*vfeps*vftab[vfitab+7];
291             Fp               = F+Geps+Heps2;
292             VV               = Y+vfeps*Fp;
293             vvdw12           = c12_00*VV;
294             FF               = Fp+Geps+2.0*Heps2;
295             fvdw12           = c12_00*FF;
296             vvdw             = vvdw12+vvdw6;
297             fvdw             = -(fvdw6+fvdw12)*vftabscale*rinv00;
298
299             /* Update potential sums from outer loop */
300             vvdwsum         += vvdw;
301
302             fscal            = fvdw;
303
304             /* Calculate temporary vectorial force */
305             tx               = fscal*dx00;
306             ty               = fscal*dy00;
307             tz               = fscal*dz00;
308
309             /* Update vectorial force */
310             fix0            += tx;
311             fiy0            += ty;
312             fiz0            += tz;
313             f[j_coord_offset+DIM*0+XX] -= tx;
314             f[j_coord_offset+DIM*0+YY] -= ty;
315             f[j_coord_offset+DIM*0+ZZ] -= tz;
316
317             /**************************
318              * CALCULATE INTERACTIONS *
319              **************************/
320
321             r11              = rsq11*rinv11;
322
323             /* Calculate table index by multiplying r with table scale and truncate to integer */
324             rt               = r11*vftabscale;
325             vfitab           = rt;
326             vfeps            = rt-vfitab;
327             vfitab           = 3*4*vfitab;
328
329             /* CUBIC SPLINE TABLE ELECTROSTATICS */
330             Y                = vftab[vfitab];
331             F                = vftab[vfitab+1];
332             Geps             = vfeps*vftab[vfitab+2];
333             Heps2            = vfeps*vfeps*vftab[vfitab+3];
334             Fp               = F+Geps+Heps2;
335             VV               = Y+vfeps*Fp;
336             velec            = qq11*VV;
337             FF               = Fp+Geps+2.0*Heps2;
338             felec            = -qq11*FF*vftabscale*rinv11;
339
340             /* Update potential sums from outer loop */
341             velecsum        += velec;
342
343             fscal            = felec;
344
345             /* Calculate temporary vectorial force */
346             tx               = fscal*dx11;
347             ty               = fscal*dy11;
348             tz               = fscal*dz11;
349
350             /* Update vectorial force */
351             fix1            += tx;
352             fiy1            += ty;
353             fiz1            += tz;
354             f[j_coord_offset+DIM*1+XX] -= tx;
355             f[j_coord_offset+DIM*1+YY] -= ty;
356             f[j_coord_offset+DIM*1+ZZ] -= tz;
357
358             /**************************
359              * CALCULATE INTERACTIONS *
360              **************************/
361
362             r12              = rsq12*rinv12;
363
364             /* Calculate table index by multiplying r with table scale and truncate to integer */
365             rt               = r12*vftabscale;
366             vfitab           = rt;
367             vfeps            = rt-vfitab;
368             vfitab           = 3*4*vfitab;
369
370             /* CUBIC SPLINE TABLE ELECTROSTATICS */
371             Y                = vftab[vfitab];
372             F                = vftab[vfitab+1];
373             Geps             = vfeps*vftab[vfitab+2];
374             Heps2            = vfeps*vfeps*vftab[vfitab+3];
375             Fp               = F+Geps+Heps2;
376             VV               = Y+vfeps*Fp;
377             velec            = qq12*VV;
378             FF               = Fp+Geps+2.0*Heps2;
379             felec            = -qq12*FF*vftabscale*rinv12;
380
381             /* Update potential sums from outer loop */
382             velecsum        += velec;
383
384             fscal            = felec;
385
386             /* Calculate temporary vectorial force */
387             tx               = fscal*dx12;
388             ty               = fscal*dy12;
389             tz               = fscal*dz12;
390
391             /* Update vectorial force */
392             fix1            += tx;
393             fiy1            += ty;
394             fiz1            += tz;
395             f[j_coord_offset+DIM*2+XX] -= tx;
396             f[j_coord_offset+DIM*2+YY] -= ty;
397             f[j_coord_offset+DIM*2+ZZ] -= tz;
398
399             /**************************
400              * CALCULATE INTERACTIONS *
401              **************************/
402
403             r13              = rsq13*rinv13;
404
405             /* Calculate table index by multiplying r with table scale and truncate to integer */
406             rt               = r13*vftabscale;
407             vfitab           = rt;
408             vfeps            = rt-vfitab;
409             vfitab           = 3*4*vfitab;
410
411             /* CUBIC SPLINE TABLE ELECTROSTATICS */
412             Y                = vftab[vfitab];
413             F                = vftab[vfitab+1];
414             Geps             = vfeps*vftab[vfitab+2];
415             Heps2            = vfeps*vfeps*vftab[vfitab+3];
416             Fp               = F+Geps+Heps2;
417             VV               = Y+vfeps*Fp;
418             velec            = qq13*VV;
419             FF               = Fp+Geps+2.0*Heps2;
420             felec            = -qq13*FF*vftabscale*rinv13;
421
422             /* Update potential sums from outer loop */
423             velecsum        += velec;
424
425             fscal            = felec;
426
427             /* Calculate temporary vectorial force */
428             tx               = fscal*dx13;
429             ty               = fscal*dy13;
430             tz               = fscal*dz13;
431
432             /* Update vectorial force */
433             fix1            += tx;
434             fiy1            += ty;
435             fiz1            += tz;
436             f[j_coord_offset+DIM*3+XX] -= tx;
437             f[j_coord_offset+DIM*3+YY] -= ty;
438             f[j_coord_offset+DIM*3+ZZ] -= tz;
439
440             /**************************
441              * CALCULATE INTERACTIONS *
442              **************************/
443
444             r21              = rsq21*rinv21;
445
446             /* Calculate table index by multiplying r with table scale and truncate to integer */
447             rt               = r21*vftabscale;
448             vfitab           = rt;
449             vfeps            = rt-vfitab;
450             vfitab           = 3*4*vfitab;
451
452             /* CUBIC SPLINE TABLE ELECTROSTATICS */
453             Y                = vftab[vfitab];
454             F                = vftab[vfitab+1];
455             Geps             = vfeps*vftab[vfitab+2];
456             Heps2            = vfeps*vfeps*vftab[vfitab+3];
457             Fp               = F+Geps+Heps2;
458             VV               = Y+vfeps*Fp;
459             velec            = qq21*VV;
460             FF               = Fp+Geps+2.0*Heps2;
461             felec            = -qq21*FF*vftabscale*rinv21;
462
463             /* Update potential sums from outer loop */
464             velecsum        += velec;
465
466             fscal            = felec;
467
468             /* Calculate temporary vectorial force */
469             tx               = fscal*dx21;
470             ty               = fscal*dy21;
471             tz               = fscal*dz21;
472
473             /* Update vectorial force */
474             fix2            += tx;
475             fiy2            += ty;
476             fiz2            += tz;
477             f[j_coord_offset+DIM*1+XX] -= tx;
478             f[j_coord_offset+DIM*1+YY] -= ty;
479             f[j_coord_offset+DIM*1+ZZ] -= tz;
480
481             /**************************
482              * CALCULATE INTERACTIONS *
483              **************************/
484
485             r22              = rsq22*rinv22;
486
487             /* Calculate table index by multiplying r with table scale and truncate to integer */
488             rt               = r22*vftabscale;
489             vfitab           = rt;
490             vfeps            = rt-vfitab;
491             vfitab           = 3*4*vfitab;
492
493             /* CUBIC SPLINE TABLE ELECTROSTATICS */
494             Y                = vftab[vfitab];
495             F                = vftab[vfitab+1];
496             Geps             = vfeps*vftab[vfitab+2];
497             Heps2            = vfeps*vfeps*vftab[vfitab+3];
498             Fp               = F+Geps+Heps2;
499             VV               = Y+vfeps*Fp;
500             velec            = qq22*VV;
501             FF               = Fp+Geps+2.0*Heps2;
502             felec            = -qq22*FF*vftabscale*rinv22;
503
504             /* Update potential sums from outer loop */
505             velecsum        += velec;
506
507             fscal            = felec;
508
509             /* Calculate temporary vectorial force */
510             tx               = fscal*dx22;
511             ty               = fscal*dy22;
512             tz               = fscal*dz22;
513
514             /* Update vectorial force */
515             fix2            += tx;
516             fiy2            += ty;
517             fiz2            += tz;
518             f[j_coord_offset+DIM*2+XX] -= tx;
519             f[j_coord_offset+DIM*2+YY] -= ty;
520             f[j_coord_offset+DIM*2+ZZ] -= tz;
521
522             /**************************
523              * CALCULATE INTERACTIONS *
524              **************************/
525
526             r23              = rsq23*rinv23;
527
528             /* Calculate table index by multiplying r with table scale and truncate to integer */
529             rt               = r23*vftabscale;
530             vfitab           = rt;
531             vfeps            = rt-vfitab;
532             vfitab           = 3*4*vfitab;
533
534             /* CUBIC SPLINE TABLE ELECTROSTATICS */
535             Y                = vftab[vfitab];
536             F                = vftab[vfitab+1];
537             Geps             = vfeps*vftab[vfitab+2];
538             Heps2            = vfeps*vfeps*vftab[vfitab+3];
539             Fp               = F+Geps+Heps2;
540             VV               = Y+vfeps*Fp;
541             velec            = qq23*VV;
542             FF               = Fp+Geps+2.0*Heps2;
543             felec            = -qq23*FF*vftabscale*rinv23;
544
545             /* Update potential sums from outer loop */
546             velecsum        += velec;
547
548             fscal            = felec;
549
550             /* Calculate temporary vectorial force */
551             tx               = fscal*dx23;
552             ty               = fscal*dy23;
553             tz               = fscal*dz23;
554
555             /* Update vectorial force */
556             fix2            += tx;
557             fiy2            += ty;
558             fiz2            += tz;
559             f[j_coord_offset+DIM*3+XX] -= tx;
560             f[j_coord_offset+DIM*3+YY] -= ty;
561             f[j_coord_offset+DIM*3+ZZ] -= tz;
562
563             /**************************
564              * CALCULATE INTERACTIONS *
565              **************************/
566
567             r31              = rsq31*rinv31;
568
569             /* Calculate table index by multiplying r with table scale and truncate to integer */
570             rt               = r31*vftabscale;
571             vfitab           = rt;
572             vfeps            = rt-vfitab;
573             vfitab           = 3*4*vfitab;
574
575             /* CUBIC SPLINE TABLE ELECTROSTATICS */
576             Y                = vftab[vfitab];
577             F                = vftab[vfitab+1];
578             Geps             = vfeps*vftab[vfitab+2];
579             Heps2            = vfeps*vfeps*vftab[vfitab+3];
580             Fp               = F+Geps+Heps2;
581             VV               = Y+vfeps*Fp;
582             velec            = qq31*VV;
583             FF               = Fp+Geps+2.0*Heps2;
584             felec            = -qq31*FF*vftabscale*rinv31;
585
586             /* Update potential sums from outer loop */
587             velecsum        += velec;
588
589             fscal            = felec;
590
591             /* Calculate temporary vectorial force */
592             tx               = fscal*dx31;
593             ty               = fscal*dy31;
594             tz               = fscal*dz31;
595
596             /* Update vectorial force */
597             fix3            += tx;
598             fiy3            += ty;
599             fiz3            += tz;
600             f[j_coord_offset+DIM*1+XX] -= tx;
601             f[j_coord_offset+DIM*1+YY] -= ty;
602             f[j_coord_offset+DIM*1+ZZ] -= tz;
603
604             /**************************
605              * CALCULATE INTERACTIONS *
606              **************************/
607
608             r32              = rsq32*rinv32;
609
610             /* Calculate table index by multiplying r with table scale and truncate to integer */
611             rt               = r32*vftabscale;
612             vfitab           = rt;
613             vfeps            = rt-vfitab;
614             vfitab           = 3*4*vfitab;
615
616             /* CUBIC SPLINE TABLE ELECTROSTATICS */
617             Y                = vftab[vfitab];
618             F                = vftab[vfitab+1];
619             Geps             = vfeps*vftab[vfitab+2];
620             Heps2            = vfeps*vfeps*vftab[vfitab+3];
621             Fp               = F+Geps+Heps2;
622             VV               = Y+vfeps*Fp;
623             velec            = qq32*VV;
624             FF               = Fp+Geps+2.0*Heps2;
625             felec            = -qq32*FF*vftabscale*rinv32;
626
627             /* Update potential sums from outer loop */
628             velecsum        += velec;
629
630             fscal            = felec;
631
632             /* Calculate temporary vectorial force */
633             tx               = fscal*dx32;
634             ty               = fscal*dy32;
635             tz               = fscal*dz32;
636
637             /* Update vectorial force */
638             fix3            += tx;
639             fiy3            += ty;
640             fiz3            += tz;
641             f[j_coord_offset+DIM*2+XX] -= tx;
642             f[j_coord_offset+DIM*2+YY] -= ty;
643             f[j_coord_offset+DIM*2+ZZ] -= tz;
644
645             /**************************
646              * CALCULATE INTERACTIONS *
647              **************************/
648
649             r33              = rsq33*rinv33;
650
651             /* Calculate table index by multiplying r with table scale and truncate to integer */
652             rt               = r33*vftabscale;
653             vfitab           = rt;
654             vfeps            = rt-vfitab;
655             vfitab           = 3*4*vfitab;
656
657             /* CUBIC SPLINE TABLE ELECTROSTATICS */
658             Y                = vftab[vfitab];
659             F                = vftab[vfitab+1];
660             Geps             = vfeps*vftab[vfitab+2];
661             Heps2            = vfeps*vfeps*vftab[vfitab+3];
662             Fp               = F+Geps+Heps2;
663             VV               = Y+vfeps*Fp;
664             velec            = qq33*VV;
665             FF               = Fp+Geps+2.0*Heps2;
666             felec            = -qq33*FF*vftabscale*rinv33;
667
668             /* Update potential sums from outer loop */
669             velecsum        += velec;
670
671             fscal            = felec;
672
673             /* Calculate temporary vectorial force */
674             tx               = fscal*dx33;
675             ty               = fscal*dy33;
676             tz               = fscal*dz33;
677
678             /* Update vectorial force */
679             fix3            += tx;
680             fiy3            += ty;
681             fiz3            += tz;
682             f[j_coord_offset+DIM*3+XX] -= tx;
683             f[j_coord_offset+DIM*3+YY] -= ty;
684             f[j_coord_offset+DIM*3+ZZ] -= tz;
685
686             /* Inner loop uses 424 flops */
687         }
688         /* End of innermost loop */
689
690         tx = ty = tz = 0;
691         f[i_coord_offset+DIM*0+XX] += fix0;
692         f[i_coord_offset+DIM*0+YY] += fiy0;
693         f[i_coord_offset+DIM*0+ZZ] += fiz0;
694         tx                         += fix0;
695         ty                         += fiy0;
696         tz                         += fiz0;
697         f[i_coord_offset+DIM*1+XX] += fix1;
698         f[i_coord_offset+DIM*1+YY] += fiy1;
699         f[i_coord_offset+DIM*1+ZZ] += fiz1;
700         tx                         += fix1;
701         ty                         += fiy1;
702         tz                         += fiz1;
703         f[i_coord_offset+DIM*2+XX] += fix2;
704         f[i_coord_offset+DIM*2+YY] += fiy2;
705         f[i_coord_offset+DIM*2+ZZ] += fiz2;
706         tx                         += fix2;
707         ty                         += fiy2;
708         tz                         += fiz2;
709         f[i_coord_offset+DIM*3+XX] += fix3;
710         f[i_coord_offset+DIM*3+YY] += fiy3;
711         f[i_coord_offset+DIM*3+ZZ] += fiz3;
712         tx                         += fix3;
713         ty                         += fiy3;
714         tz                         += fiz3;
715         fshift[i_shift_offset+XX]  += tx;
716         fshift[i_shift_offset+YY]  += ty;
717         fshift[i_shift_offset+ZZ]  += tz;
718
719         ggid                        = gid[iidx];
720         /* Update potential energies */
721         kernel_data->energygrp_elec[ggid] += velecsum;
722         kernel_data->energygrp_vdw[ggid] += vvdwsum;
723
724         /* Increment number of inner iterations */
725         inneriter                  += j_index_end - j_index_start;
726
727         /* Outer loop uses 41 flops */
728     }
729
730     /* Increment number of outer iterations */
731     outeriter        += nri;
732
733     /* Update outer/inner flops */
734
735     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_VF,outeriter*41 + inneriter*424);
736 }
737 /*
738  * Gromacs nonbonded kernel:   nb_kernel_ElecCSTab_VdwCSTab_GeomW4W4_F_c
739  * Electrostatics interaction: CubicSplineTable
740  * VdW interaction:            CubicSplineTable
741  * Geometry:                   Water4-Water4
742  * Calculate force/pot:        Force
743  */
744 void
745 nb_kernel_ElecCSTab_VdwCSTab_GeomW4W4_F_c
746                     (t_nblist * gmx_restrict                nlist,
747                      rvec * gmx_restrict                    xx,
748                      rvec * gmx_restrict                    ff,
749                      t_forcerec * gmx_restrict              fr,
750                      t_mdatoms * gmx_restrict               mdatoms,
751                      nb_kernel_data_t * gmx_restrict        kernel_data,
752                      t_nrnb * gmx_restrict                  nrnb)
753 {
754     int              i_shift_offset,i_coord_offset,j_coord_offset;
755     int              j_index_start,j_index_end;
756     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
757     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
758     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
759     real             *shiftvec,*fshift,*x,*f;
760     int              vdwioffset0;
761     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
762     int              vdwioffset1;
763     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
764     int              vdwioffset2;
765     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
766     int              vdwioffset3;
767     real             ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
768     int              vdwjidx0;
769     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
770     int              vdwjidx1;
771     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
772     int              vdwjidx2;
773     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
774     int              vdwjidx3;
775     real             jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
776     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
777     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
778     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
779     real             dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13,cexp1_13,cexp2_13;
780     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
781     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
782     real             dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23,cexp1_23,cexp2_23;
783     real             dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31,cexp1_31,cexp2_31;
784     real             dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32,cexp1_32,cexp2_32;
785     real             dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33,cexp1_33,cexp2_33;
786     real             velec,felec,velecsum,facel,crf,krf,krf2;
787     real             *charge;
788     int              nvdwtype;
789     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
790     int              *vdwtype;
791     real             *vdwparam;
792     int              vfitab;
793     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
794     real             *vftab;
795
796     x                = xx[0];
797     f                = ff[0];
798
799     nri              = nlist->nri;
800     iinr             = nlist->iinr;
801     jindex           = nlist->jindex;
802     jjnr             = nlist->jjnr;
803     shiftidx         = nlist->shift;
804     gid              = nlist->gid;
805     shiftvec         = fr->shift_vec[0];
806     fshift           = fr->fshift[0];
807     facel            = fr->epsfac;
808     charge           = mdatoms->chargeA;
809     nvdwtype         = fr->ntype;
810     vdwparam         = fr->nbfp;
811     vdwtype          = mdatoms->typeA;
812
813     vftab            = kernel_data->table_elec_vdw->data;
814     vftabscale       = kernel_data->table_elec_vdw->scale;
815
816     /* Setup water-specific parameters */
817     inr              = nlist->iinr[0];
818     iq1              = facel*charge[inr+1];
819     iq2              = facel*charge[inr+2];
820     iq3              = facel*charge[inr+3];
821     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
822
823     jq1              = charge[inr+1];
824     jq2              = charge[inr+2];
825     jq3              = charge[inr+3];
826     vdwjidx0         = 2*vdwtype[inr+0];
827     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
828     c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
829     qq11             = iq1*jq1;
830     qq12             = iq1*jq2;
831     qq13             = iq1*jq3;
832     qq21             = iq2*jq1;
833     qq22             = iq2*jq2;
834     qq23             = iq2*jq3;
835     qq31             = iq3*jq1;
836     qq32             = iq3*jq2;
837     qq33             = iq3*jq3;
838
839     outeriter        = 0;
840     inneriter        = 0;
841
842     /* Start outer loop over neighborlists */
843     for(iidx=0; iidx<nri; iidx++)
844     {
845         /* Load shift vector for this list */
846         i_shift_offset   = DIM*shiftidx[iidx];
847         shX              = shiftvec[i_shift_offset+XX];
848         shY              = shiftvec[i_shift_offset+YY];
849         shZ              = shiftvec[i_shift_offset+ZZ];
850
851         /* Load limits for loop over neighbors */
852         j_index_start    = jindex[iidx];
853         j_index_end      = jindex[iidx+1];
854
855         /* Get outer coordinate index */
856         inr              = iinr[iidx];
857         i_coord_offset   = DIM*inr;
858
859         /* Load i particle coords and add shift vector */
860         ix0              = shX + x[i_coord_offset+DIM*0+XX];
861         iy0              = shY + x[i_coord_offset+DIM*0+YY];
862         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
863         ix1              = shX + x[i_coord_offset+DIM*1+XX];
864         iy1              = shY + x[i_coord_offset+DIM*1+YY];
865         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
866         ix2              = shX + x[i_coord_offset+DIM*2+XX];
867         iy2              = shY + x[i_coord_offset+DIM*2+YY];
868         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
869         ix3              = shX + x[i_coord_offset+DIM*3+XX];
870         iy3              = shY + x[i_coord_offset+DIM*3+YY];
871         iz3              = shZ + x[i_coord_offset+DIM*3+ZZ];
872
873         fix0             = 0.0;
874         fiy0             = 0.0;
875         fiz0             = 0.0;
876         fix1             = 0.0;
877         fiy1             = 0.0;
878         fiz1             = 0.0;
879         fix2             = 0.0;
880         fiy2             = 0.0;
881         fiz2             = 0.0;
882         fix3             = 0.0;
883         fiy3             = 0.0;
884         fiz3             = 0.0;
885
886         /* Start inner kernel loop */
887         for(jidx=j_index_start; jidx<j_index_end; jidx++)
888         {
889             /* Get j neighbor index, and coordinate index */
890             jnr              = jjnr[jidx];
891             j_coord_offset   = DIM*jnr;
892
893             /* load j atom coordinates */
894             jx0              = x[j_coord_offset+DIM*0+XX];
895             jy0              = x[j_coord_offset+DIM*0+YY];
896             jz0              = x[j_coord_offset+DIM*0+ZZ];
897             jx1              = x[j_coord_offset+DIM*1+XX];
898             jy1              = x[j_coord_offset+DIM*1+YY];
899             jz1              = x[j_coord_offset+DIM*1+ZZ];
900             jx2              = x[j_coord_offset+DIM*2+XX];
901             jy2              = x[j_coord_offset+DIM*2+YY];
902             jz2              = x[j_coord_offset+DIM*2+ZZ];
903             jx3              = x[j_coord_offset+DIM*3+XX];
904             jy3              = x[j_coord_offset+DIM*3+YY];
905             jz3              = x[j_coord_offset+DIM*3+ZZ];
906
907             /* Calculate displacement vector */
908             dx00             = ix0 - jx0;
909             dy00             = iy0 - jy0;
910             dz00             = iz0 - jz0;
911             dx11             = ix1 - jx1;
912             dy11             = iy1 - jy1;
913             dz11             = iz1 - jz1;
914             dx12             = ix1 - jx2;
915             dy12             = iy1 - jy2;
916             dz12             = iz1 - jz2;
917             dx13             = ix1 - jx3;
918             dy13             = iy1 - jy3;
919             dz13             = iz1 - jz3;
920             dx21             = ix2 - jx1;
921             dy21             = iy2 - jy1;
922             dz21             = iz2 - jz1;
923             dx22             = ix2 - jx2;
924             dy22             = iy2 - jy2;
925             dz22             = iz2 - jz2;
926             dx23             = ix2 - jx3;
927             dy23             = iy2 - jy3;
928             dz23             = iz2 - jz3;
929             dx31             = ix3 - jx1;
930             dy31             = iy3 - jy1;
931             dz31             = iz3 - jz1;
932             dx32             = ix3 - jx2;
933             dy32             = iy3 - jy2;
934             dz32             = iz3 - jz2;
935             dx33             = ix3 - jx3;
936             dy33             = iy3 - jy3;
937             dz33             = iz3 - jz3;
938
939             /* Calculate squared distance and things based on it */
940             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
941             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
942             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
943             rsq13            = dx13*dx13+dy13*dy13+dz13*dz13;
944             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
945             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
946             rsq23            = dx23*dx23+dy23*dy23+dz23*dz23;
947             rsq31            = dx31*dx31+dy31*dy31+dz31*dz31;
948             rsq32            = dx32*dx32+dy32*dy32+dz32*dz32;
949             rsq33            = dx33*dx33+dy33*dy33+dz33*dz33;
950
951             rinv00           = gmx_invsqrt(rsq00);
952             rinv11           = gmx_invsqrt(rsq11);
953             rinv12           = gmx_invsqrt(rsq12);
954             rinv13           = gmx_invsqrt(rsq13);
955             rinv21           = gmx_invsqrt(rsq21);
956             rinv22           = gmx_invsqrt(rsq22);
957             rinv23           = gmx_invsqrt(rsq23);
958             rinv31           = gmx_invsqrt(rsq31);
959             rinv32           = gmx_invsqrt(rsq32);
960             rinv33           = gmx_invsqrt(rsq33);
961
962             /**************************
963              * CALCULATE INTERACTIONS *
964              **************************/
965
966             r00              = rsq00*rinv00;
967
968             /* Calculate table index by multiplying r with table scale and truncate to integer */
969             rt               = r00*vftabscale;
970             vfitab           = rt;
971             vfeps            = rt-vfitab;
972             vfitab           = 3*4*vfitab;
973
974             /* CUBIC SPLINE TABLE DISPERSION */
975             vfitab          += 4;
976             F                = vftab[vfitab+1];
977             Geps             = vfeps*vftab[vfitab+2];
978             Heps2            = vfeps*vfeps*vftab[vfitab+3];
979             Fp               = F+Geps+Heps2;
980             FF               = Fp+Geps+2.0*Heps2;
981             fvdw6            = c6_00*FF;
982
983             /* CUBIC SPLINE TABLE REPULSION */
984             F                = vftab[vfitab+5];
985             Geps             = vfeps*vftab[vfitab+6];
986             Heps2            = vfeps*vfeps*vftab[vfitab+7];
987             Fp               = F+Geps+Heps2;
988             FF               = Fp+Geps+2.0*Heps2;
989             fvdw12           = c12_00*FF;
990             fvdw             = -(fvdw6+fvdw12)*vftabscale*rinv00;
991
992             fscal            = fvdw;
993
994             /* Calculate temporary vectorial force */
995             tx               = fscal*dx00;
996             ty               = fscal*dy00;
997             tz               = fscal*dz00;
998
999             /* Update vectorial force */
1000             fix0            += tx;
1001             fiy0            += ty;
1002             fiz0            += tz;
1003             f[j_coord_offset+DIM*0+XX] -= tx;
1004             f[j_coord_offset+DIM*0+YY] -= ty;
1005             f[j_coord_offset+DIM*0+ZZ] -= tz;
1006
1007             /**************************
1008              * CALCULATE INTERACTIONS *
1009              **************************/
1010
1011             r11              = rsq11*rinv11;
1012
1013             /* Calculate table index by multiplying r with table scale and truncate to integer */
1014             rt               = r11*vftabscale;
1015             vfitab           = rt;
1016             vfeps            = rt-vfitab;
1017             vfitab           = 3*4*vfitab;
1018
1019             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1020             F                = vftab[vfitab+1];
1021             Geps             = vfeps*vftab[vfitab+2];
1022             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1023             Fp               = F+Geps+Heps2;
1024             FF               = Fp+Geps+2.0*Heps2;
1025             felec            = -qq11*FF*vftabscale*rinv11;
1026
1027             fscal            = felec;
1028
1029             /* Calculate temporary vectorial force */
1030             tx               = fscal*dx11;
1031             ty               = fscal*dy11;
1032             tz               = fscal*dz11;
1033
1034             /* Update vectorial force */
1035             fix1            += tx;
1036             fiy1            += ty;
1037             fiz1            += tz;
1038             f[j_coord_offset+DIM*1+XX] -= tx;
1039             f[j_coord_offset+DIM*1+YY] -= ty;
1040             f[j_coord_offset+DIM*1+ZZ] -= tz;
1041
1042             /**************************
1043              * CALCULATE INTERACTIONS *
1044              **************************/
1045
1046             r12              = rsq12*rinv12;
1047
1048             /* Calculate table index by multiplying r with table scale and truncate to integer */
1049             rt               = r12*vftabscale;
1050             vfitab           = rt;
1051             vfeps            = rt-vfitab;
1052             vfitab           = 3*4*vfitab;
1053
1054             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1055             F                = vftab[vfitab+1];
1056             Geps             = vfeps*vftab[vfitab+2];
1057             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1058             Fp               = F+Geps+Heps2;
1059             FF               = Fp+Geps+2.0*Heps2;
1060             felec            = -qq12*FF*vftabscale*rinv12;
1061
1062             fscal            = felec;
1063
1064             /* Calculate temporary vectorial force */
1065             tx               = fscal*dx12;
1066             ty               = fscal*dy12;
1067             tz               = fscal*dz12;
1068
1069             /* Update vectorial force */
1070             fix1            += tx;
1071             fiy1            += ty;
1072             fiz1            += tz;
1073             f[j_coord_offset+DIM*2+XX] -= tx;
1074             f[j_coord_offset+DIM*2+YY] -= ty;
1075             f[j_coord_offset+DIM*2+ZZ] -= tz;
1076
1077             /**************************
1078              * CALCULATE INTERACTIONS *
1079              **************************/
1080
1081             r13              = rsq13*rinv13;
1082
1083             /* Calculate table index by multiplying r with table scale and truncate to integer */
1084             rt               = r13*vftabscale;
1085             vfitab           = rt;
1086             vfeps            = rt-vfitab;
1087             vfitab           = 3*4*vfitab;
1088
1089             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1090             F                = vftab[vfitab+1];
1091             Geps             = vfeps*vftab[vfitab+2];
1092             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1093             Fp               = F+Geps+Heps2;
1094             FF               = Fp+Geps+2.0*Heps2;
1095             felec            = -qq13*FF*vftabscale*rinv13;
1096
1097             fscal            = felec;
1098
1099             /* Calculate temporary vectorial force */
1100             tx               = fscal*dx13;
1101             ty               = fscal*dy13;
1102             tz               = fscal*dz13;
1103
1104             /* Update vectorial force */
1105             fix1            += tx;
1106             fiy1            += ty;
1107             fiz1            += tz;
1108             f[j_coord_offset+DIM*3+XX] -= tx;
1109             f[j_coord_offset+DIM*3+YY] -= ty;
1110             f[j_coord_offset+DIM*3+ZZ] -= tz;
1111
1112             /**************************
1113              * CALCULATE INTERACTIONS *
1114              **************************/
1115
1116             r21              = rsq21*rinv21;
1117
1118             /* Calculate table index by multiplying r with table scale and truncate to integer */
1119             rt               = r21*vftabscale;
1120             vfitab           = rt;
1121             vfeps            = rt-vfitab;
1122             vfitab           = 3*4*vfitab;
1123
1124             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1125             F                = vftab[vfitab+1];
1126             Geps             = vfeps*vftab[vfitab+2];
1127             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1128             Fp               = F+Geps+Heps2;
1129             FF               = Fp+Geps+2.0*Heps2;
1130             felec            = -qq21*FF*vftabscale*rinv21;
1131
1132             fscal            = felec;
1133
1134             /* Calculate temporary vectorial force */
1135             tx               = fscal*dx21;
1136             ty               = fscal*dy21;
1137             tz               = fscal*dz21;
1138
1139             /* Update vectorial force */
1140             fix2            += tx;
1141             fiy2            += ty;
1142             fiz2            += tz;
1143             f[j_coord_offset+DIM*1+XX] -= tx;
1144             f[j_coord_offset+DIM*1+YY] -= ty;
1145             f[j_coord_offset+DIM*1+ZZ] -= tz;
1146
1147             /**************************
1148              * CALCULATE INTERACTIONS *
1149              **************************/
1150
1151             r22              = rsq22*rinv22;
1152
1153             /* Calculate table index by multiplying r with table scale and truncate to integer */
1154             rt               = r22*vftabscale;
1155             vfitab           = rt;
1156             vfeps            = rt-vfitab;
1157             vfitab           = 3*4*vfitab;
1158
1159             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1160             F                = vftab[vfitab+1];
1161             Geps             = vfeps*vftab[vfitab+2];
1162             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1163             Fp               = F+Geps+Heps2;
1164             FF               = Fp+Geps+2.0*Heps2;
1165             felec            = -qq22*FF*vftabscale*rinv22;
1166
1167             fscal            = felec;
1168
1169             /* Calculate temporary vectorial force */
1170             tx               = fscal*dx22;
1171             ty               = fscal*dy22;
1172             tz               = fscal*dz22;
1173
1174             /* Update vectorial force */
1175             fix2            += tx;
1176             fiy2            += ty;
1177             fiz2            += tz;
1178             f[j_coord_offset+DIM*2+XX] -= tx;
1179             f[j_coord_offset+DIM*2+YY] -= ty;
1180             f[j_coord_offset+DIM*2+ZZ] -= tz;
1181
1182             /**************************
1183              * CALCULATE INTERACTIONS *
1184              **************************/
1185
1186             r23              = rsq23*rinv23;
1187
1188             /* Calculate table index by multiplying r with table scale and truncate to integer */
1189             rt               = r23*vftabscale;
1190             vfitab           = rt;
1191             vfeps            = rt-vfitab;
1192             vfitab           = 3*4*vfitab;
1193
1194             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1195             F                = vftab[vfitab+1];
1196             Geps             = vfeps*vftab[vfitab+2];
1197             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1198             Fp               = F+Geps+Heps2;
1199             FF               = Fp+Geps+2.0*Heps2;
1200             felec            = -qq23*FF*vftabscale*rinv23;
1201
1202             fscal            = felec;
1203
1204             /* Calculate temporary vectorial force */
1205             tx               = fscal*dx23;
1206             ty               = fscal*dy23;
1207             tz               = fscal*dz23;
1208
1209             /* Update vectorial force */
1210             fix2            += tx;
1211             fiy2            += ty;
1212             fiz2            += tz;
1213             f[j_coord_offset+DIM*3+XX] -= tx;
1214             f[j_coord_offset+DIM*3+YY] -= ty;
1215             f[j_coord_offset+DIM*3+ZZ] -= tz;
1216
1217             /**************************
1218              * CALCULATE INTERACTIONS *
1219              **************************/
1220
1221             r31              = rsq31*rinv31;
1222
1223             /* Calculate table index by multiplying r with table scale and truncate to integer */
1224             rt               = r31*vftabscale;
1225             vfitab           = rt;
1226             vfeps            = rt-vfitab;
1227             vfitab           = 3*4*vfitab;
1228
1229             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1230             F                = vftab[vfitab+1];
1231             Geps             = vfeps*vftab[vfitab+2];
1232             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1233             Fp               = F+Geps+Heps2;
1234             FF               = Fp+Geps+2.0*Heps2;
1235             felec            = -qq31*FF*vftabscale*rinv31;
1236
1237             fscal            = felec;
1238
1239             /* Calculate temporary vectorial force */
1240             tx               = fscal*dx31;
1241             ty               = fscal*dy31;
1242             tz               = fscal*dz31;
1243
1244             /* Update vectorial force */
1245             fix3            += tx;
1246             fiy3            += ty;
1247             fiz3            += tz;
1248             f[j_coord_offset+DIM*1+XX] -= tx;
1249             f[j_coord_offset+DIM*1+YY] -= ty;
1250             f[j_coord_offset+DIM*1+ZZ] -= tz;
1251
1252             /**************************
1253              * CALCULATE INTERACTIONS *
1254              **************************/
1255
1256             r32              = rsq32*rinv32;
1257
1258             /* Calculate table index by multiplying r with table scale and truncate to integer */
1259             rt               = r32*vftabscale;
1260             vfitab           = rt;
1261             vfeps            = rt-vfitab;
1262             vfitab           = 3*4*vfitab;
1263
1264             /* CUBIC SPLINE TABLE ELECTROSTATICS */
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            = -qq32*FF*vftabscale*rinv32;
1271
1272             fscal            = felec;
1273
1274             /* Calculate temporary vectorial force */
1275             tx               = fscal*dx32;
1276             ty               = fscal*dy32;
1277             tz               = fscal*dz32;
1278
1279             /* Update vectorial force */
1280             fix3            += tx;
1281             fiy3            += ty;
1282             fiz3            += tz;
1283             f[j_coord_offset+DIM*2+XX] -= tx;
1284             f[j_coord_offset+DIM*2+YY] -= ty;
1285             f[j_coord_offset+DIM*2+ZZ] -= tz;
1286
1287             /**************************
1288              * CALCULATE INTERACTIONS *
1289              **************************/
1290
1291             r33              = rsq33*rinv33;
1292
1293             /* Calculate table index by multiplying r with table scale and truncate to integer */
1294             rt               = r33*vftabscale;
1295             vfitab           = rt;
1296             vfeps            = rt-vfitab;
1297             vfitab           = 3*4*vfitab;
1298
1299             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1300             F                = vftab[vfitab+1];
1301             Geps             = vfeps*vftab[vfitab+2];
1302             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1303             Fp               = F+Geps+Heps2;
1304             FF               = Fp+Geps+2.0*Heps2;
1305             felec            = -qq33*FF*vftabscale*rinv33;
1306
1307             fscal            = felec;
1308
1309             /* Calculate temporary vectorial force */
1310             tx               = fscal*dx33;
1311             ty               = fscal*dy33;
1312             tz               = fscal*dz33;
1313
1314             /* Update vectorial force */
1315             fix3            += tx;
1316             fiy3            += ty;
1317             fiz3            += tz;
1318             f[j_coord_offset+DIM*3+XX] -= tx;
1319             f[j_coord_offset+DIM*3+YY] -= ty;
1320             f[j_coord_offset+DIM*3+ZZ] -= tz;
1321
1322             /* Inner loop uses 380 flops */
1323         }
1324         /* End of innermost loop */
1325
1326         tx = ty = tz = 0;
1327         f[i_coord_offset+DIM*0+XX] += fix0;
1328         f[i_coord_offset+DIM*0+YY] += fiy0;
1329         f[i_coord_offset+DIM*0+ZZ] += fiz0;
1330         tx                         += fix0;
1331         ty                         += fiy0;
1332         tz                         += fiz0;
1333         f[i_coord_offset+DIM*1+XX] += fix1;
1334         f[i_coord_offset+DIM*1+YY] += fiy1;
1335         f[i_coord_offset+DIM*1+ZZ] += fiz1;
1336         tx                         += fix1;
1337         ty                         += fiy1;
1338         tz                         += fiz1;
1339         f[i_coord_offset+DIM*2+XX] += fix2;
1340         f[i_coord_offset+DIM*2+YY] += fiy2;
1341         f[i_coord_offset+DIM*2+ZZ] += fiz2;
1342         tx                         += fix2;
1343         ty                         += fiy2;
1344         tz                         += fiz2;
1345         f[i_coord_offset+DIM*3+XX] += fix3;
1346         f[i_coord_offset+DIM*3+YY] += fiy3;
1347         f[i_coord_offset+DIM*3+ZZ] += fiz3;
1348         tx                         += fix3;
1349         ty                         += fiy3;
1350         tz                         += fiz3;
1351         fshift[i_shift_offset+XX]  += tx;
1352         fshift[i_shift_offset+YY]  += ty;
1353         fshift[i_shift_offset+ZZ]  += tz;
1354
1355         /* Increment number of inner iterations */
1356         inneriter                  += j_index_end - j_index_start;
1357
1358         /* Outer loop uses 39 flops */
1359     }
1360
1361     /* Increment number of outer iterations */
1362     outeriter        += nri;
1363
1364     /* Update outer/inner flops */
1365
1366     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_F,outeriter*39 + inneriter*380);
1367 }