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