Remove all unnecessary HAVE_CONFIG_H
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecCoul_VdwCSTab_GeomW4P1_c.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS c kernel generator.
37  */
38 #include "config.h"
39
40 #include <math.h>
41
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "nrnb.h"
46
47 /*
48  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwCSTab_GeomW4P1_VF_c
49  * Electrostatics interaction: Coulomb
50  * VdW interaction:            CubicSplineTable
51  * Geometry:                   Water4-Particle
52  * Calculate force/pot:        PotentialAndForce
53  */
54 void
55 nb_kernel_ElecCoul_VdwCSTab_GeomW4P1_VF_c
56                     (t_nblist                    * gmx_restrict       nlist,
57                      rvec                        * gmx_restrict          xx,
58                      rvec                        * gmx_restrict          ff,
59                      t_forcerec                  * gmx_restrict          fr,
60                      t_mdatoms                   * gmx_restrict     mdatoms,
61                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
62                      t_nrnb                      * gmx_restrict        nrnb)
63 {
64     int              i_shift_offset,i_coord_offset,j_coord_offset;
65     int              j_index_start,j_index_end;
66     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
67     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
68     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
69     real             *shiftvec,*fshift,*x,*f;
70     int              vdwioffset0;
71     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
72     int              vdwioffset1;
73     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
74     int              vdwioffset2;
75     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
76     int              vdwioffset3;
77     real             ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
78     int              vdwjidx0;
79     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
80     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
81     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
82     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
83     real             dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
84     real             velec,felec,velecsum,facel,crf,krf,krf2;
85     real             *charge;
86     int              nvdwtype;
87     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
88     int              *vdwtype;
89     real             *vdwparam;
90     int              vfitab;
91     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
92     real             *vftab;
93
94     x                = xx[0];
95     f                = ff[0];
96
97     nri              = nlist->nri;
98     iinr             = nlist->iinr;
99     jindex           = nlist->jindex;
100     jjnr             = nlist->jjnr;
101     shiftidx         = nlist->shift;
102     gid              = nlist->gid;
103     shiftvec         = fr->shift_vec[0];
104     fshift           = fr->fshift[0];
105     facel            = fr->epsfac;
106     charge           = mdatoms->chargeA;
107     nvdwtype         = fr->ntype;
108     vdwparam         = fr->nbfp;
109     vdwtype          = mdatoms->typeA;
110
111     vftab            = kernel_data->table_vdw->data;
112     vftabscale       = kernel_data->table_vdw->scale;
113
114     /* Setup water-specific parameters */
115     inr              = nlist->iinr[0];
116     iq1              = facel*charge[inr+1];
117     iq2              = facel*charge[inr+2];
118     iq3              = facel*charge[inr+3];
119     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
120
121     outeriter        = 0;
122     inneriter        = 0;
123
124     /* Start outer loop over neighborlists */
125     for(iidx=0; iidx<nri; iidx++)
126     {
127         /* Load shift vector for this list */
128         i_shift_offset   = DIM*shiftidx[iidx];
129         shX              = shiftvec[i_shift_offset+XX];
130         shY              = shiftvec[i_shift_offset+YY];
131         shZ              = shiftvec[i_shift_offset+ZZ];
132
133         /* Load limits for loop over neighbors */
134         j_index_start    = jindex[iidx];
135         j_index_end      = jindex[iidx+1];
136
137         /* Get outer coordinate index */
138         inr              = iinr[iidx];
139         i_coord_offset   = DIM*inr;
140
141         /* Load i particle coords and add shift vector */
142         ix0              = shX + x[i_coord_offset+DIM*0+XX];
143         iy0              = shY + x[i_coord_offset+DIM*0+YY];
144         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
145         ix1              = shX + x[i_coord_offset+DIM*1+XX];
146         iy1              = shY + x[i_coord_offset+DIM*1+YY];
147         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
148         ix2              = shX + x[i_coord_offset+DIM*2+XX];
149         iy2              = shY + x[i_coord_offset+DIM*2+YY];
150         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
151         ix3              = shX + x[i_coord_offset+DIM*3+XX];
152         iy3              = shY + x[i_coord_offset+DIM*3+YY];
153         iz3              = shZ + x[i_coord_offset+DIM*3+ZZ];
154
155         fix0             = 0.0;
156         fiy0             = 0.0;
157         fiz0             = 0.0;
158         fix1             = 0.0;
159         fiy1             = 0.0;
160         fiz1             = 0.0;
161         fix2             = 0.0;
162         fiy2             = 0.0;
163         fiz2             = 0.0;
164         fix3             = 0.0;
165         fiy3             = 0.0;
166         fiz3             = 0.0;
167
168         /* Reset potential sums */
169         velecsum         = 0.0;
170         vvdwsum          = 0.0;
171
172         /* Start inner kernel loop */
173         for(jidx=j_index_start; jidx<j_index_end; jidx++)
174         {
175             /* Get j neighbor index, and coordinate index */
176             jnr              = jjnr[jidx];
177             j_coord_offset   = DIM*jnr;
178
179             /* load j atom coordinates */
180             jx0              = x[j_coord_offset+DIM*0+XX];
181             jy0              = x[j_coord_offset+DIM*0+YY];
182             jz0              = x[j_coord_offset+DIM*0+ZZ];
183
184             /* Calculate displacement vector */
185             dx00             = ix0 - jx0;
186             dy00             = iy0 - jy0;
187             dz00             = iz0 - jz0;
188             dx10             = ix1 - jx0;
189             dy10             = iy1 - jy0;
190             dz10             = iz1 - jz0;
191             dx20             = ix2 - jx0;
192             dy20             = iy2 - jy0;
193             dz20             = iz2 - jz0;
194             dx30             = ix3 - jx0;
195             dy30             = iy3 - jy0;
196             dz30             = iz3 - jz0;
197
198             /* Calculate squared distance and things based on it */
199             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
200             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
201             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
202             rsq30            = dx30*dx30+dy30*dy30+dz30*dz30;
203
204             rinv00           = gmx_invsqrt(rsq00);
205             rinv10           = gmx_invsqrt(rsq10);
206             rinv20           = gmx_invsqrt(rsq20);
207             rinv30           = gmx_invsqrt(rsq30);
208
209             rinvsq10         = rinv10*rinv10;
210             rinvsq20         = rinv20*rinv20;
211             rinvsq30         = rinv30*rinv30;
212
213             /* Load parameters for j particles */
214             jq0              = charge[jnr+0];
215             vdwjidx0         = 2*vdwtype[jnr+0];
216
217             /**************************
218              * CALCULATE INTERACTIONS *
219              **************************/
220
221             r00              = rsq00*rinv00;
222
223             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
224             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
225
226             /* Calculate table index by multiplying r with table scale and truncate to integer */
227             rt               = r00*vftabscale;
228             vfitab           = rt;
229             vfeps            = rt-vfitab;
230             vfitab           = 2*4*vfitab;
231
232             /* CUBIC SPLINE TABLE DISPERSION */
233             vfitab          += 0;
234             Y                = vftab[vfitab];
235             F                = vftab[vfitab+1];
236             Geps             = vfeps*vftab[vfitab+2];
237             Heps2            = vfeps*vfeps*vftab[vfitab+3];
238             Fp               = F+Geps+Heps2;
239             VV               = Y+vfeps*Fp;
240             vvdw6            = c6_00*VV;
241             FF               = Fp+Geps+2.0*Heps2;
242             fvdw6            = c6_00*FF;
243
244             /* CUBIC SPLINE TABLE REPULSION */
245             Y                = vftab[vfitab+4];
246             F                = vftab[vfitab+5];
247             Geps             = vfeps*vftab[vfitab+6];
248             Heps2            = vfeps*vfeps*vftab[vfitab+7];
249             Fp               = F+Geps+Heps2;
250             VV               = Y+vfeps*Fp;
251             vvdw12           = c12_00*VV;
252             FF               = Fp+Geps+2.0*Heps2;
253             fvdw12           = c12_00*FF;
254             vvdw             = vvdw12+vvdw6;
255             fvdw             = -(fvdw6+fvdw12)*vftabscale*rinv00;
256
257             /* Update potential sums from outer loop */
258             vvdwsum         += vvdw;
259
260             fscal            = fvdw;
261
262             /* Calculate temporary vectorial force */
263             tx               = fscal*dx00;
264             ty               = fscal*dy00;
265             tz               = fscal*dz00;
266
267             /* Update vectorial force */
268             fix0            += tx;
269             fiy0            += ty;
270             fiz0            += tz;
271             f[j_coord_offset+DIM*0+XX] -= tx;
272             f[j_coord_offset+DIM*0+YY] -= ty;
273             f[j_coord_offset+DIM*0+ZZ] -= tz;
274
275             /**************************
276              * CALCULATE INTERACTIONS *
277              **************************/
278
279             qq10             = iq1*jq0;
280
281             /* COULOMB ELECTROSTATICS */
282             velec            = qq10*rinv10;
283             felec            = velec*rinvsq10;
284
285             /* Update potential sums from outer loop */
286             velecsum        += velec;
287
288             fscal            = felec;
289
290             /* Calculate temporary vectorial force */
291             tx               = fscal*dx10;
292             ty               = fscal*dy10;
293             tz               = fscal*dz10;
294
295             /* Update vectorial force */
296             fix1            += tx;
297             fiy1            += ty;
298             fiz1            += tz;
299             f[j_coord_offset+DIM*0+XX] -= tx;
300             f[j_coord_offset+DIM*0+YY] -= ty;
301             f[j_coord_offset+DIM*0+ZZ] -= tz;
302
303             /**************************
304              * CALCULATE INTERACTIONS *
305              **************************/
306
307             qq20             = iq2*jq0;
308
309             /* COULOMB ELECTROSTATICS */
310             velec            = qq20*rinv20;
311             felec            = velec*rinvsq20;
312
313             /* Update potential sums from outer loop */
314             velecsum        += velec;
315
316             fscal            = felec;
317
318             /* Calculate temporary vectorial force */
319             tx               = fscal*dx20;
320             ty               = fscal*dy20;
321             tz               = fscal*dz20;
322
323             /* Update vectorial force */
324             fix2            += tx;
325             fiy2            += ty;
326             fiz2            += tz;
327             f[j_coord_offset+DIM*0+XX] -= tx;
328             f[j_coord_offset+DIM*0+YY] -= ty;
329             f[j_coord_offset+DIM*0+ZZ] -= tz;
330
331             /**************************
332              * CALCULATE INTERACTIONS *
333              **************************/
334
335             qq30             = iq3*jq0;
336
337             /* COULOMB ELECTROSTATICS */
338             velec            = qq30*rinv30;
339             felec            = velec*rinvsq30;
340
341             /* Update potential sums from outer loop */
342             velecsum        += velec;
343
344             fscal            = felec;
345
346             /* Calculate temporary vectorial force */
347             tx               = fscal*dx30;
348             ty               = fscal*dy30;
349             tz               = fscal*dz30;
350
351             /* Update vectorial force */
352             fix3            += tx;
353             fiy3            += ty;
354             fiz3            += tz;
355             f[j_coord_offset+DIM*0+XX] -= tx;
356             f[j_coord_offset+DIM*0+YY] -= ty;
357             f[j_coord_offset+DIM*0+ZZ] -= tz;
358
359             /* Inner loop uses 139 flops */
360         }
361         /* End of innermost loop */
362
363         tx = ty = tz = 0;
364         f[i_coord_offset+DIM*0+XX] += fix0;
365         f[i_coord_offset+DIM*0+YY] += fiy0;
366         f[i_coord_offset+DIM*0+ZZ] += fiz0;
367         tx                         += fix0;
368         ty                         += fiy0;
369         tz                         += fiz0;
370         f[i_coord_offset+DIM*1+XX] += fix1;
371         f[i_coord_offset+DIM*1+YY] += fiy1;
372         f[i_coord_offset+DIM*1+ZZ] += fiz1;
373         tx                         += fix1;
374         ty                         += fiy1;
375         tz                         += fiz1;
376         f[i_coord_offset+DIM*2+XX] += fix2;
377         f[i_coord_offset+DIM*2+YY] += fiy2;
378         f[i_coord_offset+DIM*2+ZZ] += fiz2;
379         tx                         += fix2;
380         ty                         += fiy2;
381         tz                         += fiz2;
382         f[i_coord_offset+DIM*3+XX] += fix3;
383         f[i_coord_offset+DIM*3+YY] += fiy3;
384         f[i_coord_offset+DIM*3+ZZ] += fiz3;
385         tx                         += fix3;
386         ty                         += fiy3;
387         tz                         += fiz3;
388         fshift[i_shift_offset+XX]  += tx;
389         fshift[i_shift_offset+YY]  += ty;
390         fshift[i_shift_offset+ZZ]  += tz;
391
392         ggid                        = gid[iidx];
393         /* Update potential energies */
394         kernel_data->energygrp_elec[ggid] += velecsum;
395         kernel_data->energygrp_vdw[ggid] += vvdwsum;
396
397         /* Increment number of inner iterations */
398         inneriter                  += j_index_end - j_index_start;
399
400         /* Outer loop uses 41 flops */
401     }
402
403     /* Increment number of outer iterations */
404     outeriter        += nri;
405
406     /* Update outer/inner flops */
407
408     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*41 + inneriter*139);
409 }
410 /*
411  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwCSTab_GeomW4P1_F_c
412  * Electrostatics interaction: Coulomb
413  * VdW interaction:            CubicSplineTable
414  * Geometry:                   Water4-Particle
415  * Calculate force/pot:        Force
416  */
417 void
418 nb_kernel_ElecCoul_VdwCSTab_GeomW4P1_F_c
419                     (t_nblist                    * gmx_restrict       nlist,
420                      rvec                        * gmx_restrict          xx,
421                      rvec                        * gmx_restrict          ff,
422                      t_forcerec                  * gmx_restrict          fr,
423                      t_mdatoms                   * gmx_restrict     mdatoms,
424                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
425                      t_nrnb                      * gmx_restrict        nrnb)
426 {
427     int              i_shift_offset,i_coord_offset,j_coord_offset;
428     int              j_index_start,j_index_end;
429     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
430     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
431     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
432     real             *shiftvec,*fshift,*x,*f;
433     int              vdwioffset0;
434     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
435     int              vdwioffset1;
436     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
437     int              vdwioffset2;
438     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
439     int              vdwioffset3;
440     real             ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
441     int              vdwjidx0;
442     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
443     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
444     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
445     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
446     real             dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
447     real             velec,felec,velecsum,facel,crf,krf,krf2;
448     real             *charge;
449     int              nvdwtype;
450     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
451     int              *vdwtype;
452     real             *vdwparam;
453     int              vfitab;
454     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
455     real             *vftab;
456
457     x                = xx[0];
458     f                = ff[0];
459
460     nri              = nlist->nri;
461     iinr             = nlist->iinr;
462     jindex           = nlist->jindex;
463     jjnr             = nlist->jjnr;
464     shiftidx         = nlist->shift;
465     gid              = nlist->gid;
466     shiftvec         = fr->shift_vec[0];
467     fshift           = fr->fshift[0];
468     facel            = fr->epsfac;
469     charge           = mdatoms->chargeA;
470     nvdwtype         = fr->ntype;
471     vdwparam         = fr->nbfp;
472     vdwtype          = mdatoms->typeA;
473
474     vftab            = kernel_data->table_vdw->data;
475     vftabscale       = kernel_data->table_vdw->scale;
476
477     /* Setup water-specific parameters */
478     inr              = nlist->iinr[0];
479     iq1              = facel*charge[inr+1];
480     iq2              = facel*charge[inr+2];
481     iq3              = facel*charge[inr+3];
482     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
483
484     outeriter        = 0;
485     inneriter        = 0;
486
487     /* Start outer loop over neighborlists */
488     for(iidx=0; iidx<nri; iidx++)
489     {
490         /* Load shift vector for this list */
491         i_shift_offset   = DIM*shiftidx[iidx];
492         shX              = shiftvec[i_shift_offset+XX];
493         shY              = shiftvec[i_shift_offset+YY];
494         shZ              = shiftvec[i_shift_offset+ZZ];
495
496         /* Load limits for loop over neighbors */
497         j_index_start    = jindex[iidx];
498         j_index_end      = jindex[iidx+1];
499
500         /* Get outer coordinate index */
501         inr              = iinr[iidx];
502         i_coord_offset   = DIM*inr;
503
504         /* Load i particle coords and add shift vector */
505         ix0              = shX + x[i_coord_offset+DIM*0+XX];
506         iy0              = shY + x[i_coord_offset+DIM*0+YY];
507         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
508         ix1              = shX + x[i_coord_offset+DIM*1+XX];
509         iy1              = shY + x[i_coord_offset+DIM*1+YY];
510         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
511         ix2              = shX + x[i_coord_offset+DIM*2+XX];
512         iy2              = shY + x[i_coord_offset+DIM*2+YY];
513         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
514         ix3              = shX + x[i_coord_offset+DIM*3+XX];
515         iy3              = shY + x[i_coord_offset+DIM*3+YY];
516         iz3              = shZ + x[i_coord_offset+DIM*3+ZZ];
517
518         fix0             = 0.0;
519         fiy0             = 0.0;
520         fiz0             = 0.0;
521         fix1             = 0.0;
522         fiy1             = 0.0;
523         fiz1             = 0.0;
524         fix2             = 0.0;
525         fiy2             = 0.0;
526         fiz2             = 0.0;
527         fix3             = 0.0;
528         fiy3             = 0.0;
529         fiz3             = 0.0;
530
531         /* Start inner kernel loop */
532         for(jidx=j_index_start; jidx<j_index_end; jidx++)
533         {
534             /* Get j neighbor index, and coordinate index */
535             jnr              = jjnr[jidx];
536             j_coord_offset   = DIM*jnr;
537
538             /* load j atom coordinates */
539             jx0              = x[j_coord_offset+DIM*0+XX];
540             jy0              = x[j_coord_offset+DIM*0+YY];
541             jz0              = x[j_coord_offset+DIM*0+ZZ];
542
543             /* Calculate displacement vector */
544             dx00             = ix0 - jx0;
545             dy00             = iy0 - jy0;
546             dz00             = iz0 - jz0;
547             dx10             = ix1 - jx0;
548             dy10             = iy1 - jy0;
549             dz10             = iz1 - jz0;
550             dx20             = ix2 - jx0;
551             dy20             = iy2 - jy0;
552             dz20             = iz2 - jz0;
553             dx30             = ix3 - jx0;
554             dy30             = iy3 - jy0;
555             dz30             = iz3 - jz0;
556
557             /* Calculate squared distance and things based on it */
558             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
559             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
560             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
561             rsq30            = dx30*dx30+dy30*dy30+dz30*dz30;
562
563             rinv00           = gmx_invsqrt(rsq00);
564             rinv10           = gmx_invsqrt(rsq10);
565             rinv20           = gmx_invsqrt(rsq20);
566             rinv30           = gmx_invsqrt(rsq30);
567
568             rinvsq10         = rinv10*rinv10;
569             rinvsq20         = rinv20*rinv20;
570             rinvsq30         = rinv30*rinv30;
571
572             /* Load parameters for j particles */
573             jq0              = charge[jnr+0];
574             vdwjidx0         = 2*vdwtype[jnr+0];
575
576             /**************************
577              * CALCULATE INTERACTIONS *
578              **************************/
579
580             r00              = rsq00*rinv00;
581
582             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
583             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
584
585             /* Calculate table index by multiplying r with table scale and truncate to integer */
586             rt               = r00*vftabscale;
587             vfitab           = rt;
588             vfeps            = rt-vfitab;
589             vfitab           = 2*4*vfitab;
590
591             /* CUBIC SPLINE TABLE DISPERSION */
592             vfitab          += 0;
593             F                = vftab[vfitab+1];
594             Geps             = vfeps*vftab[vfitab+2];
595             Heps2            = vfeps*vfeps*vftab[vfitab+3];
596             Fp               = F+Geps+Heps2;
597             FF               = Fp+Geps+2.0*Heps2;
598             fvdw6            = c6_00*FF;
599
600             /* CUBIC SPLINE TABLE REPULSION */
601             F                = vftab[vfitab+5];
602             Geps             = vfeps*vftab[vfitab+6];
603             Heps2            = vfeps*vfeps*vftab[vfitab+7];
604             Fp               = F+Geps+Heps2;
605             FF               = Fp+Geps+2.0*Heps2;
606             fvdw12           = c12_00*FF;
607             fvdw             = -(fvdw6+fvdw12)*vftabscale*rinv00;
608
609             fscal            = fvdw;
610
611             /* Calculate temporary vectorial force */
612             tx               = fscal*dx00;
613             ty               = fscal*dy00;
614             tz               = fscal*dz00;
615
616             /* Update vectorial force */
617             fix0            += tx;
618             fiy0            += ty;
619             fiz0            += tz;
620             f[j_coord_offset+DIM*0+XX] -= tx;
621             f[j_coord_offset+DIM*0+YY] -= ty;
622             f[j_coord_offset+DIM*0+ZZ] -= tz;
623
624             /**************************
625              * CALCULATE INTERACTIONS *
626              **************************/
627
628             qq10             = iq1*jq0;
629
630             /* COULOMB ELECTROSTATICS */
631             velec            = qq10*rinv10;
632             felec            = velec*rinvsq10;
633
634             fscal            = felec;
635
636             /* Calculate temporary vectorial force */
637             tx               = fscal*dx10;
638             ty               = fscal*dy10;
639             tz               = fscal*dz10;
640
641             /* Update vectorial force */
642             fix1            += tx;
643             fiy1            += ty;
644             fiz1            += tz;
645             f[j_coord_offset+DIM*0+XX] -= tx;
646             f[j_coord_offset+DIM*0+YY] -= ty;
647             f[j_coord_offset+DIM*0+ZZ] -= tz;
648
649             /**************************
650              * CALCULATE INTERACTIONS *
651              **************************/
652
653             qq20             = iq2*jq0;
654
655             /* COULOMB ELECTROSTATICS */
656             velec            = qq20*rinv20;
657             felec            = velec*rinvsq20;
658
659             fscal            = felec;
660
661             /* Calculate temporary vectorial force */
662             tx               = fscal*dx20;
663             ty               = fscal*dy20;
664             tz               = fscal*dz20;
665
666             /* Update vectorial force */
667             fix2            += tx;
668             fiy2            += ty;
669             fiz2            += tz;
670             f[j_coord_offset+DIM*0+XX] -= tx;
671             f[j_coord_offset+DIM*0+YY] -= ty;
672             f[j_coord_offset+DIM*0+ZZ] -= tz;
673
674             /**************************
675              * CALCULATE INTERACTIONS *
676              **************************/
677
678             qq30             = iq3*jq0;
679
680             /* COULOMB ELECTROSTATICS */
681             velec            = qq30*rinv30;
682             felec            = velec*rinvsq30;
683
684             fscal            = felec;
685
686             /* Calculate temporary vectorial force */
687             tx               = fscal*dx30;
688             ty               = fscal*dy30;
689             tz               = fscal*dz30;
690
691             /* Update vectorial force */
692             fix3            += tx;
693             fiy3            += ty;
694             fiz3            += tz;
695             f[j_coord_offset+DIM*0+XX] -= tx;
696             f[j_coord_offset+DIM*0+YY] -= ty;
697             f[j_coord_offset+DIM*0+ZZ] -= tz;
698
699             /* Inner loop uses 128 flops */
700         }
701         /* End of innermost loop */
702
703         tx = ty = tz = 0;
704         f[i_coord_offset+DIM*0+XX] += fix0;
705         f[i_coord_offset+DIM*0+YY] += fiy0;
706         f[i_coord_offset+DIM*0+ZZ] += fiz0;
707         tx                         += fix0;
708         ty                         += fiy0;
709         tz                         += fiz0;
710         f[i_coord_offset+DIM*1+XX] += fix1;
711         f[i_coord_offset+DIM*1+YY] += fiy1;
712         f[i_coord_offset+DIM*1+ZZ] += fiz1;
713         tx                         += fix1;
714         ty                         += fiy1;
715         tz                         += fiz1;
716         f[i_coord_offset+DIM*2+XX] += fix2;
717         f[i_coord_offset+DIM*2+YY] += fiy2;
718         f[i_coord_offset+DIM*2+ZZ] += fiz2;
719         tx                         += fix2;
720         ty                         += fiy2;
721         tz                         += fiz2;
722         f[i_coord_offset+DIM*3+XX] += fix3;
723         f[i_coord_offset+DIM*3+YY] += fiy3;
724         f[i_coord_offset+DIM*3+ZZ] += fiz3;
725         tx                         += fix3;
726         ty                         += fiy3;
727         tz                         += fiz3;
728         fshift[i_shift_offset+XX]  += tx;
729         fshift[i_shift_offset+YY]  += ty;
730         fshift[i_shift_offset+ZZ]  += tz;
731
732         /* Increment number of inner iterations */
733         inneriter                  += j_index_end - j_index_start;
734
735         /* Outer loop uses 39 flops */
736     }
737
738     /* Increment number of outer iterations */
739     outeriter        += nri;
740
741     /* Update outer/inner flops */
742
743     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*39 + inneriter*128);
744 }