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