Fix component for libcudart
[alexxy/gromacs.git] / src / 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             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             fvdw6            = c6_00*FF;
983
984             /* CUBIC SPLINE TABLE REPULSION */
985             Y                = vftab[vfitab+4];
986             F                = vftab[vfitab+5];
987             Geps             = vfeps*vftab[vfitab+6];
988             Heps2            = vfeps*vfeps*vftab[vfitab+7];
989             Fp               = F+Geps+Heps2;
990             FF               = Fp+Geps+2.0*Heps2;
991             fvdw12           = c12_00*FF;
992             fvdw             = -(fvdw6+fvdw12)*vftabscale*rinv00;
993
994             fscal            = fvdw;
995
996             /* Calculate temporary vectorial force */
997             tx               = fscal*dx00;
998             ty               = fscal*dy00;
999             tz               = fscal*dz00;
1000
1001             /* Update vectorial force */
1002             fix0            += tx;
1003             fiy0            += ty;
1004             fiz0            += tz;
1005             f[j_coord_offset+DIM*0+XX] -= tx;
1006             f[j_coord_offset+DIM*0+YY] -= ty;
1007             f[j_coord_offset+DIM*0+ZZ] -= tz;
1008
1009             /**************************
1010              * CALCULATE INTERACTIONS *
1011              **************************/
1012
1013             r11              = rsq11*rinv11;
1014
1015             /* Calculate table index by multiplying r with table scale and truncate to integer */
1016             rt               = r11*vftabscale;
1017             vfitab           = rt;
1018             vfeps            = rt-vfitab;
1019             vfitab           = 3*4*vfitab;
1020
1021             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1022             Y                = vftab[vfitab];
1023             F                = vftab[vfitab+1];
1024             Geps             = vfeps*vftab[vfitab+2];
1025             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1026             Fp               = F+Geps+Heps2;
1027             FF               = Fp+Geps+2.0*Heps2;
1028             felec            = -qq11*FF*vftabscale*rinv11;
1029
1030             fscal            = felec;
1031
1032             /* Calculate temporary vectorial force */
1033             tx               = fscal*dx11;
1034             ty               = fscal*dy11;
1035             tz               = fscal*dz11;
1036
1037             /* Update vectorial force */
1038             fix1            += tx;
1039             fiy1            += ty;
1040             fiz1            += tz;
1041             f[j_coord_offset+DIM*1+XX] -= tx;
1042             f[j_coord_offset+DIM*1+YY] -= ty;
1043             f[j_coord_offset+DIM*1+ZZ] -= tz;
1044
1045             /**************************
1046              * CALCULATE INTERACTIONS *
1047              **************************/
1048
1049             r12              = rsq12*rinv12;
1050
1051             /* Calculate table index by multiplying r with table scale and truncate to integer */
1052             rt               = r12*vftabscale;
1053             vfitab           = rt;
1054             vfeps            = rt-vfitab;
1055             vfitab           = 3*4*vfitab;
1056
1057             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1058             Y                = vftab[vfitab];
1059             F                = vftab[vfitab+1];
1060             Geps             = vfeps*vftab[vfitab+2];
1061             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1062             Fp               = F+Geps+Heps2;
1063             FF               = Fp+Geps+2.0*Heps2;
1064             felec            = -qq12*FF*vftabscale*rinv12;
1065
1066             fscal            = felec;
1067
1068             /* Calculate temporary vectorial force */
1069             tx               = fscal*dx12;
1070             ty               = fscal*dy12;
1071             tz               = fscal*dz12;
1072
1073             /* Update vectorial force */
1074             fix1            += tx;
1075             fiy1            += ty;
1076             fiz1            += tz;
1077             f[j_coord_offset+DIM*2+XX] -= tx;
1078             f[j_coord_offset+DIM*2+YY] -= ty;
1079             f[j_coord_offset+DIM*2+ZZ] -= tz;
1080
1081             /**************************
1082              * CALCULATE INTERACTIONS *
1083              **************************/
1084
1085             r13              = rsq13*rinv13;
1086
1087             /* Calculate table index by multiplying r with table scale and truncate to integer */
1088             rt               = r13*vftabscale;
1089             vfitab           = rt;
1090             vfeps            = rt-vfitab;
1091             vfitab           = 3*4*vfitab;
1092
1093             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1094             Y                = vftab[vfitab];
1095             F                = vftab[vfitab+1];
1096             Geps             = vfeps*vftab[vfitab+2];
1097             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1098             Fp               = F+Geps+Heps2;
1099             FF               = Fp+Geps+2.0*Heps2;
1100             felec            = -qq13*FF*vftabscale*rinv13;
1101
1102             fscal            = felec;
1103
1104             /* Calculate temporary vectorial force */
1105             tx               = fscal*dx13;
1106             ty               = fscal*dy13;
1107             tz               = fscal*dz13;
1108
1109             /* Update vectorial force */
1110             fix1            += tx;
1111             fiy1            += ty;
1112             fiz1            += tz;
1113             f[j_coord_offset+DIM*3+XX] -= tx;
1114             f[j_coord_offset+DIM*3+YY] -= ty;
1115             f[j_coord_offset+DIM*3+ZZ] -= tz;
1116
1117             /**************************
1118              * CALCULATE INTERACTIONS *
1119              **************************/
1120
1121             r21              = rsq21*rinv21;
1122
1123             /* Calculate table index by multiplying r with table scale and truncate to integer */
1124             rt               = r21*vftabscale;
1125             vfitab           = rt;
1126             vfeps            = rt-vfitab;
1127             vfitab           = 3*4*vfitab;
1128
1129             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1130             Y                = vftab[vfitab];
1131             F                = vftab[vfitab+1];
1132             Geps             = vfeps*vftab[vfitab+2];
1133             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1134             Fp               = F+Geps+Heps2;
1135             FF               = Fp+Geps+2.0*Heps2;
1136             felec            = -qq21*FF*vftabscale*rinv21;
1137
1138             fscal            = felec;
1139
1140             /* Calculate temporary vectorial force */
1141             tx               = fscal*dx21;
1142             ty               = fscal*dy21;
1143             tz               = fscal*dz21;
1144
1145             /* Update vectorial force */
1146             fix2            += tx;
1147             fiy2            += ty;
1148             fiz2            += tz;
1149             f[j_coord_offset+DIM*1+XX] -= tx;
1150             f[j_coord_offset+DIM*1+YY] -= ty;
1151             f[j_coord_offset+DIM*1+ZZ] -= tz;
1152
1153             /**************************
1154              * CALCULATE INTERACTIONS *
1155              **************************/
1156
1157             r22              = rsq22*rinv22;
1158
1159             /* Calculate table index by multiplying r with table scale and truncate to integer */
1160             rt               = r22*vftabscale;
1161             vfitab           = rt;
1162             vfeps            = rt-vfitab;
1163             vfitab           = 3*4*vfitab;
1164
1165             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1166             Y                = vftab[vfitab];
1167             F                = vftab[vfitab+1];
1168             Geps             = vfeps*vftab[vfitab+2];
1169             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1170             Fp               = F+Geps+Heps2;
1171             FF               = Fp+Geps+2.0*Heps2;
1172             felec            = -qq22*FF*vftabscale*rinv22;
1173
1174             fscal            = felec;
1175
1176             /* Calculate temporary vectorial force */
1177             tx               = fscal*dx22;
1178             ty               = fscal*dy22;
1179             tz               = fscal*dz22;
1180
1181             /* Update vectorial force */
1182             fix2            += tx;
1183             fiy2            += ty;
1184             fiz2            += tz;
1185             f[j_coord_offset+DIM*2+XX] -= tx;
1186             f[j_coord_offset+DIM*2+YY] -= ty;
1187             f[j_coord_offset+DIM*2+ZZ] -= tz;
1188
1189             /**************************
1190              * CALCULATE INTERACTIONS *
1191              **************************/
1192
1193             r23              = rsq23*rinv23;
1194
1195             /* Calculate table index by multiplying r with table scale and truncate to integer */
1196             rt               = r23*vftabscale;
1197             vfitab           = rt;
1198             vfeps            = rt-vfitab;
1199             vfitab           = 3*4*vfitab;
1200
1201             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1202             Y                = vftab[vfitab];
1203             F                = vftab[vfitab+1];
1204             Geps             = vfeps*vftab[vfitab+2];
1205             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1206             Fp               = F+Geps+Heps2;
1207             FF               = Fp+Geps+2.0*Heps2;
1208             felec            = -qq23*FF*vftabscale*rinv23;
1209
1210             fscal            = felec;
1211
1212             /* Calculate temporary vectorial force */
1213             tx               = fscal*dx23;
1214             ty               = fscal*dy23;
1215             tz               = fscal*dz23;
1216
1217             /* Update vectorial force */
1218             fix2            += tx;
1219             fiy2            += ty;
1220             fiz2            += tz;
1221             f[j_coord_offset+DIM*3+XX] -= tx;
1222             f[j_coord_offset+DIM*3+YY] -= ty;
1223             f[j_coord_offset+DIM*3+ZZ] -= tz;
1224
1225             /**************************
1226              * CALCULATE INTERACTIONS *
1227              **************************/
1228
1229             r31              = rsq31*rinv31;
1230
1231             /* Calculate table index by multiplying r with table scale and truncate to integer */
1232             rt               = r31*vftabscale;
1233             vfitab           = rt;
1234             vfeps            = rt-vfitab;
1235             vfitab           = 3*4*vfitab;
1236
1237             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1238             Y                = vftab[vfitab];
1239             F                = vftab[vfitab+1];
1240             Geps             = vfeps*vftab[vfitab+2];
1241             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1242             Fp               = F+Geps+Heps2;
1243             FF               = Fp+Geps+2.0*Heps2;
1244             felec            = -qq31*FF*vftabscale*rinv31;
1245
1246             fscal            = felec;
1247
1248             /* Calculate temporary vectorial force */
1249             tx               = fscal*dx31;
1250             ty               = fscal*dy31;
1251             tz               = fscal*dz31;
1252
1253             /* Update vectorial force */
1254             fix3            += tx;
1255             fiy3            += ty;
1256             fiz3            += tz;
1257             f[j_coord_offset+DIM*1+XX] -= tx;
1258             f[j_coord_offset+DIM*1+YY] -= ty;
1259             f[j_coord_offset+DIM*1+ZZ] -= tz;
1260
1261             /**************************
1262              * CALCULATE INTERACTIONS *
1263              **************************/
1264
1265             r32              = rsq32*rinv32;
1266
1267             /* Calculate table index by multiplying r with table scale and truncate to integer */
1268             rt               = r32*vftabscale;
1269             vfitab           = rt;
1270             vfeps            = rt-vfitab;
1271             vfitab           = 3*4*vfitab;
1272
1273             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1274             Y                = vftab[vfitab];
1275             F                = vftab[vfitab+1];
1276             Geps             = vfeps*vftab[vfitab+2];
1277             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1278             Fp               = F+Geps+Heps2;
1279             FF               = Fp+Geps+2.0*Heps2;
1280             felec            = -qq32*FF*vftabscale*rinv32;
1281
1282             fscal            = felec;
1283
1284             /* Calculate temporary vectorial force */
1285             tx               = fscal*dx32;
1286             ty               = fscal*dy32;
1287             tz               = fscal*dz32;
1288
1289             /* Update vectorial force */
1290             fix3            += tx;
1291             fiy3            += ty;
1292             fiz3            += tz;
1293             f[j_coord_offset+DIM*2+XX] -= tx;
1294             f[j_coord_offset+DIM*2+YY] -= ty;
1295             f[j_coord_offset+DIM*2+ZZ] -= tz;
1296
1297             /**************************
1298              * CALCULATE INTERACTIONS *
1299              **************************/
1300
1301             r33              = rsq33*rinv33;
1302
1303             /* Calculate table index by multiplying r with table scale and truncate to integer */
1304             rt               = r33*vftabscale;
1305             vfitab           = rt;
1306             vfeps            = rt-vfitab;
1307             vfitab           = 3*4*vfitab;
1308
1309             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1310             Y                = vftab[vfitab];
1311             F                = vftab[vfitab+1];
1312             Geps             = vfeps*vftab[vfitab+2];
1313             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1314             Fp               = F+Geps+Heps2;
1315             FF               = Fp+Geps+2.0*Heps2;
1316             felec            = -qq33*FF*vftabscale*rinv33;
1317
1318             fscal            = felec;
1319
1320             /* Calculate temporary vectorial force */
1321             tx               = fscal*dx33;
1322             ty               = fscal*dy33;
1323             tz               = fscal*dz33;
1324
1325             /* Update vectorial force */
1326             fix3            += tx;
1327             fiy3            += ty;
1328             fiz3            += tz;
1329             f[j_coord_offset+DIM*3+XX] -= tx;
1330             f[j_coord_offset+DIM*3+YY] -= ty;
1331             f[j_coord_offset+DIM*3+ZZ] -= tz;
1332
1333             /* Inner loop uses 380 flops */
1334         }
1335         /* End of innermost loop */
1336
1337         tx = ty = tz = 0;
1338         f[i_coord_offset+DIM*0+XX] += fix0;
1339         f[i_coord_offset+DIM*0+YY] += fiy0;
1340         f[i_coord_offset+DIM*0+ZZ] += fiz0;
1341         tx                         += fix0;
1342         ty                         += fiy0;
1343         tz                         += fiz0;
1344         f[i_coord_offset+DIM*1+XX] += fix1;
1345         f[i_coord_offset+DIM*1+YY] += fiy1;
1346         f[i_coord_offset+DIM*1+ZZ] += fiz1;
1347         tx                         += fix1;
1348         ty                         += fiy1;
1349         tz                         += fiz1;
1350         f[i_coord_offset+DIM*2+XX] += fix2;
1351         f[i_coord_offset+DIM*2+YY] += fiy2;
1352         f[i_coord_offset+DIM*2+ZZ] += fiz2;
1353         tx                         += fix2;
1354         ty                         += fiy2;
1355         tz                         += fiz2;
1356         f[i_coord_offset+DIM*3+XX] += fix3;
1357         f[i_coord_offset+DIM*3+YY] += fiy3;
1358         f[i_coord_offset+DIM*3+ZZ] += fiz3;
1359         tx                         += fix3;
1360         ty                         += fiy3;
1361         tz                         += fiz3;
1362         fshift[i_shift_offset+XX]  += tx;
1363         fshift[i_shift_offset+YY]  += ty;
1364         fshift[i_shift_offset+ZZ]  += tz;
1365
1366         /* Increment number of inner iterations */
1367         inneriter                  += j_index_end - j_index_start;
1368
1369         /* Outer loop uses 39 flops */
1370     }
1371
1372     /* Increment number of outer iterations */
1373     outeriter        += nri;
1374
1375     /* Update outer/inner flops */
1376
1377     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_F,outeriter*39 + inneriter*380);
1378 }