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