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