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