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