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