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