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