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