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