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