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