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