Merge 'release-4-6' into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecCSTab_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_ElecCSTab_VdwNone_GeomP1P1_VF_c
35  * Electrostatics interaction: CubicSplineTable
36  * VdW interaction:            None
37  * Geometry:                   Particle-Particle
38  * Calculate force/pot:        PotentialAndForce
39  */
40 void
41 nb_kernel_ElecCSTab_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              vfitab;
64     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
65     real             *vftab;
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     vftab            = kernel_data->table_elec->data;
82     vftabscale       = kernel_data->table_elec->scale;
83
84     outeriter        = 0;
85     inneriter        = 0;
86
87     /* Start outer loop over neighborlists */
88     for(iidx=0; iidx<nri; iidx++)
89     {
90         /* Load shift vector for this list */
91         i_shift_offset   = DIM*shiftidx[iidx];
92         shX              = shiftvec[i_shift_offset+XX];
93         shY              = shiftvec[i_shift_offset+YY];
94         shZ              = shiftvec[i_shift_offset+ZZ];
95
96         /* Load limits for loop over neighbors */
97         j_index_start    = jindex[iidx];
98         j_index_end      = jindex[iidx+1];
99
100         /* Get outer coordinate index */
101         inr              = iinr[iidx];
102         i_coord_offset   = DIM*inr;
103
104         /* Load i particle coords and add shift vector */
105         ix0              = shX + x[i_coord_offset+DIM*0+XX];
106         iy0              = shY + x[i_coord_offset+DIM*0+YY];
107         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
108
109         fix0             = 0.0;
110         fiy0             = 0.0;
111         fiz0             = 0.0;
112
113         /* Load parameters for i particles */
114         iq0              = facel*charge[inr+0];
115
116         /* Reset potential sums */
117         velecsum         = 0.0;
118
119         /* Start inner kernel loop */
120         for(jidx=j_index_start; jidx<j_index_end; jidx++)
121         {
122             /* Get j neighbor index, and coordinate index */
123             jnr              = jjnr[jidx];
124             j_coord_offset   = DIM*jnr;
125
126             /* load j atom coordinates */
127             jx0              = x[j_coord_offset+DIM*0+XX];
128             jy0              = x[j_coord_offset+DIM*0+YY];
129             jz0              = x[j_coord_offset+DIM*0+ZZ];
130
131             /* Calculate displacement vector */
132             dx00             = ix0 - jx0;
133             dy00             = iy0 - jy0;
134             dz00             = iz0 - jz0;
135
136             /* Calculate squared distance and things based on it */
137             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
138
139             rinv00           = gmx_invsqrt(rsq00);
140
141             /* Load parameters for j particles */
142             jq0              = charge[jnr+0];
143
144             /**************************
145              * CALCULATE INTERACTIONS *
146              **************************/
147
148             r00              = rsq00*rinv00;
149
150             qq00             = iq0*jq0;
151
152             /* Calculate table index by multiplying r with table scale and truncate to integer */
153             rt               = r00*vftabscale;
154             vfitab           = rt;
155             vfeps            = rt-vfitab;
156             vfitab           = 1*4*vfitab;
157
158             /* CUBIC SPLINE TABLE ELECTROSTATICS */
159             Y                = vftab[vfitab];
160             F                = vftab[vfitab+1];
161             Geps             = vfeps*vftab[vfitab+2];
162             Heps2            = vfeps*vfeps*vftab[vfitab+3];
163             Fp               = F+Geps+Heps2;
164             VV               = Y+vfeps*Fp;
165             velec            = qq00*VV;
166             FF               = Fp+Geps+2.0*Heps2;
167             felec            = -qq00*FF*vftabscale*rinv00;
168
169             /* Update potential sums from outer loop */
170             velecsum        += velec;
171
172             fscal            = felec;
173
174             /* Calculate temporary vectorial force */
175             tx               = fscal*dx00;
176             ty               = fscal*dy00;
177             tz               = fscal*dz00;
178
179             /* Update vectorial force */
180             fix0            += tx;
181             fiy0            += ty;
182             fiz0            += tz;
183             f[j_coord_offset+DIM*0+XX] -= tx;
184             f[j_coord_offset+DIM*0+YY] -= ty;
185             f[j_coord_offset+DIM*0+ZZ] -= tz;
186
187             /* Inner loop uses 42 flops */
188         }
189         /* End of innermost loop */
190
191         tx = ty = tz = 0;
192         f[i_coord_offset+DIM*0+XX] += fix0;
193         f[i_coord_offset+DIM*0+YY] += fiy0;
194         f[i_coord_offset+DIM*0+ZZ] += fiz0;
195         tx                         += fix0;
196         ty                         += fiy0;
197         tz                         += fiz0;
198         fshift[i_shift_offset+XX]  += tx;
199         fshift[i_shift_offset+YY]  += ty;
200         fshift[i_shift_offset+ZZ]  += tz;
201
202         ggid                        = gid[iidx];
203         /* Update potential energies */
204         kernel_data->energygrp_elec[ggid] += velecsum;
205
206         /* Increment number of inner iterations */
207         inneriter                  += j_index_end - j_index_start;
208
209         /* Outer loop uses 14 flops */
210     }
211
212     /* Increment number of outer iterations */
213     outeriter        += nri;
214
215     /* Update outer/inner flops */
216
217     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*14 + inneriter*42);
218 }
219 /*
220  * Gromacs nonbonded kernel:   nb_kernel_ElecCSTab_VdwNone_GeomP1P1_F_c
221  * Electrostatics interaction: CubicSplineTable
222  * VdW interaction:            None
223  * Geometry:                   Particle-Particle
224  * Calculate force/pot:        Force
225  */
226 void
227 nb_kernel_ElecCSTab_VdwNone_GeomP1P1_F_c
228                     (t_nblist * gmx_restrict                nlist,
229                      rvec * gmx_restrict                    xx,
230                      rvec * gmx_restrict                    ff,
231                      t_forcerec * gmx_restrict              fr,
232                      t_mdatoms * gmx_restrict               mdatoms,
233                      nb_kernel_data_t * gmx_restrict        kernel_data,
234                      t_nrnb * gmx_restrict                  nrnb)
235 {
236     int              i_shift_offset,i_coord_offset,j_coord_offset;
237     int              j_index_start,j_index_end;
238     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
239     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
240     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
241     real             *shiftvec,*fshift,*x,*f;
242     int              vdwioffset0;
243     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
244     int              vdwjidx0;
245     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
246     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
247     real             velec,felec,velecsum,facel,crf,krf,krf2;
248     real             *charge;
249     int              vfitab;
250     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
251     real             *vftab;
252
253     x                = xx[0];
254     f                = ff[0];
255
256     nri              = nlist->nri;
257     iinr             = nlist->iinr;
258     jindex           = nlist->jindex;
259     jjnr             = nlist->jjnr;
260     shiftidx         = nlist->shift;
261     gid              = nlist->gid;
262     shiftvec         = fr->shift_vec[0];
263     fshift           = fr->fshift[0];
264     facel            = fr->epsfac;
265     charge           = mdatoms->chargeA;
266
267     vftab            = kernel_data->table_elec->data;
268     vftabscale       = kernel_data->table_elec->scale;
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             /* Load parameters for j particles */
325             jq0              = charge[jnr+0];
326
327             /**************************
328              * CALCULATE INTERACTIONS *
329              **************************/
330
331             r00              = rsq00*rinv00;
332
333             qq00             = iq0*jq0;
334
335             /* Calculate table index by multiplying r with table scale and truncate to integer */
336             rt               = r00*vftabscale;
337             vfitab           = rt;
338             vfeps            = rt-vfitab;
339             vfitab           = 1*4*vfitab;
340
341             /* CUBIC SPLINE TABLE ELECTROSTATICS */
342             F                = vftab[vfitab+1];
343             Geps             = vfeps*vftab[vfitab+2];
344             Heps2            = vfeps*vfeps*vftab[vfitab+3];
345             Fp               = F+Geps+Heps2;
346             FF               = Fp+Geps+2.0*Heps2;
347             felec            = -qq00*FF*vftabscale*rinv00;
348
349             fscal            = felec;
350
351             /* Calculate temporary vectorial force */
352             tx               = fscal*dx00;
353             ty               = fscal*dy00;
354             tz               = fscal*dz00;
355
356             /* Update vectorial force */
357             fix0            += tx;
358             fiy0            += ty;
359             fiz0            += tz;
360             f[j_coord_offset+DIM*0+XX] -= tx;
361             f[j_coord_offset+DIM*0+YY] -= ty;
362             f[j_coord_offset+DIM*0+ZZ] -= tz;
363
364             /* Inner loop uses 38 flops */
365         }
366         /* End of innermost loop */
367
368         tx = ty = tz = 0;
369         f[i_coord_offset+DIM*0+XX] += fix0;
370         f[i_coord_offset+DIM*0+YY] += fiy0;
371         f[i_coord_offset+DIM*0+ZZ] += fiz0;
372         tx                         += fix0;
373         ty                         += fiy0;
374         tz                         += fiz0;
375         fshift[i_shift_offset+XX]  += tx;
376         fshift[i_shift_offset+YY]  += ty;
377         fshift[i_shift_offset+ZZ]  += tz;
378
379         /* Increment number of inner iterations */
380         inneriter                  += j_index_end - j_index_start;
381
382         /* Outer loop uses 13 flops */
383     }
384
385     /* Increment number of outer iterations */
386     outeriter        += nri;
387
388     /* Update outer/inner flops */
389
390     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*13 + inneriter*38);
391 }