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