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