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