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