1db846547db1d562ce0b7786b1d3997a68718eb9
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecEw_VdwLJEw_GeomW3W3_c.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS c kernel generator.
37  */
38 #include "config.h"
39
40 #include <math.h>
41
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "nrnb.h"
46
47 /*
48  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwLJEw_GeomW3W3_VF_c
49  * Electrostatics interaction: Ewald
50  * VdW interaction:            LJEwald
51  * Geometry:                   Water3-Water3
52  * Calculate force/pot:        PotentialAndForce
53  */
54 void
55 nb_kernel_ElecEw_VdwLJEw_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     real             c6grid_00;
98     real             c6grid_01;
99     real             c6grid_02;
100     real             c6grid_10;
101     real             c6grid_11;
102     real             c6grid_12;
103     real             c6grid_20;
104     real             c6grid_21;
105     real             c6grid_22;
106     real             ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,sh_lj_ewald;
107     real             *vdwgridparam;
108     int              ewitab;
109     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
110     real             *ewtab;
111
112     x                = xx[0];
113     f                = ff[0];
114
115     nri              = nlist->nri;
116     iinr             = nlist->iinr;
117     jindex           = nlist->jindex;
118     jjnr             = nlist->jjnr;
119     shiftidx         = nlist->shift;
120     gid              = nlist->gid;
121     shiftvec         = fr->shift_vec[0];
122     fshift           = fr->fshift[0];
123     facel            = fr->epsfac;
124     charge           = mdatoms->chargeA;
125     nvdwtype         = fr->ntype;
126     vdwparam         = fr->nbfp;
127     vdwtype          = mdatoms->typeA;
128     vdwgridparam     = fr->ljpme_c6grid;
129     ewclj            = fr->ewaldcoeff_lj;
130     sh_lj_ewald      = fr->ic->sh_lj_ewald;
131     ewclj2           = ewclj*ewclj;
132     ewclj6           = ewclj2*ewclj2*ewclj2;
133
134     sh_ewald         = fr->ic->sh_ewald;
135     ewtab            = fr->ic->tabq_coul_FDV0;
136     ewtabscale       = fr->ic->tabq_scale;
137     ewtabhalfspace   = 0.5/ewtabscale;
138
139     /* Setup water-specific parameters */
140     inr              = nlist->iinr[0];
141     iq0              = facel*charge[inr+0];
142     iq1              = facel*charge[inr+1];
143     iq2              = facel*charge[inr+2];
144     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
145
146     jq0              = charge[inr+0];
147     jq1              = charge[inr+1];
148     jq2              = charge[inr+2];
149     vdwjidx0         = 2*vdwtype[inr+0];
150     qq00             = iq0*jq0;
151     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
152     c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
153     c6grid_00        = vdwgridparam[vdwioffset0+vdwjidx0];
154     qq01             = iq0*jq1;
155     qq02             = iq0*jq2;
156     qq10             = iq1*jq0;
157     qq11             = iq1*jq1;
158     qq12             = iq1*jq2;
159     qq20             = iq2*jq0;
160     qq21             = iq2*jq1;
161     qq22             = iq2*jq2;
162
163     outeriter        = 0;
164     inneriter        = 0;
165
166     /* Start outer loop over neighborlists */
167     for(iidx=0; iidx<nri; iidx++)
168     {
169         /* Load shift vector for this list */
170         i_shift_offset   = DIM*shiftidx[iidx];
171         shX              = shiftvec[i_shift_offset+XX];
172         shY              = shiftvec[i_shift_offset+YY];
173         shZ              = shiftvec[i_shift_offset+ZZ];
174
175         /* Load limits for loop over neighbors */
176         j_index_start    = jindex[iidx];
177         j_index_end      = jindex[iidx+1];
178
179         /* Get outer coordinate index */
180         inr              = iinr[iidx];
181         i_coord_offset   = DIM*inr;
182
183         /* Load i particle coords and add shift vector */
184         ix0              = shX + x[i_coord_offset+DIM*0+XX];
185         iy0              = shY + x[i_coord_offset+DIM*0+YY];
186         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
187         ix1              = shX + x[i_coord_offset+DIM*1+XX];
188         iy1              = shY + x[i_coord_offset+DIM*1+YY];
189         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
190         ix2              = shX + x[i_coord_offset+DIM*2+XX];
191         iy2              = shY + x[i_coord_offset+DIM*2+YY];
192         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
193
194         fix0             = 0.0;
195         fiy0             = 0.0;
196         fiz0             = 0.0;
197         fix1             = 0.0;
198         fiy1             = 0.0;
199         fiz1             = 0.0;
200         fix2             = 0.0;
201         fiy2             = 0.0;
202         fiz2             = 0.0;
203
204         /* Reset potential sums */
205         velecsum         = 0.0;
206         vvdwsum          = 0.0;
207
208         /* Start inner kernel loop */
209         for(jidx=j_index_start; jidx<j_index_end; jidx++)
210         {
211             /* Get j neighbor index, and coordinate index */
212             jnr              = jjnr[jidx];
213             j_coord_offset   = DIM*jnr;
214
215             /* load j atom coordinates */
216             jx0              = x[j_coord_offset+DIM*0+XX];
217             jy0              = x[j_coord_offset+DIM*0+YY];
218             jz0              = x[j_coord_offset+DIM*0+ZZ];
219             jx1              = x[j_coord_offset+DIM*1+XX];
220             jy1              = x[j_coord_offset+DIM*1+YY];
221             jz1              = x[j_coord_offset+DIM*1+ZZ];
222             jx2              = x[j_coord_offset+DIM*2+XX];
223             jy2              = x[j_coord_offset+DIM*2+YY];
224             jz2              = x[j_coord_offset+DIM*2+ZZ];
225
226             /* Calculate displacement vector */
227             dx00             = ix0 - jx0;
228             dy00             = iy0 - jy0;
229             dz00             = iz0 - jz0;
230             dx01             = ix0 - jx1;
231             dy01             = iy0 - jy1;
232             dz01             = iz0 - jz1;
233             dx02             = ix0 - jx2;
234             dy02             = iy0 - jy2;
235             dz02             = iz0 - jz2;
236             dx10             = ix1 - jx0;
237             dy10             = iy1 - jy0;
238             dz10             = iz1 - jz0;
239             dx11             = ix1 - jx1;
240             dy11             = iy1 - jy1;
241             dz11             = iz1 - jz1;
242             dx12             = ix1 - jx2;
243             dy12             = iy1 - jy2;
244             dz12             = iz1 - jz2;
245             dx20             = ix2 - jx0;
246             dy20             = iy2 - jy0;
247             dz20             = iz2 - jz0;
248             dx21             = ix2 - jx1;
249             dy21             = iy2 - jy1;
250             dz21             = iz2 - jz1;
251             dx22             = ix2 - jx2;
252             dy22             = iy2 - jy2;
253             dz22             = iz2 - jz2;
254
255             /* Calculate squared distance and things based on it */
256             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
257             rsq01            = dx01*dx01+dy01*dy01+dz01*dz01;
258             rsq02            = dx02*dx02+dy02*dy02+dz02*dz02;
259             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
260             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
261             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
262             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
263             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
264             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
265
266             rinv00           = gmx_invsqrt(rsq00);
267             rinv01           = gmx_invsqrt(rsq01);
268             rinv02           = gmx_invsqrt(rsq02);
269             rinv10           = gmx_invsqrt(rsq10);
270             rinv11           = gmx_invsqrt(rsq11);
271             rinv12           = gmx_invsqrt(rsq12);
272             rinv20           = gmx_invsqrt(rsq20);
273             rinv21           = gmx_invsqrt(rsq21);
274             rinv22           = gmx_invsqrt(rsq22);
275
276             rinvsq00         = rinv00*rinv00;
277             rinvsq01         = rinv01*rinv01;
278             rinvsq02         = rinv02*rinv02;
279             rinvsq10         = rinv10*rinv10;
280             rinvsq11         = rinv11*rinv11;
281             rinvsq12         = rinv12*rinv12;
282             rinvsq20         = rinv20*rinv20;
283             rinvsq21         = rinv21*rinv21;
284             rinvsq22         = rinv22*rinv22;
285
286             /**************************
287              * CALCULATE INTERACTIONS *
288              **************************/
289
290             r00              = rsq00*rinv00;
291
292             /* EWALD ELECTROSTATICS */
293
294             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
295             ewrt             = r00*ewtabscale;
296             ewitab           = ewrt;
297             eweps            = ewrt-ewitab;
298             ewitab           = 4*ewitab;
299             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
300             velec            = qq00*(rinv00-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
301             felec            = qq00*rinv00*(rinvsq00-felec);
302
303             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
304             ewcljrsq         = ewclj2*rsq00;
305             exponent         = exp(-ewcljrsq);
306             poly             = exponent*(1.0 + ewcljrsq + ewcljrsq*ewcljrsq*0.5);
307             vvdw6            = (c6_00-c6grid_00*(1.0-poly))*rinvsix;
308             vvdw12           = c12_00*rinvsix*rinvsix;
309             vvdw             = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
310             fvdw             = (vvdw12 - vvdw6 - c6grid_00*(1.0/6.0)*exponent*ewclj6)*rinvsq00;
311
312             /* Update potential sums from outer loop */
313             velecsum        += velec;
314             vvdwsum         += vvdw;
315
316             fscal            = felec+fvdw;
317
318             /* Calculate temporary vectorial force */
319             tx               = fscal*dx00;
320             ty               = fscal*dy00;
321             tz               = fscal*dz00;
322
323             /* Update vectorial force */
324             fix0            += tx;
325             fiy0            += ty;
326             fiz0            += tz;
327             f[j_coord_offset+DIM*0+XX] -= tx;
328             f[j_coord_offset+DIM*0+YY] -= ty;
329             f[j_coord_offset+DIM*0+ZZ] -= tz;
330
331             /**************************
332              * CALCULATE INTERACTIONS *
333              **************************/
334
335             r01              = rsq01*rinv01;
336
337             /* EWALD ELECTROSTATICS */
338
339             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
340             ewrt             = r01*ewtabscale;
341             ewitab           = ewrt;
342             eweps            = ewrt-ewitab;
343             ewitab           = 4*ewitab;
344             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
345             velec            = qq01*(rinv01-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
346             felec            = qq01*rinv01*(rinvsq01-felec);
347
348             /* Update potential sums from outer loop */
349             velecsum        += velec;
350
351             fscal            = felec;
352
353             /* Calculate temporary vectorial force */
354             tx               = fscal*dx01;
355             ty               = fscal*dy01;
356             tz               = fscal*dz01;
357
358             /* Update vectorial force */
359             fix0            += tx;
360             fiy0            += ty;
361             fiz0            += tz;
362             f[j_coord_offset+DIM*1+XX] -= tx;
363             f[j_coord_offset+DIM*1+YY] -= ty;
364             f[j_coord_offset+DIM*1+ZZ] -= tz;
365
366             /**************************
367              * CALCULATE INTERACTIONS *
368              **************************/
369
370             r02              = rsq02*rinv02;
371
372             /* EWALD ELECTROSTATICS */
373
374             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
375             ewrt             = r02*ewtabscale;
376             ewitab           = ewrt;
377             eweps            = ewrt-ewitab;
378             ewitab           = 4*ewitab;
379             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
380             velec            = qq02*(rinv02-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
381             felec            = qq02*rinv02*(rinvsq02-felec);
382
383             /* Update potential sums from outer loop */
384             velecsum        += velec;
385
386             fscal            = felec;
387
388             /* Calculate temporary vectorial force */
389             tx               = fscal*dx02;
390             ty               = fscal*dy02;
391             tz               = fscal*dz02;
392
393             /* Update vectorial force */
394             fix0            += tx;
395             fiy0            += ty;
396             fiz0            += tz;
397             f[j_coord_offset+DIM*2+XX] -= tx;
398             f[j_coord_offset+DIM*2+YY] -= ty;
399             f[j_coord_offset+DIM*2+ZZ] -= tz;
400
401             /**************************
402              * CALCULATE INTERACTIONS *
403              **************************/
404
405             r10              = rsq10*rinv10;
406
407             /* EWALD ELECTROSTATICS */
408
409             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
410             ewrt             = r10*ewtabscale;
411             ewitab           = ewrt;
412             eweps            = ewrt-ewitab;
413             ewitab           = 4*ewitab;
414             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
415             velec            = qq10*(rinv10-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
416             felec            = qq10*rinv10*(rinvsq10-felec);
417
418             /* Update potential sums from outer loop */
419             velecsum        += velec;
420
421             fscal            = felec;
422
423             /* Calculate temporary vectorial force */
424             tx               = fscal*dx10;
425             ty               = fscal*dy10;
426             tz               = fscal*dz10;
427
428             /* Update vectorial force */
429             fix1            += tx;
430             fiy1            += ty;
431             fiz1            += tz;
432             f[j_coord_offset+DIM*0+XX] -= tx;
433             f[j_coord_offset+DIM*0+YY] -= ty;
434             f[j_coord_offset+DIM*0+ZZ] -= tz;
435
436             /**************************
437              * CALCULATE INTERACTIONS *
438              **************************/
439
440             r11              = rsq11*rinv11;
441
442             /* EWALD ELECTROSTATICS */
443
444             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
445             ewrt             = r11*ewtabscale;
446             ewitab           = ewrt;
447             eweps            = ewrt-ewitab;
448             ewitab           = 4*ewitab;
449             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
450             velec            = qq11*(rinv11-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
451             felec            = qq11*rinv11*(rinvsq11-felec);
452
453             /* Update potential sums from outer loop */
454             velecsum        += velec;
455
456             fscal            = felec;
457
458             /* Calculate temporary vectorial force */
459             tx               = fscal*dx11;
460             ty               = fscal*dy11;
461             tz               = fscal*dz11;
462
463             /* Update vectorial force */
464             fix1            += tx;
465             fiy1            += ty;
466             fiz1            += tz;
467             f[j_coord_offset+DIM*1+XX] -= tx;
468             f[j_coord_offset+DIM*1+YY] -= ty;
469             f[j_coord_offset+DIM*1+ZZ] -= tz;
470
471             /**************************
472              * CALCULATE INTERACTIONS *
473              **************************/
474
475             r12              = rsq12*rinv12;
476
477             /* EWALD ELECTROSTATICS */
478
479             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
480             ewrt             = r12*ewtabscale;
481             ewitab           = ewrt;
482             eweps            = ewrt-ewitab;
483             ewitab           = 4*ewitab;
484             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
485             velec            = qq12*(rinv12-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
486             felec            = qq12*rinv12*(rinvsq12-felec);
487
488             /* Update potential sums from outer loop */
489             velecsum        += velec;
490
491             fscal            = felec;
492
493             /* Calculate temporary vectorial force */
494             tx               = fscal*dx12;
495             ty               = fscal*dy12;
496             tz               = fscal*dz12;
497
498             /* Update vectorial force */
499             fix1            += tx;
500             fiy1            += ty;
501             fiz1            += tz;
502             f[j_coord_offset+DIM*2+XX] -= tx;
503             f[j_coord_offset+DIM*2+YY] -= ty;
504             f[j_coord_offset+DIM*2+ZZ] -= tz;
505
506             /**************************
507              * CALCULATE INTERACTIONS *
508              **************************/
509
510             r20              = rsq20*rinv20;
511
512             /* EWALD ELECTROSTATICS */
513
514             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
515             ewrt             = r20*ewtabscale;
516             ewitab           = ewrt;
517             eweps            = ewrt-ewitab;
518             ewitab           = 4*ewitab;
519             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
520             velec            = qq20*(rinv20-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
521             felec            = qq20*rinv20*(rinvsq20-felec);
522
523             /* Update potential sums from outer loop */
524             velecsum        += velec;
525
526             fscal            = felec;
527
528             /* Calculate temporary vectorial force */
529             tx               = fscal*dx20;
530             ty               = fscal*dy20;
531             tz               = fscal*dz20;
532
533             /* Update vectorial force */
534             fix2            += tx;
535             fiy2            += ty;
536             fiz2            += tz;
537             f[j_coord_offset+DIM*0+XX] -= tx;
538             f[j_coord_offset+DIM*0+YY] -= ty;
539             f[j_coord_offset+DIM*0+ZZ] -= tz;
540
541             /**************************
542              * CALCULATE INTERACTIONS *
543              **************************/
544
545             r21              = rsq21*rinv21;
546
547             /* EWALD ELECTROSTATICS */
548
549             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
550             ewrt             = r21*ewtabscale;
551             ewitab           = ewrt;
552             eweps            = ewrt-ewitab;
553             ewitab           = 4*ewitab;
554             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
555             velec            = qq21*(rinv21-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
556             felec            = qq21*rinv21*(rinvsq21-felec);
557
558             /* Update potential sums from outer loop */
559             velecsum        += velec;
560
561             fscal            = felec;
562
563             /* Calculate temporary vectorial force */
564             tx               = fscal*dx21;
565             ty               = fscal*dy21;
566             tz               = fscal*dz21;
567
568             /* Update vectorial force */
569             fix2            += tx;
570             fiy2            += ty;
571             fiz2            += tz;
572             f[j_coord_offset+DIM*1+XX] -= tx;
573             f[j_coord_offset+DIM*1+YY] -= ty;
574             f[j_coord_offset+DIM*1+ZZ] -= tz;
575
576             /**************************
577              * CALCULATE INTERACTIONS *
578              **************************/
579
580             r22              = rsq22*rinv22;
581
582             /* EWALD ELECTROSTATICS */
583
584             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
585             ewrt             = r22*ewtabscale;
586             ewitab           = ewrt;
587             eweps            = ewrt-ewitab;
588             ewitab           = 4*ewitab;
589             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
590             velec            = qq22*(rinv22-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
591             felec            = qq22*rinv22*(rinvsq22-felec);
592
593             /* Update potential sums from outer loop */
594             velecsum        += velec;
595
596             fscal            = felec;
597
598             /* Calculate temporary vectorial force */
599             tx               = fscal*dx22;
600             ty               = fscal*dy22;
601             tz               = fscal*dz22;
602
603             /* Update vectorial force */
604             fix2            += tx;
605             fiy2            += ty;
606             fiz2            += tz;
607             f[j_coord_offset+DIM*2+XX] -= tx;
608             f[j_coord_offset+DIM*2+YY] -= ty;
609             f[j_coord_offset+DIM*2+ZZ] -= tz;
610
611             /* Inner loop uses 386 flops */
612         }
613         /* End of innermost loop */
614
615         tx = ty = tz = 0;
616         f[i_coord_offset+DIM*0+XX] += fix0;
617         f[i_coord_offset+DIM*0+YY] += fiy0;
618         f[i_coord_offset+DIM*0+ZZ] += fiz0;
619         tx                         += fix0;
620         ty                         += fiy0;
621         tz                         += fiz0;
622         f[i_coord_offset+DIM*1+XX] += fix1;
623         f[i_coord_offset+DIM*1+YY] += fiy1;
624         f[i_coord_offset+DIM*1+ZZ] += fiz1;
625         tx                         += fix1;
626         ty                         += fiy1;
627         tz                         += fiz1;
628         f[i_coord_offset+DIM*2+XX] += fix2;
629         f[i_coord_offset+DIM*2+YY] += fiy2;
630         f[i_coord_offset+DIM*2+ZZ] += fiz2;
631         tx                         += fix2;
632         ty                         += fiy2;
633         tz                         += fiz2;
634         fshift[i_shift_offset+XX]  += tx;
635         fshift[i_shift_offset+YY]  += ty;
636         fshift[i_shift_offset+ZZ]  += tz;
637
638         ggid                        = gid[iidx];
639         /* Update potential energies */
640         kernel_data->energygrp_elec[ggid] += velecsum;
641         kernel_data->energygrp_vdw[ggid] += vvdwsum;
642
643         /* Increment number of inner iterations */
644         inneriter                  += j_index_end - j_index_start;
645
646         /* Outer loop uses 32 flops */
647     }
648
649     /* Increment number of outer iterations */
650     outeriter        += nri;
651
652     /* Update outer/inner flops */
653
654     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_VF,outeriter*32 + inneriter*386);
655 }
656 /*
657  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwLJEw_GeomW3W3_F_c
658  * Electrostatics interaction: Ewald
659  * VdW interaction:            LJEwald
660  * Geometry:                   Water3-Water3
661  * Calculate force/pot:        Force
662  */
663 void
664 nb_kernel_ElecEw_VdwLJEw_GeomW3W3_F_c
665                     (t_nblist                    * gmx_restrict       nlist,
666                      rvec                        * gmx_restrict          xx,
667                      rvec                        * gmx_restrict          ff,
668                      t_forcerec                  * gmx_restrict          fr,
669                      t_mdatoms                   * gmx_restrict     mdatoms,
670                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
671                      t_nrnb                      * gmx_restrict        nrnb)
672 {
673     int              i_shift_offset,i_coord_offset,j_coord_offset;
674     int              j_index_start,j_index_end;
675     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
676     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
677     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
678     real             *shiftvec,*fshift,*x,*f;
679     int              vdwioffset0;
680     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
681     int              vdwioffset1;
682     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
683     int              vdwioffset2;
684     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
685     int              vdwjidx0;
686     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
687     int              vdwjidx1;
688     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
689     int              vdwjidx2;
690     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
691     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
692     real             dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01,cexp1_01,cexp2_01;
693     real             dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02,cexp1_02,cexp2_02;
694     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
695     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
696     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
697     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
698     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
699     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
700     real             velec,felec,velecsum,facel,crf,krf,krf2;
701     real             *charge;
702     int              nvdwtype;
703     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
704     int              *vdwtype;
705     real             *vdwparam;
706     real             c6grid_00;
707     real             c6grid_01;
708     real             c6grid_02;
709     real             c6grid_10;
710     real             c6grid_11;
711     real             c6grid_12;
712     real             c6grid_20;
713     real             c6grid_21;
714     real             c6grid_22;
715     real             ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,sh_lj_ewald;
716     real             *vdwgridparam;
717     int              ewitab;
718     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
719     real             *ewtab;
720
721     x                = xx[0];
722     f                = ff[0];
723
724     nri              = nlist->nri;
725     iinr             = nlist->iinr;
726     jindex           = nlist->jindex;
727     jjnr             = nlist->jjnr;
728     shiftidx         = nlist->shift;
729     gid              = nlist->gid;
730     shiftvec         = fr->shift_vec[0];
731     fshift           = fr->fshift[0];
732     facel            = fr->epsfac;
733     charge           = mdatoms->chargeA;
734     nvdwtype         = fr->ntype;
735     vdwparam         = fr->nbfp;
736     vdwtype          = mdatoms->typeA;
737     vdwgridparam     = fr->ljpme_c6grid;
738     ewclj            = fr->ewaldcoeff_lj;
739     sh_lj_ewald      = fr->ic->sh_lj_ewald;
740     ewclj2           = ewclj*ewclj;
741     ewclj6           = ewclj2*ewclj2*ewclj2;
742
743     sh_ewald         = fr->ic->sh_ewald;
744     ewtab            = fr->ic->tabq_coul_F;
745     ewtabscale       = fr->ic->tabq_scale;
746     ewtabhalfspace   = 0.5/ewtabscale;
747
748     /* Setup water-specific parameters */
749     inr              = nlist->iinr[0];
750     iq0              = facel*charge[inr+0];
751     iq1              = facel*charge[inr+1];
752     iq2              = facel*charge[inr+2];
753     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
754
755     jq0              = charge[inr+0];
756     jq1              = charge[inr+1];
757     jq2              = charge[inr+2];
758     vdwjidx0         = 2*vdwtype[inr+0];
759     qq00             = iq0*jq0;
760     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
761     c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
762     c6grid_00        = vdwgridparam[vdwioffset0+vdwjidx0];
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             /* EWALD ELECTROSTATICS */
898
899             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
900             ewrt             = r00*ewtabscale;
901             ewitab           = ewrt;
902             eweps            = ewrt-ewitab;
903             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
904             felec            = qq00*rinv00*(rinvsq00-felec);
905
906             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
907             ewcljrsq         = ewclj2*rsq00;
908             exponent         = exp(-ewcljrsq);
909             poly             = exponent*(1.0 + ewcljrsq + ewcljrsq*ewcljrsq*0.5);
910             fvdw             = (((c12_00*rinvsix - c6_00 + c6grid_00*(1.0-poly))*rinvsix) - c6grid_00*(1.0/6.0)*exponent*ewclj6)*rinvsq00;
911
912             fscal            = felec+fvdw;
913
914             /* Calculate temporary vectorial force */
915             tx               = fscal*dx00;
916             ty               = fscal*dy00;
917             tz               = fscal*dz00;
918
919             /* Update vectorial force */
920             fix0            += tx;
921             fiy0            += ty;
922             fiz0            += tz;
923             f[j_coord_offset+DIM*0+XX] -= tx;
924             f[j_coord_offset+DIM*0+YY] -= ty;
925             f[j_coord_offset+DIM*0+ZZ] -= tz;
926
927             /**************************
928              * CALCULATE INTERACTIONS *
929              **************************/
930
931             r01              = rsq01*rinv01;
932
933             /* EWALD ELECTROSTATICS */
934
935             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
936             ewrt             = r01*ewtabscale;
937             ewitab           = ewrt;
938             eweps            = ewrt-ewitab;
939             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
940             felec            = qq01*rinv01*(rinvsq01-felec);
941
942             fscal            = felec;
943
944             /* Calculate temporary vectorial force */
945             tx               = fscal*dx01;
946             ty               = fscal*dy01;
947             tz               = fscal*dz01;
948
949             /* Update vectorial force */
950             fix0            += tx;
951             fiy0            += ty;
952             fiz0            += tz;
953             f[j_coord_offset+DIM*1+XX] -= tx;
954             f[j_coord_offset+DIM*1+YY] -= ty;
955             f[j_coord_offset+DIM*1+ZZ] -= tz;
956
957             /**************************
958              * CALCULATE INTERACTIONS *
959              **************************/
960
961             r02              = rsq02*rinv02;
962
963             /* EWALD ELECTROSTATICS */
964
965             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
966             ewrt             = r02*ewtabscale;
967             ewitab           = ewrt;
968             eweps            = ewrt-ewitab;
969             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
970             felec            = qq02*rinv02*(rinvsq02-felec);
971
972             fscal            = felec;
973
974             /* Calculate temporary vectorial force */
975             tx               = fscal*dx02;
976             ty               = fscal*dy02;
977             tz               = fscal*dz02;
978
979             /* Update vectorial force */
980             fix0            += tx;
981             fiy0            += ty;
982             fiz0            += tz;
983             f[j_coord_offset+DIM*2+XX] -= tx;
984             f[j_coord_offset+DIM*2+YY] -= ty;
985             f[j_coord_offset+DIM*2+ZZ] -= tz;
986
987             /**************************
988              * CALCULATE INTERACTIONS *
989              **************************/
990
991             r10              = rsq10*rinv10;
992
993             /* EWALD ELECTROSTATICS */
994
995             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
996             ewrt             = r10*ewtabscale;
997             ewitab           = ewrt;
998             eweps            = ewrt-ewitab;
999             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1000             felec            = qq10*rinv10*(rinvsq10-felec);
1001
1002             fscal            = felec;
1003
1004             /* Calculate temporary vectorial force */
1005             tx               = fscal*dx10;
1006             ty               = fscal*dy10;
1007             tz               = fscal*dz10;
1008
1009             /* Update vectorial force */
1010             fix1            += tx;
1011             fiy1            += ty;
1012             fiz1            += tz;
1013             f[j_coord_offset+DIM*0+XX] -= tx;
1014             f[j_coord_offset+DIM*0+YY] -= ty;
1015             f[j_coord_offset+DIM*0+ZZ] -= tz;
1016
1017             /**************************
1018              * CALCULATE INTERACTIONS *
1019              **************************/
1020
1021             r11              = rsq11*rinv11;
1022
1023             /* EWALD ELECTROSTATICS */
1024
1025             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1026             ewrt             = r11*ewtabscale;
1027             ewitab           = ewrt;
1028             eweps            = ewrt-ewitab;
1029             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1030             felec            = qq11*rinv11*(rinvsq11-felec);
1031
1032             fscal            = felec;
1033
1034             /* Calculate temporary vectorial force */
1035             tx               = fscal*dx11;
1036             ty               = fscal*dy11;
1037             tz               = fscal*dz11;
1038
1039             /* Update vectorial force */
1040             fix1            += tx;
1041             fiy1            += ty;
1042             fiz1            += tz;
1043             f[j_coord_offset+DIM*1+XX] -= tx;
1044             f[j_coord_offset+DIM*1+YY] -= ty;
1045             f[j_coord_offset+DIM*1+ZZ] -= tz;
1046
1047             /**************************
1048              * CALCULATE INTERACTIONS *
1049              **************************/
1050
1051             r12              = rsq12*rinv12;
1052
1053             /* EWALD ELECTROSTATICS */
1054
1055             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1056             ewrt             = r12*ewtabscale;
1057             ewitab           = ewrt;
1058             eweps            = ewrt-ewitab;
1059             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1060             felec            = qq12*rinv12*(rinvsq12-felec);
1061
1062             fscal            = felec;
1063
1064             /* Calculate temporary vectorial force */
1065             tx               = fscal*dx12;
1066             ty               = fscal*dy12;
1067             tz               = fscal*dz12;
1068
1069             /* Update vectorial force */
1070             fix1            += tx;
1071             fiy1            += ty;
1072             fiz1            += tz;
1073             f[j_coord_offset+DIM*2+XX] -= tx;
1074             f[j_coord_offset+DIM*2+YY] -= ty;
1075             f[j_coord_offset+DIM*2+ZZ] -= tz;
1076
1077             /**************************
1078              * CALCULATE INTERACTIONS *
1079              **************************/
1080
1081             r20              = rsq20*rinv20;
1082
1083             /* EWALD ELECTROSTATICS */
1084
1085             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1086             ewrt             = r20*ewtabscale;
1087             ewitab           = ewrt;
1088             eweps            = ewrt-ewitab;
1089             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1090             felec            = qq20*rinv20*(rinvsq20-felec);
1091
1092             fscal            = felec;
1093
1094             /* Calculate temporary vectorial force */
1095             tx               = fscal*dx20;
1096             ty               = fscal*dy20;
1097             tz               = fscal*dz20;
1098
1099             /* Update vectorial force */
1100             fix2            += tx;
1101             fiy2            += ty;
1102             fiz2            += tz;
1103             f[j_coord_offset+DIM*0+XX] -= tx;
1104             f[j_coord_offset+DIM*0+YY] -= ty;
1105             f[j_coord_offset+DIM*0+ZZ] -= tz;
1106
1107             /**************************
1108              * CALCULATE INTERACTIONS *
1109              **************************/
1110
1111             r21              = rsq21*rinv21;
1112
1113             /* EWALD ELECTROSTATICS */
1114
1115             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1116             ewrt             = r21*ewtabscale;
1117             ewitab           = ewrt;
1118             eweps            = ewrt-ewitab;
1119             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1120             felec            = qq21*rinv21*(rinvsq21-felec);
1121
1122             fscal            = felec;
1123
1124             /* Calculate temporary vectorial force */
1125             tx               = fscal*dx21;
1126             ty               = fscal*dy21;
1127             tz               = fscal*dz21;
1128
1129             /* Update vectorial force */
1130             fix2            += tx;
1131             fiy2            += ty;
1132             fiz2            += tz;
1133             f[j_coord_offset+DIM*1+XX] -= tx;
1134             f[j_coord_offset+DIM*1+YY] -= ty;
1135             f[j_coord_offset+DIM*1+ZZ] -= tz;
1136
1137             /**************************
1138              * CALCULATE INTERACTIONS *
1139              **************************/
1140
1141             r22              = rsq22*rinv22;
1142
1143             /* EWALD ELECTROSTATICS */
1144
1145             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1146             ewrt             = r22*ewtabscale;
1147             ewitab           = ewrt;
1148             eweps            = ewrt-ewitab;
1149             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1150             felec            = qq22*rinv22*(rinvsq22-felec);
1151
1152             fscal            = felec;
1153
1154             /* Calculate temporary vectorial force */
1155             tx               = fscal*dx22;
1156             ty               = fscal*dy22;
1157             tz               = fscal*dz22;
1158
1159             /* Update vectorial force */
1160             fix2            += tx;
1161             fiy2            += ty;
1162             fiz2            += tz;
1163             f[j_coord_offset+DIM*2+XX] -= tx;
1164             f[j_coord_offset+DIM*2+YY] -= ty;
1165             f[j_coord_offset+DIM*2+ZZ] -= tz;
1166
1167             /* Inner loop uses 318 flops */
1168         }
1169         /* End of innermost loop */
1170
1171         tx = ty = tz = 0;
1172         f[i_coord_offset+DIM*0+XX] += fix0;
1173         f[i_coord_offset+DIM*0+YY] += fiy0;
1174         f[i_coord_offset+DIM*0+ZZ] += fiz0;
1175         tx                         += fix0;
1176         ty                         += fiy0;
1177         tz                         += fiz0;
1178         f[i_coord_offset+DIM*1+XX] += fix1;
1179         f[i_coord_offset+DIM*1+YY] += fiy1;
1180         f[i_coord_offset+DIM*1+ZZ] += fiz1;
1181         tx                         += fix1;
1182         ty                         += fiy1;
1183         tz                         += fiz1;
1184         f[i_coord_offset+DIM*2+XX] += fix2;
1185         f[i_coord_offset+DIM*2+YY] += fiy2;
1186         f[i_coord_offset+DIM*2+ZZ] += fiz2;
1187         tx                         += fix2;
1188         ty                         += fiy2;
1189         tz                         += fiz2;
1190         fshift[i_shift_offset+XX]  += tx;
1191         fshift[i_shift_offset+YY]  += ty;
1192         fshift[i_shift_offset+ZZ]  += tz;
1193
1194         /* Increment number of inner iterations */
1195         inneriter                  += j_index_end - j_index_start;
1196
1197         /* Outer loop uses 30 flops */
1198     }
1199
1200     /* Increment number of outer iterations */
1201     outeriter        += nri;
1202
1203     /* Update outer/inner flops */
1204
1205     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_F,outeriter*30 + inneriter*318);
1206 }