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