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