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