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