Fix component for libcudart
[alexxy/gromacs.git] / src / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecRFCut_VdwBhamSh_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_ElecRFCut_VdwBhamSh_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_ElecRFCut_VdwBhamSh_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     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
89     rcutoff          = fr->rcoulomb;
90     rcutoff2         = rcutoff*rcutoff;
91
92     sh_vdw_invrcut6  = fr->ic->sh_invrc6;
93     rvdw             = fr->rvdw;
94
95     outeriter        = 0;
96     inneriter        = 0;
97
98     /* Start outer loop over neighborlists */
99     for(iidx=0; iidx<nri; iidx++)
100     {
101         /* Load shift vector for this list */
102         i_shift_offset   = DIM*shiftidx[iidx];
103         shX              = shiftvec[i_shift_offset+XX];
104         shY              = shiftvec[i_shift_offset+YY];
105         shZ              = shiftvec[i_shift_offset+ZZ];
106
107         /* Load limits for loop over neighbors */
108         j_index_start    = jindex[iidx];
109         j_index_end      = jindex[iidx+1];
110
111         /* Get outer coordinate index */
112         inr              = iinr[iidx];
113         i_coord_offset   = DIM*inr;
114
115         /* Load i particle coords and add shift vector */
116         ix0              = shX + x[i_coord_offset+DIM*0+XX];
117         iy0              = shY + x[i_coord_offset+DIM*0+YY];
118         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
119
120         fix0             = 0.0;
121         fiy0             = 0.0;
122         fiz0             = 0.0;
123
124         /* Load parameters for i particles */
125         iq0              = facel*charge[inr+0];
126         vdwioffset0      = 3*nvdwtype*vdwtype[inr+0];
127
128         /* Reset potential sums */
129         velecsum         = 0.0;
130         vvdwsum          = 0.0;
131
132         /* Start inner kernel loop */
133         for(jidx=j_index_start; jidx<j_index_end; jidx++)
134         {
135             /* Get j neighbor index, and coordinate index */
136             jnr              = jjnr[jidx];
137             j_coord_offset   = DIM*jnr;
138
139             /* load j atom coordinates */
140             jx0              = x[j_coord_offset+DIM*0+XX];
141             jy0              = x[j_coord_offset+DIM*0+YY];
142             jz0              = x[j_coord_offset+DIM*0+ZZ];
143
144             /* Calculate displacement vector */
145             dx00             = ix0 - jx0;
146             dy00             = iy0 - jy0;
147             dz00             = iz0 - jz0;
148
149             /* Calculate squared distance and things based on it */
150             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
151
152             rinv00           = gmx_invsqrt(rsq00);
153
154             rinvsq00         = rinv00*rinv00;
155
156             /* Load parameters for j particles */
157             jq0              = charge[jnr+0];
158             vdwjidx0         = 3*vdwtype[jnr+0];
159
160             /**************************
161              * CALCULATE INTERACTIONS *
162              **************************/
163
164             if (rsq00<rcutoff2)
165             {
166
167             r00              = rsq00*rinv00;
168
169             qq00             = iq0*jq0;
170             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
171             cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
172             cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
173
174             /* REACTION-FIELD ELECTROSTATICS */
175             velec            = qq00*(rinv00+krf*rsq00-crf);
176             felec            = qq00*(rinv00*rinvsq00-krf2);
177
178             /* BUCKINGHAM DISPERSION/REPULSION */
179             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
180             vvdw6            = c6_00*rinvsix;
181             br               = cexp2_00*r00;
182             vvdwexp          = cexp1_00*exp(-br);
183             vvdw             = (vvdwexp-cexp1_00*exp(-cexp2_00*rvdw)) - (vvdw6 - c6_00*sh_vdw_invrcut6)*(1.0/6.0);
184             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
185
186             /* Update potential sums from outer loop */
187             velecsum        += velec;
188             vvdwsum         += vvdw;
189
190             fscal            = felec+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             }
206
207             /* Inner loop uses 102 flops */
208         }
209         /* End of innermost loop */
210
211         tx = ty = tz = 0;
212         f[i_coord_offset+DIM*0+XX] += fix0;
213         f[i_coord_offset+DIM*0+YY] += fiy0;
214         f[i_coord_offset+DIM*0+ZZ] += fiz0;
215         tx                         += fix0;
216         ty                         += fiy0;
217         tz                         += fiz0;
218         fshift[i_shift_offset+XX]  += tx;
219         fshift[i_shift_offset+YY]  += ty;
220         fshift[i_shift_offset+ZZ]  += tz;
221
222         ggid                        = gid[iidx];
223         /* Update potential energies */
224         kernel_data->energygrp_elec[ggid] += velecsum;
225         kernel_data->energygrp_vdw[ggid] += vvdwsum;
226
227         /* Increment number of inner iterations */
228         inneriter                  += j_index_end - j_index_start;
229
230         /* Outer loop uses 15 flops */
231     }
232
233     /* Increment number of outer iterations */
234     outeriter        += nri;
235
236     /* Update outer/inner flops */
237
238     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*15 + inneriter*102);
239 }
240 /*
241  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwBhamSh_GeomP1P1_F_c
242  * Electrostatics interaction: ReactionField
243  * VdW interaction:            Buckingham
244  * Geometry:                   Particle-Particle
245  * Calculate force/pot:        Force
246  */
247 void
248 nb_kernel_ElecRFCut_VdwBhamSh_GeomP1P1_F_c
249                     (t_nblist * gmx_restrict                nlist,
250                      rvec * gmx_restrict                    xx,
251                      rvec * gmx_restrict                    ff,
252                      t_forcerec * gmx_restrict              fr,
253                      t_mdatoms * gmx_restrict               mdatoms,
254                      nb_kernel_data_t * gmx_restrict        kernel_data,
255                      t_nrnb * gmx_restrict                  nrnb)
256 {
257     int              i_shift_offset,i_coord_offset,j_coord_offset;
258     int              j_index_start,j_index_end;
259     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
260     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
261     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
262     real             *shiftvec,*fshift,*x,*f;
263     int              vdwioffset0;
264     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
265     int              vdwjidx0;
266     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
267     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
268     real             velec,felec,velecsum,facel,crf,krf,krf2;
269     real             *charge;
270     int              nvdwtype;
271     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
272     int              *vdwtype;
273     real             *vdwparam;
274
275     x                = xx[0];
276     f                = ff[0];
277
278     nri              = nlist->nri;
279     iinr             = nlist->iinr;
280     jindex           = nlist->jindex;
281     jjnr             = nlist->jjnr;
282     shiftidx         = nlist->shift;
283     gid              = nlist->gid;
284     shiftvec         = fr->shift_vec[0];
285     fshift           = fr->fshift[0];
286     facel            = fr->epsfac;
287     charge           = mdatoms->chargeA;
288     krf              = fr->ic->k_rf;
289     krf2             = krf*2.0;
290     crf              = fr->ic->c_rf;
291     nvdwtype         = fr->ntype;
292     vdwparam         = fr->nbfp;
293     vdwtype          = mdatoms->typeA;
294
295     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
296     rcutoff          = fr->rcoulomb;
297     rcutoff2         = rcutoff*rcutoff;
298
299     sh_vdw_invrcut6  = fr->ic->sh_invrc6;
300     rvdw             = fr->rvdw;
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             if (rsq00<rcutoff2)
368             {
369
370             r00              = rsq00*rinv00;
371
372             qq00             = iq0*jq0;
373             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
374             cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
375             cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
376
377             /* REACTION-FIELD ELECTROSTATICS */
378             felec            = qq00*(rinv00*rinvsq00-krf2);
379
380             /* BUCKINGHAM DISPERSION/REPULSION */
381             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
382             vvdw6            = c6_00*rinvsix;
383             br               = cexp2_00*r00;
384             vvdwexp          = cexp1_00*exp(-br);
385             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
386
387             fscal            = felec+fvdw;
388
389             /* Calculate temporary vectorial force */
390             tx               = fscal*dx00;
391             ty               = fscal*dy00;
392             tz               = fscal*dz00;
393
394             /* Update vectorial force */
395             fix0            += tx;
396             fiy0            += ty;
397             fiz0            += tz;
398             f[j_coord_offset+DIM*0+XX] -= tx;
399             f[j_coord_offset+DIM*0+YY] -= ty;
400             f[j_coord_offset+DIM*0+ZZ] -= tz;
401
402             }
403
404             /* Inner loop uses 63 flops */
405         }
406         /* End of innermost loop */
407
408         tx = ty = tz = 0;
409         f[i_coord_offset+DIM*0+XX] += fix0;
410         f[i_coord_offset+DIM*0+YY] += fiy0;
411         f[i_coord_offset+DIM*0+ZZ] += fiz0;
412         tx                         += fix0;
413         ty                         += fiy0;
414         tz                         += fiz0;
415         fshift[i_shift_offset+XX]  += tx;
416         fshift[i_shift_offset+YY]  += ty;
417         fshift[i_shift_offset+ZZ]  += tz;
418
419         /* Increment number of inner iterations */
420         inneriter                  += j_index_end - j_index_start;
421
422         /* Outer loop uses 13 flops */
423     }
424
425     /* Increment number of outer iterations */
426     outeriter        += nri;
427
428     /* Update outer/inner flops */
429
430     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*13 + inneriter*63);
431 }