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