c3127b11b42fc9c11f5f9623b8689ceb7472f21d
[alexxy/gromacs.git] / src / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecEwSw_VdwLJSw_GeomW3W3_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_GeomW3W3_VF_c
35  * Electrostatics interaction: Ewald
36  * VdW interaction:            LennardJones
37  * Geometry:                   Water3-Water3
38  * Calculate force/pot:        PotentialAndForce
39  */
40 void
41 nb_kernel_ElecEwSw_VdwLJSw_GeomW3W3_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              vdwjidx0;
63     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
64     int              vdwjidx1;
65     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
66     int              vdwjidx2;
67     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
68     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
69     real             dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01,cexp1_01,cexp2_01;
70     real             dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02,cexp1_02,cexp2_02;
71     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
72     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
73     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
74     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
75     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
76     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
77     real             velec,felec,velecsum,facel,crf,krf,krf2;
78     real             *charge;
79     int              nvdwtype;
80     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
81     int              *vdwtype;
82     real             *vdwparam;
83     int              ewitab;
84     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
85     real             *ewtab;
86     real             rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
87
88     x                = xx[0];
89     f                = ff[0];
90
91     nri              = nlist->nri;
92     iinr             = nlist->iinr;
93     jindex           = nlist->jindex;
94     jjnr             = nlist->jjnr;
95     shiftidx         = nlist->shift;
96     gid              = nlist->gid;
97     shiftvec         = fr->shift_vec[0];
98     fshift           = fr->fshift[0];
99     facel            = fr->epsfac;
100     charge           = mdatoms->chargeA;
101     nvdwtype         = fr->ntype;
102     vdwparam         = fr->nbfp;
103     vdwtype          = mdatoms->typeA;
104
105     sh_ewald         = fr->ic->sh_ewald;
106     ewtab            = fr->ic->tabq_coul_FDV0;
107     ewtabscale       = fr->ic->tabq_scale;
108     ewtabhalfspace   = 0.5/ewtabscale;
109
110     /* Setup water-specific parameters */
111     inr              = nlist->iinr[0];
112     iq0              = facel*charge[inr+0];
113     iq1              = facel*charge[inr+1];
114     iq2              = facel*charge[inr+2];
115     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
116
117     jq0              = charge[inr+0];
118     jq1              = charge[inr+1];
119     jq2              = charge[inr+2];
120     vdwjidx0         = 2*vdwtype[inr+0];
121     qq00             = iq0*jq0;
122     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
123     c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
124     qq01             = iq0*jq1;
125     qq02             = iq0*jq2;
126     qq10             = iq1*jq0;
127     qq11             = iq1*jq1;
128     qq12             = iq1*jq2;
129     qq20             = iq2*jq0;
130     qq21             = iq2*jq1;
131     qq22             = iq2*jq2;
132
133     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
134     rcutoff          = fr->rcoulomb;
135     rcutoff2         = rcutoff*rcutoff;
136
137     rswitch          = fr->rcoulomb_switch;
138     /* Setup switch parameters */
139     d                = rcutoff-rswitch;
140     swV3             = -10.0/(d*d*d);
141     swV4             =  15.0/(d*d*d*d);
142     swV5             =  -6.0/(d*d*d*d*d);
143     swF2             = -30.0/(d*d*d);
144     swF3             =  60.0/(d*d*d*d);
145     swF4             = -30.0/(d*d*d*d*d);
146
147     outeriter        = 0;
148     inneriter        = 0;
149
150     /* Start outer loop over neighborlists */
151     for(iidx=0; iidx<nri; iidx++)
152     {
153         /* Load shift vector for this list */
154         i_shift_offset   = DIM*shiftidx[iidx];
155         shX              = shiftvec[i_shift_offset+XX];
156         shY              = shiftvec[i_shift_offset+YY];
157         shZ              = shiftvec[i_shift_offset+ZZ];
158
159         /* Load limits for loop over neighbors */
160         j_index_start    = jindex[iidx];
161         j_index_end      = jindex[iidx+1];
162
163         /* Get outer coordinate index */
164         inr              = iinr[iidx];
165         i_coord_offset   = DIM*inr;
166
167         /* Load i particle coords and add shift vector */
168         ix0              = shX + x[i_coord_offset+DIM*0+XX];
169         iy0              = shY + x[i_coord_offset+DIM*0+YY];
170         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
171         ix1              = shX + x[i_coord_offset+DIM*1+XX];
172         iy1              = shY + x[i_coord_offset+DIM*1+YY];
173         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
174         ix2              = shX + x[i_coord_offset+DIM*2+XX];
175         iy2              = shY + x[i_coord_offset+DIM*2+YY];
176         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
177
178         fix0             = 0.0;
179         fiy0             = 0.0;
180         fiz0             = 0.0;
181         fix1             = 0.0;
182         fiy1             = 0.0;
183         fiz1             = 0.0;
184         fix2             = 0.0;
185         fiy2             = 0.0;
186         fiz2             = 0.0;
187
188         /* Reset potential sums */
189         velecsum         = 0.0;
190         vvdwsum          = 0.0;
191
192         /* Start inner kernel loop */
193         for(jidx=j_index_start; jidx<j_index_end; jidx++)
194         {
195             /* Get j neighbor index, and coordinate index */
196             jnr              = jjnr[jidx];
197             j_coord_offset   = DIM*jnr;
198
199             /* load j atom coordinates */
200             jx0              = x[j_coord_offset+DIM*0+XX];
201             jy0              = x[j_coord_offset+DIM*0+YY];
202             jz0              = x[j_coord_offset+DIM*0+ZZ];
203             jx1              = x[j_coord_offset+DIM*1+XX];
204             jy1              = x[j_coord_offset+DIM*1+YY];
205             jz1              = x[j_coord_offset+DIM*1+ZZ];
206             jx2              = x[j_coord_offset+DIM*2+XX];
207             jy2              = x[j_coord_offset+DIM*2+YY];
208             jz2              = x[j_coord_offset+DIM*2+ZZ];
209
210             /* Calculate displacement vector */
211             dx00             = ix0 - jx0;
212             dy00             = iy0 - jy0;
213             dz00             = iz0 - jz0;
214             dx01             = ix0 - jx1;
215             dy01             = iy0 - jy1;
216             dz01             = iz0 - jz1;
217             dx02             = ix0 - jx2;
218             dy02             = iy0 - jy2;
219             dz02             = iz0 - jz2;
220             dx10             = ix1 - jx0;
221             dy10             = iy1 - jy0;
222             dz10             = iz1 - jz0;
223             dx11             = ix1 - jx1;
224             dy11             = iy1 - jy1;
225             dz11             = iz1 - jz1;
226             dx12             = ix1 - jx2;
227             dy12             = iy1 - jy2;
228             dz12             = iz1 - jz2;
229             dx20             = ix2 - jx0;
230             dy20             = iy2 - jy0;
231             dz20             = iz2 - jz0;
232             dx21             = ix2 - jx1;
233             dy21             = iy2 - jy1;
234             dz21             = iz2 - jz1;
235             dx22             = ix2 - jx2;
236             dy22             = iy2 - jy2;
237             dz22             = iz2 - jz2;
238
239             /* Calculate squared distance and things based on it */
240             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
241             rsq01            = dx01*dx01+dy01*dy01+dz01*dz01;
242             rsq02            = dx02*dx02+dy02*dy02+dz02*dz02;
243             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
244             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
245             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
246             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
247             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
248             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
249
250             rinv00           = gmx_invsqrt(rsq00);
251             rinv01           = gmx_invsqrt(rsq01);
252             rinv02           = gmx_invsqrt(rsq02);
253             rinv10           = gmx_invsqrt(rsq10);
254             rinv11           = gmx_invsqrt(rsq11);
255             rinv12           = gmx_invsqrt(rsq12);
256             rinv20           = gmx_invsqrt(rsq20);
257             rinv21           = gmx_invsqrt(rsq21);
258             rinv22           = gmx_invsqrt(rsq22);
259
260             rinvsq00         = rinv00*rinv00;
261             rinvsq01         = rinv01*rinv01;
262             rinvsq02         = rinv02*rinv02;
263             rinvsq10         = rinv10*rinv10;
264             rinvsq11         = rinv11*rinv11;
265             rinvsq12         = rinv12*rinv12;
266             rinvsq20         = rinv20*rinv20;
267             rinvsq21         = rinv21*rinv21;
268             rinvsq22         = rinv22*rinv22;
269
270             /**************************
271              * CALCULATE INTERACTIONS *
272              **************************/
273
274             if (rsq00<rcutoff2)
275             {
276
277             r00              = rsq00*rinv00;
278
279             /* EWALD ELECTROSTATICS */
280
281             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
282             ewrt             = r00*ewtabscale;
283             ewitab           = ewrt;
284             eweps            = ewrt-ewitab;
285             ewitab           = 4*ewitab;
286             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
287             velec            = qq00*(rinv00-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
288             felec            = qq00*rinv00*(rinvsq00-felec);
289
290             /* LENNARD-JONES DISPERSION/REPULSION */
291
292             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
293             vvdw6            = c6_00*rinvsix;
294             vvdw12           = c12_00*rinvsix*rinvsix;
295             vvdw             = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
296             fvdw             = (vvdw12-vvdw6)*rinvsq00;
297
298             d                = r00-rswitch;
299             d                = (d>0.0) ? d : 0.0;
300             d2               = d*d;
301             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
302
303             dsw              = d2*(swF2+d*(swF3+d*swF4));
304
305             /* Evaluate switch function */
306             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
307             felec            = felec*sw - rinv00*velec*dsw;
308             fvdw             = fvdw*sw - rinv00*vvdw*dsw;
309             velec           *= sw;
310             vvdw            *= sw;
311
312             /* Update potential sums from outer loop */
313             velecsum        += velec;
314             vvdwsum         += vvdw;
315
316             fscal            = felec+fvdw;
317
318             /* Calculate temporary vectorial force */
319             tx               = fscal*dx00;
320             ty               = fscal*dy00;
321             tz               = fscal*dz00;
322
323             /* Update vectorial force */
324             fix0            += tx;
325             fiy0            += ty;
326             fiz0            += tz;
327             f[j_coord_offset+DIM*0+XX] -= tx;
328             f[j_coord_offset+DIM*0+YY] -= ty;
329             f[j_coord_offset+DIM*0+ZZ] -= tz;
330
331             }
332
333             /**************************
334              * CALCULATE INTERACTIONS *
335              **************************/
336
337             if (rsq01<rcutoff2)
338             {
339
340             r01              = rsq01*rinv01;
341
342             /* EWALD ELECTROSTATICS */
343
344             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
345             ewrt             = r01*ewtabscale;
346             ewitab           = ewrt;
347             eweps            = ewrt-ewitab;
348             ewitab           = 4*ewitab;
349             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
350             velec            = qq01*(rinv01-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
351             felec            = qq01*rinv01*(rinvsq01-felec);
352
353             d                = r01-rswitch;
354             d                = (d>0.0) ? d : 0.0;
355             d2               = d*d;
356             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
357
358             dsw              = d2*(swF2+d*(swF3+d*swF4));
359
360             /* Evaluate switch function */
361             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
362             felec            = felec*sw - rinv01*velec*dsw;
363             velec           *= sw;
364
365             /* Update potential sums from outer loop */
366             velecsum        += velec;
367
368             fscal            = felec;
369
370             /* Calculate temporary vectorial force */
371             tx               = fscal*dx01;
372             ty               = fscal*dy01;
373             tz               = fscal*dz01;
374
375             /* Update vectorial force */
376             fix0            += tx;
377             fiy0            += ty;
378             fiz0            += tz;
379             f[j_coord_offset+DIM*1+XX] -= tx;
380             f[j_coord_offset+DIM*1+YY] -= ty;
381             f[j_coord_offset+DIM*1+ZZ] -= tz;
382
383             }
384
385             /**************************
386              * CALCULATE INTERACTIONS *
387              **************************/
388
389             if (rsq02<rcutoff2)
390             {
391
392             r02              = rsq02*rinv02;
393
394             /* EWALD ELECTROSTATICS */
395
396             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
397             ewrt             = r02*ewtabscale;
398             ewitab           = ewrt;
399             eweps            = ewrt-ewitab;
400             ewitab           = 4*ewitab;
401             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
402             velec            = qq02*(rinv02-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
403             felec            = qq02*rinv02*(rinvsq02-felec);
404
405             d                = r02-rswitch;
406             d                = (d>0.0) ? d : 0.0;
407             d2               = d*d;
408             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
409
410             dsw              = d2*(swF2+d*(swF3+d*swF4));
411
412             /* Evaluate switch function */
413             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
414             felec            = felec*sw - rinv02*velec*dsw;
415             velec           *= sw;
416
417             /* Update potential sums from outer loop */
418             velecsum        += velec;
419
420             fscal            = felec;
421
422             /* Calculate temporary vectorial force */
423             tx               = fscal*dx02;
424             ty               = fscal*dy02;
425             tz               = fscal*dz02;
426
427             /* Update vectorial force */
428             fix0            += tx;
429             fiy0            += ty;
430             fiz0            += tz;
431             f[j_coord_offset+DIM*2+XX] -= tx;
432             f[j_coord_offset+DIM*2+YY] -= ty;
433             f[j_coord_offset+DIM*2+ZZ] -= tz;
434
435             }
436
437             /**************************
438              * CALCULATE INTERACTIONS *
439              **************************/
440
441             if (rsq10<rcutoff2)
442             {
443
444             r10              = rsq10*rinv10;
445
446             /* EWALD ELECTROSTATICS */
447
448             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
449             ewrt             = r10*ewtabscale;
450             ewitab           = ewrt;
451             eweps            = ewrt-ewitab;
452             ewitab           = 4*ewitab;
453             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
454             velec            = qq10*(rinv10-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
455             felec            = qq10*rinv10*(rinvsq10-felec);
456
457             d                = r10-rswitch;
458             d                = (d>0.0) ? d : 0.0;
459             d2               = d*d;
460             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
461
462             dsw              = d2*(swF2+d*(swF3+d*swF4));
463
464             /* Evaluate switch function */
465             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
466             felec            = felec*sw - rinv10*velec*dsw;
467             velec           *= sw;
468
469             /* Update potential sums from outer loop */
470             velecsum        += velec;
471
472             fscal            = felec;
473
474             /* Calculate temporary vectorial force */
475             tx               = fscal*dx10;
476             ty               = fscal*dy10;
477             tz               = fscal*dz10;
478
479             /* Update vectorial force */
480             fix1            += tx;
481             fiy1            += ty;
482             fiz1            += tz;
483             f[j_coord_offset+DIM*0+XX] -= tx;
484             f[j_coord_offset+DIM*0+YY] -= ty;
485             f[j_coord_offset+DIM*0+ZZ] -= tz;
486
487             }
488
489             /**************************
490              * CALCULATE INTERACTIONS *
491              **************************/
492
493             if (rsq11<rcutoff2)
494             {
495
496             r11              = rsq11*rinv11;
497
498             /* EWALD ELECTROSTATICS */
499
500             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
501             ewrt             = r11*ewtabscale;
502             ewitab           = ewrt;
503             eweps            = ewrt-ewitab;
504             ewitab           = 4*ewitab;
505             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
506             velec            = qq11*(rinv11-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
507             felec            = qq11*rinv11*(rinvsq11-felec);
508
509             d                = r11-rswitch;
510             d                = (d>0.0) ? d : 0.0;
511             d2               = d*d;
512             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
513
514             dsw              = d2*(swF2+d*(swF3+d*swF4));
515
516             /* Evaluate switch function */
517             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
518             felec            = felec*sw - rinv11*velec*dsw;
519             velec           *= sw;
520
521             /* Update potential sums from outer loop */
522             velecsum        += velec;
523
524             fscal            = felec;
525
526             /* Calculate temporary vectorial force */
527             tx               = fscal*dx11;
528             ty               = fscal*dy11;
529             tz               = fscal*dz11;
530
531             /* Update vectorial force */
532             fix1            += tx;
533             fiy1            += ty;
534             fiz1            += tz;
535             f[j_coord_offset+DIM*1+XX] -= tx;
536             f[j_coord_offset+DIM*1+YY] -= ty;
537             f[j_coord_offset+DIM*1+ZZ] -= tz;
538
539             }
540
541             /**************************
542              * CALCULATE INTERACTIONS *
543              **************************/
544
545             if (rsq12<rcutoff2)
546             {
547
548             r12              = rsq12*rinv12;
549
550             /* EWALD ELECTROSTATICS */
551
552             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
553             ewrt             = r12*ewtabscale;
554             ewitab           = ewrt;
555             eweps            = ewrt-ewitab;
556             ewitab           = 4*ewitab;
557             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
558             velec            = qq12*(rinv12-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
559             felec            = qq12*rinv12*(rinvsq12-felec);
560
561             d                = r12-rswitch;
562             d                = (d>0.0) ? d : 0.0;
563             d2               = d*d;
564             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
565
566             dsw              = d2*(swF2+d*(swF3+d*swF4));
567
568             /* Evaluate switch function */
569             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
570             felec            = felec*sw - rinv12*velec*dsw;
571             velec           *= sw;
572
573             /* Update potential sums from outer loop */
574             velecsum        += velec;
575
576             fscal            = felec;
577
578             /* Calculate temporary vectorial force */
579             tx               = fscal*dx12;
580             ty               = fscal*dy12;
581             tz               = fscal*dz12;
582
583             /* Update vectorial force */
584             fix1            += tx;
585             fiy1            += ty;
586             fiz1            += tz;
587             f[j_coord_offset+DIM*2+XX] -= tx;
588             f[j_coord_offset+DIM*2+YY] -= ty;
589             f[j_coord_offset+DIM*2+ZZ] -= tz;
590
591             }
592
593             /**************************
594              * CALCULATE INTERACTIONS *
595              **************************/
596
597             if (rsq20<rcutoff2)
598             {
599
600             r20              = rsq20*rinv20;
601
602             /* EWALD ELECTROSTATICS */
603
604             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
605             ewrt             = r20*ewtabscale;
606             ewitab           = ewrt;
607             eweps            = ewrt-ewitab;
608             ewitab           = 4*ewitab;
609             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
610             velec            = qq20*(rinv20-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
611             felec            = qq20*rinv20*(rinvsq20-felec);
612
613             d                = r20-rswitch;
614             d                = (d>0.0) ? d : 0.0;
615             d2               = d*d;
616             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
617
618             dsw              = d2*(swF2+d*(swF3+d*swF4));
619
620             /* Evaluate switch function */
621             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
622             felec            = felec*sw - rinv20*velec*dsw;
623             velec           *= sw;
624
625             /* Update potential sums from outer loop */
626             velecsum        += velec;
627
628             fscal            = felec;
629
630             /* Calculate temporary vectorial force */
631             tx               = fscal*dx20;
632             ty               = fscal*dy20;
633             tz               = fscal*dz20;
634
635             /* Update vectorial force */
636             fix2            += tx;
637             fiy2            += ty;
638             fiz2            += tz;
639             f[j_coord_offset+DIM*0+XX] -= tx;
640             f[j_coord_offset+DIM*0+YY] -= ty;
641             f[j_coord_offset+DIM*0+ZZ] -= tz;
642
643             }
644
645             /**************************
646              * CALCULATE INTERACTIONS *
647              **************************/
648
649             if (rsq21<rcutoff2)
650             {
651
652             r21              = rsq21*rinv21;
653
654             /* EWALD ELECTROSTATICS */
655
656             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
657             ewrt             = r21*ewtabscale;
658             ewitab           = ewrt;
659             eweps            = ewrt-ewitab;
660             ewitab           = 4*ewitab;
661             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
662             velec            = qq21*(rinv21-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
663             felec            = qq21*rinv21*(rinvsq21-felec);
664
665             d                = r21-rswitch;
666             d                = (d>0.0) ? d : 0.0;
667             d2               = d*d;
668             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
669
670             dsw              = d2*(swF2+d*(swF3+d*swF4));
671
672             /* Evaluate switch function */
673             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
674             felec            = felec*sw - rinv21*velec*dsw;
675             velec           *= sw;
676
677             /* Update potential sums from outer loop */
678             velecsum        += velec;
679
680             fscal            = felec;
681
682             /* Calculate temporary vectorial force */
683             tx               = fscal*dx21;
684             ty               = fscal*dy21;
685             tz               = fscal*dz21;
686
687             /* Update vectorial force */
688             fix2            += tx;
689             fiy2            += ty;
690             fiz2            += tz;
691             f[j_coord_offset+DIM*1+XX] -= tx;
692             f[j_coord_offset+DIM*1+YY] -= ty;
693             f[j_coord_offset+DIM*1+ZZ] -= tz;
694
695             }
696
697             /**************************
698              * CALCULATE INTERACTIONS *
699              **************************/
700
701             if (rsq22<rcutoff2)
702             {
703
704             r22              = rsq22*rinv22;
705
706             /* EWALD ELECTROSTATICS */
707
708             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
709             ewrt             = r22*ewtabscale;
710             ewitab           = ewrt;
711             eweps            = ewrt-ewitab;
712             ewitab           = 4*ewitab;
713             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
714             velec            = qq22*(rinv22-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
715             felec            = qq22*rinv22*(rinvsq22-felec);
716
717             d                = r22-rswitch;
718             d                = (d>0.0) ? d : 0.0;
719             d2               = d*d;
720             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
721
722             dsw              = d2*(swF2+d*(swF3+d*swF4));
723
724             /* Evaluate switch function */
725             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
726             felec            = felec*sw - rinv22*velec*dsw;
727             velec           *= sw;
728
729             /* Update potential sums from outer loop */
730             velecsum        += velec;
731
732             fscal            = felec;
733
734             /* Calculate temporary vectorial force */
735             tx               = fscal*dx22;
736             ty               = fscal*dy22;
737             tz               = fscal*dz22;
738
739             /* Update vectorial force */
740             fix2            += tx;
741             fiy2            += ty;
742             fiz2            += tz;
743             f[j_coord_offset+DIM*2+XX] -= tx;
744             f[j_coord_offset+DIM*2+YY] -= ty;
745             f[j_coord_offset+DIM*2+ZZ] -= tz;
746
747             }
748
749             /* Inner loop uses 538 flops */
750         }
751         /* End of innermost loop */
752
753         tx = ty = tz = 0;
754         f[i_coord_offset+DIM*0+XX] += fix0;
755         f[i_coord_offset+DIM*0+YY] += fiy0;
756         f[i_coord_offset+DIM*0+ZZ] += fiz0;
757         tx                         += fix0;
758         ty                         += fiy0;
759         tz                         += fiz0;
760         f[i_coord_offset+DIM*1+XX] += fix1;
761         f[i_coord_offset+DIM*1+YY] += fiy1;
762         f[i_coord_offset+DIM*1+ZZ] += fiz1;
763         tx                         += fix1;
764         ty                         += fiy1;
765         tz                         += fiz1;
766         f[i_coord_offset+DIM*2+XX] += fix2;
767         f[i_coord_offset+DIM*2+YY] += fiy2;
768         f[i_coord_offset+DIM*2+ZZ] += fiz2;
769         tx                         += fix2;
770         ty                         += fiy2;
771         tz                         += fiz2;
772         fshift[i_shift_offset+XX]  += tx;
773         fshift[i_shift_offset+YY]  += ty;
774         fshift[i_shift_offset+ZZ]  += tz;
775
776         ggid                        = gid[iidx];
777         /* Update potential energies */
778         kernel_data->energygrp_elec[ggid] += velecsum;
779         kernel_data->energygrp_vdw[ggid] += vvdwsum;
780
781         /* Increment number of inner iterations */
782         inneriter                  += j_index_end - j_index_start;
783
784         /* Outer loop uses 32 flops */
785     }
786
787     /* Increment number of outer iterations */
788     outeriter        += nri;
789
790     /* Update outer/inner flops */
791
792     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_VF,outeriter*32 + inneriter*538);
793 }
794 /*
795  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSw_VdwLJSw_GeomW3W3_F_c
796  * Electrostatics interaction: Ewald
797  * VdW interaction:            LennardJones
798  * Geometry:                   Water3-Water3
799  * Calculate force/pot:        Force
800  */
801 void
802 nb_kernel_ElecEwSw_VdwLJSw_GeomW3W3_F_c
803                     (t_nblist * gmx_restrict                nlist,
804                      rvec * gmx_restrict                    xx,
805                      rvec * gmx_restrict                    ff,
806                      t_forcerec * gmx_restrict              fr,
807                      t_mdatoms * gmx_restrict               mdatoms,
808                      nb_kernel_data_t * gmx_restrict        kernel_data,
809                      t_nrnb * gmx_restrict                  nrnb)
810 {
811     int              i_shift_offset,i_coord_offset,j_coord_offset;
812     int              j_index_start,j_index_end;
813     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
814     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
815     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
816     real             *shiftvec,*fshift,*x,*f;
817     int              vdwioffset0;
818     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
819     int              vdwioffset1;
820     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
821     int              vdwioffset2;
822     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
823     int              vdwjidx0;
824     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
825     int              vdwjidx1;
826     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
827     int              vdwjidx2;
828     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
829     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
830     real             dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01,cexp1_01,cexp2_01;
831     real             dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02,cexp1_02,cexp2_02;
832     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
833     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
834     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
835     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
836     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
837     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
838     real             velec,felec,velecsum,facel,crf,krf,krf2;
839     real             *charge;
840     int              nvdwtype;
841     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
842     int              *vdwtype;
843     real             *vdwparam;
844     int              ewitab;
845     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
846     real             *ewtab;
847     real             rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
848
849     x                = xx[0];
850     f                = ff[0];
851
852     nri              = nlist->nri;
853     iinr             = nlist->iinr;
854     jindex           = nlist->jindex;
855     jjnr             = nlist->jjnr;
856     shiftidx         = nlist->shift;
857     gid              = nlist->gid;
858     shiftvec         = fr->shift_vec[0];
859     fshift           = fr->fshift[0];
860     facel            = fr->epsfac;
861     charge           = mdatoms->chargeA;
862     nvdwtype         = fr->ntype;
863     vdwparam         = fr->nbfp;
864     vdwtype          = mdatoms->typeA;
865
866     sh_ewald         = fr->ic->sh_ewald;
867     ewtab            = fr->ic->tabq_coul_FDV0;
868     ewtabscale       = fr->ic->tabq_scale;
869     ewtabhalfspace   = 0.5/ewtabscale;
870
871     /* Setup water-specific parameters */
872     inr              = nlist->iinr[0];
873     iq0              = facel*charge[inr+0];
874     iq1              = facel*charge[inr+1];
875     iq2              = facel*charge[inr+2];
876     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
877
878     jq0              = charge[inr+0];
879     jq1              = charge[inr+1];
880     jq2              = charge[inr+2];
881     vdwjidx0         = 2*vdwtype[inr+0];
882     qq00             = iq0*jq0;
883     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
884     c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
885     qq01             = iq0*jq1;
886     qq02             = iq0*jq2;
887     qq10             = iq1*jq0;
888     qq11             = iq1*jq1;
889     qq12             = iq1*jq2;
890     qq20             = iq2*jq0;
891     qq21             = iq2*jq1;
892     qq22             = iq2*jq2;
893
894     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
895     rcutoff          = fr->rcoulomb;
896     rcutoff2         = rcutoff*rcutoff;
897
898     rswitch          = fr->rcoulomb_switch;
899     /* Setup switch parameters */
900     d                = rcutoff-rswitch;
901     swV3             = -10.0/(d*d*d);
902     swV4             =  15.0/(d*d*d*d);
903     swV5             =  -6.0/(d*d*d*d*d);
904     swF2             = -30.0/(d*d*d);
905     swF3             =  60.0/(d*d*d*d);
906     swF4             = -30.0/(d*d*d*d*d);
907
908     outeriter        = 0;
909     inneriter        = 0;
910
911     /* Start outer loop over neighborlists */
912     for(iidx=0; iidx<nri; iidx++)
913     {
914         /* Load shift vector for this list */
915         i_shift_offset   = DIM*shiftidx[iidx];
916         shX              = shiftvec[i_shift_offset+XX];
917         shY              = shiftvec[i_shift_offset+YY];
918         shZ              = shiftvec[i_shift_offset+ZZ];
919
920         /* Load limits for loop over neighbors */
921         j_index_start    = jindex[iidx];
922         j_index_end      = jindex[iidx+1];
923
924         /* Get outer coordinate index */
925         inr              = iinr[iidx];
926         i_coord_offset   = DIM*inr;
927
928         /* Load i particle coords and add shift vector */
929         ix0              = shX + x[i_coord_offset+DIM*0+XX];
930         iy0              = shY + x[i_coord_offset+DIM*0+YY];
931         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
932         ix1              = shX + x[i_coord_offset+DIM*1+XX];
933         iy1              = shY + x[i_coord_offset+DIM*1+YY];
934         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
935         ix2              = shX + x[i_coord_offset+DIM*2+XX];
936         iy2              = shY + x[i_coord_offset+DIM*2+YY];
937         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
938
939         fix0             = 0.0;
940         fiy0             = 0.0;
941         fiz0             = 0.0;
942         fix1             = 0.0;
943         fiy1             = 0.0;
944         fiz1             = 0.0;
945         fix2             = 0.0;
946         fiy2             = 0.0;
947         fiz2             = 0.0;
948
949         /* Start inner kernel loop */
950         for(jidx=j_index_start; jidx<j_index_end; jidx++)
951         {
952             /* Get j neighbor index, and coordinate index */
953             jnr              = jjnr[jidx];
954             j_coord_offset   = DIM*jnr;
955
956             /* load j atom coordinates */
957             jx0              = x[j_coord_offset+DIM*0+XX];
958             jy0              = x[j_coord_offset+DIM*0+YY];
959             jz0              = x[j_coord_offset+DIM*0+ZZ];
960             jx1              = x[j_coord_offset+DIM*1+XX];
961             jy1              = x[j_coord_offset+DIM*1+YY];
962             jz1              = x[j_coord_offset+DIM*1+ZZ];
963             jx2              = x[j_coord_offset+DIM*2+XX];
964             jy2              = x[j_coord_offset+DIM*2+YY];
965             jz2              = x[j_coord_offset+DIM*2+ZZ];
966
967             /* Calculate displacement vector */
968             dx00             = ix0 - jx0;
969             dy00             = iy0 - jy0;
970             dz00             = iz0 - jz0;
971             dx01             = ix0 - jx1;
972             dy01             = iy0 - jy1;
973             dz01             = iz0 - jz1;
974             dx02             = ix0 - jx2;
975             dy02             = iy0 - jy2;
976             dz02             = iz0 - jz2;
977             dx10             = ix1 - jx0;
978             dy10             = iy1 - jy0;
979             dz10             = iz1 - jz0;
980             dx11             = ix1 - jx1;
981             dy11             = iy1 - jy1;
982             dz11             = iz1 - jz1;
983             dx12             = ix1 - jx2;
984             dy12             = iy1 - jy2;
985             dz12             = iz1 - jz2;
986             dx20             = ix2 - jx0;
987             dy20             = iy2 - jy0;
988             dz20             = iz2 - jz0;
989             dx21             = ix2 - jx1;
990             dy21             = iy2 - jy1;
991             dz21             = iz2 - jz1;
992             dx22             = ix2 - jx2;
993             dy22             = iy2 - jy2;
994             dz22             = iz2 - jz2;
995
996             /* Calculate squared distance and things based on it */
997             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
998             rsq01            = dx01*dx01+dy01*dy01+dz01*dz01;
999             rsq02            = dx02*dx02+dy02*dy02+dz02*dz02;
1000             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
1001             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
1002             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
1003             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
1004             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
1005             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
1006
1007             rinv00           = gmx_invsqrt(rsq00);
1008             rinv01           = gmx_invsqrt(rsq01);
1009             rinv02           = gmx_invsqrt(rsq02);
1010             rinv10           = gmx_invsqrt(rsq10);
1011             rinv11           = gmx_invsqrt(rsq11);
1012             rinv12           = gmx_invsqrt(rsq12);
1013             rinv20           = gmx_invsqrt(rsq20);
1014             rinv21           = gmx_invsqrt(rsq21);
1015             rinv22           = gmx_invsqrt(rsq22);
1016
1017             rinvsq00         = rinv00*rinv00;
1018             rinvsq01         = rinv01*rinv01;
1019             rinvsq02         = rinv02*rinv02;
1020             rinvsq10         = rinv10*rinv10;
1021             rinvsq11         = rinv11*rinv11;
1022             rinvsq12         = rinv12*rinv12;
1023             rinvsq20         = rinv20*rinv20;
1024             rinvsq21         = rinv21*rinv21;
1025             rinvsq22         = rinv22*rinv22;
1026
1027             /**************************
1028              * CALCULATE INTERACTIONS *
1029              **************************/
1030
1031             if (rsq00<rcutoff2)
1032             {
1033
1034             r00              = rsq00*rinv00;
1035
1036             /* EWALD ELECTROSTATICS */
1037
1038             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1039             ewrt             = r00*ewtabscale;
1040             ewitab           = ewrt;
1041             eweps            = ewrt-ewitab;
1042             ewitab           = 4*ewitab;
1043             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1044             velec            = qq00*(rinv00-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1045             felec            = qq00*rinv00*(rinvsq00-felec);
1046
1047             /* LENNARD-JONES DISPERSION/REPULSION */
1048
1049             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
1050             vvdw6            = c6_00*rinvsix;
1051             vvdw12           = c12_00*rinvsix*rinvsix;
1052             vvdw             = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
1053             fvdw             = (vvdw12-vvdw6)*rinvsq00;
1054
1055             d                = r00-rswitch;
1056             d                = (d>0.0) ? d : 0.0;
1057             d2               = d*d;
1058             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1059
1060             dsw              = d2*(swF2+d*(swF3+d*swF4));
1061
1062             /* Evaluate switch function */
1063             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1064             felec            = felec*sw - rinv00*velec*dsw;
1065             fvdw             = fvdw*sw - rinv00*vvdw*dsw;
1066
1067             fscal            = felec+fvdw;
1068
1069             /* Calculate temporary vectorial force */
1070             tx               = fscal*dx00;
1071             ty               = fscal*dy00;
1072             tz               = fscal*dz00;
1073
1074             /* Update vectorial force */
1075             fix0            += tx;
1076             fiy0            += ty;
1077             fiz0            += tz;
1078             f[j_coord_offset+DIM*0+XX] -= tx;
1079             f[j_coord_offset+DIM*0+YY] -= ty;
1080             f[j_coord_offset+DIM*0+ZZ] -= tz;
1081
1082             }
1083
1084             /**************************
1085              * CALCULATE INTERACTIONS *
1086              **************************/
1087
1088             if (rsq01<rcutoff2)
1089             {
1090
1091             r01              = rsq01*rinv01;
1092
1093             /* EWALD ELECTROSTATICS */
1094
1095             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1096             ewrt             = r01*ewtabscale;
1097             ewitab           = ewrt;
1098             eweps            = ewrt-ewitab;
1099             ewitab           = 4*ewitab;
1100             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1101             velec            = qq01*(rinv01-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1102             felec            = qq01*rinv01*(rinvsq01-felec);
1103
1104             d                = r01-rswitch;
1105             d                = (d>0.0) ? d : 0.0;
1106             d2               = d*d;
1107             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1108
1109             dsw              = d2*(swF2+d*(swF3+d*swF4));
1110
1111             /* Evaluate switch function */
1112             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1113             felec            = felec*sw - rinv01*velec*dsw;
1114
1115             fscal            = felec;
1116
1117             /* Calculate temporary vectorial force */
1118             tx               = fscal*dx01;
1119             ty               = fscal*dy01;
1120             tz               = fscal*dz01;
1121
1122             /* Update vectorial force */
1123             fix0            += tx;
1124             fiy0            += ty;
1125             fiz0            += tz;
1126             f[j_coord_offset+DIM*1+XX] -= tx;
1127             f[j_coord_offset+DIM*1+YY] -= ty;
1128             f[j_coord_offset+DIM*1+ZZ] -= tz;
1129
1130             }
1131
1132             /**************************
1133              * CALCULATE INTERACTIONS *
1134              **************************/
1135
1136             if (rsq02<rcutoff2)
1137             {
1138
1139             r02              = rsq02*rinv02;
1140
1141             /* EWALD ELECTROSTATICS */
1142
1143             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1144             ewrt             = r02*ewtabscale;
1145             ewitab           = ewrt;
1146             eweps            = ewrt-ewitab;
1147             ewitab           = 4*ewitab;
1148             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1149             velec            = qq02*(rinv02-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1150             felec            = qq02*rinv02*(rinvsq02-felec);
1151
1152             d                = r02-rswitch;
1153             d                = (d>0.0) ? d : 0.0;
1154             d2               = d*d;
1155             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1156
1157             dsw              = d2*(swF2+d*(swF3+d*swF4));
1158
1159             /* Evaluate switch function */
1160             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1161             felec            = felec*sw - rinv02*velec*dsw;
1162
1163             fscal            = felec;
1164
1165             /* Calculate temporary vectorial force */
1166             tx               = fscal*dx02;
1167             ty               = fscal*dy02;
1168             tz               = fscal*dz02;
1169
1170             /* Update vectorial force */
1171             fix0            += tx;
1172             fiy0            += ty;
1173             fiz0            += tz;
1174             f[j_coord_offset+DIM*2+XX] -= tx;
1175             f[j_coord_offset+DIM*2+YY] -= ty;
1176             f[j_coord_offset+DIM*2+ZZ] -= tz;
1177
1178             }
1179
1180             /**************************
1181              * CALCULATE INTERACTIONS *
1182              **************************/
1183
1184             if (rsq10<rcutoff2)
1185             {
1186
1187             r10              = rsq10*rinv10;
1188
1189             /* EWALD ELECTROSTATICS */
1190
1191             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1192             ewrt             = r10*ewtabscale;
1193             ewitab           = ewrt;
1194             eweps            = ewrt-ewitab;
1195             ewitab           = 4*ewitab;
1196             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1197             velec            = qq10*(rinv10-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1198             felec            = qq10*rinv10*(rinvsq10-felec);
1199
1200             d                = r10-rswitch;
1201             d                = (d>0.0) ? d : 0.0;
1202             d2               = d*d;
1203             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1204
1205             dsw              = d2*(swF2+d*(swF3+d*swF4));
1206
1207             /* Evaluate switch function */
1208             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1209             felec            = felec*sw - rinv10*velec*dsw;
1210
1211             fscal            = felec;
1212
1213             /* Calculate temporary vectorial force */
1214             tx               = fscal*dx10;
1215             ty               = fscal*dy10;
1216             tz               = fscal*dz10;
1217
1218             /* Update vectorial force */
1219             fix1            += tx;
1220             fiy1            += ty;
1221             fiz1            += tz;
1222             f[j_coord_offset+DIM*0+XX] -= tx;
1223             f[j_coord_offset+DIM*0+YY] -= ty;
1224             f[j_coord_offset+DIM*0+ZZ] -= tz;
1225
1226             }
1227
1228             /**************************
1229              * CALCULATE INTERACTIONS *
1230              **************************/
1231
1232             if (rsq11<rcutoff2)
1233             {
1234
1235             r11              = rsq11*rinv11;
1236
1237             /* EWALD ELECTROSTATICS */
1238
1239             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1240             ewrt             = r11*ewtabscale;
1241             ewitab           = ewrt;
1242             eweps            = ewrt-ewitab;
1243             ewitab           = 4*ewitab;
1244             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1245             velec            = qq11*(rinv11-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1246             felec            = qq11*rinv11*(rinvsq11-felec);
1247
1248             d                = r11-rswitch;
1249             d                = (d>0.0) ? d : 0.0;
1250             d2               = d*d;
1251             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1252
1253             dsw              = d2*(swF2+d*(swF3+d*swF4));
1254
1255             /* Evaluate switch function */
1256             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1257             felec            = felec*sw - rinv11*velec*dsw;
1258
1259             fscal            = felec;
1260
1261             /* Calculate temporary vectorial force */
1262             tx               = fscal*dx11;
1263             ty               = fscal*dy11;
1264             tz               = fscal*dz11;
1265
1266             /* Update vectorial force */
1267             fix1            += tx;
1268             fiy1            += ty;
1269             fiz1            += tz;
1270             f[j_coord_offset+DIM*1+XX] -= tx;
1271             f[j_coord_offset+DIM*1+YY] -= ty;
1272             f[j_coord_offset+DIM*1+ZZ] -= tz;
1273
1274             }
1275
1276             /**************************
1277              * CALCULATE INTERACTIONS *
1278              **************************/
1279
1280             if (rsq12<rcutoff2)
1281             {
1282
1283             r12              = rsq12*rinv12;
1284
1285             /* EWALD ELECTROSTATICS */
1286
1287             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1288             ewrt             = r12*ewtabscale;
1289             ewitab           = ewrt;
1290             eweps            = ewrt-ewitab;
1291             ewitab           = 4*ewitab;
1292             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1293             velec            = qq12*(rinv12-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1294             felec            = qq12*rinv12*(rinvsq12-felec);
1295
1296             d                = r12-rswitch;
1297             d                = (d>0.0) ? d : 0.0;
1298             d2               = d*d;
1299             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1300
1301             dsw              = d2*(swF2+d*(swF3+d*swF4));
1302
1303             /* Evaluate switch function */
1304             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1305             felec            = felec*sw - rinv12*velec*dsw;
1306
1307             fscal            = felec;
1308
1309             /* Calculate temporary vectorial force */
1310             tx               = fscal*dx12;
1311             ty               = fscal*dy12;
1312             tz               = fscal*dz12;
1313
1314             /* Update vectorial force */
1315             fix1            += tx;
1316             fiy1            += ty;
1317             fiz1            += tz;
1318             f[j_coord_offset+DIM*2+XX] -= tx;
1319             f[j_coord_offset+DIM*2+YY] -= ty;
1320             f[j_coord_offset+DIM*2+ZZ] -= tz;
1321
1322             }
1323
1324             /**************************
1325              * CALCULATE INTERACTIONS *
1326              **************************/
1327
1328             if (rsq20<rcutoff2)
1329             {
1330
1331             r20              = rsq20*rinv20;
1332
1333             /* EWALD ELECTROSTATICS */
1334
1335             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1336             ewrt             = r20*ewtabscale;
1337             ewitab           = ewrt;
1338             eweps            = ewrt-ewitab;
1339             ewitab           = 4*ewitab;
1340             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1341             velec            = qq20*(rinv20-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1342             felec            = qq20*rinv20*(rinvsq20-felec);
1343
1344             d                = r20-rswitch;
1345             d                = (d>0.0) ? d : 0.0;
1346             d2               = d*d;
1347             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1348
1349             dsw              = d2*(swF2+d*(swF3+d*swF4));
1350
1351             /* Evaluate switch function */
1352             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1353             felec            = felec*sw - rinv20*velec*dsw;
1354
1355             fscal            = felec;
1356
1357             /* Calculate temporary vectorial force */
1358             tx               = fscal*dx20;
1359             ty               = fscal*dy20;
1360             tz               = fscal*dz20;
1361
1362             /* Update vectorial force */
1363             fix2            += tx;
1364             fiy2            += ty;
1365             fiz2            += tz;
1366             f[j_coord_offset+DIM*0+XX] -= tx;
1367             f[j_coord_offset+DIM*0+YY] -= ty;
1368             f[j_coord_offset+DIM*0+ZZ] -= tz;
1369
1370             }
1371
1372             /**************************
1373              * CALCULATE INTERACTIONS *
1374              **************************/
1375
1376             if (rsq21<rcutoff2)
1377             {
1378
1379             r21              = rsq21*rinv21;
1380
1381             /* EWALD ELECTROSTATICS */
1382
1383             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1384             ewrt             = r21*ewtabscale;
1385             ewitab           = ewrt;
1386             eweps            = ewrt-ewitab;
1387             ewitab           = 4*ewitab;
1388             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1389             velec            = qq21*(rinv21-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1390             felec            = qq21*rinv21*(rinvsq21-felec);
1391
1392             d                = r21-rswitch;
1393             d                = (d>0.0) ? d : 0.0;
1394             d2               = d*d;
1395             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1396
1397             dsw              = d2*(swF2+d*(swF3+d*swF4));
1398
1399             /* Evaluate switch function */
1400             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1401             felec            = felec*sw - rinv21*velec*dsw;
1402
1403             fscal            = felec;
1404
1405             /* Calculate temporary vectorial force */
1406             tx               = fscal*dx21;
1407             ty               = fscal*dy21;
1408             tz               = fscal*dz21;
1409
1410             /* Update vectorial force */
1411             fix2            += tx;
1412             fiy2            += ty;
1413             fiz2            += tz;
1414             f[j_coord_offset+DIM*1+XX] -= tx;
1415             f[j_coord_offset+DIM*1+YY] -= ty;
1416             f[j_coord_offset+DIM*1+ZZ] -= tz;
1417
1418             }
1419
1420             /**************************
1421              * CALCULATE INTERACTIONS *
1422              **************************/
1423
1424             if (rsq22<rcutoff2)
1425             {
1426
1427             r22              = rsq22*rinv22;
1428
1429             /* EWALD ELECTROSTATICS */
1430
1431             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1432             ewrt             = r22*ewtabscale;
1433             ewitab           = ewrt;
1434             eweps            = ewrt-ewitab;
1435             ewitab           = 4*ewitab;
1436             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1437             velec            = qq22*(rinv22-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1438             felec            = qq22*rinv22*(rinvsq22-felec);
1439
1440             d                = r22-rswitch;
1441             d                = (d>0.0) ? d : 0.0;
1442             d2               = d*d;
1443             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1444
1445             dsw              = d2*(swF2+d*(swF3+d*swF4));
1446
1447             /* Evaluate switch function */
1448             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1449             felec            = felec*sw - rinv22*velec*dsw;
1450
1451             fscal            = felec;
1452
1453             /* Calculate temporary vectorial force */
1454             tx               = fscal*dx22;
1455             ty               = fscal*dy22;
1456             tz               = fscal*dz22;
1457
1458             /* Update vectorial force */
1459             fix2            += tx;
1460             fiy2            += ty;
1461             fiz2            += tz;
1462             f[j_coord_offset+DIM*2+XX] -= tx;
1463             f[j_coord_offset+DIM*2+YY] -= ty;
1464             f[j_coord_offset+DIM*2+ZZ] -= tz;
1465
1466             }
1467
1468             /* Inner loop uses 518 flops */
1469         }
1470         /* End of innermost loop */
1471
1472         tx = ty = tz = 0;
1473         f[i_coord_offset+DIM*0+XX] += fix0;
1474         f[i_coord_offset+DIM*0+YY] += fiy0;
1475         f[i_coord_offset+DIM*0+ZZ] += fiz0;
1476         tx                         += fix0;
1477         ty                         += fiy0;
1478         tz                         += fiz0;
1479         f[i_coord_offset+DIM*1+XX] += fix1;
1480         f[i_coord_offset+DIM*1+YY] += fiy1;
1481         f[i_coord_offset+DIM*1+ZZ] += fiz1;
1482         tx                         += fix1;
1483         ty                         += fiy1;
1484         tz                         += fiz1;
1485         f[i_coord_offset+DIM*2+XX] += fix2;
1486         f[i_coord_offset+DIM*2+YY] += fiy2;
1487         f[i_coord_offset+DIM*2+ZZ] += fiz2;
1488         tx                         += fix2;
1489         ty                         += fiy2;
1490         tz                         += fiz2;
1491         fshift[i_shift_offset+XX]  += tx;
1492         fshift[i_shift_offset+YY]  += ty;
1493         fshift[i_shift_offset+ZZ]  += tz;
1494
1495         /* Increment number of inner iterations */
1496         inneriter                  += j_index_end - j_index_start;
1497
1498         /* Outer loop uses 30 flops */
1499     }
1500
1501     /* Increment number of outer iterations */
1502     outeriter        += nri;
1503
1504     /* Update outer/inner flops */
1505
1506     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_F,outeriter*30 + inneriter*518);
1507 }