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