Merge 'release-4-6' into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecRF_VdwCSTab_GeomW3W3_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_ElecRF_VdwCSTab_GeomW3W3_VF_c
35  * Electrostatics interaction: ReactionField
36  * VdW interaction:            CubicSplineTable
37  * Geometry:                   Water3-Water3
38  * Calculate force/pot:        PotentialAndForce
39  */
40 void
41 nb_kernel_ElecRF_VdwCSTab_GeomW3W3_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              vdwjidx0;
63     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
64     int              vdwjidx1;
65     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
66     int              vdwjidx2;
67     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
68     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
69     real             dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01,cexp1_01,cexp2_01;
70     real             dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02,cexp1_02,cexp2_02;
71     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
72     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
73     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
74     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
75     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
76     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
77     real             velec,felec,velecsum,facel,crf,krf,krf2;
78     real             *charge;
79     int              nvdwtype;
80     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
81     int              *vdwtype;
82     real             *vdwparam;
83     int              vfitab;
84     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
85     real             *vftab;
86
87     x                = xx[0];
88     f                = ff[0];
89
90     nri              = nlist->nri;
91     iinr             = nlist->iinr;
92     jindex           = nlist->jindex;
93     jjnr             = nlist->jjnr;
94     shiftidx         = nlist->shift;
95     gid              = nlist->gid;
96     shiftvec         = fr->shift_vec[0];
97     fshift           = fr->fshift[0];
98     facel            = fr->epsfac;
99     charge           = mdatoms->chargeA;
100     krf              = fr->ic->k_rf;
101     krf2             = krf*2.0;
102     crf              = fr->ic->c_rf;
103     nvdwtype         = fr->ntype;
104     vdwparam         = fr->nbfp;
105     vdwtype          = mdatoms->typeA;
106
107     vftab            = kernel_data->table_vdw->data;
108     vftabscale       = kernel_data->table_vdw->scale;
109
110     /* Setup water-specific parameters */
111     inr              = nlist->iinr[0];
112     iq0              = facel*charge[inr+0];
113     iq1              = facel*charge[inr+1];
114     iq2              = facel*charge[inr+2];
115     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
116
117     jq0              = charge[inr+0];
118     jq1              = charge[inr+1];
119     jq2              = charge[inr+2];
120     vdwjidx0         = 2*vdwtype[inr+0];
121     qq00             = iq0*jq0;
122     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
123     c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
124     qq01             = iq0*jq1;
125     qq02             = iq0*jq2;
126     qq10             = iq1*jq0;
127     qq11             = iq1*jq1;
128     qq12             = iq1*jq2;
129     qq20             = iq2*jq0;
130     qq21             = iq2*jq1;
131     qq22             = iq2*jq2;
132
133     outeriter        = 0;
134     inneriter        = 0;
135
136     /* Start outer loop over neighborlists */
137     for(iidx=0; iidx<nri; iidx++)
138     {
139         /* Load shift vector for this list */
140         i_shift_offset   = DIM*shiftidx[iidx];
141         shX              = shiftvec[i_shift_offset+XX];
142         shY              = shiftvec[i_shift_offset+YY];
143         shZ              = shiftvec[i_shift_offset+ZZ];
144
145         /* Load limits for loop over neighbors */
146         j_index_start    = jindex[iidx];
147         j_index_end      = jindex[iidx+1];
148
149         /* Get outer coordinate index */
150         inr              = iinr[iidx];
151         i_coord_offset   = DIM*inr;
152
153         /* Load i particle coords and add shift vector */
154         ix0              = shX + x[i_coord_offset+DIM*0+XX];
155         iy0              = shY + x[i_coord_offset+DIM*0+YY];
156         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
157         ix1              = shX + x[i_coord_offset+DIM*1+XX];
158         iy1              = shY + x[i_coord_offset+DIM*1+YY];
159         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
160         ix2              = shX + x[i_coord_offset+DIM*2+XX];
161         iy2              = shY + x[i_coord_offset+DIM*2+YY];
162         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
163
164         fix0             = 0.0;
165         fiy0             = 0.0;
166         fiz0             = 0.0;
167         fix1             = 0.0;
168         fiy1             = 0.0;
169         fiz1             = 0.0;
170         fix2             = 0.0;
171         fiy2             = 0.0;
172         fiz2             = 0.0;
173
174         /* Reset potential sums */
175         velecsum         = 0.0;
176         vvdwsum          = 0.0;
177
178         /* Start inner kernel loop */
179         for(jidx=j_index_start; jidx<j_index_end; jidx++)
180         {
181             /* Get j neighbor index, and coordinate index */
182             jnr              = jjnr[jidx];
183             j_coord_offset   = DIM*jnr;
184
185             /* load j atom coordinates */
186             jx0              = x[j_coord_offset+DIM*0+XX];
187             jy0              = x[j_coord_offset+DIM*0+YY];
188             jz0              = x[j_coord_offset+DIM*0+ZZ];
189             jx1              = x[j_coord_offset+DIM*1+XX];
190             jy1              = x[j_coord_offset+DIM*1+YY];
191             jz1              = x[j_coord_offset+DIM*1+ZZ];
192             jx2              = x[j_coord_offset+DIM*2+XX];
193             jy2              = x[j_coord_offset+DIM*2+YY];
194             jz2              = x[j_coord_offset+DIM*2+ZZ];
195
196             /* Calculate displacement vector */
197             dx00             = ix0 - jx0;
198             dy00             = iy0 - jy0;
199             dz00             = iz0 - jz0;
200             dx01             = ix0 - jx1;
201             dy01             = iy0 - jy1;
202             dz01             = iz0 - jz1;
203             dx02             = ix0 - jx2;
204             dy02             = iy0 - jy2;
205             dz02             = iz0 - jz2;
206             dx10             = ix1 - jx0;
207             dy10             = iy1 - jy0;
208             dz10             = iz1 - jz0;
209             dx11             = ix1 - jx1;
210             dy11             = iy1 - jy1;
211             dz11             = iz1 - jz1;
212             dx12             = ix1 - jx2;
213             dy12             = iy1 - jy2;
214             dz12             = iz1 - jz2;
215             dx20             = ix2 - jx0;
216             dy20             = iy2 - jy0;
217             dz20             = iz2 - jz0;
218             dx21             = ix2 - jx1;
219             dy21             = iy2 - jy1;
220             dz21             = iz2 - jz1;
221             dx22             = ix2 - jx2;
222             dy22             = iy2 - jy2;
223             dz22             = iz2 - jz2;
224
225             /* Calculate squared distance and things based on it */
226             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
227             rsq01            = dx01*dx01+dy01*dy01+dz01*dz01;
228             rsq02            = dx02*dx02+dy02*dy02+dz02*dz02;
229             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
230             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
231             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
232             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
233             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
234             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
235
236             rinv00           = gmx_invsqrt(rsq00);
237             rinv01           = gmx_invsqrt(rsq01);
238             rinv02           = gmx_invsqrt(rsq02);
239             rinv10           = gmx_invsqrt(rsq10);
240             rinv11           = gmx_invsqrt(rsq11);
241             rinv12           = gmx_invsqrt(rsq12);
242             rinv20           = gmx_invsqrt(rsq20);
243             rinv21           = gmx_invsqrt(rsq21);
244             rinv22           = gmx_invsqrt(rsq22);
245
246             rinvsq00         = rinv00*rinv00;
247             rinvsq01         = rinv01*rinv01;
248             rinvsq02         = rinv02*rinv02;
249             rinvsq10         = rinv10*rinv10;
250             rinvsq11         = rinv11*rinv11;
251             rinvsq12         = rinv12*rinv12;
252             rinvsq20         = rinv20*rinv20;
253             rinvsq21         = rinv21*rinv21;
254             rinvsq22         = rinv22*rinv22;
255
256             /**************************
257              * CALCULATE INTERACTIONS *
258              **************************/
259
260             r00              = rsq00*rinv00;
261
262             /* Calculate table index by multiplying r with table scale and truncate to integer */
263             rt               = r00*vftabscale;
264             vfitab           = rt;
265             vfeps            = rt-vfitab;
266             vfitab           = 2*4*vfitab;
267
268             /* REACTION-FIELD ELECTROSTATICS */
269             velec            = qq00*(rinv00+krf*rsq00-crf);
270             felec            = qq00*(rinv00*rinvsq00-krf2);
271
272             /* CUBIC SPLINE TABLE DISPERSION */
273             vfitab          += 0;
274             Y                = vftab[vfitab];
275             F                = vftab[vfitab+1];
276             Geps             = vfeps*vftab[vfitab+2];
277             Heps2            = vfeps*vfeps*vftab[vfitab+3];
278             Fp               = F+Geps+Heps2;
279             VV               = Y+vfeps*Fp;
280             vvdw6            = c6_00*VV;
281             FF               = Fp+Geps+2.0*Heps2;
282             fvdw6            = c6_00*FF;
283
284             /* CUBIC SPLINE TABLE REPULSION */
285             Y                = vftab[vfitab+4];
286             F                = vftab[vfitab+5];
287             Geps             = vfeps*vftab[vfitab+6];
288             Heps2            = vfeps*vfeps*vftab[vfitab+7];
289             Fp               = F+Geps+Heps2;
290             VV               = Y+vfeps*Fp;
291             vvdw12           = c12_00*VV;
292             FF               = Fp+Geps+2.0*Heps2;
293             fvdw12           = c12_00*FF;
294             vvdw             = vvdw12+vvdw6;
295             fvdw             = -(fvdw6+fvdw12)*vftabscale*rinv00;
296
297             /* Update potential sums from outer loop */
298             velecsum        += velec;
299             vvdwsum         += vvdw;
300
301             fscal            = felec+fvdw;
302
303             /* Calculate temporary vectorial force */
304             tx               = fscal*dx00;
305             ty               = fscal*dy00;
306             tz               = fscal*dz00;
307
308             /* Update vectorial force */
309             fix0            += tx;
310             fiy0            += ty;
311             fiz0            += tz;
312             f[j_coord_offset+DIM*0+XX] -= tx;
313             f[j_coord_offset+DIM*0+YY] -= ty;
314             f[j_coord_offset+DIM*0+ZZ] -= tz;
315
316             /**************************
317              * CALCULATE INTERACTIONS *
318              **************************/
319
320             /* REACTION-FIELD ELECTROSTATICS */
321             velec            = qq01*(rinv01+krf*rsq01-crf);
322             felec            = qq01*(rinv01*rinvsq01-krf2);
323
324             /* Update potential sums from outer loop */
325             velecsum        += velec;
326
327             fscal            = felec;
328
329             /* Calculate temporary vectorial force */
330             tx               = fscal*dx01;
331             ty               = fscal*dy01;
332             tz               = fscal*dz01;
333
334             /* Update vectorial force */
335             fix0            += tx;
336             fiy0            += ty;
337             fiz0            += tz;
338             f[j_coord_offset+DIM*1+XX] -= tx;
339             f[j_coord_offset+DIM*1+YY] -= ty;
340             f[j_coord_offset+DIM*1+ZZ] -= tz;
341
342             /**************************
343              * CALCULATE INTERACTIONS *
344              **************************/
345
346             /* REACTION-FIELD ELECTROSTATICS */
347             velec            = qq02*(rinv02+krf*rsq02-crf);
348             felec            = qq02*(rinv02*rinvsq02-krf2);
349
350             /* Update potential sums from outer loop */
351             velecsum        += velec;
352
353             fscal            = felec;
354
355             /* Calculate temporary vectorial force */
356             tx               = fscal*dx02;
357             ty               = fscal*dy02;
358             tz               = fscal*dz02;
359
360             /* Update vectorial force */
361             fix0            += tx;
362             fiy0            += ty;
363             fiz0            += tz;
364             f[j_coord_offset+DIM*2+XX] -= tx;
365             f[j_coord_offset+DIM*2+YY] -= ty;
366             f[j_coord_offset+DIM*2+ZZ] -= tz;
367
368             /**************************
369              * CALCULATE INTERACTIONS *
370              **************************/
371
372             /* REACTION-FIELD ELECTROSTATICS */
373             velec            = qq10*(rinv10+krf*rsq10-crf);
374             felec            = qq10*(rinv10*rinvsq10-krf2);
375
376             /* Update potential sums from outer loop */
377             velecsum        += velec;
378
379             fscal            = felec;
380
381             /* Calculate temporary vectorial force */
382             tx               = fscal*dx10;
383             ty               = fscal*dy10;
384             tz               = fscal*dz10;
385
386             /* Update vectorial force */
387             fix1            += tx;
388             fiy1            += ty;
389             fiz1            += tz;
390             f[j_coord_offset+DIM*0+XX] -= tx;
391             f[j_coord_offset+DIM*0+YY] -= ty;
392             f[j_coord_offset+DIM*0+ZZ] -= tz;
393
394             /**************************
395              * CALCULATE INTERACTIONS *
396              **************************/
397
398             /* REACTION-FIELD ELECTROSTATICS */
399             velec            = qq11*(rinv11+krf*rsq11-crf);
400             felec            = qq11*(rinv11*rinvsq11-krf2);
401
402             /* Update potential sums from outer loop */
403             velecsum        += velec;
404
405             fscal            = felec;
406
407             /* Calculate temporary vectorial force */
408             tx               = fscal*dx11;
409             ty               = fscal*dy11;
410             tz               = fscal*dz11;
411
412             /* Update vectorial force */
413             fix1            += tx;
414             fiy1            += ty;
415             fiz1            += tz;
416             f[j_coord_offset+DIM*1+XX] -= tx;
417             f[j_coord_offset+DIM*1+YY] -= ty;
418             f[j_coord_offset+DIM*1+ZZ] -= tz;
419
420             /**************************
421              * CALCULATE INTERACTIONS *
422              **************************/
423
424             /* REACTION-FIELD ELECTROSTATICS */
425             velec            = qq12*(rinv12+krf*rsq12-crf);
426             felec            = qq12*(rinv12*rinvsq12-krf2);
427
428             /* Update potential sums from outer loop */
429             velecsum        += velec;
430
431             fscal            = felec;
432
433             /* Calculate temporary vectorial force */
434             tx               = fscal*dx12;
435             ty               = fscal*dy12;
436             tz               = fscal*dz12;
437
438             /* Update vectorial force */
439             fix1            += tx;
440             fiy1            += ty;
441             fiz1            += tz;
442             f[j_coord_offset+DIM*2+XX] -= tx;
443             f[j_coord_offset+DIM*2+YY] -= ty;
444             f[j_coord_offset+DIM*2+ZZ] -= tz;
445
446             /**************************
447              * CALCULATE INTERACTIONS *
448              **************************/
449
450             /* REACTION-FIELD ELECTROSTATICS */
451             velec            = qq20*(rinv20+krf*rsq20-crf);
452             felec            = qq20*(rinv20*rinvsq20-krf2);
453
454             /* Update potential sums from outer loop */
455             velecsum        += velec;
456
457             fscal            = felec;
458
459             /* Calculate temporary vectorial force */
460             tx               = fscal*dx20;
461             ty               = fscal*dy20;
462             tz               = fscal*dz20;
463
464             /* Update vectorial force */
465             fix2            += tx;
466             fiy2            += ty;
467             fiz2            += tz;
468             f[j_coord_offset+DIM*0+XX] -= tx;
469             f[j_coord_offset+DIM*0+YY] -= ty;
470             f[j_coord_offset+DIM*0+ZZ] -= tz;
471
472             /**************************
473              * CALCULATE INTERACTIONS *
474              **************************/
475
476             /* REACTION-FIELD ELECTROSTATICS */
477             velec            = qq21*(rinv21+krf*rsq21-crf);
478             felec            = qq21*(rinv21*rinvsq21-krf2);
479
480             /* Update potential sums from outer loop */
481             velecsum        += velec;
482
483             fscal            = felec;
484
485             /* Calculate temporary vectorial force */
486             tx               = fscal*dx21;
487             ty               = fscal*dy21;
488             tz               = fscal*dz21;
489
490             /* Update vectorial force */
491             fix2            += tx;
492             fiy2            += ty;
493             fiz2            += tz;
494             f[j_coord_offset+DIM*1+XX] -= tx;
495             f[j_coord_offset+DIM*1+YY] -= ty;
496             f[j_coord_offset+DIM*1+ZZ] -= tz;
497
498             /**************************
499              * CALCULATE INTERACTIONS *
500              **************************/
501
502             /* REACTION-FIELD ELECTROSTATICS */
503             velec            = qq22*(rinv22+krf*rsq22-crf);
504             felec            = qq22*(rinv22*rinvsq22-krf2);
505
506             /* Update potential sums from outer loop */
507             velecsum        += velec;
508
509             fscal            = felec;
510
511             /* Calculate temporary vectorial force */
512             tx               = fscal*dx22;
513             ty               = fscal*dy22;
514             tz               = fscal*dz22;
515
516             /* Update vectorial force */
517             fix2            += tx;
518             fiy2            += ty;
519             fiz2            += tz;
520             f[j_coord_offset+DIM*2+XX] -= tx;
521             f[j_coord_offset+DIM*2+YY] -= ty;
522             f[j_coord_offset+DIM*2+ZZ] -= tz;
523
524             /* Inner loop uses 313 flops */
525         }
526         /* End of innermost loop */
527
528         tx = ty = tz = 0;
529         f[i_coord_offset+DIM*0+XX] += fix0;
530         f[i_coord_offset+DIM*0+YY] += fiy0;
531         f[i_coord_offset+DIM*0+ZZ] += fiz0;
532         tx                         += fix0;
533         ty                         += fiy0;
534         tz                         += fiz0;
535         f[i_coord_offset+DIM*1+XX] += fix1;
536         f[i_coord_offset+DIM*1+YY] += fiy1;
537         f[i_coord_offset+DIM*1+ZZ] += fiz1;
538         tx                         += fix1;
539         ty                         += fiy1;
540         tz                         += fiz1;
541         f[i_coord_offset+DIM*2+XX] += fix2;
542         f[i_coord_offset+DIM*2+YY] += fiy2;
543         f[i_coord_offset+DIM*2+ZZ] += fiz2;
544         tx                         += fix2;
545         ty                         += fiy2;
546         tz                         += fiz2;
547         fshift[i_shift_offset+XX]  += tx;
548         fshift[i_shift_offset+YY]  += ty;
549         fshift[i_shift_offset+ZZ]  += tz;
550
551         ggid                        = gid[iidx];
552         /* Update potential energies */
553         kernel_data->energygrp_elec[ggid] += velecsum;
554         kernel_data->energygrp_vdw[ggid] += vvdwsum;
555
556         /* Increment number of inner iterations */
557         inneriter                  += j_index_end - j_index_start;
558
559         /* Outer loop uses 32 flops */
560     }
561
562     /* Increment number of outer iterations */
563     outeriter        += nri;
564
565     /* Update outer/inner flops */
566
567     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_VF,outeriter*32 + inneriter*313);
568 }
569 /*
570  * Gromacs nonbonded kernel:   nb_kernel_ElecRF_VdwCSTab_GeomW3W3_F_c
571  * Electrostatics interaction: ReactionField
572  * VdW interaction:            CubicSplineTable
573  * Geometry:                   Water3-Water3
574  * Calculate force/pot:        Force
575  */
576 void
577 nb_kernel_ElecRF_VdwCSTab_GeomW3W3_F_c
578                     (t_nblist * gmx_restrict                nlist,
579                      rvec * gmx_restrict                    xx,
580                      rvec * gmx_restrict                    ff,
581                      t_forcerec * gmx_restrict              fr,
582                      t_mdatoms * gmx_restrict               mdatoms,
583                      nb_kernel_data_t * gmx_restrict        kernel_data,
584                      t_nrnb * gmx_restrict                  nrnb)
585 {
586     int              i_shift_offset,i_coord_offset,j_coord_offset;
587     int              j_index_start,j_index_end;
588     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
589     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
590     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
591     real             *shiftvec,*fshift,*x,*f;
592     int              vdwioffset0;
593     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
594     int              vdwioffset1;
595     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
596     int              vdwioffset2;
597     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
598     int              vdwjidx0;
599     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
600     int              vdwjidx1;
601     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
602     int              vdwjidx2;
603     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
604     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
605     real             dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01,cexp1_01,cexp2_01;
606     real             dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02,cexp1_02,cexp2_02;
607     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
608     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
609     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
610     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
611     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
612     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
613     real             velec,felec,velecsum,facel,crf,krf,krf2;
614     real             *charge;
615     int              nvdwtype;
616     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
617     int              *vdwtype;
618     real             *vdwparam;
619     int              vfitab;
620     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
621     real             *vftab;
622
623     x                = xx[0];
624     f                = ff[0];
625
626     nri              = nlist->nri;
627     iinr             = nlist->iinr;
628     jindex           = nlist->jindex;
629     jjnr             = nlist->jjnr;
630     shiftidx         = nlist->shift;
631     gid              = nlist->gid;
632     shiftvec         = fr->shift_vec[0];
633     fshift           = fr->fshift[0];
634     facel            = fr->epsfac;
635     charge           = mdatoms->chargeA;
636     krf              = fr->ic->k_rf;
637     krf2             = krf*2.0;
638     crf              = fr->ic->c_rf;
639     nvdwtype         = fr->ntype;
640     vdwparam         = fr->nbfp;
641     vdwtype          = mdatoms->typeA;
642
643     vftab            = kernel_data->table_vdw->data;
644     vftabscale       = kernel_data->table_vdw->scale;
645
646     /* Setup water-specific parameters */
647     inr              = nlist->iinr[0];
648     iq0              = facel*charge[inr+0];
649     iq1              = facel*charge[inr+1];
650     iq2              = facel*charge[inr+2];
651     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
652
653     jq0              = charge[inr+0];
654     jq1              = charge[inr+1];
655     jq2              = charge[inr+2];
656     vdwjidx0         = 2*vdwtype[inr+0];
657     qq00             = iq0*jq0;
658     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
659     c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
660     qq01             = iq0*jq1;
661     qq02             = iq0*jq2;
662     qq10             = iq1*jq0;
663     qq11             = iq1*jq1;
664     qq12             = iq1*jq2;
665     qq20             = iq2*jq0;
666     qq21             = iq2*jq1;
667     qq22             = iq2*jq2;
668
669     outeriter        = 0;
670     inneriter        = 0;
671
672     /* Start outer loop over neighborlists */
673     for(iidx=0; iidx<nri; iidx++)
674     {
675         /* Load shift vector for this list */
676         i_shift_offset   = DIM*shiftidx[iidx];
677         shX              = shiftvec[i_shift_offset+XX];
678         shY              = shiftvec[i_shift_offset+YY];
679         shZ              = shiftvec[i_shift_offset+ZZ];
680
681         /* Load limits for loop over neighbors */
682         j_index_start    = jindex[iidx];
683         j_index_end      = jindex[iidx+1];
684
685         /* Get outer coordinate index */
686         inr              = iinr[iidx];
687         i_coord_offset   = DIM*inr;
688
689         /* Load i particle coords and add shift vector */
690         ix0              = shX + x[i_coord_offset+DIM*0+XX];
691         iy0              = shY + x[i_coord_offset+DIM*0+YY];
692         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
693         ix1              = shX + x[i_coord_offset+DIM*1+XX];
694         iy1              = shY + x[i_coord_offset+DIM*1+YY];
695         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
696         ix2              = shX + x[i_coord_offset+DIM*2+XX];
697         iy2              = shY + x[i_coord_offset+DIM*2+YY];
698         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
699
700         fix0             = 0.0;
701         fiy0             = 0.0;
702         fiz0             = 0.0;
703         fix1             = 0.0;
704         fiy1             = 0.0;
705         fiz1             = 0.0;
706         fix2             = 0.0;
707         fiy2             = 0.0;
708         fiz2             = 0.0;
709
710         /* Start inner kernel loop */
711         for(jidx=j_index_start; jidx<j_index_end; jidx++)
712         {
713             /* Get j neighbor index, and coordinate index */
714             jnr              = jjnr[jidx];
715             j_coord_offset   = DIM*jnr;
716
717             /* load j atom coordinates */
718             jx0              = x[j_coord_offset+DIM*0+XX];
719             jy0              = x[j_coord_offset+DIM*0+YY];
720             jz0              = x[j_coord_offset+DIM*0+ZZ];
721             jx1              = x[j_coord_offset+DIM*1+XX];
722             jy1              = x[j_coord_offset+DIM*1+YY];
723             jz1              = x[j_coord_offset+DIM*1+ZZ];
724             jx2              = x[j_coord_offset+DIM*2+XX];
725             jy2              = x[j_coord_offset+DIM*2+YY];
726             jz2              = x[j_coord_offset+DIM*2+ZZ];
727
728             /* Calculate displacement vector */
729             dx00             = ix0 - jx0;
730             dy00             = iy0 - jy0;
731             dz00             = iz0 - jz0;
732             dx01             = ix0 - jx1;
733             dy01             = iy0 - jy1;
734             dz01             = iz0 - jz1;
735             dx02             = ix0 - jx2;
736             dy02             = iy0 - jy2;
737             dz02             = iz0 - jz2;
738             dx10             = ix1 - jx0;
739             dy10             = iy1 - jy0;
740             dz10             = iz1 - jz0;
741             dx11             = ix1 - jx1;
742             dy11             = iy1 - jy1;
743             dz11             = iz1 - jz1;
744             dx12             = ix1 - jx2;
745             dy12             = iy1 - jy2;
746             dz12             = iz1 - jz2;
747             dx20             = ix2 - jx0;
748             dy20             = iy2 - jy0;
749             dz20             = iz2 - jz0;
750             dx21             = ix2 - jx1;
751             dy21             = iy2 - jy1;
752             dz21             = iz2 - jz1;
753             dx22             = ix2 - jx2;
754             dy22             = iy2 - jy2;
755             dz22             = iz2 - jz2;
756
757             /* Calculate squared distance and things based on it */
758             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
759             rsq01            = dx01*dx01+dy01*dy01+dz01*dz01;
760             rsq02            = dx02*dx02+dy02*dy02+dz02*dz02;
761             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
762             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
763             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
764             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
765             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
766             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
767
768             rinv00           = gmx_invsqrt(rsq00);
769             rinv01           = gmx_invsqrt(rsq01);
770             rinv02           = gmx_invsqrt(rsq02);
771             rinv10           = gmx_invsqrt(rsq10);
772             rinv11           = gmx_invsqrt(rsq11);
773             rinv12           = gmx_invsqrt(rsq12);
774             rinv20           = gmx_invsqrt(rsq20);
775             rinv21           = gmx_invsqrt(rsq21);
776             rinv22           = gmx_invsqrt(rsq22);
777
778             rinvsq00         = rinv00*rinv00;
779             rinvsq01         = rinv01*rinv01;
780             rinvsq02         = rinv02*rinv02;
781             rinvsq10         = rinv10*rinv10;
782             rinvsq11         = rinv11*rinv11;
783             rinvsq12         = rinv12*rinv12;
784             rinvsq20         = rinv20*rinv20;
785             rinvsq21         = rinv21*rinv21;
786             rinvsq22         = rinv22*rinv22;
787
788             /**************************
789              * CALCULATE INTERACTIONS *
790              **************************/
791
792             r00              = rsq00*rinv00;
793
794             /* Calculate table index by multiplying r with table scale and truncate to integer */
795             rt               = r00*vftabscale;
796             vfitab           = rt;
797             vfeps            = rt-vfitab;
798             vfitab           = 2*4*vfitab;
799
800             /* REACTION-FIELD ELECTROSTATICS */
801             felec            = qq00*(rinv00*rinvsq00-krf2);
802
803             /* CUBIC SPLINE TABLE DISPERSION */
804             vfitab          += 0;
805             F                = vftab[vfitab+1];
806             Geps             = vfeps*vftab[vfitab+2];
807             Heps2            = vfeps*vfeps*vftab[vfitab+3];
808             Fp               = F+Geps+Heps2;
809             FF               = Fp+Geps+2.0*Heps2;
810             fvdw6            = c6_00*FF;
811
812             /* CUBIC SPLINE TABLE REPULSION */
813             F                = vftab[vfitab+5];
814             Geps             = vfeps*vftab[vfitab+6];
815             Heps2            = vfeps*vfeps*vftab[vfitab+7];
816             Fp               = F+Geps+Heps2;
817             FF               = Fp+Geps+2.0*Heps2;
818             fvdw12           = c12_00*FF;
819             fvdw             = -(fvdw6+fvdw12)*vftabscale*rinv00;
820
821             fscal            = felec+fvdw;
822
823             /* Calculate temporary vectorial force */
824             tx               = fscal*dx00;
825             ty               = fscal*dy00;
826             tz               = fscal*dz00;
827
828             /* Update vectorial force */
829             fix0            += tx;
830             fiy0            += ty;
831             fiz0            += tz;
832             f[j_coord_offset+DIM*0+XX] -= tx;
833             f[j_coord_offset+DIM*0+YY] -= ty;
834             f[j_coord_offset+DIM*0+ZZ] -= tz;
835
836             /**************************
837              * CALCULATE INTERACTIONS *
838              **************************/
839
840             /* REACTION-FIELD ELECTROSTATICS */
841             felec            = qq01*(rinv01*rinvsq01-krf2);
842
843             fscal            = felec;
844
845             /* Calculate temporary vectorial force */
846             tx               = fscal*dx01;
847             ty               = fscal*dy01;
848             tz               = fscal*dz01;
849
850             /* Update vectorial force */
851             fix0            += tx;
852             fiy0            += ty;
853             fiz0            += tz;
854             f[j_coord_offset+DIM*1+XX] -= tx;
855             f[j_coord_offset+DIM*1+YY] -= ty;
856             f[j_coord_offset+DIM*1+ZZ] -= tz;
857
858             /**************************
859              * CALCULATE INTERACTIONS *
860              **************************/
861
862             /* REACTION-FIELD ELECTROSTATICS */
863             felec            = qq02*(rinv02*rinvsq02-krf2);
864
865             fscal            = felec;
866
867             /* Calculate temporary vectorial force */
868             tx               = fscal*dx02;
869             ty               = fscal*dy02;
870             tz               = fscal*dz02;
871
872             /* Update vectorial force */
873             fix0            += tx;
874             fiy0            += ty;
875             fiz0            += tz;
876             f[j_coord_offset+DIM*2+XX] -= tx;
877             f[j_coord_offset+DIM*2+YY] -= ty;
878             f[j_coord_offset+DIM*2+ZZ] -= tz;
879
880             /**************************
881              * CALCULATE INTERACTIONS *
882              **************************/
883
884             /* REACTION-FIELD ELECTROSTATICS */
885             felec            = qq10*(rinv10*rinvsq10-krf2);
886
887             fscal            = felec;
888
889             /* Calculate temporary vectorial force */
890             tx               = fscal*dx10;
891             ty               = fscal*dy10;
892             tz               = fscal*dz10;
893
894             /* Update vectorial force */
895             fix1            += tx;
896             fiy1            += ty;
897             fiz1            += tz;
898             f[j_coord_offset+DIM*0+XX] -= tx;
899             f[j_coord_offset+DIM*0+YY] -= ty;
900             f[j_coord_offset+DIM*0+ZZ] -= tz;
901
902             /**************************
903              * CALCULATE INTERACTIONS *
904              **************************/
905
906             /* REACTION-FIELD ELECTROSTATICS */
907             felec            = qq11*(rinv11*rinvsq11-krf2);
908
909             fscal            = felec;
910
911             /* Calculate temporary vectorial force */
912             tx               = fscal*dx11;
913             ty               = fscal*dy11;
914             tz               = fscal*dz11;
915
916             /* Update vectorial force */
917             fix1            += tx;
918             fiy1            += ty;
919             fiz1            += tz;
920             f[j_coord_offset+DIM*1+XX] -= tx;
921             f[j_coord_offset+DIM*1+YY] -= ty;
922             f[j_coord_offset+DIM*1+ZZ] -= tz;
923
924             /**************************
925              * CALCULATE INTERACTIONS *
926              **************************/
927
928             /* REACTION-FIELD ELECTROSTATICS */
929             felec            = qq12*(rinv12*rinvsq12-krf2);
930
931             fscal            = felec;
932
933             /* Calculate temporary vectorial force */
934             tx               = fscal*dx12;
935             ty               = fscal*dy12;
936             tz               = fscal*dz12;
937
938             /* Update vectorial force */
939             fix1            += tx;
940             fiy1            += ty;
941             fiz1            += tz;
942             f[j_coord_offset+DIM*2+XX] -= tx;
943             f[j_coord_offset+DIM*2+YY] -= ty;
944             f[j_coord_offset+DIM*2+ZZ] -= tz;
945
946             /**************************
947              * CALCULATE INTERACTIONS *
948              **************************/
949
950             /* REACTION-FIELD ELECTROSTATICS */
951             felec            = qq20*(rinv20*rinvsq20-krf2);
952
953             fscal            = felec;
954
955             /* Calculate temporary vectorial force */
956             tx               = fscal*dx20;
957             ty               = fscal*dy20;
958             tz               = fscal*dz20;
959
960             /* Update vectorial force */
961             fix2            += tx;
962             fiy2            += ty;
963             fiz2            += tz;
964             f[j_coord_offset+DIM*0+XX] -= tx;
965             f[j_coord_offset+DIM*0+YY] -= ty;
966             f[j_coord_offset+DIM*0+ZZ] -= tz;
967
968             /**************************
969              * CALCULATE INTERACTIONS *
970              **************************/
971
972             /* REACTION-FIELD ELECTROSTATICS */
973             felec            = qq21*(rinv21*rinvsq21-krf2);
974
975             fscal            = felec;
976
977             /* Calculate temporary vectorial force */
978             tx               = fscal*dx21;
979             ty               = fscal*dy21;
980             tz               = fscal*dz21;
981
982             /* Update vectorial force */
983             fix2            += tx;
984             fiy2            += ty;
985             fiz2            += tz;
986             f[j_coord_offset+DIM*1+XX] -= tx;
987             f[j_coord_offset+DIM*1+YY] -= ty;
988             f[j_coord_offset+DIM*1+ZZ] -= tz;
989
990             /**************************
991              * CALCULATE INTERACTIONS *
992              **************************/
993
994             /* REACTION-FIELD ELECTROSTATICS */
995             felec            = qq22*(rinv22*rinvsq22-krf2);
996
997             fscal            = felec;
998
999             /* Calculate temporary vectorial force */
1000             tx               = fscal*dx22;
1001             ty               = fscal*dy22;
1002             tz               = fscal*dz22;
1003
1004             /* Update vectorial force */
1005             fix2            += tx;
1006             fiy2            += ty;
1007             fiz2            += tz;
1008             f[j_coord_offset+DIM*2+XX] -= tx;
1009             f[j_coord_offset+DIM*2+YY] -= ty;
1010             f[j_coord_offset+DIM*2+ZZ] -= tz;
1011
1012             /* Inner loop uses 260 flops */
1013         }
1014         /* End of innermost loop */
1015
1016         tx = ty = tz = 0;
1017         f[i_coord_offset+DIM*0+XX] += fix0;
1018         f[i_coord_offset+DIM*0+YY] += fiy0;
1019         f[i_coord_offset+DIM*0+ZZ] += fiz0;
1020         tx                         += fix0;
1021         ty                         += fiy0;
1022         tz                         += fiz0;
1023         f[i_coord_offset+DIM*1+XX] += fix1;
1024         f[i_coord_offset+DIM*1+YY] += fiy1;
1025         f[i_coord_offset+DIM*1+ZZ] += fiz1;
1026         tx                         += fix1;
1027         ty                         += fiy1;
1028         tz                         += fiz1;
1029         f[i_coord_offset+DIM*2+XX] += fix2;
1030         f[i_coord_offset+DIM*2+YY] += fiy2;
1031         f[i_coord_offset+DIM*2+ZZ] += fiz2;
1032         tx                         += fix2;
1033         ty                         += fiy2;
1034         tz                         += fiz2;
1035         fshift[i_shift_offset+XX]  += tx;
1036         fshift[i_shift_offset+YY]  += ty;
1037         fshift[i_shift_offset+ZZ]  += tz;
1038
1039         /* Increment number of inner iterations */
1040         inneriter                  += j_index_end - j_index_start;
1041
1042         /* Outer loop uses 30 flops */
1043     }
1044
1045     /* Increment number of outer iterations */
1046     outeriter        += nri;
1047
1048     /* Update outer/inner flops */
1049
1050     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_F,outeriter*30 + inneriter*260);
1051 }