Merge branch release-4-6 into release-5-0
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecEw_VdwBham_GeomW3P1_c.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013, 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_VdwBham_GeomW3P1_VF_c
51  * Electrostatics interaction: Ewald
52  * VdW interaction:            Buckingham
53  * Geometry:                   Water3-Particle
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecEw_VdwBham_GeomW3P1_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     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
81     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
82     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
83     real             velec,felec,velecsum,facel,crf,krf,krf2;
84     real             *charge;
85     int              nvdwtype;
86     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
87     int              *vdwtype;
88     real             *vdwparam;
89     int              ewitab;
90     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
91     real             *ewtab;
92
93     x                = xx[0];
94     f                = ff[0];
95
96     nri              = nlist->nri;
97     iinr             = nlist->iinr;
98     jindex           = nlist->jindex;
99     jjnr             = nlist->jjnr;
100     shiftidx         = nlist->shift;
101     gid              = nlist->gid;
102     shiftvec         = fr->shift_vec[0];
103     fshift           = fr->fshift[0];
104     facel            = fr->epsfac;
105     charge           = mdatoms->chargeA;
106     nvdwtype         = fr->ntype;
107     vdwparam         = fr->nbfp;
108     vdwtype          = mdatoms->typeA;
109
110     sh_ewald         = fr->ic->sh_ewald;
111     ewtab            = fr->ic->tabq_coul_FDV0;
112     ewtabscale       = fr->ic->tabq_scale;
113     ewtabhalfspace   = 0.5/ewtabscale;
114
115     /* Setup water-specific parameters */
116     inr              = nlist->iinr[0];
117     iq0              = facel*charge[inr+0];
118     iq1              = facel*charge[inr+1];
119     iq2              = facel*charge[inr+2];
120     vdwioffset0      = 3*nvdwtype*vdwtype[inr+0];
121
122     outeriter        = 0;
123     inneriter        = 0;
124
125     /* Start outer loop over neighborlists */
126     for(iidx=0; iidx<nri; iidx++)
127     {
128         /* Load shift vector for this list */
129         i_shift_offset   = DIM*shiftidx[iidx];
130         shX              = shiftvec[i_shift_offset+XX];
131         shY              = shiftvec[i_shift_offset+YY];
132         shZ              = shiftvec[i_shift_offset+ZZ];
133
134         /* Load limits for loop over neighbors */
135         j_index_start    = jindex[iidx];
136         j_index_end      = jindex[iidx+1];
137
138         /* Get outer coordinate index */
139         inr              = iinr[iidx];
140         i_coord_offset   = DIM*inr;
141
142         /* Load i particle coords and add shift vector */
143         ix0              = shX + x[i_coord_offset+DIM*0+XX];
144         iy0              = shY + x[i_coord_offset+DIM*0+YY];
145         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
146         ix1              = shX + x[i_coord_offset+DIM*1+XX];
147         iy1              = shY + x[i_coord_offset+DIM*1+YY];
148         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
149         ix2              = shX + x[i_coord_offset+DIM*2+XX];
150         iy2              = shY + x[i_coord_offset+DIM*2+YY];
151         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
152
153         fix0             = 0.0;
154         fiy0             = 0.0;
155         fiz0             = 0.0;
156         fix1             = 0.0;
157         fiy1             = 0.0;
158         fiz1             = 0.0;
159         fix2             = 0.0;
160         fiy2             = 0.0;
161         fiz2             = 0.0;
162
163         /* Reset potential sums */
164         velecsum         = 0.0;
165         vvdwsum          = 0.0;
166
167         /* Start inner kernel loop */
168         for(jidx=j_index_start; jidx<j_index_end; jidx++)
169         {
170             /* Get j neighbor index, and coordinate index */
171             jnr              = jjnr[jidx];
172             j_coord_offset   = DIM*jnr;
173
174             /* load j atom coordinates */
175             jx0              = x[j_coord_offset+DIM*0+XX];
176             jy0              = x[j_coord_offset+DIM*0+YY];
177             jz0              = x[j_coord_offset+DIM*0+ZZ];
178
179             /* Calculate displacement vector */
180             dx00             = ix0 - jx0;
181             dy00             = iy0 - jy0;
182             dz00             = iz0 - jz0;
183             dx10             = ix1 - jx0;
184             dy10             = iy1 - jy0;
185             dz10             = iz1 - jz0;
186             dx20             = ix2 - jx0;
187             dy20             = iy2 - jy0;
188             dz20             = iz2 - jz0;
189
190             /* Calculate squared distance and things based on it */
191             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
192             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
193             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
194
195             rinv00           = gmx_invsqrt(rsq00);
196             rinv10           = gmx_invsqrt(rsq10);
197             rinv20           = gmx_invsqrt(rsq20);
198
199             rinvsq00         = rinv00*rinv00;
200             rinvsq10         = rinv10*rinv10;
201             rinvsq20         = rinv20*rinv20;
202
203             /* Load parameters for j particles */
204             jq0              = charge[jnr+0];
205             vdwjidx0         = 3*vdwtype[jnr+0];
206
207             /**************************
208              * CALCULATE INTERACTIONS *
209              **************************/
210
211             r00              = rsq00*rinv00;
212
213             qq00             = iq0*jq0;
214             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
215             cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
216             cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
217
218             /* EWALD ELECTROSTATICS */
219
220             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
221             ewrt             = r00*ewtabscale;
222             ewitab           = ewrt;
223             eweps            = ewrt-ewitab;
224             ewitab           = 4*ewitab;
225             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
226             velec            = qq00*(rinv00-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
227             felec            = qq00*rinv00*(rinvsq00-felec);
228
229             /* BUCKINGHAM DISPERSION/REPULSION */
230             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
231             vvdw6            = c6_00*rinvsix;
232             br               = cexp2_00*r00;
233             vvdwexp          = cexp1_00*exp(-br);
234             vvdw             = vvdwexp - vvdw6*(1.0/6.0);
235             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
236
237             /* Update potential sums from outer loop */
238             velecsum        += velec;
239             vvdwsum         += vvdw;
240
241             fscal            = felec+fvdw;
242
243             /* Calculate temporary vectorial force */
244             tx               = fscal*dx00;
245             ty               = fscal*dy00;
246             tz               = fscal*dz00;
247
248             /* Update vectorial force */
249             fix0            += tx;
250             fiy0            += ty;
251             fiz0            += tz;
252             f[j_coord_offset+DIM*0+XX] -= tx;
253             f[j_coord_offset+DIM*0+YY] -= ty;
254             f[j_coord_offset+DIM*0+ZZ] -= tz;
255
256             /**************************
257              * CALCULATE INTERACTIONS *
258              **************************/
259
260             r10              = rsq10*rinv10;
261
262             qq10             = iq1*jq0;
263
264             /* EWALD ELECTROSTATICS */
265
266             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
267             ewrt             = r10*ewtabscale;
268             ewitab           = ewrt;
269             eweps            = ewrt-ewitab;
270             ewitab           = 4*ewitab;
271             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
272             velec            = qq10*(rinv10-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
273             felec            = qq10*rinv10*(rinvsq10-felec);
274
275             /* Update potential sums from outer loop */
276             velecsum        += velec;
277
278             fscal            = felec;
279
280             /* Calculate temporary vectorial force */
281             tx               = fscal*dx10;
282             ty               = fscal*dy10;
283             tz               = fscal*dz10;
284
285             /* Update vectorial force */
286             fix1            += tx;
287             fiy1            += ty;
288             fiz1            += tz;
289             f[j_coord_offset+DIM*0+XX] -= tx;
290             f[j_coord_offset+DIM*0+YY] -= ty;
291             f[j_coord_offset+DIM*0+ZZ] -= tz;
292
293             /**************************
294              * CALCULATE INTERACTIONS *
295              **************************/
296
297             r20              = rsq20*rinv20;
298
299             qq20             = iq2*jq0;
300
301             /* EWALD ELECTROSTATICS */
302
303             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
304             ewrt             = r20*ewtabscale;
305             ewitab           = ewrt;
306             eweps            = ewrt-ewitab;
307             ewitab           = 4*ewitab;
308             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
309             velec            = qq20*(rinv20-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
310             felec            = qq20*rinv20*(rinvsq20-felec);
311
312             /* Update potential sums from outer loop */
313             velecsum        += velec;
314
315             fscal            = felec;
316
317             /* Calculate temporary vectorial force */
318             tx               = fscal*dx20;
319             ty               = fscal*dy20;
320             tz               = fscal*dz20;
321
322             /* Update vectorial force */
323             fix2            += tx;
324             fiy2            += ty;
325             fiz2            += tz;
326             f[j_coord_offset+DIM*0+XX] -= tx;
327             f[j_coord_offset+DIM*0+YY] -= ty;
328             f[j_coord_offset+DIM*0+ZZ] -= tz;
329
330             /* Inner loop uses 161 flops */
331         }
332         /* End of innermost loop */
333
334         tx = ty = tz = 0;
335         f[i_coord_offset+DIM*0+XX] += fix0;
336         f[i_coord_offset+DIM*0+YY] += fiy0;
337         f[i_coord_offset+DIM*0+ZZ] += fiz0;
338         tx                         += fix0;
339         ty                         += fiy0;
340         tz                         += fiz0;
341         f[i_coord_offset+DIM*1+XX] += fix1;
342         f[i_coord_offset+DIM*1+YY] += fiy1;
343         f[i_coord_offset+DIM*1+ZZ] += fiz1;
344         tx                         += fix1;
345         ty                         += fiy1;
346         tz                         += fiz1;
347         f[i_coord_offset+DIM*2+XX] += fix2;
348         f[i_coord_offset+DIM*2+YY] += fiy2;
349         f[i_coord_offset+DIM*2+ZZ] += fiz2;
350         tx                         += fix2;
351         ty                         += fiy2;
352         tz                         += fiz2;
353         fshift[i_shift_offset+XX]  += tx;
354         fshift[i_shift_offset+YY]  += ty;
355         fshift[i_shift_offset+ZZ]  += tz;
356
357         ggid                        = gid[iidx];
358         /* Update potential energies */
359         kernel_data->energygrp_elec[ggid] += velecsum;
360         kernel_data->energygrp_vdw[ggid] += vvdwsum;
361
362         /* Increment number of inner iterations */
363         inneriter                  += j_index_end - j_index_start;
364
365         /* Outer loop uses 32 flops */
366     }
367
368     /* Increment number of outer iterations */
369     outeriter        += nri;
370
371     /* Update outer/inner flops */
372
373     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*32 + inneriter*161);
374 }
375 /*
376  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwBham_GeomW3P1_F_c
377  * Electrostatics interaction: Ewald
378  * VdW interaction:            Buckingham
379  * Geometry:                   Water3-Particle
380  * Calculate force/pot:        Force
381  */
382 void
383 nb_kernel_ElecEw_VdwBham_GeomW3P1_F_c
384                     (t_nblist                    * gmx_restrict       nlist,
385                      rvec                        * gmx_restrict          xx,
386                      rvec                        * gmx_restrict          ff,
387                      t_forcerec                  * gmx_restrict          fr,
388                      t_mdatoms                   * gmx_restrict     mdatoms,
389                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
390                      t_nrnb                      * gmx_restrict        nrnb)
391 {
392     int              i_shift_offset,i_coord_offset,j_coord_offset;
393     int              j_index_start,j_index_end;
394     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
395     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
396     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
397     real             *shiftvec,*fshift,*x,*f;
398     int              vdwioffset0;
399     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
400     int              vdwioffset1;
401     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
402     int              vdwioffset2;
403     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
404     int              vdwjidx0;
405     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
406     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
407     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
408     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
409     real             velec,felec,velecsum,facel,crf,krf,krf2;
410     real             *charge;
411     int              nvdwtype;
412     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
413     int              *vdwtype;
414     real             *vdwparam;
415     int              ewitab;
416     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
417     real             *ewtab;
418
419     x                = xx[0];
420     f                = ff[0];
421
422     nri              = nlist->nri;
423     iinr             = nlist->iinr;
424     jindex           = nlist->jindex;
425     jjnr             = nlist->jjnr;
426     shiftidx         = nlist->shift;
427     gid              = nlist->gid;
428     shiftvec         = fr->shift_vec[0];
429     fshift           = fr->fshift[0];
430     facel            = fr->epsfac;
431     charge           = mdatoms->chargeA;
432     nvdwtype         = fr->ntype;
433     vdwparam         = fr->nbfp;
434     vdwtype          = mdatoms->typeA;
435
436     sh_ewald         = fr->ic->sh_ewald;
437     ewtab            = fr->ic->tabq_coul_F;
438     ewtabscale       = fr->ic->tabq_scale;
439     ewtabhalfspace   = 0.5/ewtabscale;
440
441     /* Setup water-specific parameters */
442     inr              = nlist->iinr[0];
443     iq0              = facel*charge[inr+0];
444     iq1              = facel*charge[inr+1];
445     iq2              = facel*charge[inr+2];
446     vdwioffset0      = 3*nvdwtype*vdwtype[inr+0];
447
448     outeriter        = 0;
449     inneriter        = 0;
450
451     /* Start outer loop over neighborlists */
452     for(iidx=0; iidx<nri; iidx++)
453     {
454         /* Load shift vector for this list */
455         i_shift_offset   = DIM*shiftidx[iidx];
456         shX              = shiftvec[i_shift_offset+XX];
457         shY              = shiftvec[i_shift_offset+YY];
458         shZ              = shiftvec[i_shift_offset+ZZ];
459
460         /* Load limits for loop over neighbors */
461         j_index_start    = jindex[iidx];
462         j_index_end      = jindex[iidx+1];
463
464         /* Get outer coordinate index */
465         inr              = iinr[iidx];
466         i_coord_offset   = DIM*inr;
467
468         /* Load i particle coords and add shift vector */
469         ix0              = shX + x[i_coord_offset+DIM*0+XX];
470         iy0              = shY + x[i_coord_offset+DIM*0+YY];
471         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
472         ix1              = shX + x[i_coord_offset+DIM*1+XX];
473         iy1              = shY + x[i_coord_offset+DIM*1+YY];
474         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
475         ix2              = shX + x[i_coord_offset+DIM*2+XX];
476         iy2              = shY + x[i_coord_offset+DIM*2+YY];
477         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
478
479         fix0             = 0.0;
480         fiy0             = 0.0;
481         fiz0             = 0.0;
482         fix1             = 0.0;
483         fiy1             = 0.0;
484         fiz1             = 0.0;
485         fix2             = 0.0;
486         fiy2             = 0.0;
487         fiz2             = 0.0;
488
489         /* Start inner kernel loop */
490         for(jidx=j_index_start; jidx<j_index_end; jidx++)
491         {
492             /* Get j neighbor index, and coordinate index */
493             jnr              = jjnr[jidx];
494             j_coord_offset   = DIM*jnr;
495
496             /* load j atom coordinates */
497             jx0              = x[j_coord_offset+DIM*0+XX];
498             jy0              = x[j_coord_offset+DIM*0+YY];
499             jz0              = x[j_coord_offset+DIM*0+ZZ];
500
501             /* Calculate displacement vector */
502             dx00             = ix0 - jx0;
503             dy00             = iy0 - jy0;
504             dz00             = iz0 - jz0;
505             dx10             = ix1 - jx0;
506             dy10             = iy1 - jy0;
507             dz10             = iz1 - jz0;
508             dx20             = ix2 - jx0;
509             dy20             = iy2 - jy0;
510             dz20             = iz2 - jz0;
511
512             /* Calculate squared distance and things based on it */
513             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
514             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
515             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
516
517             rinv00           = gmx_invsqrt(rsq00);
518             rinv10           = gmx_invsqrt(rsq10);
519             rinv20           = gmx_invsqrt(rsq20);
520
521             rinvsq00         = rinv00*rinv00;
522             rinvsq10         = rinv10*rinv10;
523             rinvsq20         = rinv20*rinv20;
524
525             /* Load parameters for j particles */
526             jq0              = charge[jnr+0];
527             vdwjidx0         = 3*vdwtype[jnr+0];
528
529             /**************************
530              * CALCULATE INTERACTIONS *
531              **************************/
532
533             r00              = rsq00*rinv00;
534
535             qq00             = iq0*jq0;
536             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
537             cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
538             cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
539
540             /* EWALD ELECTROSTATICS */
541
542             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
543             ewrt             = r00*ewtabscale;
544             ewitab           = ewrt;
545             eweps            = ewrt-ewitab;
546             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
547             felec            = qq00*rinv00*(rinvsq00-felec);
548
549             /* BUCKINGHAM DISPERSION/REPULSION */
550             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
551             vvdw6            = c6_00*rinvsix;
552             br               = cexp2_00*r00;
553             vvdwexp          = cexp1_00*exp(-br);
554             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
555
556             fscal            = felec+fvdw;
557
558             /* Calculate temporary vectorial force */
559             tx               = fscal*dx00;
560             ty               = fscal*dy00;
561             tz               = fscal*dz00;
562
563             /* Update vectorial force */
564             fix0            += tx;
565             fiy0            += ty;
566             fiz0            += tz;
567             f[j_coord_offset+DIM*0+XX] -= tx;
568             f[j_coord_offset+DIM*0+YY] -= ty;
569             f[j_coord_offset+DIM*0+ZZ] -= tz;
570
571             /**************************
572              * CALCULATE INTERACTIONS *
573              **************************/
574
575             r10              = rsq10*rinv10;
576
577             qq10             = iq1*jq0;
578
579             /* EWALD ELECTROSTATICS */
580
581             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
582             ewrt             = r10*ewtabscale;
583             ewitab           = ewrt;
584             eweps            = ewrt-ewitab;
585             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
586             felec            = qq10*rinv10*(rinvsq10-felec);
587
588             fscal            = felec;
589
590             /* Calculate temporary vectorial force */
591             tx               = fscal*dx10;
592             ty               = fscal*dy10;
593             tz               = fscal*dz10;
594
595             /* Update vectorial force */
596             fix1            += tx;
597             fiy1            += ty;
598             fiz1            += tz;
599             f[j_coord_offset+DIM*0+XX] -= tx;
600             f[j_coord_offset+DIM*0+YY] -= ty;
601             f[j_coord_offset+DIM*0+ZZ] -= tz;
602
603             /**************************
604              * CALCULATE INTERACTIONS *
605              **************************/
606
607             r20              = rsq20*rinv20;
608
609             qq20             = iq2*jq0;
610
611             /* EWALD ELECTROSTATICS */
612
613             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
614             ewrt             = r20*ewtabscale;
615             ewitab           = ewrt;
616             eweps            = ewrt-ewitab;
617             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
618             felec            = qq20*rinv20*(rinvsq20-felec);
619
620             fscal            = felec;
621
622             /* Calculate temporary vectorial force */
623             tx               = fscal*dx20;
624             ty               = fscal*dy20;
625             tz               = fscal*dz20;
626
627             /* Update vectorial force */
628             fix2            += tx;
629             fiy2            += ty;
630             fiz2            += tz;
631             f[j_coord_offset+DIM*0+XX] -= tx;
632             f[j_coord_offset+DIM*0+YY] -= ty;
633             f[j_coord_offset+DIM*0+ZZ] -= tz;
634
635             /* Inner loop uses 137 flops */
636         }
637         /* End of innermost loop */
638
639         tx = ty = tz = 0;
640         f[i_coord_offset+DIM*0+XX] += fix0;
641         f[i_coord_offset+DIM*0+YY] += fiy0;
642         f[i_coord_offset+DIM*0+ZZ] += fiz0;
643         tx                         += fix0;
644         ty                         += fiy0;
645         tz                         += fiz0;
646         f[i_coord_offset+DIM*1+XX] += fix1;
647         f[i_coord_offset+DIM*1+YY] += fiy1;
648         f[i_coord_offset+DIM*1+ZZ] += fiz1;
649         tx                         += fix1;
650         ty                         += fiy1;
651         tz                         += fiz1;
652         f[i_coord_offset+DIM*2+XX] += fix2;
653         f[i_coord_offset+DIM*2+YY] += fiy2;
654         f[i_coord_offset+DIM*2+ZZ] += fiz2;
655         tx                         += fix2;
656         ty                         += fiy2;
657         tz                         += fiz2;
658         fshift[i_shift_offset+XX]  += tx;
659         fshift[i_shift_offset+YY]  += ty;
660         fshift[i_shift_offset+ZZ]  += tz;
661
662         /* Increment number of inner iterations */
663         inneriter                  += j_index_end - j_index_start;
664
665         /* Outer loop uses 30 flops */
666     }
667
668     /* Increment number of outer iterations */
669     outeriter        += nri;
670
671     /* Update outer/inner flops */
672
673     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*30 + inneriter*137);
674 }