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