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