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