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