Introduce gmxpre.h for truly global definitions
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecEw_VdwLJ_GeomW3P1_c.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS c kernel generator.
37  */
38 #include "gmxpre.h"
39
40 #include "config.h"
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
48
49 /*
50  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwLJ_GeomW3P1_VF_c
51  * Electrostatics interaction: Ewald
52  * VdW interaction:            LennardJones
53  * Geometry:                   Water3-Particle
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecEw_VdwLJ_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      = 2*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         = 2*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             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
216
217             /* EWALD ELECTROSTATICS */
218
219             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
220             ewrt             = r00*ewtabscale;
221             ewitab           = ewrt;
222             eweps            = ewrt-ewitab;
223             ewitab           = 4*ewitab;
224             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
225             velec            = qq00*(rinv00-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
226             felec            = qq00*rinv00*(rinvsq00-felec);
227
228             /* LENNARD-JONES DISPERSION/REPULSION */
229
230             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
231             vvdw6            = c6_00*rinvsix;
232             vvdw12           = c12_00*rinvsix*rinvsix;
233             vvdw             = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
234             fvdw             = (vvdw12-vvdw6)*rinvsq00;
235
236             /* Update potential sums from outer loop */
237             velecsum        += velec;
238             vvdwsum         += vvdw;
239
240             fscal            = felec+fvdw;
241
242             /* Calculate temporary vectorial force */
243             tx               = fscal*dx00;
244             ty               = fscal*dy00;
245             tz               = fscal*dz00;
246
247             /* Update vectorial force */
248             fix0            += tx;
249             fiy0            += ty;
250             fiz0            += tz;
251             f[j_coord_offset+DIM*0+XX] -= tx;
252             f[j_coord_offset+DIM*0+YY] -= ty;
253             f[j_coord_offset+DIM*0+ZZ] -= tz;
254
255             /**************************
256              * CALCULATE INTERACTIONS *
257              **************************/
258
259             r10              = rsq10*rinv10;
260
261             qq10             = iq1*jq0;
262
263             /* EWALD ELECTROSTATICS */
264
265             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
266             ewrt             = r10*ewtabscale;
267             ewitab           = ewrt;
268             eweps            = ewrt-ewitab;
269             ewitab           = 4*ewitab;
270             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
271             velec            = qq10*(rinv10-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
272             felec            = qq10*rinv10*(rinvsq10-felec);
273
274             /* Update potential sums from outer loop */
275             velecsum        += velec;
276
277             fscal            = felec;
278
279             /* Calculate temporary vectorial force */
280             tx               = fscal*dx10;
281             ty               = fscal*dy10;
282             tz               = fscal*dz10;
283
284             /* Update vectorial force */
285             fix1            += tx;
286             fiy1            += ty;
287             fiz1            += tz;
288             f[j_coord_offset+DIM*0+XX] -= tx;
289             f[j_coord_offset+DIM*0+YY] -= ty;
290             f[j_coord_offset+DIM*0+ZZ] -= tz;
291
292             /**************************
293              * CALCULATE INTERACTIONS *
294              **************************/
295
296             r20              = rsq20*rinv20;
297
298             qq20             = iq2*jq0;
299
300             /* EWALD ELECTROSTATICS */
301
302             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
303             ewrt             = r20*ewtabscale;
304             ewitab           = ewrt;
305             eweps            = ewrt-ewitab;
306             ewitab           = 4*ewitab;
307             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
308             velec            = qq20*(rinv20-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
309             felec            = qq20*rinv20*(rinvsq20-felec);
310
311             /* Update potential sums from outer loop */
312             velecsum        += velec;
313
314             fscal            = felec;
315
316             /* Calculate temporary vectorial force */
317             tx               = fscal*dx20;
318             ty               = fscal*dy20;
319             tz               = fscal*dz20;
320
321             /* Update vectorial force */
322             fix2            += tx;
323             fiy2            += ty;
324             fiz2            += tz;
325             f[j_coord_offset+DIM*0+XX] -= tx;
326             f[j_coord_offset+DIM*0+YY] -= ty;
327             f[j_coord_offset+DIM*0+ZZ] -= tz;
328
329             /* Inner loop uses 135 flops */
330         }
331         /* End of innermost loop */
332
333         tx = ty = tz = 0;
334         f[i_coord_offset+DIM*0+XX] += fix0;
335         f[i_coord_offset+DIM*0+YY] += fiy0;
336         f[i_coord_offset+DIM*0+ZZ] += fiz0;
337         tx                         += fix0;
338         ty                         += fiy0;
339         tz                         += fiz0;
340         f[i_coord_offset+DIM*1+XX] += fix1;
341         f[i_coord_offset+DIM*1+YY] += fiy1;
342         f[i_coord_offset+DIM*1+ZZ] += fiz1;
343         tx                         += fix1;
344         ty                         += fiy1;
345         tz                         += fiz1;
346         f[i_coord_offset+DIM*2+XX] += fix2;
347         f[i_coord_offset+DIM*2+YY] += fiy2;
348         f[i_coord_offset+DIM*2+ZZ] += fiz2;
349         tx                         += fix2;
350         ty                         += fiy2;
351         tz                         += fiz2;
352         fshift[i_shift_offset+XX]  += tx;
353         fshift[i_shift_offset+YY]  += ty;
354         fshift[i_shift_offset+ZZ]  += tz;
355
356         ggid                        = gid[iidx];
357         /* Update potential energies */
358         kernel_data->energygrp_elec[ggid] += velecsum;
359         kernel_data->energygrp_vdw[ggid] += vvdwsum;
360
361         /* Increment number of inner iterations */
362         inneriter                  += j_index_end - j_index_start;
363
364         /* Outer loop uses 32 flops */
365     }
366
367     /* Increment number of outer iterations */
368     outeriter        += nri;
369
370     /* Update outer/inner flops */
371
372     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*32 + inneriter*135);
373 }
374 /*
375  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwLJ_GeomW3P1_F_c
376  * Electrostatics interaction: Ewald
377  * VdW interaction:            LennardJones
378  * Geometry:                   Water3-Particle
379  * Calculate force/pot:        Force
380  */
381 void
382 nb_kernel_ElecEw_VdwLJ_GeomW3P1_F_c
383                     (t_nblist                    * gmx_restrict       nlist,
384                      rvec                        * gmx_restrict          xx,
385                      rvec                        * gmx_restrict          ff,
386                      t_forcerec                  * gmx_restrict          fr,
387                      t_mdatoms                   * gmx_restrict     mdatoms,
388                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
389                      t_nrnb                      * gmx_restrict        nrnb)
390 {
391     int              i_shift_offset,i_coord_offset,j_coord_offset;
392     int              j_index_start,j_index_end;
393     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
394     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
395     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
396     real             *shiftvec,*fshift,*x,*f;
397     int              vdwioffset0;
398     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
399     int              vdwioffset1;
400     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
401     int              vdwioffset2;
402     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
403     int              vdwjidx0;
404     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
405     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
406     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
407     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
408     real             velec,felec,velecsum,facel,crf,krf,krf2;
409     real             *charge;
410     int              nvdwtype;
411     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
412     int              *vdwtype;
413     real             *vdwparam;
414     int              ewitab;
415     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
416     real             *ewtab;
417
418     x                = xx[0];
419     f                = ff[0];
420
421     nri              = nlist->nri;
422     iinr             = nlist->iinr;
423     jindex           = nlist->jindex;
424     jjnr             = nlist->jjnr;
425     shiftidx         = nlist->shift;
426     gid              = nlist->gid;
427     shiftvec         = fr->shift_vec[0];
428     fshift           = fr->fshift[0];
429     facel            = fr->epsfac;
430     charge           = mdatoms->chargeA;
431     nvdwtype         = fr->ntype;
432     vdwparam         = fr->nbfp;
433     vdwtype          = mdatoms->typeA;
434
435     sh_ewald         = fr->ic->sh_ewald;
436     ewtab            = fr->ic->tabq_coul_F;
437     ewtabscale       = fr->ic->tabq_scale;
438     ewtabhalfspace   = 0.5/ewtabscale;
439
440     /* Setup water-specific parameters */
441     inr              = nlist->iinr[0];
442     iq0              = facel*charge[inr+0];
443     iq1              = facel*charge[inr+1];
444     iq2              = facel*charge[inr+2];
445     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
446
447     outeriter        = 0;
448     inneriter        = 0;
449
450     /* Start outer loop over neighborlists */
451     for(iidx=0; iidx<nri; iidx++)
452     {
453         /* Load shift vector for this list */
454         i_shift_offset   = DIM*shiftidx[iidx];
455         shX              = shiftvec[i_shift_offset+XX];
456         shY              = shiftvec[i_shift_offset+YY];
457         shZ              = shiftvec[i_shift_offset+ZZ];
458
459         /* Load limits for loop over neighbors */
460         j_index_start    = jindex[iidx];
461         j_index_end      = jindex[iidx+1];
462
463         /* Get outer coordinate index */
464         inr              = iinr[iidx];
465         i_coord_offset   = DIM*inr;
466
467         /* Load i particle coords and add shift vector */
468         ix0              = shX + x[i_coord_offset+DIM*0+XX];
469         iy0              = shY + x[i_coord_offset+DIM*0+YY];
470         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
471         ix1              = shX + x[i_coord_offset+DIM*1+XX];
472         iy1              = shY + x[i_coord_offset+DIM*1+YY];
473         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
474         ix2              = shX + x[i_coord_offset+DIM*2+XX];
475         iy2              = shY + x[i_coord_offset+DIM*2+YY];
476         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
477
478         fix0             = 0.0;
479         fiy0             = 0.0;
480         fiz0             = 0.0;
481         fix1             = 0.0;
482         fiy1             = 0.0;
483         fiz1             = 0.0;
484         fix2             = 0.0;
485         fiy2             = 0.0;
486         fiz2             = 0.0;
487
488         /* Start inner kernel loop */
489         for(jidx=j_index_start; jidx<j_index_end; jidx++)
490         {
491             /* Get j neighbor index, and coordinate index */
492             jnr              = jjnr[jidx];
493             j_coord_offset   = DIM*jnr;
494
495             /* load j atom coordinates */
496             jx0              = x[j_coord_offset+DIM*0+XX];
497             jy0              = x[j_coord_offset+DIM*0+YY];
498             jz0              = x[j_coord_offset+DIM*0+ZZ];
499
500             /* Calculate displacement vector */
501             dx00             = ix0 - jx0;
502             dy00             = iy0 - jy0;
503             dz00             = iz0 - jz0;
504             dx10             = ix1 - jx0;
505             dy10             = iy1 - jy0;
506             dz10             = iz1 - jz0;
507             dx20             = ix2 - jx0;
508             dy20             = iy2 - jy0;
509             dz20             = iz2 - jz0;
510
511             /* Calculate squared distance and things based on it */
512             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
513             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
514             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
515
516             rinv00           = gmx_invsqrt(rsq00);
517             rinv10           = gmx_invsqrt(rsq10);
518             rinv20           = gmx_invsqrt(rsq20);
519
520             rinvsq00         = rinv00*rinv00;
521             rinvsq10         = rinv10*rinv10;
522             rinvsq20         = rinv20*rinv20;
523
524             /* Load parameters for j particles */
525             jq0              = charge[jnr+0];
526             vdwjidx0         = 2*vdwtype[jnr+0];
527
528             /**************************
529              * CALCULATE INTERACTIONS *
530              **************************/
531
532             r00              = rsq00*rinv00;
533
534             qq00             = iq0*jq0;
535             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
536             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
537
538             /* EWALD ELECTROSTATICS */
539
540             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
541             ewrt             = r00*ewtabscale;
542             ewitab           = ewrt;
543             eweps            = ewrt-ewitab;
544             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
545             felec            = qq00*rinv00*(rinvsq00-felec);
546
547             /* LENNARD-JONES DISPERSION/REPULSION */
548
549             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
550             fvdw             = (c12_00*rinvsix-c6_00)*rinvsix*rinvsq00;
551
552             fscal            = felec+fvdw;
553
554             /* Calculate temporary vectorial force */
555             tx               = fscal*dx00;
556             ty               = fscal*dy00;
557             tz               = fscal*dz00;
558
559             /* Update vectorial force */
560             fix0            += tx;
561             fiy0            += ty;
562             fiz0            += tz;
563             f[j_coord_offset+DIM*0+XX] -= tx;
564             f[j_coord_offset+DIM*0+YY] -= ty;
565             f[j_coord_offset+DIM*0+ZZ] -= tz;
566
567             /**************************
568              * CALCULATE INTERACTIONS *
569              **************************/
570
571             r10              = rsq10*rinv10;
572
573             qq10             = iq1*jq0;
574
575             /* EWALD ELECTROSTATICS */
576
577             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
578             ewrt             = r10*ewtabscale;
579             ewitab           = ewrt;
580             eweps            = ewrt-ewitab;
581             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
582             felec            = qq10*rinv10*(rinvsq10-felec);
583
584             fscal            = felec;
585
586             /* Calculate temporary vectorial force */
587             tx               = fscal*dx10;
588             ty               = fscal*dy10;
589             tz               = fscal*dz10;
590
591             /* Update vectorial force */
592             fix1            += tx;
593             fiy1            += ty;
594             fiz1            += tz;
595             f[j_coord_offset+DIM*0+XX] -= tx;
596             f[j_coord_offset+DIM*0+YY] -= ty;
597             f[j_coord_offset+DIM*0+ZZ] -= tz;
598
599             /**************************
600              * CALCULATE INTERACTIONS *
601              **************************/
602
603             r20              = rsq20*rinv20;
604
605             qq20             = iq2*jq0;
606
607             /* EWALD ELECTROSTATICS */
608
609             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
610             ewrt             = r20*ewtabscale;
611             ewitab           = ewrt;
612             eweps            = ewrt-ewitab;
613             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
614             felec            = qq20*rinv20*(rinvsq20-felec);
615
616             fscal            = felec;
617
618             /* Calculate temporary vectorial force */
619             tx               = fscal*dx20;
620             ty               = fscal*dy20;
621             tz               = fscal*dz20;
622
623             /* Update vectorial force */
624             fix2            += tx;
625             fiy2            += ty;
626             fiz2            += tz;
627             f[j_coord_offset+DIM*0+XX] -= tx;
628             f[j_coord_offset+DIM*0+YY] -= ty;
629             f[j_coord_offset+DIM*0+ZZ] -= tz;
630
631             /* Inner loop uses 109 flops */
632         }
633         /* End of innermost loop */
634
635         tx = ty = tz = 0;
636         f[i_coord_offset+DIM*0+XX] += fix0;
637         f[i_coord_offset+DIM*0+YY] += fiy0;
638         f[i_coord_offset+DIM*0+ZZ] += fiz0;
639         tx                         += fix0;
640         ty                         += fiy0;
641         tz                         += fiz0;
642         f[i_coord_offset+DIM*1+XX] += fix1;
643         f[i_coord_offset+DIM*1+YY] += fiy1;
644         f[i_coord_offset+DIM*1+ZZ] += fiz1;
645         tx                         += fix1;
646         ty                         += fiy1;
647         tz                         += fiz1;
648         f[i_coord_offset+DIM*2+XX] += fix2;
649         f[i_coord_offset+DIM*2+YY] += fiy2;
650         f[i_coord_offset+DIM*2+ZZ] += fiz2;
651         tx                         += fix2;
652         ty                         += fiy2;
653         tz                         += fiz2;
654         fshift[i_shift_offset+XX]  += tx;
655         fshift[i_shift_offset+YY]  += ty;
656         fshift[i_shift_offset+ZZ]  += tz;
657
658         /* Increment number of inner iterations */
659         inneriter                  += j_index_end - j_index_start;
660
661         /* Outer loop uses 30 flops */
662     }
663
664     /* Increment number of outer iterations */
665     outeriter        += nri;
666
667     /* Update outer/inner flops */
668
669     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*30 + inneriter*109);
670 }