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