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