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