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