Merge origin/release-4-6 into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecEw_VdwLJ_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_VdwLJ_GeomW3P1_VF_c
35  * Electrostatics interaction: Ewald
36  * VdW interaction:            LennardJones
37  * Geometry:                   Water3-Particle
38  * Calculate force/pot:        PotentialAndForce
39  */
40 void
41 nb_kernel_ElecEw_VdwLJ_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              ewitab;
74     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
75     real             *ewtab;
76
77     x                = xx[0];
78     f                = ff[0];
79
80     nri              = nlist->nri;
81     iinr             = nlist->iinr;
82     jindex           = nlist->jindex;
83     jjnr             = nlist->jjnr;
84     shiftidx         = nlist->shift;
85     gid              = nlist->gid;
86     shiftvec         = fr->shift_vec[0];
87     fshift           = fr->fshift[0];
88     facel            = fr->epsfac;
89     charge           = mdatoms->chargeA;
90     nvdwtype         = fr->ntype;
91     vdwparam         = fr->nbfp;
92     vdwtype          = mdatoms->typeA;
93
94     sh_ewald         = fr->ic->sh_ewald;
95     ewtab            = fr->ic->tabq_coul_FDV0;
96     ewtabscale       = fr->ic->tabq_scale;
97     ewtabhalfspace   = 0.5/ewtabscale;
98
99     /* Setup water-specific parameters */
100     inr              = nlist->iinr[0];
101     iq0              = facel*charge[inr+0];
102     iq1              = facel*charge[inr+1];
103     iq2              = facel*charge[inr+2];
104     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
105
106     outeriter        = 0;
107     inneriter        = 0;
108
109     /* Start outer loop over neighborlists */
110     for(iidx=0; iidx<nri; iidx++)
111     {
112         /* Load shift vector for this list */
113         i_shift_offset   = DIM*shiftidx[iidx];
114         shX              = shiftvec[i_shift_offset+XX];
115         shY              = shiftvec[i_shift_offset+YY];
116         shZ              = shiftvec[i_shift_offset+ZZ];
117
118         /* Load limits for loop over neighbors */
119         j_index_start    = jindex[iidx];
120         j_index_end      = jindex[iidx+1];
121
122         /* Get outer coordinate index */
123         inr              = iinr[iidx];
124         i_coord_offset   = DIM*inr;
125
126         /* Load i particle coords and add shift vector */
127         ix0              = shX + x[i_coord_offset+DIM*0+XX];
128         iy0              = shY + x[i_coord_offset+DIM*0+YY];
129         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
130         ix1              = shX + x[i_coord_offset+DIM*1+XX];
131         iy1              = shY + x[i_coord_offset+DIM*1+YY];
132         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
133         ix2              = shX + x[i_coord_offset+DIM*2+XX];
134         iy2              = shY + x[i_coord_offset+DIM*2+YY];
135         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
136
137         fix0             = 0.0;
138         fiy0             = 0.0;
139         fiz0             = 0.0;
140         fix1             = 0.0;
141         fiy1             = 0.0;
142         fiz1             = 0.0;
143         fix2             = 0.0;
144         fiy2             = 0.0;
145         fiz2             = 0.0;
146
147         /* Reset potential sums */
148         velecsum         = 0.0;
149         vvdwsum          = 0.0;
150
151         /* Start inner kernel loop */
152         for(jidx=j_index_start; jidx<j_index_end; jidx++)
153         {
154             /* Get j neighbor index, and coordinate index */
155             jnr              = jjnr[jidx];
156             j_coord_offset   = DIM*jnr;
157
158             /* load j atom coordinates */
159             jx0              = x[j_coord_offset+DIM*0+XX];
160             jy0              = x[j_coord_offset+DIM*0+YY];
161             jz0              = x[j_coord_offset+DIM*0+ZZ];
162
163             /* Calculate displacement vector */
164             dx00             = ix0 - jx0;
165             dy00             = iy0 - jy0;
166             dz00             = iz0 - jz0;
167             dx10             = ix1 - jx0;
168             dy10             = iy1 - jy0;
169             dz10             = iz1 - jz0;
170             dx20             = ix2 - jx0;
171             dy20             = iy2 - jy0;
172             dz20             = iz2 - jz0;
173
174             /* Calculate squared distance and things based on it */
175             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
176             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
177             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
178
179             rinv00           = gmx_invsqrt(rsq00);
180             rinv10           = gmx_invsqrt(rsq10);
181             rinv20           = gmx_invsqrt(rsq20);
182
183             rinvsq00         = rinv00*rinv00;
184             rinvsq10         = rinv10*rinv10;
185             rinvsq20         = rinv20*rinv20;
186
187             /* Load parameters for j particles */
188             jq0              = charge[jnr+0];
189             vdwjidx0         = 2*vdwtype[jnr+0];
190
191             /**************************
192              * CALCULATE INTERACTIONS *
193              **************************/
194
195             r00              = rsq00*rinv00;
196
197             qq00             = iq0*jq0;
198             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
199             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
200
201             /* EWALD ELECTROSTATICS */
202
203             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
204             ewrt             = r00*ewtabscale;
205             ewitab           = ewrt;
206             eweps            = ewrt-ewitab;
207             ewitab           = 4*ewitab;
208             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
209             velec            = qq00*(rinv00-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
210             felec            = qq00*rinv00*(rinvsq00-felec);
211
212             /* LENNARD-JONES DISPERSION/REPULSION */
213
214             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
215             vvdw6            = c6_00*rinvsix;
216             vvdw12           = c12_00*rinvsix*rinvsix;
217             vvdw             = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
218             fvdw             = (vvdw12-vvdw6)*rinvsq00;
219
220             /* Update potential sums from outer loop */
221             velecsum        += velec;
222             vvdwsum         += vvdw;
223
224             fscal            = felec+fvdw;
225
226             /* Calculate temporary vectorial force */
227             tx               = fscal*dx00;
228             ty               = fscal*dy00;
229             tz               = fscal*dz00;
230
231             /* Update vectorial force */
232             fix0            += tx;
233             fiy0            += ty;
234             fiz0            += tz;
235             f[j_coord_offset+DIM*0+XX] -= tx;
236             f[j_coord_offset+DIM*0+YY] -= ty;
237             f[j_coord_offset+DIM*0+ZZ] -= tz;
238
239             /**************************
240              * CALCULATE INTERACTIONS *
241              **************************/
242
243             r10              = rsq10*rinv10;
244
245             qq10             = iq1*jq0;
246
247             /* EWALD ELECTROSTATICS */
248
249             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
250             ewrt             = r10*ewtabscale;
251             ewitab           = ewrt;
252             eweps            = ewrt-ewitab;
253             ewitab           = 4*ewitab;
254             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
255             velec            = qq10*(rinv10-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
256             felec            = qq10*rinv10*(rinvsq10-felec);
257
258             /* Update potential sums from outer loop */
259             velecsum        += velec;
260
261             fscal            = felec;
262
263             /* Calculate temporary vectorial force */
264             tx               = fscal*dx10;
265             ty               = fscal*dy10;
266             tz               = fscal*dz10;
267
268             /* Update vectorial force */
269             fix1            += tx;
270             fiy1            += ty;
271             fiz1            += tz;
272             f[j_coord_offset+DIM*0+XX] -= tx;
273             f[j_coord_offset+DIM*0+YY] -= ty;
274             f[j_coord_offset+DIM*0+ZZ] -= tz;
275
276             /**************************
277              * CALCULATE INTERACTIONS *
278              **************************/
279
280             r20              = rsq20*rinv20;
281
282             qq20             = iq2*jq0;
283
284             /* EWALD ELECTROSTATICS */
285
286             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
287             ewrt             = r20*ewtabscale;
288             ewitab           = ewrt;
289             eweps            = ewrt-ewitab;
290             ewitab           = 4*ewitab;
291             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
292             velec            = qq20*(rinv20-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
293             felec            = qq20*rinv20*(rinvsq20-felec);
294
295             /* Update potential sums from outer loop */
296             velecsum        += velec;
297
298             fscal            = felec;
299
300             /* Calculate temporary vectorial force */
301             tx               = fscal*dx20;
302             ty               = fscal*dy20;
303             tz               = fscal*dz20;
304
305             /* Update vectorial force */
306             fix2            += tx;
307             fiy2            += ty;
308             fiz2            += tz;
309             f[j_coord_offset+DIM*0+XX] -= tx;
310             f[j_coord_offset+DIM*0+YY] -= ty;
311             f[j_coord_offset+DIM*0+ZZ] -= tz;
312
313             /* Inner loop uses 135 flops */
314         }
315         /* End of innermost loop */
316
317         tx = ty = tz = 0;
318         f[i_coord_offset+DIM*0+XX] += fix0;
319         f[i_coord_offset+DIM*0+YY] += fiy0;
320         f[i_coord_offset+DIM*0+ZZ] += fiz0;
321         tx                         += fix0;
322         ty                         += fiy0;
323         tz                         += fiz0;
324         f[i_coord_offset+DIM*1+XX] += fix1;
325         f[i_coord_offset+DIM*1+YY] += fiy1;
326         f[i_coord_offset+DIM*1+ZZ] += fiz1;
327         tx                         += fix1;
328         ty                         += fiy1;
329         tz                         += fiz1;
330         f[i_coord_offset+DIM*2+XX] += fix2;
331         f[i_coord_offset+DIM*2+YY] += fiy2;
332         f[i_coord_offset+DIM*2+ZZ] += fiz2;
333         tx                         += fix2;
334         ty                         += fiy2;
335         tz                         += fiz2;
336         fshift[i_shift_offset+XX]  += tx;
337         fshift[i_shift_offset+YY]  += ty;
338         fshift[i_shift_offset+ZZ]  += tz;
339
340         ggid                        = gid[iidx];
341         /* Update potential energies */
342         kernel_data->energygrp_elec[ggid] += velecsum;
343         kernel_data->energygrp_vdw[ggid] += vvdwsum;
344
345         /* Increment number of inner iterations */
346         inneriter                  += j_index_end - j_index_start;
347
348         /* Outer loop uses 32 flops */
349     }
350
351     /* Increment number of outer iterations */
352     outeriter        += nri;
353
354     /* Update outer/inner flops */
355
356     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*32 + inneriter*135);
357 }
358 /*
359  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwLJ_GeomW3P1_F_c
360  * Electrostatics interaction: Ewald
361  * VdW interaction:            LennardJones
362  * Geometry:                   Water3-Particle
363  * Calculate force/pot:        Force
364  */
365 void
366 nb_kernel_ElecEw_VdwLJ_GeomW3P1_F_c
367                     (t_nblist * gmx_restrict                nlist,
368                      rvec * gmx_restrict                    xx,
369                      rvec * gmx_restrict                    ff,
370                      t_forcerec * gmx_restrict              fr,
371                      t_mdatoms * gmx_restrict               mdatoms,
372                      nb_kernel_data_t * gmx_restrict        kernel_data,
373                      t_nrnb * gmx_restrict                  nrnb)
374 {
375     int              i_shift_offset,i_coord_offset,j_coord_offset;
376     int              j_index_start,j_index_end;
377     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
378     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
379     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
380     real             *shiftvec,*fshift,*x,*f;
381     int              vdwioffset0;
382     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
383     int              vdwioffset1;
384     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
385     int              vdwioffset2;
386     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
387     int              vdwjidx0;
388     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
389     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
390     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
391     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
392     real             velec,felec,velecsum,facel,crf,krf,krf2;
393     real             *charge;
394     int              nvdwtype;
395     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
396     int              *vdwtype;
397     real             *vdwparam;
398     int              ewitab;
399     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
400     real             *ewtab;
401
402     x                = xx[0];
403     f                = ff[0];
404
405     nri              = nlist->nri;
406     iinr             = nlist->iinr;
407     jindex           = nlist->jindex;
408     jjnr             = nlist->jjnr;
409     shiftidx         = nlist->shift;
410     gid              = nlist->gid;
411     shiftvec         = fr->shift_vec[0];
412     fshift           = fr->fshift[0];
413     facel            = fr->epsfac;
414     charge           = mdatoms->chargeA;
415     nvdwtype         = fr->ntype;
416     vdwparam         = fr->nbfp;
417     vdwtype          = mdatoms->typeA;
418
419     sh_ewald         = fr->ic->sh_ewald;
420     ewtab            = fr->ic->tabq_coul_F;
421     ewtabscale       = fr->ic->tabq_scale;
422     ewtabhalfspace   = 0.5/ewtabscale;
423
424     /* Setup water-specific parameters */
425     inr              = nlist->iinr[0];
426     iq0              = facel*charge[inr+0];
427     iq1              = facel*charge[inr+1];
428     iq2              = facel*charge[inr+2];
429     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
430
431     outeriter        = 0;
432     inneriter        = 0;
433
434     /* Start outer loop over neighborlists */
435     for(iidx=0; iidx<nri; iidx++)
436     {
437         /* Load shift vector for this list */
438         i_shift_offset   = DIM*shiftidx[iidx];
439         shX              = shiftvec[i_shift_offset+XX];
440         shY              = shiftvec[i_shift_offset+YY];
441         shZ              = shiftvec[i_shift_offset+ZZ];
442
443         /* Load limits for loop over neighbors */
444         j_index_start    = jindex[iidx];
445         j_index_end      = jindex[iidx+1];
446
447         /* Get outer coordinate index */
448         inr              = iinr[iidx];
449         i_coord_offset   = DIM*inr;
450
451         /* Load i particle coords and add shift vector */
452         ix0              = shX + x[i_coord_offset+DIM*0+XX];
453         iy0              = shY + x[i_coord_offset+DIM*0+YY];
454         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
455         ix1              = shX + x[i_coord_offset+DIM*1+XX];
456         iy1              = shY + x[i_coord_offset+DIM*1+YY];
457         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
458         ix2              = shX + x[i_coord_offset+DIM*2+XX];
459         iy2              = shY + x[i_coord_offset+DIM*2+YY];
460         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
461
462         fix0             = 0.0;
463         fiy0             = 0.0;
464         fiz0             = 0.0;
465         fix1             = 0.0;
466         fiy1             = 0.0;
467         fiz1             = 0.0;
468         fix2             = 0.0;
469         fiy2             = 0.0;
470         fiz2             = 0.0;
471
472         /* Start inner kernel loop */
473         for(jidx=j_index_start; jidx<j_index_end; jidx++)
474         {
475             /* Get j neighbor index, and coordinate index */
476             jnr              = jjnr[jidx];
477             j_coord_offset   = DIM*jnr;
478
479             /* load j atom coordinates */
480             jx0              = x[j_coord_offset+DIM*0+XX];
481             jy0              = x[j_coord_offset+DIM*0+YY];
482             jz0              = x[j_coord_offset+DIM*0+ZZ];
483
484             /* Calculate displacement vector */
485             dx00             = ix0 - jx0;
486             dy00             = iy0 - jy0;
487             dz00             = iz0 - jz0;
488             dx10             = ix1 - jx0;
489             dy10             = iy1 - jy0;
490             dz10             = iz1 - jz0;
491             dx20             = ix2 - jx0;
492             dy20             = iy2 - jy0;
493             dz20             = iz2 - jz0;
494
495             /* Calculate squared distance and things based on it */
496             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
497             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
498             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
499
500             rinv00           = gmx_invsqrt(rsq00);
501             rinv10           = gmx_invsqrt(rsq10);
502             rinv20           = gmx_invsqrt(rsq20);
503
504             rinvsq00         = rinv00*rinv00;
505             rinvsq10         = rinv10*rinv10;
506             rinvsq20         = rinv20*rinv20;
507
508             /* Load parameters for j particles */
509             jq0              = charge[jnr+0];
510             vdwjidx0         = 2*vdwtype[jnr+0];
511
512             /**************************
513              * CALCULATE INTERACTIONS *
514              **************************/
515
516             r00              = rsq00*rinv00;
517
518             qq00             = iq0*jq0;
519             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
520             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
521
522             /* EWALD ELECTROSTATICS */
523
524             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
525             ewrt             = r00*ewtabscale;
526             ewitab           = ewrt;
527             eweps            = ewrt-ewitab;
528             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
529             felec            = qq00*rinv00*(rinvsq00-felec);
530
531             /* LENNARD-JONES DISPERSION/REPULSION */
532
533             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
534             fvdw             = (c12_00*rinvsix-c6_00)*rinvsix*rinvsq00;
535
536             fscal            = felec+fvdw;
537
538             /* Calculate temporary vectorial force */
539             tx               = fscal*dx00;
540             ty               = fscal*dy00;
541             tz               = fscal*dz00;
542
543             /* Update vectorial force */
544             fix0            += tx;
545             fiy0            += ty;
546             fiz0            += tz;
547             f[j_coord_offset+DIM*0+XX] -= tx;
548             f[j_coord_offset+DIM*0+YY] -= ty;
549             f[j_coord_offset+DIM*0+ZZ] -= tz;
550
551             /**************************
552              * CALCULATE INTERACTIONS *
553              **************************/
554
555             r10              = rsq10*rinv10;
556
557             qq10             = iq1*jq0;
558
559             /* EWALD ELECTROSTATICS */
560
561             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
562             ewrt             = r10*ewtabscale;
563             ewitab           = ewrt;
564             eweps            = ewrt-ewitab;
565             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
566             felec            = qq10*rinv10*(rinvsq10-felec);
567
568             fscal            = felec;
569
570             /* Calculate temporary vectorial force */
571             tx               = fscal*dx10;
572             ty               = fscal*dy10;
573             tz               = fscal*dz10;
574
575             /* Update vectorial force */
576             fix1            += tx;
577             fiy1            += ty;
578             fiz1            += tz;
579             f[j_coord_offset+DIM*0+XX] -= tx;
580             f[j_coord_offset+DIM*0+YY] -= ty;
581             f[j_coord_offset+DIM*0+ZZ] -= tz;
582
583             /**************************
584              * CALCULATE INTERACTIONS *
585              **************************/
586
587             r20              = rsq20*rinv20;
588
589             qq20             = iq2*jq0;
590
591             /* EWALD ELECTROSTATICS */
592
593             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
594             ewrt             = r20*ewtabscale;
595             ewitab           = ewrt;
596             eweps            = ewrt-ewitab;
597             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
598             felec            = qq20*rinv20*(rinvsq20-felec);
599
600             fscal            = felec;
601
602             /* Calculate temporary vectorial force */
603             tx               = fscal*dx20;
604             ty               = fscal*dy20;
605             tz               = fscal*dz20;
606
607             /* Update vectorial force */
608             fix2            += tx;
609             fiy2            += ty;
610             fiz2            += tz;
611             f[j_coord_offset+DIM*0+XX] -= tx;
612             f[j_coord_offset+DIM*0+YY] -= ty;
613             f[j_coord_offset+DIM*0+ZZ] -= tz;
614
615             /* Inner loop uses 109 flops */
616         }
617         /* End of innermost loop */
618
619         tx = ty = tz = 0;
620         f[i_coord_offset+DIM*0+XX] += fix0;
621         f[i_coord_offset+DIM*0+YY] += fiy0;
622         f[i_coord_offset+DIM*0+ZZ] += fiz0;
623         tx                         += fix0;
624         ty                         += fiy0;
625         tz                         += fiz0;
626         f[i_coord_offset+DIM*1+XX] += fix1;
627         f[i_coord_offset+DIM*1+YY] += fiy1;
628         f[i_coord_offset+DIM*1+ZZ] += fiz1;
629         tx                         += fix1;
630         ty                         += fiy1;
631         tz                         += fiz1;
632         f[i_coord_offset+DIM*2+XX] += fix2;
633         f[i_coord_offset+DIM*2+YY] += fiy2;
634         f[i_coord_offset+DIM*2+ZZ] += fiz2;
635         tx                         += fix2;
636         ty                         += fiy2;
637         tz                         += fiz2;
638         fshift[i_shift_offset+XX]  += tx;
639         fshift[i_shift_offset+YY]  += ty;
640         fshift[i_shift_offset+ZZ]  += tz;
641
642         /* Increment number of inner iterations */
643         inneriter                  += j_index_end - j_index_start;
644
645         /* Outer loop uses 30 flops */
646     }
647
648     /* Increment number of outer iterations */
649     outeriter        += nri;
650
651     /* Update outer/inner flops */
652
653     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*30 + inneriter*109);
654 }