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