Remove no-inline-max-size and suppress remark
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecEw_VdwLJEw_GeomW3W3_c.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS c kernel generator.
37  */
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "types/simple.h"
46 #include "vec.h"
47 #include "nrnb.h"
48
49 /*
50  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwLJEw_GeomW3W3_VF_c
51  * Electrostatics interaction: Ewald
52  * VdW interaction:            LJEwald
53  * Geometry:                   Water3-Water3
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecEw_VdwLJEw_GeomW3W3_VF_c
58                     (t_nblist                    * gmx_restrict       nlist,
59                      rvec                        * gmx_restrict          xx,
60                      rvec                        * gmx_restrict          ff,
61                      t_forcerec                  * gmx_restrict          fr,
62                      t_mdatoms                   * gmx_restrict     mdatoms,
63                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64                      t_nrnb                      * gmx_restrict        nrnb)
65 {
66     int              i_shift_offset,i_coord_offset,j_coord_offset;
67     int              j_index_start,j_index_end;
68     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
69     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
70     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
71     real             *shiftvec,*fshift,*x,*f;
72     int              vdwioffset0;
73     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
74     int              vdwioffset1;
75     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
76     int              vdwioffset2;
77     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
78     int              vdwjidx0;
79     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
80     int              vdwjidx1;
81     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
82     int              vdwjidx2;
83     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
84     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
85     real             dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01,cexp1_01,cexp2_01;
86     real             dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02,cexp1_02,cexp2_02;
87     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
88     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
89     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
90     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
91     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
92     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
93     real             velec,felec,velecsum,facel,crf,krf,krf2;
94     real             *charge;
95     int              nvdwtype;
96     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
97     int              *vdwtype;
98     real             *vdwparam;
99     real             c6grid_00;
100     real             c6grid_01;
101     real             c6grid_02;
102     real             c6grid_10;
103     real             c6grid_11;
104     real             c6grid_12;
105     real             c6grid_20;
106     real             c6grid_21;
107     real             c6grid_22;
108     real             ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,sh_lj_ewald;
109     real             *vdwgridparam;
110     int              ewitab;
111     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
112     real             *ewtab;
113
114     x                = xx[0];
115     f                = ff[0];
116
117     nri              = nlist->nri;
118     iinr             = nlist->iinr;
119     jindex           = nlist->jindex;
120     jjnr             = nlist->jjnr;
121     shiftidx         = nlist->shift;
122     gid              = nlist->gid;
123     shiftvec         = fr->shift_vec[0];
124     fshift           = fr->fshift[0];
125     facel            = fr->epsfac;
126     charge           = mdatoms->chargeA;
127     nvdwtype         = fr->ntype;
128     vdwparam         = fr->nbfp;
129     vdwtype          = mdatoms->typeA;
130     vdwgridparam     = fr->ljpme_c6grid;
131     ewclj            = fr->ewaldcoeff_lj;
132     sh_lj_ewald      = fr->ic->sh_lj_ewald;
133     ewclj2           = ewclj*ewclj;
134     ewclj6           = ewclj2*ewclj2*ewclj2;
135
136     sh_ewald         = fr->ic->sh_ewald;
137     ewtab            = fr->ic->tabq_coul_FDV0;
138     ewtabscale       = fr->ic->tabq_scale;
139     ewtabhalfspace   = 0.5/ewtabscale;
140
141     /* Setup water-specific parameters */
142     inr              = nlist->iinr[0];
143     iq0              = facel*charge[inr+0];
144     iq1              = facel*charge[inr+1];
145     iq2              = facel*charge[inr+2];
146     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
147
148     jq0              = charge[inr+0];
149     jq1              = charge[inr+1];
150     jq2              = charge[inr+2];
151     vdwjidx0         = 2*vdwtype[inr+0];
152     qq00             = iq0*jq0;
153     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
154     c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
155     c6grid_00        = vdwgridparam[vdwioffset0+vdwjidx0];
156     qq01             = iq0*jq1;
157     qq02             = iq0*jq2;
158     qq10             = iq1*jq0;
159     qq11             = iq1*jq1;
160     qq12             = iq1*jq2;
161     qq20             = iq2*jq0;
162     qq21             = iq2*jq1;
163     qq22             = iq2*jq2;
164
165     outeriter        = 0;
166     inneriter        = 0;
167
168     /* Start outer loop over neighborlists */
169     for(iidx=0; iidx<nri; iidx++)
170     {
171         /* Load shift vector for this list */
172         i_shift_offset   = DIM*shiftidx[iidx];
173         shX              = shiftvec[i_shift_offset+XX];
174         shY              = shiftvec[i_shift_offset+YY];
175         shZ              = shiftvec[i_shift_offset+ZZ];
176
177         /* Load limits for loop over neighbors */
178         j_index_start    = jindex[iidx];
179         j_index_end      = jindex[iidx+1];
180
181         /* Get outer coordinate index */
182         inr              = iinr[iidx];
183         i_coord_offset   = DIM*inr;
184
185         /* Load i particle coords and add shift vector */
186         ix0              = shX + x[i_coord_offset+DIM*0+XX];
187         iy0              = shY + x[i_coord_offset+DIM*0+YY];
188         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
189         ix1              = shX + x[i_coord_offset+DIM*1+XX];
190         iy1              = shY + x[i_coord_offset+DIM*1+YY];
191         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
192         ix2              = shX + x[i_coord_offset+DIM*2+XX];
193         iy2              = shY + x[i_coord_offset+DIM*2+YY];
194         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
195
196         fix0             = 0.0;
197         fiy0             = 0.0;
198         fiz0             = 0.0;
199         fix1             = 0.0;
200         fiy1             = 0.0;
201         fiz1             = 0.0;
202         fix2             = 0.0;
203         fiy2             = 0.0;
204         fiz2             = 0.0;
205
206         /* Reset potential sums */
207         velecsum         = 0.0;
208         vvdwsum          = 0.0;
209
210         /* Start inner kernel loop */
211         for(jidx=j_index_start; jidx<j_index_end; jidx++)
212         {
213             /* Get j neighbor index, and coordinate index */
214             jnr              = jjnr[jidx];
215             j_coord_offset   = DIM*jnr;
216
217             /* load j atom coordinates */
218             jx0              = x[j_coord_offset+DIM*0+XX];
219             jy0              = x[j_coord_offset+DIM*0+YY];
220             jz0              = x[j_coord_offset+DIM*0+ZZ];
221             jx1              = x[j_coord_offset+DIM*1+XX];
222             jy1              = x[j_coord_offset+DIM*1+YY];
223             jz1              = x[j_coord_offset+DIM*1+ZZ];
224             jx2              = x[j_coord_offset+DIM*2+XX];
225             jy2              = x[j_coord_offset+DIM*2+YY];
226             jz2              = x[j_coord_offset+DIM*2+ZZ];
227
228             /* Calculate displacement vector */
229             dx00             = ix0 - jx0;
230             dy00             = iy0 - jy0;
231             dz00             = iz0 - jz0;
232             dx01             = ix0 - jx1;
233             dy01             = iy0 - jy1;
234             dz01             = iz0 - jz1;
235             dx02             = ix0 - jx2;
236             dy02             = iy0 - jy2;
237             dz02             = iz0 - jz2;
238             dx10             = ix1 - jx0;
239             dy10             = iy1 - jy0;
240             dz10             = iz1 - jz0;
241             dx11             = ix1 - jx1;
242             dy11             = iy1 - jy1;
243             dz11             = iz1 - jz1;
244             dx12             = ix1 - jx2;
245             dy12             = iy1 - jy2;
246             dz12             = iz1 - jz2;
247             dx20             = ix2 - jx0;
248             dy20             = iy2 - jy0;
249             dz20             = iz2 - jz0;
250             dx21             = ix2 - jx1;
251             dy21             = iy2 - jy1;
252             dz21             = iz2 - jz1;
253             dx22             = ix2 - jx2;
254             dy22             = iy2 - jy2;
255             dz22             = iz2 - jz2;
256
257             /* Calculate squared distance and things based on it */
258             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
259             rsq01            = dx01*dx01+dy01*dy01+dz01*dz01;
260             rsq02            = dx02*dx02+dy02*dy02+dz02*dz02;
261             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
262             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
263             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
264             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
265             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
266             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
267
268             rinv00           = gmx_invsqrt(rsq00);
269             rinv01           = gmx_invsqrt(rsq01);
270             rinv02           = gmx_invsqrt(rsq02);
271             rinv10           = gmx_invsqrt(rsq10);
272             rinv11           = gmx_invsqrt(rsq11);
273             rinv12           = gmx_invsqrt(rsq12);
274             rinv20           = gmx_invsqrt(rsq20);
275             rinv21           = gmx_invsqrt(rsq21);
276             rinv22           = gmx_invsqrt(rsq22);
277
278             rinvsq00         = rinv00*rinv00;
279             rinvsq01         = rinv01*rinv01;
280             rinvsq02         = rinv02*rinv02;
281             rinvsq10         = rinv10*rinv10;
282             rinvsq11         = rinv11*rinv11;
283             rinvsq12         = rinv12*rinv12;
284             rinvsq20         = rinv20*rinv20;
285             rinvsq21         = rinv21*rinv21;
286             rinvsq22         = rinv22*rinv22;
287
288             /**************************
289              * CALCULATE INTERACTIONS *
290              **************************/
291
292             r00              = rsq00*rinv00;
293
294             /* EWALD ELECTROSTATICS */
295
296             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
297             ewrt             = r00*ewtabscale;
298             ewitab           = ewrt;
299             eweps            = ewrt-ewitab;
300             ewitab           = 4*ewitab;
301             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
302             velec            = qq00*(rinv00-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
303             felec            = qq00*rinv00*(rinvsq00-felec);
304
305             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
306             ewcljrsq         = ewclj2*rsq00;
307             exponent         = exp(-ewcljrsq);
308             poly             = exponent*(1.0 + ewcljrsq + ewcljrsq*ewcljrsq*0.5);
309             vvdw6            = (c6_00-c6grid_00*(1.0-poly))*rinvsix;
310             vvdw12           = c12_00*rinvsix*rinvsix;
311             vvdw             = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
312             fvdw             = (vvdw12 - vvdw6 - c6grid_00*(1.0/6.0)*exponent*ewclj6)*rinvsq00;
313
314             /* Update potential sums from outer loop */
315             velecsum        += velec;
316             vvdwsum         += vvdw;
317
318             fscal            = felec+fvdw;
319
320             /* Calculate temporary vectorial force */
321             tx               = fscal*dx00;
322             ty               = fscal*dy00;
323             tz               = fscal*dz00;
324
325             /* Update vectorial force */
326             fix0            += tx;
327             fiy0            += ty;
328             fiz0            += tz;
329             f[j_coord_offset+DIM*0+XX] -= tx;
330             f[j_coord_offset+DIM*0+YY] -= ty;
331             f[j_coord_offset+DIM*0+ZZ] -= tz;
332
333             /**************************
334              * CALCULATE INTERACTIONS *
335              **************************/
336
337             r01              = rsq01*rinv01;
338
339             /* EWALD ELECTROSTATICS */
340
341             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
342             ewrt             = r01*ewtabscale;
343             ewitab           = ewrt;
344             eweps            = ewrt-ewitab;
345             ewitab           = 4*ewitab;
346             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
347             velec            = qq01*(rinv01-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
348             felec            = qq01*rinv01*(rinvsq01-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*dx01;
357             ty               = fscal*dy01;
358             tz               = fscal*dz01;
359
360             /* Update vectorial force */
361             fix0            += tx;
362             fiy0            += ty;
363             fiz0            += 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              * CALCULATE INTERACTIONS *
370              **************************/
371
372             r02              = rsq02*rinv02;
373
374             /* EWALD ELECTROSTATICS */
375
376             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
377             ewrt             = r02*ewtabscale;
378             ewitab           = ewrt;
379             eweps            = ewrt-ewitab;
380             ewitab           = 4*ewitab;
381             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
382             velec            = qq02*(rinv02-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
383             felec            = qq02*rinv02*(rinvsq02-felec);
384
385             /* Update potential sums from outer loop */
386             velecsum        += velec;
387
388             fscal            = felec;
389
390             /* Calculate temporary vectorial force */
391             tx               = fscal*dx02;
392             ty               = fscal*dy02;
393             tz               = fscal*dz02;
394
395             /* Update vectorial force */
396             fix0            += tx;
397             fiy0            += ty;
398             fiz0            += tz;
399             f[j_coord_offset+DIM*2+XX] -= tx;
400             f[j_coord_offset+DIM*2+YY] -= ty;
401             f[j_coord_offset+DIM*2+ZZ] -= tz;
402
403             /**************************
404              * CALCULATE INTERACTIONS *
405              **************************/
406
407             r10              = rsq10*rinv10;
408
409             /* EWALD ELECTROSTATICS */
410
411             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
412             ewrt             = r10*ewtabscale;
413             ewitab           = ewrt;
414             eweps            = ewrt-ewitab;
415             ewitab           = 4*ewitab;
416             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
417             velec            = qq10*(rinv10-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
418             felec            = qq10*rinv10*(rinvsq10-felec);
419
420             /* Update potential sums from outer loop */
421             velecsum        += velec;
422
423             fscal            = felec;
424
425             /* Calculate temporary vectorial force */
426             tx               = fscal*dx10;
427             ty               = fscal*dy10;
428             tz               = fscal*dz10;
429
430             /* Update vectorial force */
431             fix1            += tx;
432             fiy1            += ty;
433             fiz1            += tz;
434             f[j_coord_offset+DIM*0+XX] -= tx;
435             f[j_coord_offset+DIM*0+YY] -= ty;
436             f[j_coord_offset+DIM*0+ZZ] -= tz;
437
438             /**************************
439              * CALCULATE INTERACTIONS *
440              **************************/
441
442             r11              = rsq11*rinv11;
443
444             /* EWALD ELECTROSTATICS */
445
446             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
447             ewrt             = r11*ewtabscale;
448             ewitab           = ewrt;
449             eweps            = ewrt-ewitab;
450             ewitab           = 4*ewitab;
451             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
452             velec            = qq11*(rinv11-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
453             felec            = qq11*rinv11*(rinvsq11-felec);
454
455             /* Update potential sums from outer loop */
456             velecsum        += velec;
457
458             fscal            = felec;
459
460             /* Calculate temporary vectorial force */
461             tx               = fscal*dx11;
462             ty               = fscal*dy11;
463             tz               = fscal*dz11;
464
465             /* Update vectorial force */
466             fix1            += tx;
467             fiy1            += ty;
468             fiz1            += tz;
469             f[j_coord_offset+DIM*1+XX] -= tx;
470             f[j_coord_offset+DIM*1+YY] -= ty;
471             f[j_coord_offset+DIM*1+ZZ] -= tz;
472
473             /**************************
474              * CALCULATE INTERACTIONS *
475              **************************/
476
477             r12              = rsq12*rinv12;
478
479             /* EWALD ELECTROSTATICS */
480
481             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
482             ewrt             = r12*ewtabscale;
483             ewitab           = ewrt;
484             eweps            = ewrt-ewitab;
485             ewitab           = 4*ewitab;
486             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
487             velec            = qq12*(rinv12-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
488             felec            = qq12*rinv12*(rinvsq12-felec);
489
490             /* Update potential sums from outer loop */
491             velecsum        += velec;
492
493             fscal            = felec;
494
495             /* Calculate temporary vectorial force */
496             tx               = fscal*dx12;
497             ty               = fscal*dy12;
498             tz               = fscal*dz12;
499
500             /* Update vectorial force */
501             fix1            += tx;
502             fiy1            += ty;
503             fiz1            += tz;
504             f[j_coord_offset+DIM*2+XX] -= tx;
505             f[j_coord_offset+DIM*2+YY] -= ty;
506             f[j_coord_offset+DIM*2+ZZ] -= tz;
507
508             /**************************
509              * CALCULATE INTERACTIONS *
510              **************************/
511
512             r20              = rsq20*rinv20;
513
514             /* EWALD ELECTROSTATICS */
515
516             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
517             ewrt             = r20*ewtabscale;
518             ewitab           = ewrt;
519             eweps            = ewrt-ewitab;
520             ewitab           = 4*ewitab;
521             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
522             velec            = qq20*(rinv20-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
523             felec            = qq20*rinv20*(rinvsq20-felec);
524
525             /* Update potential sums from outer loop */
526             velecsum        += velec;
527
528             fscal            = felec;
529
530             /* Calculate temporary vectorial force */
531             tx               = fscal*dx20;
532             ty               = fscal*dy20;
533             tz               = fscal*dz20;
534
535             /* Update vectorial force */
536             fix2            += tx;
537             fiy2            += ty;
538             fiz2            += tz;
539             f[j_coord_offset+DIM*0+XX] -= tx;
540             f[j_coord_offset+DIM*0+YY] -= ty;
541             f[j_coord_offset+DIM*0+ZZ] -= tz;
542
543             /**************************
544              * CALCULATE INTERACTIONS *
545              **************************/
546
547             r21              = rsq21*rinv21;
548
549             /* EWALD ELECTROSTATICS */
550
551             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
552             ewrt             = r21*ewtabscale;
553             ewitab           = ewrt;
554             eweps            = ewrt-ewitab;
555             ewitab           = 4*ewitab;
556             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
557             velec            = qq21*(rinv21-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
558             felec            = qq21*rinv21*(rinvsq21-felec);
559
560             /* Update potential sums from outer loop */
561             velecsum        += velec;
562
563             fscal            = felec;
564
565             /* Calculate temporary vectorial force */
566             tx               = fscal*dx21;
567             ty               = fscal*dy21;
568             tz               = fscal*dz21;
569
570             /* Update vectorial force */
571             fix2            += tx;
572             fiy2            += ty;
573             fiz2            += tz;
574             f[j_coord_offset+DIM*1+XX] -= tx;
575             f[j_coord_offset+DIM*1+YY] -= ty;
576             f[j_coord_offset+DIM*1+ZZ] -= tz;
577
578             /**************************
579              * CALCULATE INTERACTIONS *
580              **************************/
581
582             r22              = rsq22*rinv22;
583
584             /* EWALD ELECTROSTATICS */
585
586             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
587             ewrt             = r22*ewtabscale;
588             ewitab           = ewrt;
589             eweps            = ewrt-ewitab;
590             ewitab           = 4*ewitab;
591             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
592             velec            = qq22*(rinv22-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
593             felec            = qq22*rinv22*(rinvsq22-felec);
594
595             /* Update potential sums from outer loop */
596             velecsum        += velec;
597
598             fscal            = felec;
599
600             /* Calculate temporary vectorial force */
601             tx               = fscal*dx22;
602             ty               = fscal*dy22;
603             tz               = fscal*dz22;
604
605             /* Update vectorial force */
606             fix2            += tx;
607             fiy2            += ty;
608             fiz2            += tz;
609             f[j_coord_offset+DIM*2+XX] -= tx;
610             f[j_coord_offset+DIM*2+YY] -= ty;
611             f[j_coord_offset+DIM*2+ZZ] -= tz;
612
613             /* Inner loop uses 386 flops */
614         }
615         /* End of innermost loop */
616
617         tx = ty = tz = 0;
618         f[i_coord_offset+DIM*0+XX] += fix0;
619         f[i_coord_offset+DIM*0+YY] += fiy0;
620         f[i_coord_offset+DIM*0+ZZ] += fiz0;
621         tx                         += fix0;
622         ty                         += fiy0;
623         tz                         += fiz0;
624         f[i_coord_offset+DIM*1+XX] += fix1;
625         f[i_coord_offset+DIM*1+YY] += fiy1;
626         f[i_coord_offset+DIM*1+ZZ] += fiz1;
627         tx                         += fix1;
628         ty                         += fiy1;
629         tz                         += fiz1;
630         f[i_coord_offset+DIM*2+XX] += fix2;
631         f[i_coord_offset+DIM*2+YY] += fiy2;
632         f[i_coord_offset+DIM*2+ZZ] += fiz2;
633         tx                         += fix2;
634         ty                         += fiy2;
635         tz                         += fiz2;
636         fshift[i_shift_offset+XX]  += tx;
637         fshift[i_shift_offset+YY]  += ty;
638         fshift[i_shift_offset+ZZ]  += tz;
639
640         ggid                        = gid[iidx];
641         /* Update potential energies */
642         kernel_data->energygrp_elec[ggid] += velecsum;
643         kernel_data->energygrp_vdw[ggid] += vvdwsum;
644
645         /* Increment number of inner iterations */
646         inneriter                  += j_index_end - j_index_start;
647
648         /* Outer loop uses 32 flops */
649     }
650
651     /* Increment number of outer iterations */
652     outeriter        += nri;
653
654     /* Update outer/inner flops */
655
656     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_VF,outeriter*32 + inneriter*386);
657 }
658 /*
659  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwLJEw_GeomW3W3_F_c
660  * Electrostatics interaction: Ewald
661  * VdW interaction:            LJEwald
662  * Geometry:                   Water3-Water3
663  * Calculate force/pot:        Force
664  */
665 void
666 nb_kernel_ElecEw_VdwLJEw_GeomW3W3_F_c
667                     (t_nblist                    * gmx_restrict       nlist,
668                      rvec                        * gmx_restrict          xx,
669                      rvec                        * gmx_restrict          ff,
670                      t_forcerec                  * gmx_restrict          fr,
671                      t_mdatoms                   * gmx_restrict     mdatoms,
672                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
673                      t_nrnb                      * gmx_restrict        nrnb)
674 {
675     int              i_shift_offset,i_coord_offset,j_coord_offset;
676     int              j_index_start,j_index_end;
677     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
678     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
679     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
680     real             *shiftvec,*fshift,*x,*f;
681     int              vdwioffset0;
682     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
683     int              vdwioffset1;
684     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
685     int              vdwioffset2;
686     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
687     int              vdwjidx0;
688     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
689     int              vdwjidx1;
690     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
691     int              vdwjidx2;
692     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
693     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
694     real             dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01,cexp1_01,cexp2_01;
695     real             dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02,cexp1_02,cexp2_02;
696     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
697     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
698     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
699     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
700     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
701     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
702     real             velec,felec,velecsum,facel,crf,krf,krf2;
703     real             *charge;
704     int              nvdwtype;
705     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
706     int              *vdwtype;
707     real             *vdwparam;
708     real             c6grid_00;
709     real             c6grid_01;
710     real             c6grid_02;
711     real             c6grid_10;
712     real             c6grid_11;
713     real             c6grid_12;
714     real             c6grid_20;
715     real             c6grid_21;
716     real             c6grid_22;
717     real             ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,sh_lj_ewald;
718     real             *vdwgridparam;
719     int              ewitab;
720     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
721     real             *ewtab;
722
723     x                = xx[0];
724     f                = ff[0];
725
726     nri              = nlist->nri;
727     iinr             = nlist->iinr;
728     jindex           = nlist->jindex;
729     jjnr             = nlist->jjnr;
730     shiftidx         = nlist->shift;
731     gid              = nlist->gid;
732     shiftvec         = fr->shift_vec[0];
733     fshift           = fr->fshift[0];
734     facel            = fr->epsfac;
735     charge           = mdatoms->chargeA;
736     nvdwtype         = fr->ntype;
737     vdwparam         = fr->nbfp;
738     vdwtype          = mdatoms->typeA;
739     vdwgridparam     = fr->ljpme_c6grid;
740     ewclj            = fr->ewaldcoeff_lj;
741     sh_lj_ewald      = fr->ic->sh_lj_ewald;
742     ewclj2           = ewclj*ewclj;
743     ewclj6           = ewclj2*ewclj2*ewclj2;
744
745     sh_ewald         = fr->ic->sh_ewald;
746     ewtab            = fr->ic->tabq_coul_F;
747     ewtabscale       = fr->ic->tabq_scale;
748     ewtabhalfspace   = 0.5/ewtabscale;
749
750     /* Setup water-specific parameters */
751     inr              = nlist->iinr[0];
752     iq0              = facel*charge[inr+0];
753     iq1              = facel*charge[inr+1];
754     iq2              = facel*charge[inr+2];
755     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
756
757     jq0              = charge[inr+0];
758     jq1              = charge[inr+1];
759     jq2              = charge[inr+2];
760     vdwjidx0         = 2*vdwtype[inr+0];
761     qq00             = iq0*jq0;
762     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
763     c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
764     c6grid_00        = vdwgridparam[vdwioffset0+vdwjidx0];
765     qq01             = iq0*jq1;
766     qq02             = iq0*jq2;
767     qq10             = iq1*jq0;
768     qq11             = iq1*jq1;
769     qq12             = iq1*jq2;
770     qq20             = iq2*jq0;
771     qq21             = iq2*jq1;
772     qq22             = iq2*jq2;
773
774     outeriter        = 0;
775     inneriter        = 0;
776
777     /* Start outer loop over neighborlists */
778     for(iidx=0; iidx<nri; iidx++)
779     {
780         /* Load shift vector for this list */
781         i_shift_offset   = DIM*shiftidx[iidx];
782         shX              = shiftvec[i_shift_offset+XX];
783         shY              = shiftvec[i_shift_offset+YY];
784         shZ              = shiftvec[i_shift_offset+ZZ];
785
786         /* Load limits for loop over neighbors */
787         j_index_start    = jindex[iidx];
788         j_index_end      = jindex[iidx+1];
789
790         /* Get outer coordinate index */
791         inr              = iinr[iidx];
792         i_coord_offset   = DIM*inr;
793
794         /* Load i particle coords and add shift vector */
795         ix0              = shX + x[i_coord_offset+DIM*0+XX];
796         iy0              = shY + x[i_coord_offset+DIM*0+YY];
797         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
798         ix1              = shX + x[i_coord_offset+DIM*1+XX];
799         iy1              = shY + x[i_coord_offset+DIM*1+YY];
800         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
801         ix2              = shX + x[i_coord_offset+DIM*2+XX];
802         iy2              = shY + x[i_coord_offset+DIM*2+YY];
803         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
804
805         fix0             = 0.0;
806         fiy0             = 0.0;
807         fiz0             = 0.0;
808         fix1             = 0.0;
809         fiy1             = 0.0;
810         fiz1             = 0.0;
811         fix2             = 0.0;
812         fiy2             = 0.0;
813         fiz2             = 0.0;
814
815         /* Start inner kernel loop */
816         for(jidx=j_index_start; jidx<j_index_end; jidx++)
817         {
818             /* Get j neighbor index, and coordinate index */
819             jnr              = jjnr[jidx];
820             j_coord_offset   = DIM*jnr;
821
822             /* load j atom coordinates */
823             jx0              = x[j_coord_offset+DIM*0+XX];
824             jy0              = x[j_coord_offset+DIM*0+YY];
825             jz0              = x[j_coord_offset+DIM*0+ZZ];
826             jx1              = x[j_coord_offset+DIM*1+XX];
827             jy1              = x[j_coord_offset+DIM*1+YY];
828             jz1              = x[j_coord_offset+DIM*1+ZZ];
829             jx2              = x[j_coord_offset+DIM*2+XX];
830             jy2              = x[j_coord_offset+DIM*2+YY];
831             jz2              = x[j_coord_offset+DIM*2+ZZ];
832
833             /* Calculate displacement vector */
834             dx00             = ix0 - jx0;
835             dy00             = iy0 - jy0;
836             dz00             = iz0 - jz0;
837             dx01             = ix0 - jx1;
838             dy01             = iy0 - jy1;
839             dz01             = iz0 - jz1;
840             dx02             = ix0 - jx2;
841             dy02             = iy0 - jy2;
842             dz02             = iz0 - jz2;
843             dx10             = ix1 - jx0;
844             dy10             = iy1 - jy0;
845             dz10             = iz1 - jz0;
846             dx11             = ix1 - jx1;
847             dy11             = iy1 - jy1;
848             dz11             = iz1 - jz1;
849             dx12             = ix1 - jx2;
850             dy12             = iy1 - jy2;
851             dz12             = iz1 - jz2;
852             dx20             = ix2 - jx0;
853             dy20             = iy2 - jy0;
854             dz20             = iz2 - jz0;
855             dx21             = ix2 - jx1;
856             dy21             = iy2 - jy1;
857             dz21             = iz2 - jz1;
858             dx22             = ix2 - jx2;
859             dy22             = iy2 - jy2;
860             dz22             = iz2 - jz2;
861
862             /* Calculate squared distance and things based on it */
863             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
864             rsq01            = dx01*dx01+dy01*dy01+dz01*dz01;
865             rsq02            = dx02*dx02+dy02*dy02+dz02*dz02;
866             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
867             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
868             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
869             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
870             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
871             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
872
873             rinv00           = gmx_invsqrt(rsq00);
874             rinv01           = gmx_invsqrt(rsq01);
875             rinv02           = gmx_invsqrt(rsq02);
876             rinv10           = gmx_invsqrt(rsq10);
877             rinv11           = gmx_invsqrt(rsq11);
878             rinv12           = gmx_invsqrt(rsq12);
879             rinv20           = gmx_invsqrt(rsq20);
880             rinv21           = gmx_invsqrt(rsq21);
881             rinv22           = gmx_invsqrt(rsq22);
882
883             rinvsq00         = rinv00*rinv00;
884             rinvsq01         = rinv01*rinv01;
885             rinvsq02         = rinv02*rinv02;
886             rinvsq10         = rinv10*rinv10;
887             rinvsq11         = rinv11*rinv11;
888             rinvsq12         = rinv12*rinv12;
889             rinvsq20         = rinv20*rinv20;
890             rinvsq21         = rinv21*rinv21;
891             rinvsq22         = rinv22*rinv22;
892
893             /**************************
894              * CALCULATE INTERACTIONS *
895              **************************/
896
897             r00              = rsq00*rinv00;
898
899             /* EWALD ELECTROSTATICS */
900
901             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
902             ewrt             = r00*ewtabscale;
903             ewitab           = ewrt;
904             eweps            = ewrt-ewitab;
905             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
906             felec            = qq00*rinv00*(rinvsq00-felec);
907
908             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
909             ewcljrsq         = ewclj2*rsq00;
910             exponent         = exp(-ewcljrsq);
911             poly             = exponent*(1.0 + ewcljrsq + ewcljrsq*ewcljrsq*0.5);
912             fvdw             = (((c12_00*rinvsix - c6_00 + c6grid_00*(1.0-poly))*rinvsix) - c6grid_00*(1.0/6.0)*exponent*ewclj6)*rinvsq00;
913
914             fscal            = felec+fvdw;
915
916             /* Calculate temporary vectorial force */
917             tx               = fscal*dx00;
918             ty               = fscal*dy00;
919             tz               = fscal*dz00;
920
921             /* Update vectorial force */
922             fix0            += tx;
923             fiy0            += ty;
924             fiz0            += tz;
925             f[j_coord_offset+DIM*0+XX] -= tx;
926             f[j_coord_offset+DIM*0+YY] -= ty;
927             f[j_coord_offset+DIM*0+ZZ] -= tz;
928
929             /**************************
930              * CALCULATE INTERACTIONS *
931              **************************/
932
933             r01              = rsq01*rinv01;
934
935             /* EWALD ELECTROSTATICS */
936
937             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
938             ewrt             = r01*ewtabscale;
939             ewitab           = ewrt;
940             eweps            = ewrt-ewitab;
941             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
942             felec            = qq01*rinv01*(rinvsq01-felec);
943
944             fscal            = felec;
945
946             /* Calculate temporary vectorial force */
947             tx               = fscal*dx01;
948             ty               = fscal*dy01;
949             tz               = fscal*dz01;
950
951             /* Update vectorial force */
952             fix0            += tx;
953             fiy0            += ty;
954             fiz0            += tz;
955             f[j_coord_offset+DIM*1+XX] -= tx;
956             f[j_coord_offset+DIM*1+YY] -= ty;
957             f[j_coord_offset+DIM*1+ZZ] -= tz;
958
959             /**************************
960              * CALCULATE INTERACTIONS *
961              **************************/
962
963             r02              = rsq02*rinv02;
964
965             /* EWALD ELECTROSTATICS */
966
967             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
968             ewrt             = r02*ewtabscale;
969             ewitab           = ewrt;
970             eweps            = ewrt-ewitab;
971             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
972             felec            = qq02*rinv02*(rinvsq02-felec);
973
974             fscal            = felec;
975
976             /* Calculate temporary vectorial force */
977             tx               = fscal*dx02;
978             ty               = fscal*dy02;
979             tz               = fscal*dz02;
980
981             /* Update vectorial force */
982             fix0            += tx;
983             fiy0            += ty;
984             fiz0            += tz;
985             f[j_coord_offset+DIM*2+XX] -= tx;
986             f[j_coord_offset+DIM*2+YY] -= ty;
987             f[j_coord_offset+DIM*2+ZZ] -= tz;
988
989             /**************************
990              * CALCULATE INTERACTIONS *
991              **************************/
992
993             r10              = rsq10*rinv10;
994
995             /* EWALD ELECTROSTATICS */
996
997             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
998             ewrt             = r10*ewtabscale;
999             ewitab           = ewrt;
1000             eweps            = ewrt-ewitab;
1001             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1002             felec            = qq10*rinv10*(rinvsq10-felec);
1003
1004             fscal            = felec;
1005
1006             /* Calculate temporary vectorial force */
1007             tx               = fscal*dx10;
1008             ty               = fscal*dy10;
1009             tz               = fscal*dz10;
1010
1011             /* Update vectorial force */
1012             fix1            += tx;
1013             fiy1            += ty;
1014             fiz1            += tz;
1015             f[j_coord_offset+DIM*0+XX] -= tx;
1016             f[j_coord_offset+DIM*0+YY] -= ty;
1017             f[j_coord_offset+DIM*0+ZZ] -= tz;
1018
1019             /**************************
1020              * CALCULATE INTERACTIONS *
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              * CALCULATE INTERACTIONS *
1051              **************************/
1052
1053             r12              = rsq12*rinv12;
1054
1055             /* EWALD ELECTROSTATICS */
1056
1057             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1058             ewrt             = r12*ewtabscale;
1059             ewitab           = ewrt;
1060             eweps            = ewrt-ewitab;
1061             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1062             felec            = qq12*rinv12*(rinvsq12-felec);
1063
1064             fscal            = felec;
1065
1066             /* Calculate temporary vectorial force */
1067             tx               = fscal*dx12;
1068             ty               = fscal*dy12;
1069             tz               = fscal*dz12;
1070
1071             /* Update vectorial force */
1072             fix1            += tx;
1073             fiy1            += ty;
1074             fiz1            += tz;
1075             f[j_coord_offset+DIM*2+XX] -= tx;
1076             f[j_coord_offset+DIM*2+YY] -= ty;
1077             f[j_coord_offset+DIM*2+ZZ] -= tz;
1078
1079             /**************************
1080              * CALCULATE INTERACTIONS *
1081              **************************/
1082
1083             r20              = rsq20*rinv20;
1084
1085             /* EWALD ELECTROSTATICS */
1086
1087             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1088             ewrt             = r20*ewtabscale;
1089             ewitab           = ewrt;
1090             eweps            = ewrt-ewitab;
1091             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1092             felec            = qq20*rinv20*(rinvsq20-felec);
1093
1094             fscal            = felec;
1095
1096             /* Calculate temporary vectorial force */
1097             tx               = fscal*dx20;
1098             ty               = fscal*dy20;
1099             tz               = fscal*dz20;
1100
1101             /* Update vectorial force */
1102             fix2            += tx;
1103             fiy2            += ty;
1104             fiz2            += tz;
1105             f[j_coord_offset+DIM*0+XX] -= tx;
1106             f[j_coord_offset+DIM*0+YY] -= ty;
1107             f[j_coord_offset+DIM*0+ZZ] -= tz;
1108
1109             /**************************
1110              * CALCULATE INTERACTIONS *
1111              **************************/
1112
1113             r21              = rsq21*rinv21;
1114
1115             /* EWALD ELECTROSTATICS */
1116
1117             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1118             ewrt             = r21*ewtabscale;
1119             ewitab           = ewrt;
1120             eweps            = ewrt-ewitab;
1121             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1122             felec            = qq21*rinv21*(rinvsq21-felec);
1123
1124             fscal            = felec;
1125
1126             /* Calculate temporary vectorial force */
1127             tx               = fscal*dx21;
1128             ty               = fscal*dy21;
1129             tz               = fscal*dz21;
1130
1131             /* Update vectorial force */
1132             fix2            += tx;
1133             fiy2            += ty;
1134             fiz2            += tz;
1135             f[j_coord_offset+DIM*1+XX] -= tx;
1136             f[j_coord_offset+DIM*1+YY] -= ty;
1137             f[j_coord_offset+DIM*1+ZZ] -= tz;
1138
1139             /**************************
1140              * CALCULATE INTERACTIONS *
1141              **************************/
1142
1143             r22              = rsq22*rinv22;
1144
1145             /* EWALD ELECTROSTATICS */
1146
1147             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1148             ewrt             = r22*ewtabscale;
1149             ewitab           = ewrt;
1150             eweps            = ewrt-ewitab;
1151             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1152             felec            = qq22*rinv22*(rinvsq22-felec);
1153
1154             fscal            = felec;
1155
1156             /* Calculate temporary vectorial force */
1157             tx               = fscal*dx22;
1158             ty               = fscal*dy22;
1159             tz               = fscal*dz22;
1160
1161             /* Update vectorial force */
1162             fix2            += tx;
1163             fiy2            += ty;
1164             fiz2            += tz;
1165             f[j_coord_offset+DIM*2+XX] -= tx;
1166             f[j_coord_offset+DIM*2+YY] -= ty;
1167             f[j_coord_offset+DIM*2+ZZ] -= tz;
1168
1169             /* Inner loop uses 318 flops */
1170         }
1171         /* End of innermost loop */
1172
1173         tx = ty = tz = 0;
1174         f[i_coord_offset+DIM*0+XX] += fix0;
1175         f[i_coord_offset+DIM*0+YY] += fiy0;
1176         f[i_coord_offset+DIM*0+ZZ] += fiz0;
1177         tx                         += fix0;
1178         ty                         += fiy0;
1179         tz                         += fiz0;
1180         f[i_coord_offset+DIM*1+XX] += fix1;
1181         f[i_coord_offset+DIM*1+YY] += fiy1;
1182         f[i_coord_offset+DIM*1+ZZ] += fiz1;
1183         tx                         += fix1;
1184         ty                         += fiy1;
1185         tz                         += fiz1;
1186         f[i_coord_offset+DIM*2+XX] += fix2;
1187         f[i_coord_offset+DIM*2+YY] += fiy2;
1188         f[i_coord_offset+DIM*2+ZZ] += fiz2;
1189         tx                         += fix2;
1190         ty                         += fiy2;
1191         tz                         += fiz2;
1192         fshift[i_shift_offset+XX]  += tx;
1193         fshift[i_shift_offset+YY]  += ty;
1194         fshift[i_shift_offset+ZZ]  += tz;
1195
1196         /* Increment number of inner iterations */
1197         inneriter                  += j_index_end - j_index_start;
1198
1199         /* Outer loop uses 30 flops */
1200     }
1201
1202     /* Increment number of outer iterations */
1203     outeriter        += nri;
1204
1205     /* Update outer/inner flops */
1206
1207     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_F,outeriter*30 + inneriter*318);
1208 }