Merge 'release-4-6' into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecCSTab_VdwBham_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_VdwBham_GeomW4P1_VF_c
35  * Electrostatics interaction: CubicSplineTable
36  * VdW interaction:            Buckingham
37  * Geometry:                   Water4-Particle
38  * Calculate force/pot:        PotentialAndForce
39  */
40 void
41 nb_kernel_ElecCSTab_VdwBham_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      = 3*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             rinv00           = gmx_invsqrt(rsq00);
191             rinv10           = gmx_invsqrt(rsq10);
192             rinv20           = gmx_invsqrt(rsq20);
193             rinv30           = gmx_invsqrt(rsq30);
194
195             rinvsq00         = rinv00*rinv00;
196
197             /* Load parameters for j particles */
198             jq0              = charge[jnr+0];
199             vdwjidx0         = 3*vdwtype[jnr+0];
200
201             /**************************
202              * CALCULATE INTERACTIONS *
203              **************************/
204
205             r00              = rsq00*rinv00;
206
207             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
208             cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
209             cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
210
211             /* BUCKINGHAM DISPERSION/REPULSION */
212             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
213             vvdw6            = c6_00*rinvsix;
214             br               = cexp2_00*r00;
215             vvdwexp          = cexp1_00*exp(-br);
216             vvdw             = vvdwexp - vvdw6*(1.0/6.0);
217             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
218
219             /* Update potential sums from outer loop */
220             vvdwsum         += vvdw;
221
222             fscal            = fvdw;
223
224             /* Calculate temporary vectorial force */
225             tx               = fscal*dx00;
226             ty               = fscal*dy00;
227             tz               = fscal*dz00;
228
229             /* Update vectorial force */
230             fix0            += tx;
231             fiy0            += ty;
232             fiz0            += tz;
233             f[j_coord_offset+DIM*0+XX] -= tx;
234             f[j_coord_offset+DIM*0+YY] -= ty;
235             f[j_coord_offset+DIM*0+ZZ] -= tz;
236
237             /**************************
238              * CALCULATE INTERACTIONS *
239              **************************/
240
241             r10              = rsq10*rinv10;
242
243             qq10             = iq1*jq0;
244
245             /* Calculate table index by multiplying r with table scale and truncate to integer */
246             rt               = r10*vftabscale;
247             vfitab           = rt;
248             vfeps            = rt-vfitab;
249             vfitab           = 1*4*vfitab;
250
251             /* CUBIC SPLINE TABLE ELECTROSTATICS */
252             Y                = vftab[vfitab];
253             F                = vftab[vfitab+1];
254             Geps             = vfeps*vftab[vfitab+2];
255             Heps2            = vfeps*vfeps*vftab[vfitab+3];
256             Fp               = F+Geps+Heps2;
257             VV               = Y+vfeps*Fp;
258             velec            = qq10*VV;
259             FF               = Fp+Geps+2.0*Heps2;
260             felec            = -qq10*FF*vftabscale*rinv10;
261
262             /* Update potential sums from outer loop */
263             velecsum        += velec;
264
265             fscal            = felec;
266
267             /* Calculate temporary vectorial force */
268             tx               = fscal*dx10;
269             ty               = fscal*dy10;
270             tz               = fscal*dz10;
271
272             /* Update vectorial force */
273             fix1            += tx;
274             fiy1            += ty;
275             fiz1            += tz;
276             f[j_coord_offset+DIM*0+XX] -= tx;
277             f[j_coord_offset+DIM*0+YY] -= ty;
278             f[j_coord_offset+DIM*0+ZZ] -= tz;
279
280             /**************************
281              * CALCULATE INTERACTIONS *
282              **************************/
283
284             r20              = rsq20*rinv20;
285
286             qq20             = iq2*jq0;
287
288             /* Calculate table index by multiplying r with table scale and truncate to integer */
289             rt               = r20*vftabscale;
290             vfitab           = rt;
291             vfeps            = rt-vfitab;
292             vfitab           = 1*4*vfitab;
293
294             /* CUBIC SPLINE TABLE ELECTROSTATICS */
295             Y                = vftab[vfitab];
296             F                = vftab[vfitab+1];
297             Geps             = vfeps*vftab[vfitab+2];
298             Heps2            = vfeps*vfeps*vftab[vfitab+3];
299             Fp               = F+Geps+Heps2;
300             VV               = Y+vfeps*Fp;
301             velec            = qq20*VV;
302             FF               = Fp+Geps+2.0*Heps2;
303             felec            = -qq20*FF*vftabscale*rinv20;
304
305             /* Update potential sums from outer loop */
306             velecsum        += velec;
307
308             fscal            = felec;
309
310             /* Calculate temporary vectorial force */
311             tx               = fscal*dx20;
312             ty               = fscal*dy20;
313             tz               = fscal*dz20;
314
315             /* Update vectorial force */
316             fix2            += tx;
317             fiy2            += ty;
318             fiz2            += tz;
319             f[j_coord_offset+DIM*0+XX] -= tx;
320             f[j_coord_offset+DIM*0+YY] -= ty;
321             f[j_coord_offset+DIM*0+ZZ] -= tz;
322
323             /**************************
324              * CALCULATE INTERACTIONS *
325              **************************/
326
327             r30              = rsq30*rinv30;
328
329             qq30             = iq3*jq0;
330
331             /* Calculate table index by multiplying r with table scale and truncate to integer */
332             rt               = r30*vftabscale;
333             vfitab           = rt;
334             vfeps            = rt-vfitab;
335             vfitab           = 1*4*vfitab;
336
337             /* CUBIC SPLINE TABLE ELECTROSTATICS */
338             Y                = vftab[vfitab];
339             F                = vftab[vfitab+1];
340             Geps             = vfeps*vftab[vfitab+2];
341             Heps2            = vfeps*vfeps*vftab[vfitab+3];
342             Fp               = F+Geps+Heps2;
343             VV               = Y+vfeps*Fp;
344             velec            = qq30*VV;
345             FF               = Fp+Geps+2.0*Heps2;
346             felec            = -qq30*FF*vftabscale*rinv30;
347
348             /* Update potential sums from outer loop */
349             velecsum        += velec;
350
351             fscal            = felec;
352
353             /* Calculate temporary vectorial force */
354             tx               = fscal*dx30;
355             ty               = fscal*dy30;
356             tz               = fscal*dz30;
357
358             /* Update vectorial force */
359             fix3            += tx;
360             fiy3            += ty;
361             fiz3            += tz;
362             f[j_coord_offset+DIM*0+XX] -= tx;
363             f[j_coord_offset+DIM*0+YY] -= ty;
364             f[j_coord_offset+DIM*0+ZZ] -= tz;
365
366             /* Inner loop uses 187 flops */
367         }
368         /* End of innermost loop */
369
370         tx = ty = tz = 0;
371         f[i_coord_offset+DIM*0+XX] += fix0;
372         f[i_coord_offset+DIM*0+YY] += fiy0;
373         f[i_coord_offset+DIM*0+ZZ] += fiz0;
374         tx                         += fix0;
375         ty                         += fiy0;
376         tz                         += fiz0;
377         f[i_coord_offset+DIM*1+XX] += fix1;
378         f[i_coord_offset+DIM*1+YY] += fiy1;
379         f[i_coord_offset+DIM*1+ZZ] += fiz1;
380         tx                         += fix1;
381         ty                         += fiy1;
382         tz                         += fiz1;
383         f[i_coord_offset+DIM*2+XX] += fix2;
384         f[i_coord_offset+DIM*2+YY] += fiy2;
385         f[i_coord_offset+DIM*2+ZZ] += fiz2;
386         tx                         += fix2;
387         ty                         += fiy2;
388         tz                         += fiz2;
389         f[i_coord_offset+DIM*3+XX] += fix3;
390         f[i_coord_offset+DIM*3+YY] += fiy3;
391         f[i_coord_offset+DIM*3+ZZ] += fiz3;
392         tx                         += fix3;
393         ty                         += fiy3;
394         tz                         += fiz3;
395         fshift[i_shift_offset+XX]  += tx;
396         fshift[i_shift_offset+YY]  += ty;
397         fshift[i_shift_offset+ZZ]  += tz;
398
399         ggid                        = gid[iidx];
400         /* Update potential energies */
401         kernel_data->energygrp_elec[ggid] += velecsum;
402         kernel_data->energygrp_vdw[ggid] += vvdwsum;
403
404         /* Increment number of inner iterations */
405         inneriter                  += j_index_end - j_index_start;
406
407         /* Outer loop uses 41 flops */
408     }
409
410     /* Increment number of outer iterations */
411     outeriter        += nri;
412
413     /* Update outer/inner flops */
414
415     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*41 + inneriter*187);
416 }
417 /*
418  * Gromacs nonbonded kernel:   nb_kernel_ElecCSTab_VdwBham_GeomW4P1_F_c
419  * Electrostatics interaction: CubicSplineTable
420  * VdW interaction:            Buckingham
421  * Geometry:                   Water4-Particle
422  * Calculate force/pot:        Force
423  */
424 void
425 nb_kernel_ElecCSTab_VdwBham_GeomW4P1_F_c
426                     (t_nblist * gmx_restrict                nlist,
427                      rvec * gmx_restrict                    xx,
428                      rvec * gmx_restrict                    ff,
429                      t_forcerec * gmx_restrict              fr,
430                      t_mdatoms * gmx_restrict               mdatoms,
431                      nb_kernel_data_t * gmx_restrict        kernel_data,
432                      t_nrnb * gmx_restrict                  nrnb)
433 {
434     int              i_shift_offset,i_coord_offset,j_coord_offset;
435     int              j_index_start,j_index_end;
436     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
437     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
438     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
439     real             *shiftvec,*fshift,*x,*f;
440     int              vdwioffset0;
441     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
442     int              vdwioffset1;
443     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
444     int              vdwioffset2;
445     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
446     int              vdwioffset3;
447     real             ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
448     int              vdwjidx0;
449     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
450     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
451     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
452     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
453     real             dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
454     real             velec,felec,velecsum,facel,crf,krf,krf2;
455     real             *charge;
456     int              nvdwtype;
457     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
458     int              *vdwtype;
459     real             *vdwparam;
460     int              vfitab;
461     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
462     real             *vftab;
463
464     x                = xx[0];
465     f                = ff[0];
466
467     nri              = nlist->nri;
468     iinr             = nlist->iinr;
469     jindex           = nlist->jindex;
470     jjnr             = nlist->jjnr;
471     shiftidx         = nlist->shift;
472     gid              = nlist->gid;
473     shiftvec         = fr->shift_vec[0];
474     fshift           = fr->fshift[0];
475     facel            = fr->epsfac;
476     charge           = mdatoms->chargeA;
477     nvdwtype         = fr->ntype;
478     vdwparam         = fr->nbfp;
479     vdwtype          = mdatoms->typeA;
480
481     vftab            = kernel_data->table_elec->data;
482     vftabscale       = kernel_data->table_elec->scale;
483
484     /* Setup water-specific parameters */
485     inr              = nlist->iinr[0];
486     iq1              = facel*charge[inr+1];
487     iq2              = facel*charge[inr+2];
488     iq3              = facel*charge[inr+3];
489     vdwioffset0      = 3*nvdwtype*vdwtype[inr+0];
490
491     outeriter        = 0;
492     inneriter        = 0;
493
494     /* Start outer loop over neighborlists */
495     for(iidx=0; iidx<nri; iidx++)
496     {
497         /* Load shift vector for this list */
498         i_shift_offset   = DIM*shiftidx[iidx];
499         shX              = shiftvec[i_shift_offset+XX];
500         shY              = shiftvec[i_shift_offset+YY];
501         shZ              = shiftvec[i_shift_offset+ZZ];
502
503         /* Load limits for loop over neighbors */
504         j_index_start    = jindex[iidx];
505         j_index_end      = jindex[iidx+1];
506
507         /* Get outer coordinate index */
508         inr              = iinr[iidx];
509         i_coord_offset   = DIM*inr;
510
511         /* Load i particle coords and add shift vector */
512         ix0              = shX + x[i_coord_offset+DIM*0+XX];
513         iy0              = shY + x[i_coord_offset+DIM*0+YY];
514         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
515         ix1              = shX + x[i_coord_offset+DIM*1+XX];
516         iy1              = shY + x[i_coord_offset+DIM*1+YY];
517         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
518         ix2              = shX + x[i_coord_offset+DIM*2+XX];
519         iy2              = shY + x[i_coord_offset+DIM*2+YY];
520         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
521         ix3              = shX + x[i_coord_offset+DIM*3+XX];
522         iy3              = shY + x[i_coord_offset+DIM*3+YY];
523         iz3              = shZ + x[i_coord_offset+DIM*3+ZZ];
524
525         fix0             = 0.0;
526         fiy0             = 0.0;
527         fiz0             = 0.0;
528         fix1             = 0.0;
529         fiy1             = 0.0;
530         fiz1             = 0.0;
531         fix2             = 0.0;
532         fiy2             = 0.0;
533         fiz2             = 0.0;
534         fix3             = 0.0;
535         fiy3             = 0.0;
536         fiz3             = 0.0;
537
538         /* Start inner kernel loop */
539         for(jidx=j_index_start; jidx<j_index_end; jidx++)
540         {
541             /* Get j neighbor index, and coordinate index */
542             jnr              = jjnr[jidx];
543             j_coord_offset   = DIM*jnr;
544
545             /* load j atom coordinates */
546             jx0              = x[j_coord_offset+DIM*0+XX];
547             jy0              = x[j_coord_offset+DIM*0+YY];
548             jz0              = x[j_coord_offset+DIM*0+ZZ];
549
550             /* Calculate displacement vector */
551             dx00             = ix0 - jx0;
552             dy00             = iy0 - jy0;
553             dz00             = iz0 - jz0;
554             dx10             = ix1 - jx0;
555             dy10             = iy1 - jy0;
556             dz10             = iz1 - jz0;
557             dx20             = ix2 - jx0;
558             dy20             = iy2 - jy0;
559             dz20             = iz2 - jz0;
560             dx30             = ix3 - jx0;
561             dy30             = iy3 - jy0;
562             dz30             = iz3 - jz0;
563
564             /* Calculate squared distance and things based on it */
565             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
566             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
567             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
568             rsq30            = dx30*dx30+dy30*dy30+dz30*dz30;
569
570             rinv00           = gmx_invsqrt(rsq00);
571             rinv10           = gmx_invsqrt(rsq10);
572             rinv20           = gmx_invsqrt(rsq20);
573             rinv30           = gmx_invsqrt(rsq30);
574
575             rinvsq00         = rinv00*rinv00;
576
577             /* Load parameters for j particles */
578             jq0              = charge[jnr+0];
579             vdwjidx0         = 3*vdwtype[jnr+0];
580
581             /**************************
582              * CALCULATE INTERACTIONS *
583              **************************/
584
585             r00              = rsq00*rinv00;
586
587             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
588             cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
589             cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
590
591             /* BUCKINGHAM DISPERSION/REPULSION */
592             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
593             vvdw6            = c6_00*rinvsix;
594             br               = cexp2_00*r00;
595             vvdwexp          = cexp1_00*exp(-br);
596             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
597
598             fscal            = fvdw;
599
600             /* Calculate temporary vectorial force */
601             tx               = fscal*dx00;
602             ty               = fscal*dy00;
603             tz               = fscal*dz00;
604
605             /* Update vectorial force */
606             fix0            += tx;
607             fiy0            += ty;
608             fiz0            += tz;
609             f[j_coord_offset+DIM*0+XX] -= tx;
610             f[j_coord_offset+DIM*0+YY] -= ty;
611             f[j_coord_offset+DIM*0+ZZ] -= tz;
612
613             /**************************
614              * CALCULATE INTERACTIONS *
615              **************************/
616
617             r10              = rsq10*rinv10;
618
619             qq10             = iq1*jq0;
620
621             /* Calculate table index by multiplying r with table scale and truncate to integer */
622             rt               = r10*vftabscale;
623             vfitab           = rt;
624             vfeps            = rt-vfitab;
625             vfitab           = 1*4*vfitab;
626
627             /* CUBIC SPLINE TABLE ELECTROSTATICS */
628             F                = vftab[vfitab+1];
629             Geps             = vfeps*vftab[vfitab+2];
630             Heps2            = vfeps*vfeps*vftab[vfitab+3];
631             Fp               = F+Geps+Heps2;
632             FF               = Fp+Geps+2.0*Heps2;
633             felec            = -qq10*FF*vftabscale*rinv10;
634
635             fscal            = felec;
636
637             /* Calculate temporary vectorial force */
638             tx               = fscal*dx10;
639             ty               = fscal*dy10;
640             tz               = fscal*dz10;
641
642             /* Update vectorial force */
643             fix1            += tx;
644             fiy1            += ty;
645             fiz1            += tz;
646             f[j_coord_offset+DIM*0+XX] -= tx;
647             f[j_coord_offset+DIM*0+YY] -= ty;
648             f[j_coord_offset+DIM*0+ZZ] -= tz;
649
650             /**************************
651              * CALCULATE INTERACTIONS *
652              **************************/
653
654             r20              = rsq20*rinv20;
655
656             qq20             = iq2*jq0;
657
658             /* Calculate table index by multiplying r with table scale and truncate to integer */
659             rt               = r20*vftabscale;
660             vfitab           = rt;
661             vfeps            = rt-vfitab;
662             vfitab           = 1*4*vfitab;
663
664             /* CUBIC SPLINE TABLE ELECTROSTATICS */
665             F                = vftab[vfitab+1];
666             Geps             = vfeps*vftab[vfitab+2];
667             Heps2            = vfeps*vfeps*vftab[vfitab+3];
668             Fp               = F+Geps+Heps2;
669             FF               = Fp+Geps+2.0*Heps2;
670             felec            = -qq20*FF*vftabscale*rinv20;
671
672             fscal            = felec;
673
674             /* Calculate temporary vectorial force */
675             tx               = fscal*dx20;
676             ty               = fscal*dy20;
677             tz               = fscal*dz20;
678
679             /* Update vectorial force */
680             fix2            += tx;
681             fiy2            += ty;
682             fiz2            += tz;
683             f[j_coord_offset+DIM*0+XX] -= tx;
684             f[j_coord_offset+DIM*0+YY] -= ty;
685             f[j_coord_offset+DIM*0+ZZ] -= tz;
686
687             /**************************
688              * CALCULATE INTERACTIONS *
689              **************************/
690
691             r30              = rsq30*rinv30;
692
693             qq30             = iq3*jq0;
694
695             /* Calculate table index by multiplying r with table scale and truncate to integer */
696             rt               = r30*vftabscale;
697             vfitab           = rt;
698             vfeps            = rt-vfitab;
699             vfitab           = 1*4*vfitab;
700
701             /* CUBIC SPLINE TABLE ELECTROSTATICS */
702             F                = vftab[vfitab+1];
703             Geps             = vfeps*vftab[vfitab+2];
704             Heps2            = vfeps*vfeps*vftab[vfitab+3];
705             Fp               = F+Geps+Heps2;
706             FF               = Fp+Geps+2.0*Heps2;
707             felec            = -qq30*FF*vftabscale*rinv30;
708
709             fscal            = felec;
710
711             /* Calculate temporary vectorial force */
712             tx               = fscal*dx30;
713             ty               = fscal*dy30;
714             tz               = fscal*dz30;
715
716             /* Update vectorial force */
717             fix3            += tx;
718             fiy3            += ty;
719             fiz3            += tz;
720             f[j_coord_offset+DIM*0+XX] -= tx;
721             f[j_coord_offset+DIM*0+YY] -= ty;
722             f[j_coord_offset+DIM*0+ZZ] -= tz;
723
724             /* Inner loop uses 172 flops */
725         }
726         /* End of innermost loop */
727
728         tx = ty = tz = 0;
729         f[i_coord_offset+DIM*0+XX] += fix0;
730         f[i_coord_offset+DIM*0+YY] += fiy0;
731         f[i_coord_offset+DIM*0+ZZ] += fiz0;
732         tx                         += fix0;
733         ty                         += fiy0;
734         tz                         += fiz0;
735         f[i_coord_offset+DIM*1+XX] += fix1;
736         f[i_coord_offset+DIM*1+YY] += fiy1;
737         f[i_coord_offset+DIM*1+ZZ] += fiz1;
738         tx                         += fix1;
739         ty                         += fiy1;
740         tz                         += fiz1;
741         f[i_coord_offset+DIM*2+XX] += fix2;
742         f[i_coord_offset+DIM*2+YY] += fiy2;
743         f[i_coord_offset+DIM*2+ZZ] += fiz2;
744         tx                         += fix2;
745         ty                         += fiy2;
746         tz                         += fiz2;
747         f[i_coord_offset+DIM*3+XX] += fix3;
748         f[i_coord_offset+DIM*3+YY] += fiy3;
749         f[i_coord_offset+DIM*3+ZZ] += fiz3;
750         tx                         += fix3;
751         ty                         += fiy3;
752         tz                         += fiz3;
753         fshift[i_shift_offset+XX]  += tx;
754         fshift[i_shift_offset+YY]  += ty;
755         fshift[i_shift_offset+ZZ]  += tz;
756
757         /* Increment number of inner iterations */
758         inneriter                  += j_index_end - j_index_start;
759
760         /* Outer loop uses 39 flops */
761     }
762
763     /* Increment number of outer iterations */
764     outeriter        += nri;
765
766     /* Update outer/inner flops */
767
768     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*39 + inneriter*172);
769 }