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