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