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