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