Merge release-5-0 into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecEwSh_VdwLJSh_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_VdwLJSh_GeomW3P1_VF_c
51  * Electrostatics interaction: Ewald
52  * VdW interaction:            LennardJones
53  * Geometry:                   Water3-Particle
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecEwSh_VdwLJSh_GeomW3P1_VF_c
58                     (t_nblist                    * gmx_restrict       nlist,
59                      rvec                        * gmx_restrict          xx,
60                      rvec                        * gmx_restrict          ff,
61                      t_forcerec                  * gmx_restrict          fr,
62                      t_mdatoms                   * gmx_restrict     mdatoms,
63                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64                      t_nrnb                      * gmx_restrict        nrnb)
65 {
66     int              i_shift_offset,i_coord_offset,j_coord_offset;
67     int              j_index_start,j_index_end;
68     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
69     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
70     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
71     real             *shiftvec,*fshift,*x,*f;
72     int              vdwioffset0;
73     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
74     int              vdwioffset1;
75     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
76     int              vdwioffset2;
77     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
78     int              vdwjidx0;
79     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
80     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
81     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
82     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
83     real             velec,felec,velecsum,facel,crf,krf,krf2;
84     real             *charge;
85     int              nvdwtype;
86     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
87     int              *vdwtype;
88     real             *vdwparam;
89     int              ewitab;
90     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
91     real             *ewtab;
92
93     x                = xx[0];
94     f                = ff[0];
95
96     nri              = nlist->nri;
97     iinr             = nlist->iinr;
98     jindex           = nlist->jindex;
99     jjnr             = nlist->jjnr;
100     shiftidx         = nlist->shift;
101     gid              = nlist->gid;
102     shiftvec         = fr->shift_vec[0];
103     fshift           = fr->fshift[0];
104     facel            = fr->epsfac;
105     charge           = mdatoms->chargeA;
106     nvdwtype         = fr->ntype;
107     vdwparam         = fr->nbfp;
108     vdwtype          = mdatoms->typeA;
109
110     sh_ewald         = fr->ic->sh_ewald;
111     ewtab            = fr->ic->tabq_coul_FDV0;
112     ewtabscale       = fr->ic->tabq_scale;
113     ewtabhalfspace   = 0.5/ewtabscale;
114
115     /* Setup water-specific parameters */
116     inr              = nlist->iinr[0];
117     iq0              = facel*charge[inr+0];
118     iq1              = facel*charge[inr+1];
119     iq2              = facel*charge[inr+2];
120     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
121
122     /* 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         = 2*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             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
226
227             /* EWALD ELECTROSTATICS */
228
229             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
230             ewrt             = r00*ewtabscale;
231             ewitab           = ewrt;
232             eweps            = ewrt-ewitab;
233             ewitab           = 4*ewitab;
234             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
235             velec            = qq00*((rinv00-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
236             felec            = qq00*rinv00*(rinvsq00-felec);
237
238             /* LENNARD-JONES DISPERSION/REPULSION */
239
240             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
241             vvdw6            = c6_00*rinvsix;
242             vvdw12           = c12_00*rinvsix*rinvsix;
243             vvdw             = (vvdw12 - c12_00*sh_vdw_invrcut6*sh_vdw_invrcut6)*(1.0/12.0) - (vvdw6 - c6_00*sh_vdw_invrcut6)*(1.0/6.0);
244             fvdw             = (vvdw12-vvdw6)*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
267             /**************************
268              * CALCULATE INTERACTIONS *
269              **************************/
270
271             if (rsq10<rcutoff2)
272             {
273
274             r10              = rsq10*rinv10;
275
276             qq10             = iq1*jq0;
277
278             /* EWALD ELECTROSTATICS */
279
280             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
281             ewrt             = r10*ewtabscale;
282             ewitab           = ewrt;
283             eweps            = ewrt-ewitab;
284             ewitab           = 4*ewitab;
285             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
286             velec            = qq10*((rinv10-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
287             felec            = qq10*rinv10*(rinvsq10-felec);
288
289             /* Update potential sums from outer loop */
290             velecsum        += velec;
291
292             fscal            = felec;
293
294             /* Calculate temporary vectorial force */
295             tx               = fscal*dx10;
296             ty               = fscal*dy10;
297             tz               = fscal*dz10;
298
299             /* Update vectorial force */
300             fix1            += tx;
301             fiy1            += ty;
302             fiz1            += tz;
303             f[j_coord_offset+DIM*0+XX] -= tx;
304             f[j_coord_offset+DIM*0+YY] -= ty;
305             f[j_coord_offset+DIM*0+ZZ] -= tz;
306
307             }
308
309             /**************************
310              * CALCULATE INTERACTIONS *
311              **************************/
312
313             if (rsq20<rcutoff2)
314             {
315
316             r20              = rsq20*rinv20;
317
318             qq20             = iq2*jq0;
319
320             /* EWALD ELECTROSTATICS */
321
322             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
323             ewrt             = r20*ewtabscale;
324             ewitab           = ewrt;
325             eweps            = ewrt-ewitab;
326             ewitab           = 4*ewitab;
327             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
328             velec            = qq20*((rinv20-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
329             felec            = qq20*rinv20*(rinvsq20-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*dx20;
338             ty               = fscal*dy20;
339             tz               = fscal*dz20;
340
341             /* Update vectorial force */
342             fix2            += tx;
343             fiy2            += ty;
344             fiz2            += 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             }
350
351             /* Inner loop uses 143 flops */
352         }
353         /* End of innermost loop */
354
355         tx = ty = tz = 0;
356         f[i_coord_offset+DIM*0+XX] += fix0;
357         f[i_coord_offset+DIM*0+YY] += fiy0;
358         f[i_coord_offset+DIM*0+ZZ] += fiz0;
359         tx                         += fix0;
360         ty                         += fiy0;
361         tz                         += fiz0;
362         f[i_coord_offset+DIM*1+XX] += fix1;
363         f[i_coord_offset+DIM*1+YY] += fiy1;
364         f[i_coord_offset+DIM*1+ZZ] += fiz1;
365         tx                         += fix1;
366         ty                         += fiy1;
367         tz                         += fiz1;
368         f[i_coord_offset+DIM*2+XX] += fix2;
369         f[i_coord_offset+DIM*2+YY] += fiy2;
370         f[i_coord_offset+DIM*2+ZZ] += fiz2;
371         tx                         += fix2;
372         ty                         += fiy2;
373         tz                         += fiz2;
374         fshift[i_shift_offset+XX]  += tx;
375         fshift[i_shift_offset+YY]  += ty;
376         fshift[i_shift_offset+ZZ]  += tz;
377
378         ggid                        = gid[iidx];
379         /* Update potential energies */
380         kernel_data->energygrp_elec[ggid] += velecsum;
381         kernel_data->energygrp_vdw[ggid] += vvdwsum;
382
383         /* Increment number of inner iterations */
384         inneriter                  += j_index_end - j_index_start;
385
386         /* Outer loop uses 32 flops */
387     }
388
389     /* Increment number of outer iterations */
390     outeriter        += nri;
391
392     /* Update outer/inner flops */
393
394     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*32 + inneriter*143);
395 }
396 /*
397  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSh_VdwLJSh_GeomW3P1_F_c
398  * Electrostatics interaction: Ewald
399  * VdW interaction:            LennardJones
400  * Geometry:                   Water3-Particle
401  * Calculate force/pot:        Force
402  */
403 void
404 nb_kernel_ElecEwSh_VdwLJSh_GeomW3P1_F_c
405                     (t_nblist                    * gmx_restrict       nlist,
406                      rvec                        * gmx_restrict          xx,
407                      rvec                        * gmx_restrict          ff,
408                      t_forcerec                  * gmx_restrict          fr,
409                      t_mdatoms                   * gmx_restrict     mdatoms,
410                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
411                      t_nrnb                      * gmx_restrict        nrnb)
412 {
413     int              i_shift_offset,i_coord_offset,j_coord_offset;
414     int              j_index_start,j_index_end;
415     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
416     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
417     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
418     real             *shiftvec,*fshift,*x,*f;
419     int              vdwioffset0;
420     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
421     int              vdwioffset1;
422     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
423     int              vdwioffset2;
424     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
425     int              vdwjidx0;
426     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
427     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
428     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
429     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
430     real             velec,felec,velecsum,facel,crf,krf,krf2;
431     real             *charge;
432     int              nvdwtype;
433     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
434     int              *vdwtype;
435     real             *vdwparam;
436     int              ewitab;
437     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
438     real             *ewtab;
439
440     x                = xx[0];
441     f                = ff[0];
442
443     nri              = nlist->nri;
444     iinr             = nlist->iinr;
445     jindex           = nlist->jindex;
446     jjnr             = nlist->jjnr;
447     shiftidx         = nlist->shift;
448     gid              = nlist->gid;
449     shiftvec         = fr->shift_vec[0];
450     fshift           = fr->fshift[0];
451     facel            = fr->epsfac;
452     charge           = mdatoms->chargeA;
453     nvdwtype         = fr->ntype;
454     vdwparam         = fr->nbfp;
455     vdwtype          = mdatoms->typeA;
456
457     sh_ewald         = fr->ic->sh_ewald;
458     ewtab            = fr->ic->tabq_coul_F;
459     ewtabscale       = fr->ic->tabq_scale;
460     ewtabhalfspace   = 0.5/ewtabscale;
461
462     /* Setup water-specific parameters */
463     inr              = nlist->iinr[0];
464     iq0              = facel*charge[inr+0];
465     iq1              = facel*charge[inr+1];
466     iq2              = facel*charge[inr+2];
467     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
468
469     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
470     rcutoff          = fr->rcoulomb;
471     rcutoff2         = rcutoff*rcutoff;
472
473     sh_vdw_invrcut6  = fr->ic->sh_invrc6;
474     rvdw             = fr->rvdw;
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
507         fix0             = 0.0;
508         fiy0             = 0.0;
509         fiz0             = 0.0;
510         fix1             = 0.0;
511         fiy1             = 0.0;
512         fiz1             = 0.0;
513         fix2             = 0.0;
514         fiy2             = 0.0;
515         fiz2             = 0.0;
516
517         /* Start inner kernel loop */
518         for(jidx=j_index_start; jidx<j_index_end; jidx++)
519         {
520             /* Get j neighbor index, and coordinate index */
521             jnr              = jjnr[jidx];
522             j_coord_offset   = DIM*jnr;
523
524             /* load j atom coordinates */
525             jx0              = x[j_coord_offset+DIM*0+XX];
526             jy0              = x[j_coord_offset+DIM*0+YY];
527             jz0              = x[j_coord_offset+DIM*0+ZZ];
528
529             /* Calculate displacement vector */
530             dx00             = ix0 - jx0;
531             dy00             = iy0 - jy0;
532             dz00             = iz0 - jz0;
533             dx10             = ix1 - jx0;
534             dy10             = iy1 - jy0;
535             dz10             = iz1 - jz0;
536             dx20             = ix2 - jx0;
537             dy20             = iy2 - jy0;
538             dz20             = iz2 - jz0;
539
540             /* Calculate squared distance and things based on it */
541             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
542             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
543             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
544
545             rinv00           = gmx_invsqrt(rsq00);
546             rinv10           = gmx_invsqrt(rsq10);
547             rinv20           = gmx_invsqrt(rsq20);
548
549             rinvsq00         = rinv00*rinv00;
550             rinvsq10         = rinv10*rinv10;
551             rinvsq20         = rinv20*rinv20;
552
553             /* Load parameters for j particles */
554             jq0              = charge[jnr+0];
555             vdwjidx0         = 2*vdwtype[jnr+0];
556
557             /**************************
558              * CALCULATE INTERACTIONS *
559              **************************/
560
561             if (rsq00<rcutoff2)
562             {
563
564             r00              = rsq00*rinv00;
565
566             qq00             = iq0*jq0;
567             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
568             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
569
570             /* EWALD ELECTROSTATICS */
571
572             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
573             ewrt             = r00*ewtabscale;
574             ewitab           = ewrt;
575             eweps            = ewrt-ewitab;
576             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
577             felec            = qq00*rinv00*(rinvsq00-felec);
578
579             /* LENNARD-JONES DISPERSION/REPULSION */
580
581             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
582             fvdw             = (c12_00*rinvsix-c6_00)*rinvsix*rinvsq00;
583
584             fscal            = felec+fvdw;
585
586             /* Calculate temporary vectorial force */
587             tx               = fscal*dx00;
588             ty               = fscal*dy00;
589             tz               = fscal*dz00;
590
591             /* Update vectorial force */
592             fix0            += tx;
593             fiy0            += ty;
594             fiz0            += tz;
595             f[j_coord_offset+DIM*0+XX] -= tx;
596             f[j_coord_offset+DIM*0+YY] -= ty;
597             f[j_coord_offset+DIM*0+ZZ] -= tz;
598
599             }
600
601             /**************************
602              * CALCULATE INTERACTIONS *
603              **************************/
604
605             if (rsq10<rcutoff2)
606             {
607
608             r10              = rsq10*rinv10;
609
610             qq10             = iq1*jq0;
611
612             /* EWALD ELECTROSTATICS */
613
614             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
615             ewrt             = r10*ewtabscale;
616             ewitab           = ewrt;
617             eweps            = ewrt-ewitab;
618             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
619             felec            = qq10*rinv10*(rinvsq10-felec);
620
621             fscal            = felec;
622
623             /* Calculate temporary vectorial force */
624             tx               = fscal*dx10;
625             ty               = fscal*dy10;
626             tz               = fscal*dz10;
627
628             /* Update vectorial force */
629             fix1            += tx;
630             fiy1            += ty;
631             fiz1            += tz;
632             f[j_coord_offset+DIM*0+XX] -= tx;
633             f[j_coord_offset+DIM*0+YY] -= ty;
634             f[j_coord_offset+DIM*0+ZZ] -= tz;
635
636             }
637
638             /**************************
639              * CALCULATE INTERACTIONS *
640              **************************/
641
642             if (rsq20<rcutoff2)
643             {
644
645             r20              = rsq20*rinv20;
646
647             qq20             = iq2*jq0;
648
649             /* EWALD ELECTROSTATICS */
650
651             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
652             ewrt             = r20*ewtabscale;
653             ewitab           = ewrt;
654             eweps            = ewrt-ewitab;
655             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
656             felec            = qq20*rinv20*(rinvsq20-felec);
657
658             fscal            = felec;
659
660             /* Calculate temporary vectorial force */
661             tx               = fscal*dx20;
662             ty               = fscal*dy20;
663             tz               = fscal*dz20;
664
665             /* Update vectorial force */
666             fix2            += tx;
667             fiy2            += ty;
668             fiz2            += tz;
669             f[j_coord_offset+DIM*0+XX] -= tx;
670             f[j_coord_offset+DIM*0+YY] -= ty;
671             f[j_coord_offset+DIM*0+ZZ] -= tz;
672
673             }
674
675             /* Inner loop uses 109 flops */
676         }
677         /* End of innermost loop */
678
679         tx = ty = tz = 0;
680         f[i_coord_offset+DIM*0+XX] += fix0;
681         f[i_coord_offset+DIM*0+YY] += fiy0;
682         f[i_coord_offset+DIM*0+ZZ] += fiz0;
683         tx                         += fix0;
684         ty                         += fiy0;
685         tz                         += fiz0;
686         f[i_coord_offset+DIM*1+XX] += fix1;
687         f[i_coord_offset+DIM*1+YY] += fiy1;
688         f[i_coord_offset+DIM*1+ZZ] += fiz1;
689         tx                         += fix1;
690         ty                         += fiy1;
691         tz                         += fiz1;
692         f[i_coord_offset+DIM*2+XX] += fix2;
693         f[i_coord_offset+DIM*2+YY] += fiy2;
694         f[i_coord_offset+DIM*2+ZZ] += fiz2;
695         tx                         += fix2;
696         ty                         += fiy2;
697         tz                         += fiz2;
698         fshift[i_shift_offset+XX]  += tx;
699         fshift[i_shift_offset+YY]  += ty;
700         fshift[i_shift_offset+ZZ]  += tz;
701
702         /* Increment number of inner iterations */
703         inneriter                  += j_index_end - j_index_start;
704
705         /* Outer loop uses 30 flops */
706     }
707
708     /* Increment number of outer iterations */
709     outeriter        += nri;
710
711     /* Update outer/inner flops */
712
713     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*30 + inneriter*109);
714 }