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