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