a1e350217063447c2279a81d2375f9751796a186
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecCSTab_VdwLJ_GeomW3W3_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_GeomW3W3_VF_c
49  * Electrostatics interaction: CubicSplineTable
50  * VdW interaction:            LennardJones
51  * Geometry:                   Water3-Water3
52  * Calculate force/pot:        PotentialAndForce
53  */
54 void
55 nb_kernel_ElecCSTab_VdwLJ_GeomW3W3_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              vdwjidx0;
77     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
78     int              vdwjidx1;
79     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
80     int              vdwjidx2;
81     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
82     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
83     real             dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01,cexp1_01,cexp2_01;
84     real             dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02,cexp1_02,cexp2_02;
85     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
86     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
87     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
88     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
89     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
90     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
91     real             velec,felec,velecsum,facel,crf,krf,krf2;
92     real             *charge;
93     int              nvdwtype;
94     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
95     int              *vdwtype;
96     real             *vdwparam;
97     int              vfitab;
98     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
99     real             *vftab;
100
101     x                = xx[0];
102     f                = ff[0];
103
104     nri              = nlist->nri;
105     iinr             = nlist->iinr;
106     jindex           = nlist->jindex;
107     jjnr             = nlist->jjnr;
108     shiftidx         = nlist->shift;
109     gid              = nlist->gid;
110     shiftvec         = fr->shift_vec[0];
111     fshift           = fr->fshift[0];
112     facel            = fr->epsfac;
113     charge           = mdatoms->chargeA;
114     nvdwtype         = fr->ntype;
115     vdwparam         = fr->nbfp;
116     vdwtype          = mdatoms->typeA;
117
118     vftab            = kernel_data->table_elec->data;
119     vftabscale       = kernel_data->table_elec->scale;
120
121     /* Setup water-specific parameters */
122     inr              = nlist->iinr[0];
123     iq0              = facel*charge[inr+0];
124     iq1              = facel*charge[inr+1];
125     iq2              = facel*charge[inr+2];
126     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
127
128     jq0              = charge[inr+0];
129     jq1              = charge[inr+1];
130     jq2              = charge[inr+2];
131     vdwjidx0         = 2*vdwtype[inr+0];
132     qq00             = iq0*jq0;
133     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
134     c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
135     qq01             = iq0*jq1;
136     qq02             = iq0*jq2;
137     qq10             = iq1*jq0;
138     qq11             = iq1*jq1;
139     qq12             = iq1*jq2;
140     qq20             = iq2*jq0;
141     qq21             = iq2*jq1;
142     qq22             = iq2*jq2;
143
144     outeriter        = 0;
145     inneriter        = 0;
146
147     /* Start outer loop over neighborlists */
148     for(iidx=0; iidx<nri; iidx++)
149     {
150         /* Load shift vector for this list */
151         i_shift_offset   = DIM*shiftidx[iidx];
152         shX              = shiftvec[i_shift_offset+XX];
153         shY              = shiftvec[i_shift_offset+YY];
154         shZ              = shiftvec[i_shift_offset+ZZ];
155
156         /* Load limits for loop over neighbors */
157         j_index_start    = jindex[iidx];
158         j_index_end      = jindex[iidx+1];
159
160         /* Get outer coordinate index */
161         inr              = iinr[iidx];
162         i_coord_offset   = DIM*inr;
163
164         /* Load i particle coords and add shift vector */
165         ix0              = shX + x[i_coord_offset+DIM*0+XX];
166         iy0              = shY + x[i_coord_offset+DIM*0+YY];
167         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
168         ix1              = shX + x[i_coord_offset+DIM*1+XX];
169         iy1              = shY + x[i_coord_offset+DIM*1+YY];
170         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
171         ix2              = shX + x[i_coord_offset+DIM*2+XX];
172         iy2              = shY + x[i_coord_offset+DIM*2+YY];
173         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
174
175         fix0             = 0.0;
176         fiy0             = 0.0;
177         fiz0             = 0.0;
178         fix1             = 0.0;
179         fiy1             = 0.0;
180         fiz1             = 0.0;
181         fix2             = 0.0;
182         fiy2             = 0.0;
183         fiz2             = 0.0;
184
185         /* Reset potential sums */
186         velecsum         = 0.0;
187         vvdwsum          = 0.0;
188
189         /* Start inner kernel loop */
190         for(jidx=j_index_start; jidx<j_index_end; jidx++)
191         {
192             /* Get j neighbor index, and coordinate index */
193             jnr              = jjnr[jidx];
194             j_coord_offset   = DIM*jnr;
195
196             /* load j atom coordinates */
197             jx0              = x[j_coord_offset+DIM*0+XX];
198             jy0              = x[j_coord_offset+DIM*0+YY];
199             jz0              = x[j_coord_offset+DIM*0+ZZ];
200             jx1              = x[j_coord_offset+DIM*1+XX];
201             jy1              = x[j_coord_offset+DIM*1+YY];
202             jz1              = x[j_coord_offset+DIM*1+ZZ];
203             jx2              = x[j_coord_offset+DIM*2+XX];
204             jy2              = x[j_coord_offset+DIM*2+YY];
205             jz2              = x[j_coord_offset+DIM*2+ZZ];
206
207             /* Calculate displacement vector */
208             dx00             = ix0 - jx0;
209             dy00             = iy0 - jy0;
210             dz00             = iz0 - jz0;
211             dx01             = ix0 - jx1;
212             dy01             = iy0 - jy1;
213             dz01             = iz0 - jz1;
214             dx02             = ix0 - jx2;
215             dy02             = iy0 - jy2;
216             dz02             = iz0 - jz2;
217             dx10             = ix1 - jx0;
218             dy10             = iy1 - jy0;
219             dz10             = iz1 - jz0;
220             dx11             = ix1 - jx1;
221             dy11             = iy1 - jy1;
222             dz11             = iz1 - jz1;
223             dx12             = ix1 - jx2;
224             dy12             = iy1 - jy2;
225             dz12             = iz1 - jz2;
226             dx20             = ix2 - jx0;
227             dy20             = iy2 - jy0;
228             dz20             = iz2 - jz0;
229             dx21             = ix2 - jx1;
230             dy21             = iy2 - jy1;
231             dz21             = iz2 - jz1;
232             dx22             = ix2 - jx2;
233             dy22             = iy2 - jy2;
234             dz22             = iz2 - jz2;
235
236             /* Calculate squared distance and things based on it */
237             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
238             rsq01            = dx01*dx01+dy01*dy01+dz01*dz01;
239             rsq02            = dx02*dx02+dy02*dy02+dz02*dz02;
240             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
241             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
242             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
243             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
244             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
245             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
246
247             rinv00           = gmx_invsqrt(rsq00);
248             rinv01           = gmx_invsqrt(rsq01);
249             rinv02           = gmx_invsqrt(rsq02);
250             rinv10           = gmx_invsqrt(rsq10);
251             rinv11           = gmx_invsqrt(rsq11);
252             rinv12           = gmx_invsqrt(rsq12);
253             rinv20           = gmx_invsqrt(rsq20);
254             rinv21           = gmx_invsqrt(rsq21);
255             rinv22           = gmx_invsqrt(rsq22);
256
257             rinvsq00         = rinv00*rinv00;
258
259             /**************************
260              * CALCULATE INTERACTIONS *
261              **************************/
262
263             r00              = rsq00*rinv00;
264
265             /* Calculate table index by multiplying r with table scale and truncate to integer */
266             rt               = r00*vftabscale;
267             vfitab           = rt;
268             vfeps            = rt-vfitab;
269             vfitab           = 1*4*vfitab;
270
271             /* CUBIC SPLINE TABLE ELECTROSTATICS */
272             Y                = vftab[vfitab];
273             F                = vftab[vfitab+1];
274             Geps             = vfeps*vftab[vfitab+2];
275             Heps2            = vfeps*vfeps*vftab[vfitab+3];
276             Fp               = F+Geps+Heps2;
277             VV               = Y+vfeps*Fp;
278             velec            = qq00*VV;
279             FF               = Fp+Geps+2.0*Heps2;
280             felec            = -qq00*FF*vftabscale*rinv00;
281
282             /* LENNARD-JONES DISPERSION/REPULSION */
283
284             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
285             vvdw6            = c6_00*rinvsix;
286             vvdw12           = c12_00*rinvsix*rinvsix;
287             vvdw             = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
288             fvdw             = (vvdw12-vvdw6)*rinvsq00;
289
290             /* Update potential sums from outer loop */
291             velecsum        += velec;
292             vvdwsum         += vvdw;
293
294             fscal            = felec+fvdw;
295
296             /* Calculate temporary vectorial force */
297             tx               = fscal*dx00;
298             ty               = fscal*dy00;
299             tz               = fscal*dz00;
300
301             /* Update vectorial force */
302             fix0            += tx;
303             fiy0            += ty;
304             fiz0            += tz;
305             f[j_coord_offset+DIM*0+XX] -= tx;
306             f[j_coord_offset+DIM*0+YY] -= ty;
307             f[j_coord_offset+DIM*0+ZZ] -= tz;
308
309             /**************************
310              * CALCULATE INTERACTIONS *
311              **************************/
312
313             r01              = rsq01*rinv01;
314
315             /* Calculate table index by multiplying r with table scale and truncate to integer */
316             rt               = r01*vftabscale;
317             vfitab           = rt;
318             vfeps            = rt-vfitab;
319             vfitab           = 1*4*vfitab;
320
321             /* CUBIC SPLINE TABLE ELECTROSTATICS */
322             Y                = vftab[vfitab];
323             F                = vftab[vfitab+1];
324             Geps             = vfeps*vftab[vfitab+2];
325             Heps2            = vfeps*vfeps*vftab[vfitab+3];
326             Fp               = F+Geps+Heps2;
327             VV               = Y+vfeps*Fp;
328             velec            = qq01*VV;
329             FF               = Fp+Geps+2.0*Heps2;
330             felec            = -qq01*FF*vftabscale*rinv01;
331
332             /* Update potential sums from outer loop */
333             velecsum        += velec;
334
335             fscal            = felec;
336
337             /* Calculate temporary vectorial force */
338             tx               = fscal*dx01;
339             ty               = fscal*dy01;
340             tz               = fscal*dz01;
341
342             /* Update vectorial force */
343             fix0            += tx;
344             fiy0            += ty;
345             fiz0            += tz;
346             f[j_coord_offset+DIM*1+XX] -= tx;
347             f[j_coord_offset+DIM*1+YY] -= ty;
348             f[j_coord_offset+DIM*1+ZZ] -= tz;
349
350             /**************************
351              * CALCULATE INTERACTIONS *
352              **************************/
353
354             r02              = rsq02*rinv02;
355
356             /* Calculate table index by multiplying r with table scale and truncate to integer */
357             rt               = r02*vftabscale;
358             vfitab           = rt;
359             vfeps            = rt-vfitab;
360             vfitab           = 1*4*vfitab;
361
362             /* CUBIC SPLINE TABLE ELECTROSTATICS */
363             Y                = vftab[vfitab];
364             F                = vftab[vfitab+1];
365             Geps             = vfeps*vftab[vfitab+2];
366             Heps2            = vfeps*vfeps*vftab[vfitab+3];
367             Fp               = F+Geps+Heps2;
368             VV               = Y+vfeps*Fp;
369             velec            = qq02*VV;
370             FF               = Fp+Geps+2.0*Heps2;
371             felec            = -qq02*FF*vftabscale*rinv02;
372
373             /* Update potential sums from outer loop */
374             velecsum        += velec;
375
376             fscal            = felec;
377
378             /* Calculate temporary vectorial force */
379             tx               = fscal*dx02;
380             ty               = fscal*dy02;
381             tz               = fscal*dz02;
382
383             /* Update vectorial force */
384             fix0            += tx;
385             fiy0            += ty;
386             fiz0            += tz;
387             f[j_coord_offset+DIM*2+XX] -= tx;
388             f[j_coord_offset+DIM*2+YY] -= ty;
389             f[j_coord_offset+DIM*2+ZZ] -= tz;
390
391             /**************************
392              * CALCULATE INTERACTIONS *
393              **************************/
394
395             r10              = rsq10*rinv10;
396
397             /* Calculate table index by multiplying r with table scale and truncate to integer */
398             rt               = r10*vftabscale;
399             vfitab           = rt;
400             vfeps            = rt-vfitab;
401             vfitab           = 1*4*vfitab;
402
403             /* CUBIC SPLINE TABLE ELECTROSTATICS */
404             Y                = vftab[vfitab];
405             F                = vftab[vfitab+1];
406             Geps             = vfeps*vftab[vfitab+2];
407             Heps2            = vfeps*vfeps*vftab[vfitab+3];
408             Fp               = F+Geps+Heps2;
409             VV               = Y+vfeps*Fp;
410             velec            = qq10*VV;
411             FF               = Fp+Geps+2.0*Heps2;
412             felec            = -qq10*FF*vftabscale*rinv10;
413
414             /* Update potential sums from outer loop */
415             velecsum        += velec;
416
417             fscal            = felec;
418
419             /* Calculate temporary vectorial force */
420             tx               = fscal*dx10;
421             ty               = fscal*dy10;
422             tz               = fscal*dz10;
423
424             /* Update vectorial force */
425             fix1            += tx;
426             fiy1            += ty;
427             fiz1            += tz;
428             f[j_coord_offset+DIM*0+XX] -= tx;
429             f[j_coord_offset+DIM*0+YY] -= ty;
430             f[j_coord_offset+DIM*0+ZZ] -= tz;
431
432             /**************************
433              * CALCULATE INTERACTIONS *
434              **************************/
435
436             r11              = rsq11*rinv11;
437
438             /* Calculate table index by multiplying r with table scale and truncate to integer */
439             rt               = r11*vftabscale;
440             vfitab           = rt;
441             vfeps            = rt-vfitab;
442             vfitab           = 1*4*vfitab;
443
444             /* CUBIC SPLINE TABLE ELECTROSTATICS */
445             Y                = vftab[vfitab];
446             F                = vftab[vfitab+1];
447             Geps             = vfeps*vftab[vfitab+2];
448             Heps2            = vfeps*vfeps*vftab[vfitab+3];
449             Fp               = F+Geps+Heps2;
450             VV               = Y+vfeps*Fp;
451             velec            = qq11*VV;
452             FF               = Fp+Geps+2.0*Heps2;
453             felec            = -qq11*FF*vftabscale*rinv11;
454
455             /* Update potential sums from outer loop */
456             velecsum        += velec;
457
458             fscal            = felec;
459
460             /* Calculate temporary vectorial force */
461             tx               = fscal*dx11;
462             ty               = fscal*dy11;
463             tz               = fscal*dz11;
464
465             /* Update vectorial force */
466             fix1            += tx;
467             fiy1            += ty;
468             fiz1            += tz;
469             f[j_coord_offset+DIM*1+XX] -= tx;
470             f[j_coord_offset+DIM*1+YY] -= ty;
471             f[j_coord_offset+DIM*1+ZZ] -= tz;
472
473             /**************************
474              * CALCULATE INTERACTIONS *
475              **************************/
476
477             r12              = rsq12*rinv12;
478
479             /* Calculate table index by multiplying r with table scale and truncate to integer */
480             rt               = r12*vftabscale;
481             vfitab           = rt;
482             vfeps            = rt-vfitab;
483             vfitab           = 1*4*vfitab;
484
485             /* CUBIC SPLINE TABLE ELECTROSTATICS */
486             Y                = vftab[vfitab];
487             F                = vftab[vfitab+1];
488             Geps             = vfeps*vftab[vfitab+2];
489             Heps2            = vfeps*vfeps*vftab[vfitab+3];
490             Fp               = F+Geps+Heps2;
491             VV               = Y+vfeps*Fp;
492             velec            = qq12*VV;
493             FF               = Fp+Geps+2.0*Heps2;
494             felec            = -qq12*FF*vftabscale*rinv12;
495
496             /* Update potential sums from outer loop */
497             velecsum        += velec;
498
499             fscal            = felec;
500
501             /* Calculate temporary vectorial force */
502             tx               = fscal*dx12;
503             ty               = fscal*dy12;
504             tz               = fscal*dz12;
505
506             /* Update vectorial force */
507             fix1            += tx;
508             fiy1            += ty;
509             fiz1            += tz;
510             f[j_coord_offset+DIM*2+XX] -= tx;
511             f[j_coord_offset+DIM*2+YY] -= ty;
512             f[j_coord_offset+DIM*2+ZZ] -= tz;
513
514             /**************************
515              * CALCULATE INTERACTIONS *
516              **************************/
517
518             r20              = rsq20*rinv20;
519
520             /* Calculate table index by multiplying r with table scale and truncate to integer */
521             rt               = r20*vftabscale;
522             vfitab           = rt;
523             vfeps            = rt-vfitab;
524             vfitab           = 1*4*vfitab;
525
526             /* CUBIC SPLINE TABLE ELECTROSTATICS */
527             Y                = vftab[vfitab];
528             F                = vftab[vfitab+1];
529             Geps             = vfeps*vftab[vfitab+2];
530             Heps2            = vfeps*vfeps*vftab[vfitab+3];
531             Fp               = F+Geps+Heps2;
532             VV               = Y+vfeps*Fp;
533             velec            = qq20*VV;
534             FF               = Fp+Geps+2.0*Heps2;
535             felec            = -qq20*FF*vftabscale*rinv20;
536
537             /* Update potential sums from outer loop */
538             velecsum        += velec;
539
540             fscal            = felec;
541
542             /* Calculate temporary vectorial force */
543             tx               = fscal*dx20;
544             ty               = fscal*dy20;
545             tz               = fscal*dz20;
546
547             /* Update vectorial force */
548             fix2            += tx;
549             fiy2            += ty;
550             fiz2            += tz;
551             f[j_coord_offset+DIM*0+XX] -= tx;
552             f[j_coord_offset+DIM*0+YY] -= ty;
553             f[j_coord_offset+DIM*0+ZZ] -= tz;
554
555             /**************************
556              * CALCULATE INTERACTIONS *
557              **************************/
558
559             r21              = rsq21*rinv21;
560
561             /* Calculate table index by multiplying r with table scale and truncate to integer */
562             rt               = r21*vftabscale;
563             vfitab           = rt;
564             vfeps            = rt-vfitab;
565             vfitab           = 1*4*vfitab;
566
567             /* CUBIC SPLINE TABLE ELECTROSTATICS */
568             Y                = vftab[vfitab];
569             F                = vftab[vfitab+1];
570             Geps             = vfeps*vftab[vfitab+2];
571             Heps2            = vfeps*vfeps*vftab[vfitab+3];
572             Fp               = F+Geps+Heps2;
573             VV               = Y+vfeps*Fp;
574             velec            = qq21*VV;
575             FF               = Fp+Geps+2.0*Heps2;
576             felec            = -qq21*FF*vftabscale*rinv21;
577
578             /* Update potential sums from outer loop */
579             velecsum        += velec;
580
581             fscal            = felec;
582
583             /* Calculate temporary vectorial force */
584             tx               = fscal*dx21;
585             ty               = fscal*dy21;
586             tz               = fscal*dz21;
587
588             /* Update vectorial force */
589             fix2            += tx;
590             fiy2            += ty;
591             fiz2            += tz;
592             f[j_coord_offset+DIM*1+XX] -= tx;
593             f[j_coord_offset+DIM*1+YY] -= ty;
594             f[j_coord_offset+DIM*1+ZZ] -= tz;
595
596             /**************************
597              * CALCULATE INTERACTIONS *
598              **************************/
599
600             r22              = rsq22*rinv22;
601
602             /* Calculate table index by multiplying r with table scale and truncate to integer */
603             rt               = r22*vftabscale;
604             vfitab           = rt;
605             vfeps            = rt-vfitab;
606             vfitab           = 1*4*vfitab;
607
608             /* CUBIC SPLINE TABLE ELECTROSTATICS */
609             Y                = vftab[vfitab];
610             F                = vftab[vfitab+1];
611             Geps             = vfeps*vftab[vfitab+2];
612             Heps2            = vfeps*vfeps*vftab[vfitab+3];
613             Fp               = F+Geps+Heps2;
614             VV               = Y+vfeps*Fp;
615             velec            = qq22*VV;
616             FF               = Fp+Geps+2.0*Heps2;
617             felec            = -qq22*FF*vftabscale*rinv22;
618
619             /* Update potential sums from outer loop */
620             velecsum        += velec;
621
622             fscal            = felec;
623
624             /* Calculate temporary vectorial force */
625             tx               = fscal*dx22;
626             ty               = fscal*dy22;
627             tz               = fscal*dz22;
628
629             /* Update vectorial force */
630             fix2            += tx;
631             fiy2            += ty;
632             fiz2            += tz;
633             f[j_coord_offset+DIM*2+XX] -= tx;
634             f[j_coord_offset+DIM*2+YY] -= ty;
635             f[j_coord_offset+DIM*2+ZZ] -= tz;
636
637             /* Inner loop uses 382 flops */
638         }
639         /* End of innermost loop */
640
641         tx = ty = tz = 0;
642         f[i_coord_offset+DIM*0+XX] += fix0;
643         f[i_coord_offset+DIM*0+YY] += fiy0;
644         f[i_coord_offset+DIM*0+ZZ] += fiz0;
645         tx                         += fix0;
646         ty                         += fiy0;
647         tz                         += fiz0;
648         f[i_coord_offset+DIM*1+XX] += fix1;
649         f[i_coord_offset+DIM*1+YY] += fiy1;
650         f[i_coord_offset+DIM*1+ZZ] += fiz1;
651         tx                         += fix1;
652         ty                         += fiy1;
653         tz                         += fiz1;
654         f[i_coord_offset+DIM*2+XX] += fix2;
655         f[i_coord_offset+DIM*2+YY] += fiy2;
656         f[i_coord_offset+DIM*2+ZZ] += fiz2;
657         tx                         += fix2;
658         ty                         += fiy2;
659         tz                         += fiz2;
660         fshift[i_shift_offset+XX]  += tx;
661         fshift[i_shift_offset+YY]  += ty;
662         fshift[i_shift_offset+ZZ]  += tz;
663
664         ggid                        = gid[iidx];
665         /* Update potential energies */
666         kernel_data->energygrp_elec[ggid] += velecsum;
667         kernel_data->energygrp_vdw[ggid] += vvdwsum;
668
669         /* Increment number of inner iterations */
670         inneriter                  += j_index_end - j_index_start;
671
672         /* Outer loop uses 32 flops */
673     }
674
675     /* Increment number of outer iterations */
676     outeriter        += nri;
677
678     /* Update outer/inner flops */
679
680     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_VF,outeriter*32 + inneriter*382);
681 }
682 /*
683  * Gromacs nonbonded kernel:   nb_kernel_ElecCSTab_VdwLJ_GeomW3W3_F_c
684  * Electrostatics interaction: CubicSplineTable
685  * VdW interaction:            LennardJones
686  * Geometry:                   Water3-Water3
687  * Calculate force/pot:        Force
688  */
689 void
690 nb_kernel_ElecCSTab_VdwLJ_GeomW3W3_F_c
691                     (t_nblist                    * gmx_restrict       nlist,
692                      rvec                        * gmx_restrict          xx,
693                      rvec                        * gmx_restrict          ff,
694                      t_forcerec                  * gmx_restrict          fr,
695                      t_mdatoms                   * gmx_restrict     mdatoms,
696                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
697                      t_nrnb                      * gmx_restrict        nrnb)
698 {
699     int              i_shift_offset,i_coord_offset,j_coord_offset;
700     int              j_index_start,j_index_end;
701     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
702     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
703     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
704     real             *shiftvec,*fshift,*x,*f;
705     int              vdwioffset0;
706     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
707     int              vdwioffset1;
708     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
709     int              vdwioffset2;
710     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
711     int              vdwjidx0;
712     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
713     int              vdwjidx1;
714     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
715     int              vdwjidx2;
716     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
717     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
718     real             dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01,cexp1_01,cexp2_01;
719     real             dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02,cexp1_02,cexp2_02;
720     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
721     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
722     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
723     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
724     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
725     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
726     real             velec,felec,velecsum,facel,crf,krf,krf2;
727     real             *charge;
728     int              nvdwtype;
729     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
730     int              *vdwtype;
731     real             *vdwparam;
732     int              vfitab;
733     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
734     real             *vftab;
735
736     x                = xx[0];
737     f                = ff[0];
738
739     nri              = nlist->nri;
740     iinr             = nlist->iinr;
741     jindex           = nlist->jindex;
742     jjnr             = nlist->jjnr;
743     shiftidx         = nlist->shift;
744     gid              = nlist->gid;
745     shiftvec         = fr->shift_vec[0];
746     fshift           = fr->fshift[0];
747     facel            = fr->epsfac;
748     charge           = mdatoms->chargeA;
749     nvdwtype         = fr->ntype;
750     vdwparam         = fr->nbfp;
751     vdwtype          = mdatoms->typeA;
752
753     vftab            = kernel_data->table_elec->data;
754     vftabscale       = kernel_data->table_elec->scale;
755
756     /* Setup water-specific parameters */
757     inr              = nlist->iinr[0];
758     iq0              = facel*charge[inr+0];
759     iq1              = facel*charge[inr+1];
760     iq2              = facel*charge[inr+2];
761     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
762
763     jq0              = charge[inr+0];
764     jq1              = charge[inr+1];
765     jq2              = charge[inr+2];
766     vdwjidx0         = 2*vdwtype[inr+0];
767     qq00             = iq0*jq0;
768     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
769     c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
770     qq01             = iq0*jq1;
771     qq02             = iq0*jq2;
772     qq10             = iq1*jq0;
773     qq11             = iq1*jq1;
774     qq12             = iq1*jq2;
775     qq20             = iq2*jq0;
776     qq21             = iq2*jq1;
777     qq22             = iq2*jq2;
778
779     outeriter        = 0;
780     inneriter        = 0;
781
782     /* Start outer loop over neighborlists */
783     for(iidx=0; iidx<nri; iidx++)
784     {
785         /* Load shift vector for this list */
786         i_shift_offset   = DIM*shiftidx[iidx];
787         shX              = shiftvec[i_shift_offset+XX];
788         shY              = shiftvec[i_shift_offset+YY];
789         shZ              = shiftvec[i_shift_offset+ZZ];
790
791         /* Load limits for loop over neighbors */
792         j_index_start    = jindex[iidx];
793         j_index_end      = jindex[iidx+1];
794
795         /* Get outer coordinate index */
796         inr              = iinr[iidx];
797         i_coord_offset   = DIM*inr;
798
799         /* Load i particle coords and add shift vector */
800         ix0              = shX + x[i_coord_offset+DIM*0+XX];
801         iy0              = shY + x[i_coord_offset+DIM*0+YY];
802         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
803         ix1              = shX + x[i_coord_offset+DIM*1+XX];
804         iy1              = shY + x[i_coord_offset+DIM*1+YY];
805         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
806         ix2              = shX + x[i_coord_offset+DIM*2+XX];
807         iy2              = shY + x[i_coord_offset+DIM*2+YY];
808         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
809
810         fix0             = 0.0;
811         fiy0             = 0.0;
812         fiz0             = 0.0;
813         fix1             = 0.0;
814         fiy1             = 0.0;
815         fiz1             = 0.0;
816         fix2             = 0.0;
817         fiy2             = 0.0;
818         fiz2             = 0.0;
819
820         /* Start inner kernel loop */
821         for(jidx=j_index_start; jidx<j_index_end; jidx++)
822         {
823             /* Get j neighbor index, and coordinate index */
824             jnr              = jjnr[jidx];
825             j_coord_offset   = DIM*jnr;
826
827             /* load j atom coordinates */
828             jx0              = x[j_coord_offset+DIM*0+XX];
829             jy0              = x[j_coord_offset+DIM*0+YY];
830             jz0              = x[j_coord_offset+DIM*0+ZZ];
831             jx1              = x[j_coord_offset+DIM*1+XX];
832             jy1              = x[j_coord_offset+DIM*1+YY];
833             jz1              = x[j_coord_offset+DIM*1+ZZ];
834             jx2              = x[j_coord_offset+DIM*2+XX];
835             jy2              = x[j_coord_offset+DIM*2+YY];
836             jz2              = x[j_coord_offset+DIM*2+ZZ];
837
838             /* Calculate displacement vector */
839             dx00             = ix0 - jx0;
840             dy00             = iy0 - jy0;
841             dz00             = iz0 - jz0;
842             dx01             = ix0 - jx1;
843             dy01             = iy0 - jy1;
844             dz01             = iz0 - jz1;
845             dx02             = ix0 - jx2;
846             dy02             = iy0 - jy2;
847             dz02             = iz0 - jz2;
848             dx10             = ix1 - jx0;
849             dy10             = iy1 - jy0;
850             dz10             = iz1 - jz0;
851             dx11             = ix1 - jx1;
852             dy11             = iy1 - jy1;
853             dz11             = iz1 - jz1;
854             dx12             = ix1 - jx2;
855             dy12             = iy1 - jy2;
856             dz12             = iz1 - jz2;
857             dx20             = ix2 - jx0;
858             dy20             = iy2 - jy0;
859             dz20             = iz2 - jz0;
860             dx21             = ix2 - jx1;
861             dy21             = iy2 - jy1;
862             dz21             = iz2 - jz1;
863             dx22             = ix2 - jx2;
864             dy22             = iy2 - jy2;
865             dz22             = iz2 - jz2;
866
867             /* Calculate squared distance and things based on it */
868             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
869             rsq01            = dx01*dx01+dy01*dy01+dz01*dz01;
870             rsq02            = dx02*dx02+dy02*dy02+dz02*dz02;
871             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
872             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
873             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
874             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
875             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
876             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
877
878             rinv00           = gmx_invsqrt(rsq00);
879             rinv01           = gmx_invsqrt(rsq01);
880             rinv02           = gmx_invsqrt(rsq02);
881             rinv10           = gmx_invsqrt(rsq10);
882             rinv11           = gmx_invsqrt(rsq11);
883             rinv12           = gmx_invsqrt(rsq12);
884             rinv20           = gmx_invsqrt(rsq20);
885             rinv21           = gmx_invsqrt(rsq21);
886             rinv22           = gmx_invsqrt(rsq22);
887
888             rinvsq00         = rinv00*rinv00;
889
890             /**************************
891              * CALCULATE INTERACTIONS *
892              **************************/
893
894             r00              = rsq00*rinv00;
895
896             /* Calculate table index by multiplying r with table scale and truncate to integer */
897             rt               = r00*vftabscale;
898             vfitab           = rt;
899             vfeps            = rt-vfitab;
900             vfitab           = 1*4*vfitab;
901
902             /* CUBIC SPLINE TABLE ELECTROSTATICS */
903             F                = vftab[vfitab+1];
904             Geps             = vfeps*vftab[vfitab+2];
905             Heps2            = vfeps*vfeps*vftab[vfitab+3];
906             Fp               = F+Geps+Heps2;
907             FF               = Fp+Geps+2.0*Heps2;
908             felec            = -qq00*FF*vftabscale*rinv00;
909
910             /* LENNARD-JONES DISPERSION/REPULSION */
911
912             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
913             fvdw             = (c12_00*rinvsix-c6_00)*rinvsix*rinvsq00;
914
915             fscal            = felec+fvdw;
916
917             /* Calculate temporary vectorial force */
918             tx               = fscal*dx00;
919             ty               = fscal*dy00;
920             tz               = fscal*dz00;
921
922             /* Update vectorial force */
923             fix0            += tx;
924             fiy0            += ty;
925             fiz0            += tz;
926             f[j_coord_offset+DIM*0+XX] -= tx;
927             f[j_coord_offset+DIM*0+YY] -= ty;
928             f[j_coord_offset+DIM*0+ZZ] -= tz;
929
930             /**************************
931              * CALCULATE INTERACTIONS *
932              **************************/
933
934             r01              = rsq01*rinv01;
935
936             /* Calculate table index by multiplying r with table scale and truncate to integer */
937             rt               = r01*vftabscale;
938             vfitab           = rt;
939             vfeps            = rt-vfitab;
940             vfitab           = 1*4*vfitab;
941
942             /* CUBIC SPLINE TABLE ELECTROSTATICS */
943             F                = vftab[vfitab+1];
944             Geps             = vfeps*vftab[vfitab+2];
945             Heps2            = vfeps*vfeps*vftab[vfitab+3];
946             Fp               = F+Geps+Heps2;
947             FF               = Fp+Geps+2.0*Heps2;
948             felec            = -qq01*FF*vftabscale*rinv01;
949
950             fscal            = felec;
951
952             /* Calculate temporary vectorial force */
953             tx               = fscal*dx01;
954             ty               = fscal*dy01;
955             tz               = fscal*dz01;
956
957             /* Update vectorial force */
958             fix0            += tx;
959             fiy0            += ty;
960             fiz0            += tz;
961             f[j_coord_offset+DIM*1+XX] -= tx;
962             f[j_coord_offset+DIM*1+YY] -= ty;
963             f[j_coord_offset+DIM*1+ZZ] -= tz;
964
965             /**************************
966              * CALCULATE INTERACTIONS *
967              **************************/
968
969             r02              = rsq02*rinv02;
970
971             /* Calculate table index by multiplying r with table scale and truncate to integer */
972             rt               = r02*vftabscale;
973             vfitab           = rt;
974             vfeps            = rt-vfitab;
975             vfitab           = 1*4*vfitab;
976
977             /* CUBIC SPLINE TABLE ELECTROSTATICS */
978             F                = vftab[vfitab+1];
979             Geps             = vfeps*vftab[vfitab+2];
980             Heps2            = vfeps*vfeps*vftab[vfitab+3];
981             Fp               = F+Geps+Heps2;
982             FF               = Fp+Geps+2.0*Heps2;
983             felec            = -qq02*FF*vftabscale*rinv02;
984
985             fscal            = felec;
986
987             /* Calculate temporary vectorial force */
988             tx               = fscal*dx02;
989             ty               = fscal*dy02;
990             tz               = fscal*dz02;
991
992             /* Update vectorial force */
993             fix0            += tx;
994             fiy0            += ty;
995             fiz0            += tz;
996             f[j_coord_offset+DIM*2+XX] -= tx;
997             f[j_coord_offset+DIM*2+YY] -= ty;
998             f[j_coord_offset+DIM*2+ZZ] -= tz;
999
1000             /**************************
1001              * CALCULATE INTERACTIONS *
1002              **************************/
1003
1004             r10              = rsq10*rinv10;
1005
1006             /* Calculate table index by multiplying r with table scale and truncate to integer */
1007             rt               = r10*vftabscale;
1008             vfitab           = rt;
1009             vfeps            = rt-vfitab;
1010             vfitab           = 1*4*vfitab;
1011
1012             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1013             F                = vftab[vfitab+1];
1014             Geps             = vfeps*vftab[vfitab+2];
1015             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1016             Fp               = F+Geps+Heps2;
1017             FF               = Fp+Geps+2.0*Heps2;
1018             felec            = -qq10*FF*vftabscale*rinv10;
1019
1020             fscal            = felec;
1021
1022             /* Calculate temporary vectorial force */
1023             tx               = fscal*dx10;
1024             ty               = fscal*dy10;
1025             tz               = fscal*dz10;
1026
1027             /* Update vectorial force */
1028             fix1            += tx;
1029             fiy1            += ty;
1030             fiz1            += tz;
1031             f[j_coord_offset+DIM*0+XX] -= tx;
1032             f[j_coord_offset+DIM*0+YY] -= ty;
1033             f[j_coord_offset+DIM*0+ZZ] -= tz;
1034
1035             /**************************
1036              * CALCULATE INTERACTIONS *
1037              **************************/
1038
1039             r11              = rsq11*rinv11;
1040
1041             /* Calculate table index by multiplying r with table scale and truncate to integer */
1042             rt               = r11*vftabscale;
1043             vfitab           = rt;
1044             vfeps            = rt-vfitab;
1045             vfitab           = 1*4*vfitab;
1046
1047             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1048             F                = vftab[vfitab+1];
1049             Geps             = vfeps*vftab[vfitab+2];
1050             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1051             Fp               = F+Geps+Heps2;
1052             FF               = Fp+Geps+2.0*Heps2;
1053             felec            = -qq11*FF*vftabscale*rinv11;
1054
1055             fscal            = felec;
1056
1057             /* Calculate temporary vectorial force */
1058             tx               = fscal*dx11;
1059             ty               = fscal*dy11;
1060             tz               = fscal*dz11;
1061
1062             /* Update vectorial force */
1063             fix1            += tx;
1064             fiy1            += ty;
1065             fiz1            += tz;
1066             f[j_coord_offset+DIM*1+XX] -= tx;
1067             f[j_coord_offset+DIM*1+YY] -= ty;
1068             f[j_coord_offset+DIM*1+ZZ] -= tz;
1069
1070             /**************************
1071              * CALCULATE INTERACTIONS *
1072              **************************/
1073
1074             r12              = rsq12*rinv12;
1075
1076             /* Calculate table index by multiplying r with table scale and truncate to integer */
1077             rt               = r12*vftabscale;
1078             vfitab           = rt;
1079             vfeps            = rt-vfitab;
1080             vfitab           = 1*4*vfitab;
1081
1082             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1083             F                = vftab[vfitab+1];
1084             Geps             = vfeps*vftab[vfitab+2];
1085             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1086             Fp               = F+Geps+Heps2;
1087             FF               = Fp+Geps+2.0*Heps2;
1088             felec            = -qq12*FF*vftabscale*rinv12;
1089
1090             fscal            = felec;
1091
1092             /* Calculate temporary vectorial force */
1093             tx               = fscal*dx12;
1094             ty               = fscal*dy12;
1095             tz               = fscal*dz12;
1096
1097             /* Update vectorial force */
1098             fix1            += tx;
1099             fiy1            += ty;
1100             fiz1            += tz;
1101             f[j_coord_offset+DIM*2+XX] -= tx;
1102             f[j_coord_offset+DIM*2+YY] -= ty;
1103             f[j_coord_offset+DIM*2+ZZ] -= tz;
1104
1105             /**************************
1106              * CALCULATE INTERACTIONS *
1107              **************************/
1108
1109             r20              = rsq20*rinv20;
1110
1111             /* Calculate table index by multiplying r with table scale and truncate to integer */
1112             rt               = r20*vftabscale;
1113             vfitab           = rt;
1114             vfeps            = rt-vfitab;
1115             vfitab           = 1*4*vfitab;
1116
1117             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1118             F                = vftab[vfitab+1];
1119             Geps             = vfeps*vftab[vfitab+2];
1120             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1121             Fp               = F+Geps+Heps2;
1122             FF               = Fp+Geps+2.0*Heps2;
1123             felec            = -qq20*FF*vftabscale*rinv20;
1124
1125             fscal            = felec;
1126
1127             /* Calculate temporary vectorial force */
1128             tx               = fscal*dx20;
1129             ty               = fscal*dy20;
1130             tz               = fscal*dz20;
1131
1132             /* Update vectorial force */
1133             fix2            += tx;
1134             fiy2            += ty;
1135             fiz2            += tz;
1136             f[j_coord_offset+DIM*0+XX] -= tx;
1137             f[j_coord_offset+DIM*0+YY] -= ty;
1138             f[j_coord_offset+DIM*0+ZZ] -= tz;
1139
1140             /**************************
1141              * CALCULATE INTERACTIONS *
1142              **************************/
1143
1144             r21              = rsq21*rinv21;
1145
1146             /* Calculate table index by multiplying r with table scale and truncate to integer */
1147             rt               = r21*vftabscale;
1148             vfitab           = rt;
1149             vfeps            = rt-vfitab;
1150             vfitab           = 1*4*vfitab;
1151
1152             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1153             F                = vftab[vfitab+1];
1154             Geps             = vfeps*vftab[vfitab+2];
1155             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1156             Fp               = F+Geps+Heps2;
1157             FF               = Fp+Geps+2.0*Heps2;
1158             felec            = -qq21*FF*vftabscale*rinv21;
1159
1160             fscal            = felec;
1161
1162             /* Calculate temporary vectorial force */
1163             tx               = fscal*dx21;
1164             ty               = fscal*dy21;
1165             tz               = fscal*dz21;
1166
1167             /* Update vectorial force */
1168             fix2            += tx;
1169             fiy2            += ty;
1170             fiz2            += tz;
1171             f[j_coord_offset+DIM*1+XX] -= tx;
1172             f[j_coord_offset+DIM*1+YY] -= ty;
1173             f[j_coord_offset+DIM*1+ZZ] -= tz;
1174
1175             /**************************
1176              * CALCULATE INTERACTIONS *
1177              **************************/
1178
1179             r22              = rsq22*rinv22;
1180
1181             /* Calculate table index by multiplying r with table scale and truncate to integer */
1182             rt               = r22*vftabscale;
1183             vfitab           = rt;
1184             vfeps            = rt-vfitab;
1185             vfitab           = 1*4*vfitab;
1186
1187             /* CUBIC SPLINE TABLE ELECTROSTATICS */
1188             F                = vftab[vfitab+1];
1189             Geps             = vfeps*vftab[vfitab+2];
1190             Heps2            = vfeps*vfeps*vftab[vfitab+3];
1191             Fp               = F+Geps+Heps2;
1192             FF               = Fp+Geps+2.0*Heps2;
1193             felec            = -qq22*FF*vftabscale*rinv22;
1194
1195             fscal            = felec;
1196
1197             /* Calculate temporary vectorial force */
1198             tx               = fscal*dx22;
1199             ty               = fscal*dy22;
1200             tz               = fscal*dz22;
1201
1202             /* Update vectorial force */
1203             fix2            += tx;
1204             fiy2            += ty;
1205             fiz2            += tz;
1206             f[j_coord_offset+DIM*2+XX] -= tx;
1207             f[j_coord_offset+DIM*2+YY] -= ty;
1208             f[j_coord_offset+DIM*2+ZZ] -= tz;
1209
1210             /* Inner loop uses 341 flops */
1211         }
1212         /* End of innermost loop */
1213
1214         tx = ty = tz = 0;
1215         f[i_coord_offset+DIM*0+XX] += fix0;
1216         f[i_coord_offset+DIM*0+YY] += fiy0;
1217         f[i_coord_offset+DIM*0+ZZ] += fiz0;
1218         tx                         += fix0;
1219         ty                         += fiy0;
1220         tz                         += fiz0;
1221         f[i_coord_offset+DIM*1+XX] += fix1;
1222         f[i_coord_offset+DIM*1+YY] += fiy1;
1223         f[i_coord_offset+DIM*1+ZZ] += fiz1;
1224         tx                         += fix1;
1225         ty                         += fiy1;
1226         tz                         += fiz1;
1227         f[i_coord_offset+DIM*2+XX] += fix2;
1228         f[i_coord_offset+DIM*2+YY] += fiy2;
1229         f[i_coord_offset+DIM*2+ZZ] += fiz2;
1230         tx                         += fix2;
1231         ty                         += fiy2;
1232         tz                         += fiz2;
1233         fshift[i_shift_offset+XX]  += tx;
1234         fshift[i_shift_offset+YY]  += ty;
1235         fshift[i_shift_offset+ZZ]  += tz;
1236
1237         /* Increment number of inner iterations */
1238         inneriter                  += j_index_end - j_index_start;
1239
1240         /* Outer loop uses 30 flops */
1241     }
1242
1243     /* Increment number of outer iterations */
1244     outeriter        += nri;
1245
1246     /* Update outer/inner flops */
1247
1248     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_F,outeriter*30 + inneriter*341);
1249 }