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