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