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