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