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