Merge 'release-4-6' into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecEw_VdwCSTab_GeomW3P1_c.c
1 /*
2  * Note: this file was generated by the Gromacs c kernel generator.
3  *
4  *                This source code is part of
5  *
6  *                 G   R   O   M   A   C   S
7  *
8  * Copyright (c) 2001-2012, The GROMACS Development Team
9  *
10  * Gromacs is a library for molecular simulation and trajectory analysis,
11  * written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
12  * a full list of developers and information, check out http://www.gromacs.org
13  *
14  * This program is free software; you can redistribute it and/or modify it under
15  * the terms of the GNU Lesser General Public License as published by the Free
16  * Software Foundation; either version 2 of the License, or (at your option) any
17  * later version.
18  *
19  * To help fund GROMACS development, we humbly ask that you cite
20  * the papers people have written on it - you can find them on the website.
21  */
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <math.h>
27
28 #include "../nb_kernel.h"
29 #include "types/simple.h"
30 #include "vec.h"
31 #include "nrnb.h"
32
33 /*
34  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwCSTab_GeomW3P1_VF_c
35  * Electrostatics interaction: Ewald
36  * VdW interaction:            CubicSplineTable
37  * Geometry:                   Water3-Particle
38  * Calculate force/pot:        PotentialAndForce
39  */
40 void
41 nb_kernel_ElecEw_VdwCSTab_GeomW3P1_VF_c
42                     (t_nblist * gmx_restrict                nlist,
43                      rvec * gmx_restrict                    xx,
44                      rvec * gmx_restrict                    ff,
45                      t_forcerec * gmx_restrict              fr,
46                      t_mdatoms * gmx_restrict               mdatoms,
47                      nb_kernel_data_t * gmx_restrict        kernel_data,
48                      t_nrnb * gmx_restrict                  nrnb)
49 {
50     int              i_shift_offset,i_coord_offset,j_coord_offset;
51     int              j_index_start,j_index_end;
52     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
53     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
54     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
55     real             *shiftvec,*fshift,*x,*f;
56     int              vdwioffset0;
57     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
58     int              vdwioffset1;
59     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
60     int              vdwioffset2;
61     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
62     int              vdwjidx0;
63     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
64     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
65     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
66     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
67     real             velec,felec,velecsum,facel,crf,krf,krf2;
68     real             *charge;
69     int              nvdwtype;
70     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
71     int              *vdwtype;
72     real             *vdwparam;
73     int              vfitab;
74     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
75     real             *vftab;
76     int              ewitab;
77     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
78     real             *ewtab;
79
80     x                = xx[0];
81     f                = ff[0];
82
83     nri              = nlist->nri;
84     iinr             = nlist->iinr;
85     jindex           = nlist->jindex;
86     jjnr             = nlist->jjnr;
87     shiftidx         = nlist->shift;
88     gid              = nlist->gid;
89     shiftvec         = fr->shift_vec[0];
90     fshift           = fr->fshift[0];
91     facel            = fr->epsfac;
92     charge           = mdatoms->chargeA;
93     nvdwtype         = fr->ntype;
94     vdwparam         = fr->nbfp;
95     vdwtype          = mdatoms->typeA;
96
97     vftab            = kernel_data->table_vdw->data;
98     vftabscale       = kernel_data->table_vdw->scale;
99
100     sh_ewald         = fr->ic->sh_ewald;
101     ewtab            = fr->ic->tabq_coul_FDV0;
102     ewtabscale       = fr->ic->tabq_scale;
103     ewtabhalfspace   = 0.5/ewtabscale;
104
105     /* Setup water-specific parameters */
106     inr              = nlist->iinr[0];
107     iq0              = facel*charge[inr+0];
108     iq1              = facel*charge[inr+1];
109     iq2              = facel*charge[inr+2];
110     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
111
112     outeriter        = 0;
113     inneriter        = 0;
114
115     /* Start outer loop over neighborlists */
116     for(iidx=0; iidx<nri; iidx++)
117     {
118         /* Load shift vector for this list */
119         i_shift_offset   = DIM*shiftidx[iidx];
120         shX              = shiftvec[i_shift_offset+XX];
121         shY              = shiftvec[i_shift_offset+YY];
122         shZ              = shiftvec[i_shift_offset+ZZ];
123
124         /* Load limits for loop over neighbors */
125         j_index_start    = jindex[iidx];
126         j_index_end      = jindex[iidx+1];
127
128         /* Get outer coordinate index */
129         inr              = iinr[iidx];
130         i_coord_offset   = DIM*inr;
131
132         /* Load i particle coords and add shift vector */
133         ix0              = shX + x[i_coord_offset+DIM*0+XX];
134         iy0              = shY + x[i_coord_offset+DIM*0+YY];
135         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
136         ix1              = shX + x[i_coord_offset+DIM*1+XX];
137         iy1              = shY + x[i_coord_offset+DIM*1+YY];
138         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
139         ix2              = shX + x[i_coord_offset+DIM*2+XX];
140         iy2              = shY + x[i_coord_offset+DIM*2+YY];
141         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
142
143         fix0             = 0.0;
144         fiy0             = 0.0;
145         fiz0             = 0.0;
146         fix1             = 0.0;
147         fiy1             = 0.0;
148         fiz1             = 0.0;
149         fix2             = 0.0;
150         fiy2             = 0.0;
151         fiz2             = 0.0;
152
153         /* Reset potential sums */
154         velecsum         = 0.0;
155         vvdwsum          = 0.0;
156
157         /* Start inner kernel loop */
158         for(jidx=j_index_start; jidx<j_index_end; jidx++)
159         {
160             /* Get j neighbor index, and coordinate index */
161             jnr              = jjnr[jidx];
162             j_coord_offset   = DIM*jnr;
163
164             /* load j atom coordinates */
165             jx0              = x[j_coord_offset+DIM*0+XX];
166             jy0              = x[j_coord_offset+DIM*0+YY];
167             jz0              = x[j_coord_offset+DIM*0+ZZ];
168
169             /* Calculate displacement vector */
170             dx00             = ix0 - jx0;
171             dy00             = iy0 - jy0;
172             dz00             = iz0 - jz0;
173             dx10             = ix1 - jx0;
174             dy10             = iy1 - jy0;
175             dz10             = iz1 - jz0;
176             dx20             = ix2 - jx0;
177             dy20             = iy2 - jy0;
178             dz20             = iz2 - jz0;
179
180             /* Calculate squared distance and things based on it */
181             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
182             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
183             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
184
185             rinv00           = gmx_invsqrt(rsq00);
186             rinv10           = gmx_invsqrt(rsq10);
187             rinv20           = gmx_invsqrt(rsq20);
188
189             rinvsq00         = rinv00*rinv00;
190             rinvsq10         = rinv10*rinv10;
191             rinvsq20         = rinv20*rinv20;
192
193             /* Load parameters for j particles */
194             jq0              = charge[jnr+0];
195             vdwjidx0         = 2*vdwtype[jnr+0];
196
197             /**************************
198              * CALCULATE INTERACTIONS *
199              **************************/
200
201             r00              = rsq00*rinv00;
202
203             qq00             = iq0*jq0;
204             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
205             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
206
207             /* Calculate table index by multiplying r with table scale and truncate to integer */
208             rt               = r00*vftabscale;
209             vfitab           = rt;
210             vfeps            = rt-vfitab;
211             vfitab           = 2*4*vfitab;
212
213             /* EWALD ELECTROSTATICS */
214
215             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
216             ewrt             = r00*ewtabscale;
217             ewitab           = ewrt;
218             eweps            = ewrt-ewitab;
219             ewitab           = 4*ewitab;
220             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
221             velec            = qq00*(rinv00-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
222             felec            = qq00*rinv00*(rinvsq00-felec);
223
224             /* CUBIC SPLINE TABLE DISPERSION */
225             vfitab          += 0;
226             Y                = vftab[vfitab];
227             F                = vftab[vfitab+1];
228             Geps             = vfeps*vftab[vfitab+2];
229             Heps2            = vfeps*vfeps*vftab[vfitab+3];
230             Fp               = F+Geps+Heps2;
231             VV               = Y+vfeps*Fp;
232             vvdw6            = c6_00*VV;
233             FF               = Fp+Geps+2.0*Heps2;
234             fvdw6            = c6_00*FF;
235
236             /* CUBIC SPLINE TABLE REPULSION */
237             Y                = vftab[vfitab+4];
238             F                = vftab[vfitab+5];
239             Geps             = vfeps*vftab[vfitab+6];
240             Heps2            = vfeps*vfeps*vftab[vfitab+7];
241             Fp               = F+Geps+Heps2;
242             VV               = Y+vfeps*Fp;
243             vvdw12           = c12_00*VV;
244             FF               = Fp+Geps+2.0*Heps2;
245             fvdw12           = c12_00*FF;
246             vvdw             = vvdw12+vvdw6;
247             fvdw             = -(fvdw6+fvdw12)*vftabscale*rinv00;
248
249             /* Update potential sums from outer loop */
250             velecsum        += velec;
251             vvdwsum         += vvdw;
252
253             fscal            = felec+fvdw;
254
255             /* Calculate temporary vectorial force */
256             tx               = fscal*dx00;
257             ty               = fscal*dy00;
258             tz               = fscal*dz00;
259
260             /* Update vectorial force */
261             fix0            += tx;
262             fiy0            += ty;
263             fiz0            += tz;
264             f[j_coord_offset+DIM*0+XX] -= tx;
265             f[j_coord_offset+DIM*0+YY] -= ty;
266             f[j_coord_offset+DIM*0+ZZ] -= tz;
267
268             /**************************
269              * CALCULATE INTERACTIONS *
270              **************************/
271
272             r10              = rsq10*rinv10;
273
274             qq10             = iq1*jq0;
275
276             /* EWALD ELECTROSTATICS */
277
278             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
279             ewrt             = r10*ewtabscale;
280             ewitab           = ewrt;
281             eweps            = ewrt-ewitab;
282             ewitab           = 4*ewitab;
283             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
284             velec            = qq10*(rinv10-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
285             felec            = qq10*rinv10*(rinvsq10-felec);
286
287             /* Update potential sums from outer loop */
288             velecsum        += velec;
289
290             fscal            = felec;
291
292             /* Calculate temporary vectorial force */
293             tx               = fscal*dx10;
294             ty               = fscal*dy10;
295             tz               = fscal*dz10;
296
297             /* Update vectorial force */
298             fix1            += tx;
299             fiy1            += ty;
300             fiz1            += tz;
301             f[j_coord_offset+DIM*0+XX] -= tx;
302             f[j_coord_offset+DIM*0+YY] -= ty;
303             f[j_coord_offset+DIM*0+ZZ] -= tz;
304
305             /**************************
306              * CALCULATE INTERACTIONS *
307              **************************/
308
309             r20              = rsq20*rinv20;
310
311             qq20             = iq2*jq0;
312
313             /* EWALD ELECTROSTATICS */
314
315             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
316             ewrt             = r20*ewtabscale;
317             ewitab           = ewrt;
318             eweps            = ewrt-ewitab;
319             ewitab           = 4*ewitab;
320             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
321             velec            = qq20*(rinv20-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
322             felec            = qq20*rinv20*(rinvsq20-felec);
323
324             /* Update potential sums from outer loop */
325             velecsum        += velec;
326
327             fscal            = felec;
328
329             /* Calculate temporary vectorial force */
330             tx               = fscal*dx20;
331             ty               = fscal*dy20;
332             tz               = fscal*dz20;
333
334             /* Update vectorial force */
335             fix2            += tx;
336             fiy2            += ty;
337             fiz2            += tz;
338             f[j_coord_offset+DIM*0+XX] -= tx;
339             f[j_coord_offset+DIM*0+YY] -= ty;
340             f[j_coord_offset+DIM*0+ZZ] -= tz;
341
342             /* Inner loop uses 156 flops */
343         }
344         /* End of innermost loop */
345
346         tx = ty = tz = 0;
347         f[i_coord_offset+DIM*0+XX] += fix0;
348         f[i_coord_offset+DIM*0+YY] += fiy0;
349         f[i_coord_offset+DIM*0+ZZ] += fiz0;
350         tx                         += fix0;
351         ty                         += fiy0;
352         tz                         += fiz0;
353         f[i_coord_offset+DIM*1+XX] += fix1;
354         f[i_coord_offset+DIM*1+YY] += fiy1;
355         f[i_coord_offset+DIM*1+ZZ] += fiz1;
356         tx                         += fix1;
357         ty                         += fiy1;
358         tz                         += fiz1;
359         f[i_coord_offset+DIM*2+XX] += fix2;
360         f[i_coord_offset+DIM*2+YY] += fiy2;
361         f[i_coord_offset+DIM*2+ZZ] += fiz2;
362         tx                         += fix2;
363         ty                         += fiy2;
364         tz                         += fiz2;
365         fshift[i_shift_offset+XX]  += tx;
366         fshift[i_shift_offset+YY]  += ty;
367         fshift[i_shift_offset+ZZ]  += tz;
368
369         ggid                        = gid[iidx];
370         /* Update potential energies */
371         kernel_data->energygrp_elec[ggid] += velecsum;
372         kernel_data->energygrp_vdw[ggid] += vvdwsum;
373
374         /* Increment number of inner iterations */
375         inneriter                  += j_index_end - j_index_start;
376
377         /* Outer loop uses 32 flops */
378     }
379
380     /* Increment number of outer iterations */
381     outeriter        += nri;
382
383     /* Update outer/inner flops */
384
385     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*32 + inneriter*156);
386 }
387 /*
388  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwCSTab_GeomW3P1_F_c
389  * Electrostatics interaction: Ewald
390  * VdW interaction:            CubicSplineTable
391  * Geometry:                   Water3-Particle
392  * Calculate force/pot:        Force
393  */
394 void
395 nb_kernel_ElecEw_VdwCSTab_GeomW3P1_F_c
396                     (t_nblist * gmx_restrict                nlist,
397                      rvec * gmx_restrict                    xx,
398                      rvec * gmx_restrict                    ff,
399                      t_forcerec * gmx_restrict              fr,
400                      t_mdatoms * gmx_restrict               mdatoms,
401                      nb_kernel_data_t * gmx_restrict        kernel_data,
402                      t_nrnb * gmx_restrict                  nrnb)
403 {
404     int              i_shift_offset,i_coord_offset,j_coord_offset;
405     int              j_index_start,j_index_end;
406     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
407     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
408     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
409     real             *shiftvec,*fshift,*x,*f;
410     int              vdwioffset0;
411     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
412     int              vdwioffset1;
413     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
414     int              vdwioffset2;
415     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
416     int              vdwjidx0;
417     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
418     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
419     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
420     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
421     real             velec,felec,velecsum,facel,crf,krf,krf2;
422     real             *charge;
423     int              nvdwtype;
424     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
425     int              *vdwtype;
426     real             *vdwparam;
427     int              vfitab;
428     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
429     real             *vftab;
430     int              ewitab;
431     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
432     real             *ewtab;
433
434     x                = xx[0];
435     f                = ff[0];
436
437     nri              = nlist->nri;
438     iinr             = nlist->iinr;
439     jindex           = nlist->jindex;
440     jjnr             = nlist->jjnr;
441     shiftidx         = nlist->shift;
442     gid              = nlist->gid;
443     shiftvec         = fr->shift_vec[0];
444     fshift           = fr->fshift[0];
445     facel            = fr->epsfac;
446     charge           = mdatoms->chargeA;
447     nvdwtype         = fr->ntype;
448     vdwparam         = fr->nbfp;
449     vdwtype          = mdatoms->typeA;
450
451     vftab            = kernel_data->table_vdw->data;
452     vftabscale       = kernel_data->table_vdw->scale;
453
454     sh_ewald         = fr->ic->sh_ewald;
455     ewtab            = fr->ic->tabq_coul_F;
456     ewtabscale       = fr->ic->tabq_scale;
457     ewtabhalfspace   = 0.5/ewtabscale;
458
459     /* Setup water-specific parameters */
460     inr              = nlist->iinr[0];
461     iq0              = facel*charge[inr+0];
462     iq1              = facel*charge[inr+1];
463     iq2              = facel*charge[inr+2];
464     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
465
466     outeriter        = 0;
467     inneriter        = 0;
468
469     /* Start outer loop over neighborlists */
470     for(iidx=0; iidx<nri; iidx++)
471     {
472         /* Load shift vector for this list */
473         i_shift_offset   = DIM*shiftidx[iidx];
474         shX              = shiftvec[i_shift_offset+XX];
475         shY              = shiftvec[i_shift_offset+YY];
476         shZ              = shiftvec[i_shift_offset+ZZ];
477
478         /* Load limits for loop over neighbors */
479         j_index_start    = jindex[iidx];
480         j_index_end      = jindex[iidx+1];
481
482         /* Get outer coordinate index */
483         inr              = iinr[iidx];
484         i_coord_offset   = DIM*inr;
485
486         /* Load i particle coords and add shift vector */
487         ix0              = shX + x[i_coord_offset+DIM*0+XX];
488         iy0              = shY + x[i_coord_offset+DIM*0+YY];
489         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
490         ix1              = shX + x[i_coord_offset+DIM*1+XX];
491         iy1              = shY + x[i_coord_offset+DIM*1+YY];
492         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
493         ix2              = shX + x[i_coord_offset+DIM*2+XX];
494         iy2              = shY + x[i_coord_offset+DIM*2+YY];
495         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
496
497         fix0             = 0.0;
498         fiy0             = 0.0;
499         fiz0             = 0.0;
500         fix1             = 0.0;
501         fiy1             = 0.0;
502         fiz1             = 0.0;
503         fix2             = 0.0;
504         fiy2             = 0.0;
505         fiz2             = 0.0;
506
507         /* Start inner kernel loop */
508         for(jidx=j_index_start; jidx<j_index_end; jidx++)
509         {
510             /* Get j neighbor index, and coordinate index */
511             jnr              = jjnr[jidx];
512             j_coord_offset   = DIM*jnr;
513
514             /* load j atom coordinates */
515             jx0              = x[j_coord_offset+DIM*0+XX];
516             jy0              = x[j_coord_offset+DIM*0+YY];
517             jz0              = x[j_coord_offset+DIM*0+ZZ];
518
519             /* Calculate displacement vector */
520             dx00             = ix0 - jx0;
521             dy00             = iy0 - jy0;
522             dz00             = iz0 - jz0;
523             dx10             = ix1 - jx0;
524             dy10             = iy1 - jy0;
525             dz10             = iz1 - jz0;
526             dx20             = ix2 - jx0;
527             dy20             = iy2 - jy0;
528             dz20             = iz2 - jz0;
529
530             /* Calculate squared distance and things based on it */
531             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
532             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
533             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
534
535             rinv00           = gmx_invsqrt(rsq00);
536             rinv10           = gmx_invsqrt(rsq10);
537             rinv20           = gmx_invsqrt(rsq20);
538
539             rinvsq00         = rinv00*rinv00;
540             rinvsq10         = rinv10*rinv10;
541             rinvsq20         = rinv20*rinv20;
542
543             /* Load parameters for j particles */
544             jq0              = charge[jnr+0];
545             vdwjidx0         = 2*vdwtype[jnr+0];
546
547             /**************************
548              * CALCULATE INTERACTIONS *
549              **************************/
550
551             r00              = rsq00*rinv00;
552
553             qq00             = iq0*jq0;
554             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
555             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
556
557             /* Calculate table index by multiplying r with table scale and truncate to integer */
558             rt               = r00*vftabscale;
559             vfitab           = rt;
560             vfeps            = rt-vfitab;
561             vfitab           = 2*4*vfitab;
562
563             /* EWALD ELECTROSTATICS */
564
565             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
566             ewrt             = r00*ewtabscale;
567             ewitab           = ewrt;
568             eweps            = ewrt-ewitab;
569             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
570             felec            = qq00*rinv00*(rinvsq00-felec);
571
572             /* CUBIC SPLINE TABLE DISPERSION */
573             vfitab          += 0;
574             F                = vftab[vfitab+1];
575             Geps             = vfeps*vftab[vfitab+2];
576             Heps2            = vfeps*vfeps*vftab[vfitab+3];
577             Fp               = F+Geps+Heps2;
578             FF               = Fp+Geps+2.0*Heps2;
579             fvdw6            = c6_00*FF;
580
581             /* CUBIC SPLINE TABLE REPULSION */
582             F                = vftab[vfitab+5];
583             Geps             = vfeps*vftab[vfitab+6];
584             Heps2            = vfeps*vfeps*vftab[vfitab+7];
585             Fp               = F+Geps+Heps2;
586             FF               = Fp+Geps+2.0*Heps2;
587             fvdw12           = c12_00*FF;
588             fvdw             = -(fvdw6+fvdw12)*vftabscale*rinv00;
589
590             fscal            = felec+fvdw;
591
592             /* Calculate temporary vectorial force */
593             tx               = fscal*dx00;
594             ty               = fscal*dy00;
595             tz               = fscal*dz00;
596
597             /* Update vectorial force */
598             fix0            += tx;
599             fiy0            += ty;
600             fiz0            += tz;
601             f[j_coord_offset+DIM*0+XX] -= tx;
602             f[j_coord_offset+DIM*0+YY] -= ty;
603             f[j_coord_offset+DIM*0+ZZ] -= tz;
604
605             /**************************
606              * CALCULATE INTERACTIONS *
607              **************************/
608
609             r10              = rsq10*rinv10;
610
611             qq10             = iq1*jq0;
612
613             /* EWALD ELECTROSTATICS */
614
615             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
616             ewrt             = r10*ewtabscale;
617             ewitab           = ewrt;
618             eweps            = ewrt-ewitab;
619             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
620             felec            = qq10*rinv10*(rinvsq10-felec);
621
622             fscal            = felec;
623
624             /* Calculate temporary vectorial force */
625             tx               = fscal*dx10;
626             ty               = fscal*dy10;
627             tz               = fscal*dz10;
628
629             /* Update vectorial force */
630             fix1            += tx;
631             fiy1            += ty;
632             fiz1            += tz;
633             f[j_coord_offset+DIM*0+XX] -= tx;
634             f[j_coord_offset+DIM*0+YY] -= ty;
635             f[j_coord_offset+DIM*0+ZZ] -= tz;
636
637             /**************************
638              * CALCULATE INTERACTIONS *
639              **************************/
640
641             r20              = rsq20*rinv20;
642
643             qq20             = iq2*jq0;
644
645             /* EWALD ELECTROSTATICS */
646
647             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
648             ewrt             = r20*ewtabscale;
649             ewitab           = ewrt;
650             eweps            = ewrt-ewitab;
651             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
652             felec            = qq20*rinv20*(rinvsq20-felec);
653
654             fscal            = felec;
655
656             /* Calculate temporary vectorial force */
657             tx               = fscal*dx20;
658             ty               = fscal*dy20;
659             tz               = fscal*dz20;
660
661             /* Update vectorial force */
662             fix2            += tx;
663             fiy2            += ty;
664             fiz2            += tz;
665             f[j_coord_offset+DIM*0+XX] -= tx;
666             f[j_coord_offset+DIM*0+YY] -= ty;
667             f[j_coord_offset+DIM*0+ZZ] -= tz;
668
669             /* Inner loop uses 127 flops */
670         }
671         /* End of innermost loop */
672
673         tx = ty = tz = 0;
674         f[i_coord_offset+DIM*0+XX] += fix0;
675         f[i_coord_offset+DIM*0+YY] += fiy0;
676         f[i_coord_offset+DIM*0+ZZ] += fiz0;
677         tx                         += fix0;
678         ty                         += fiy0;
679         tz                         += fiz0;
680         f[i_coord_offset+DIM*1+XX] += fix1;
681         f[i_coord_offset+DIM*1+YY] += fiy1;
682         f[i_coord_offset+DIM*1+ZZ] += fiz1;
683         tx                         += fix1;
684         ty                         += fiy1;
685         tz                         += fiz1;
686         f[i_coord_offset+DIM*2+XX] += fix2;
687         f[i_coord_offset+DIM*2+YY] += fiy2;
688         f[i_coord_offset+DIM*2+ZZ] += fiz2;
689         tx                         += fix2;
690         ty                         += fiy2;
691         tz                         += fiz2;
692         fshift[i_shift_offset+XX]  += tx;
693         fshift[i_shift_offset+YY]  += ty;
694         fshift[i_shift_offset+ZZ]  += tz;
695
696         /* Increment number of inner iterations */
697         inneriter                  += j_index_end - j_index_start;
698
699         /* Outer loop uses 30 flops */
700     }
701
702     /* Increment number of outer iterations */
703     outeriter        += nri;
704
705     /* Update outer/inner flops */
706
707     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*30 + inneriter*127);
708 }