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