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