Merge 'release-4-6' into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecNone_VdwCSTab_GeomP1P1_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_ElecNone_VdwCSTab_GeomP1P1_VF_c
35  * Electrostatics interaction: None
36  * VdW interaction:            CubicSplineTable
37  * Geometry:                   Particle-Particle
38  * Calculate force/pot:        PotentialAndForce
39  */
40 void
41 nb_kernel_ElecNone_VdwCSTab_GeomP1P1_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              vdwjidx0;
59     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
60     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
61     int              nvdwtype;
62     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
63     int              *vdwtype;
64     real             *vdwparam;
65     int              vfitab;
66     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
67     real             *vftab;
68
69     x                = xx[0];
70     f                = ff[0];
71
72     nri              = nlist->nri;
73     iinr             = nlist->iinr;
74     jindex           = nlist->jindex;
75     jjnr             = nlist->jjnr;
76     shiftidx         = nlist->shift;
77     gid              = nlist->gid;
78     shiftvec         = fr->shift_vec[0];
79     fshift           = fr->fshift[0];
80     nvdwtype         = fr->ntype;
81     vdwparam         = fr->nbfp;
82     vdwtype          = mdatoms->typeA;
83
84     vftab            = kernel_data->table_vdw->data;
85     vftabscale       = kernel_data->table_vdw->scale;
86
87     outeriter        = 0;
88     inneriter        = 0;
89
90     /* Start outer loop over neighborlists */
91     for(iidx=0; iidx<nri; iidx++)
92     {
93         /* Load shift vector for this list */
94         i_shift_offset   = DIM*shiftidx[iidx];
95         shX              = shiftvec[i_shift_offset+XX];
96         shY              = shiftvec[i_shift_offset+YY];
97         shZ              = shiftvec[i_shift_offset+ZZ];
98
99         /* Load limits for loop over neighbors */
100         j_index_start    = jindex[iidx];
101         j_index_end      = jindex[iidx+1];
102
103         /* Get outer coordinate index */
104         inr              = iinr[iidx];
105         i_coord_offset   = DIM*inr;
106
107         /* Load i particle coords and add shift vector */
108         ix0              = shX + x[i_coord_offset+DIM*0+XX];
109         iy0              = shY + x[i_coord_offset+DIM*0+YY];
110         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
111
112         fix0             = 0.0;
113         fiy0             = 0.0;
114         fiz0             = 0.0;
115
116         /* Load parameters for i particles */
117         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
118
119         /* Reset potential sums */
120         vvdwsum          = 0.0;
121
122         /* Start inner kernel loop */
123         for(jidx=j_index_start; jidx<j_index_end; jidx++)
124         {
125             /* Get j neighbor index, and coordinate index */
126             jnr              = jjnr[jidx];
127             j_coord_offset   = DIM*jnr;
128
129             /* load j atom coordinates */
130             jx0              = x[j_coord_offset+DIM*0+XX];
131             jy0              = x[j_coord_offset+DIM*0+YY];
132             jz0              = x[j_coord_offset+DIM*0+ZZ];
133
134             /* Calculate displacement vector */
135             dx00             = ix0 - jx0;
136             dy00             = iy0 - jy0;
137             dz00             = iz0 - jz0;
138
139             /* Calculate squared distance and things based on it */
140             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
141
142             rinv00           = gmx_invsqrt(rsq00);
143
144             /* Load parameters for j particles */
145             vdwjidx0         = 2*vdwtype[jnr+0];
146
147             /**************************
148              * CALCULATE INTERACTIONS *
149              **************************/
150
151             r00              = rsq00*rinv00;
152
153             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
154             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
155
156             /* Calculate table index by multiplying r with table scale and truncate to integer */
157             rt               = r00*vftabscale;
158             vfitab           = rt;
159             vfeps            = rt-vfitab;
160             vfitab           = 2*4*vfitab;
161
162             /* CUBIC SPLINE TABLE DISPERSION */
163             vfitab          += 0;
164             Y                = vftab[vfitab];
165             F                = vftab[vfitab+1];
166             Geps             = vfeps*vftab[vfitab+2];
167             Heps2            = vfeps*vfeps*vftab[vfitab+3];
168             Fp               = F+Geps+Heps2;
169             VV               = Y+vfeps*Fp;
170             vvdw6            = c6_00*VV;
171             FF               = Fp+Geps+2.0*Heps2;
172             fvdw6            = c6_00*FF;
173
174             /* CUBIC SPLINE TABLE REPULSION */
175             Y                = vftab[vfitab+4];
176             F                = vftab[vfitab+5];
177             Geps             = vfeps*vftab[vfitab+6];
178             Heps2            = vfeps*vfeps*vftab[vfitab+7];
179             Fp               = F+Geps+Heps2;
180             VV               = Y+vfeps*Fp;
181             vvdw12           = c12_00*VV;
182             FF               = Fp+Geps+2.0*Heps2;
183             fvdw12           = c12_00*FF;
184             vvdw             = vvdw12+vvdw6;
185             fvdw             = -(fvdw6+fvdw12)*vftabscale*rinv00;
186
187             /* Update potential sums from outer loop */
188             vvdwsum         += vvdw;
189
190             fscal            = fvdw;
191
192             /* Calculate temporary vectorial force */
193             tx               = fscal*dx00;
194             ty               = fscal*dy00;
195             tz               = fscal*dz00;
196
197             /* Update vectorial force */
198             fix0            += tx;
199             fiy0            += ty;
200             fiz0            += tz;
201             f[j_coord_offset+DIM*0+XX] -= tx;
202             f[j_coord_offset+DIM*0+YY] -= ty;
203             f[j_coord_offset+DIM*0+ZZ] -= tz;
204
205             /* Inner loop uses 55 flops */
206         }
207         /* End of innermost loop */
208
209         tx = ty = tz = 0;
210         f[i_coord_offset+DIM*0+XX] += fix0;
211         f[i_coord_offset+DIM*0+YY] += fiy0;
212         f[i_coord_offset+DIM*0+ZZ] += fiz0;
213         tx                         += fix0;
214         ty                         += fiy0;
215         tz                         += fiz0;
216         fshift[i_shift_offset+XX]  += tx;
217         fshift[i_shift_offset+YY]  += ty;
218         fshift[i_shift_offset+ZZ]  += tz;
219
220         ggid                        = gid[iidx];
221         /* Update potential energies */
222         kernel_data->energygrp_vdw[ggid] += vvdwsum;
223
224         /* Increment number of inner iterations */
225         inneriter                  += j_index_end - j_index_start;
226
227         /* Outer loop uses 13 flops */
228     }
229
230     /* Increment number of outer iterations */
231     outeriter        += nri;
232
233     /* Update outer/inner flops */
234
235     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_VF,outeriter*13 + inneriter*55);
236 }
237 /*
238  * Gromacs nonbonded kernel:   nb_kernel_ElecNone_VdwCSTab_GeomP1P1_F_c
239  * Electrostatics interaction: None
240  * VdW interaction:            CubicSplineTable
241  * Geometry:                   Particle-Particle
242  * Calculate force/pot:        Force
243  */
244 void
245 nb_kernel_ElecNone_VdwCSTab_GeomP1P1_F_c
246                     (t_nblist * gmx_restrict                nlist,
247                      rvec * gmx_restrict                    xx,
248                      rvec * gmx_restrict                    ff,
249                      t_forcerec * gmx_restrict              fr,
250                      t_mdatoms * gmx_restrict               mdatoms,
251                      nb_kernel_data_t * gmx_restrict        kernel_data,
252                      t_nrnb * gmx_restrict                  nrnb)
253 {
254     int              i_shift_offset,i_coord_offset,j_coord_offset;
255     int              j_index_start,j_index_end;
256     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
257     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
258     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
259     real             *shiftvec,*fshift,*x,*f;
260     int              vdwioffset0;
261     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
262     int              vdwjidx0;
263     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
264     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
265     int              nvdwtype;
266     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
267     int              *vdwtype;
268     real             *vdwparam;
269     int              vfitab;
270     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
271     real             *vftab;
272
273     x                = xx[0];
274     f                = ff[0];
275
276     nri              = nlist->nri;
277     iinr             = nlist->iinr;
278     jindex           = nlist->jindex;
279     jjnr             = nlist->jjnr;
280     shiftidx         = nlist->shift;
281     gid              = nlist->gid;
282     shiftvec         = fr->shift_vec[0];
283     fshift           = fr->fshift[0];
284     nvdwtype         = fr->ntype;
285     vdwparam         = fr->nbfp;
286     vdwtype          = mdatoms->typeA;
287
288     vftab            = kernel_data->table_vdw->data;
289     vftabscale       = kernel_data->table_vdw->scale;
290
291     outeriter        = 0;
292     inneriter        = 0;
293
294     /* Start outer loop over neighborlists */
295     for(iidx=0; iidx<nri; iidx++)
296     {
297         /* Load shift vector for this list */
298         i_shift_offset   = DIM*shiftidx[iidx];
299         shX              = shiftvec[i_shift_offset+XX];
300         shY              = shiftvec[i_shift_offset+YY];
301         shZ              = shiftvec[i_shift_offset+ZZ];
302
303         /* Load limits for loop over neighbors */
304         j_index_start    = jindex[iidx];
305         j_index_end      = jindex[iidx+1];
306
307         /* Get outer coordinate index */
308         inr              = iinr[iidx];
309         i_coord_offset   = DIM*inr;
310
311         /* Load i particle coords and add shift vector */
312         ix0              = shX + x[i_coord_offset+DIM*0+XX];
313         iy0              = shY + x[i_coord_offset+DIM*0+YY];
314         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
315
316         fix0             = 0.0;
317         fiy0             = 0.0;
318         fiz0             = 0.0;
319
320         /* Load parameters for i particles */
321         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
322
323         /* Start inner kernel loop */
324         for(jidx=j_index_start; jidx<j_index_end; jidx++)
325         {
326             /* Get j neighbor index, and coordinate index */
327             jnr              = jjnr[jidx];
328             j_coord_offset   = DIM*jnr;
329
330             /* load j atom coordinates */
331             jx0              = x[j_coord_offset+DIM*0+XX];
332             jy0              = x[j_coord_offset+DIM*0+YY];
333             jz0              = x[j_coord_offset+DIM*0+ZZ];
334
335             /* Calculate displacement vector */
336             dx00             = ix0 - jx0;
337             dy00             = iy0 - jy0;
338             dz00             = iz0 - jz0;
339
340             /* Calculate squared distance and things based on it */
341             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
342
343             rinv00           = gmx_invsqrt(rsq00);
344
345             /* Load parameters for j particles */
346             vdwjidx0         = 2*vdwtype[jnr+0];
347
348             /**************************
349              * CALCULATE INTERACTIONS *
350              **************************/
351
352             r00              = rsq00*rinv00;
353
354             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
355             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
356
357             /* Calculate table index by multiplying r with table scale and truncate to integer */
358             rt               = r00*vftabscale;
359             vfitab           = rt;
360             vfeps            = rt-vfitab;
361             vfitab           = 2*4*vfitab;
362
363             /* CUBIC SPLINE TABLE DISPERSION */
364             vfitab          += 0;
365             F                = vftab[vfitab+1];
366             Geps             = vfeps*vftab[vfitab+2];
367             Heps2            = vfeps*vfeps*vftab[vfitab+3];
368             Fp               = F+Geps+Heps2;
369             FF               = Fp+Geps+2.0*Heps2;
370             fvdw6            = c6_00*FF;
371
372             /* CUBIC SPLINE TABLE REPULSION */
373             F                = vftab[vfitab+5];
374             Geps             = vfeps*vftab[vfitab+6];
375             Heps2            = vfeps*vfeps*vftab[vfitab+7];
376             Fp               = F+Geps+Heps2;
377             FF               = Fp+Geps+2.0*Heps2;
378             fvdw12           = c12_00*FF;
379             fvdw             = -(fvdw6+fvdw12)*vftabscale*rinv00;
380
381             fscal            = fvdw;
382
383             /* Calculate temporary vectorial force */
384             tx               = fscal*dx00;
385             ty               = fscal*dy00;
386             tz               = fscal*dz00;
387
388             /* Update vectorial force */
389             fix0            += tx;
390             fiy0            += ty;
391             fiz0            += tz;
392             f[j_coord_offset+DIM*0+XX] -= tx;
393             f[j_coord_offset+DIM*0+YY] -= ty;
394             f[j_coord_offset+DIM*0+ZZ] -= tz;
395
396             /* Inner loop uses 47 flops */
397         }
398         /* End of innermost loop */
399
400         tx = ty = tz = 0;
401         f[i_coord_offset+DIM*0+XX] += fix0;
402         f[i_coord_offset+DIM*0+YY] += fiy0;
403         f[i_coord_offset+DIM*0+ZZ] += fiz0;
404         tx                         += fix0;
405         ty                         += fiy0;
406         tz                         += fiz0;
407         fshift[i_shift_offset+XX]  += tx;
408         fshift[i_shift_offset+YY]  += ty;
409         fshift[i_shift_offset+ZZ]  += tz;
410
411         /* Increment number of inner iterations */
412         inneriter                  += j_index_end - j_index_start;
413
414         /* Outer loop uses 12 flops */
415     }
416
417     /* Increment number of outer iterations */
418     outeriter        += nri;
419
420     /* Update outer/inner flops */
421
422     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_F,outeriter*12 + inneriter*47);
423 }