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