Merge 'release-4-6' into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecCoul_VdwCSTab_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_ElecCoul_VdwCSTab_GeomP1P1_VF_c
35  * Electrostatics interaction: Coulomb
36  * VdW interaction:            CubicSplineTable
37  * Geometry:                   Particle-Particle
38  * Calculate force/pot:        PotentialAndForce
39  */
40 void
41 nb_kernel_ElecCoul_VdwCSTab_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     int              vfitab;
68     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
69     real             *vftab;
70
71     x                = xx[0];
72     f                = ff[0];
73
74     nri              = nlist->nri;
75     iinr             = nlist->iinr;
76     jindex           = nlist->jindex;
77     jjnr             = nlist->jjnr;
78     shiftidx         = nlist->shift;
79     gid              = nlist->gid;
80     shiftvec         = fr->shift_vec[0];
81     fshift           = fr->fshift[0];
82     facel            = fr->epsfac;
83     charge           = mdatoms->chargeA;
84     nvdwtype         = fr->ntype;
85     vdwparam         = fr->nbfp;
86     vdwtype          = mdatoms->typeA;
87
88     vftab            = kernel_data->table_vdw->data;
89     vftabscale       = kernel_data->table_vdw->scale;
90
91     outeriter        = 0;
92     inneriter        = 0;
93
94     /* Start outer loop over neighborlists */
95     for(iidx=0; iidx<nri; iidx++)
96     {
97         /* Load shift vector for this list */
98         i_shift_offset   = DIM*shiftidx[iidx];
99         shX              = shiftvec[i_shift_offset+XX];
100         shY              = shiftvec[i_shift_offset+YY];
101         shZ              = shiftvec[i_shift_offset+ZZ];
102
103         /* Load limits for loop over neighbors */
104         j_index_start    = jindex[iidx];
105         j_index_end      = jindex[iidx+1];
106
107         /* Get outer coordinate index */
108         inr              = iinr[iidx];
109         i_coord_offset   = DIM*inr;
110
111         /* Load i particle coords and add shift vector */
112         ix0              = shX + x[i_coord_offset+DIM*0+XX];
113         iy0              = shY + x[i_coord_offset+DIM*0+YY];
114         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
115
116         fix0             = 0.0;
117         fiy0             = 0.0;
118         fiz0             = 0.0;
119
120         /* Load parameters for i particles */
121         iq0              = facel*charge[inr+0];
122         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
123
124         /* Reset potential sums */
125         velecsum         = 0.0;
126         vvdwsum          = 0.0;
127
128         /* Start inner kernel loop */
129         for(jidx=j_index_start; jidx<j_index_end; jidx++)
130         {
131             /* Get j neighbor index, and coordinate index */
132             jnr              = jjnr[jidx];
133             j_coord_offset   = DIM*jnr;
134
135             /* load j atom coordinates */
136             jx0              = x[j_coord_offset+DIM*0+XX];
137             jy0              = x[j_coord_offset+DIM*0+YY];
138             jz0              = x[j_coord_offset+DIM*0+ZZ];
139
140             /* Calculate displacement vector */
141             dx00             = ix0 - jx0;
142             dy00             = iy0 - jy0;
143             dz00             = iz0 - jz0;
144
145             /* Calculate squared distance and things based on it */
146             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
147
148             rinv00           = gmx_invsqrt(rsq00);
149
150             rinvsq00         = rinv00*rinv00;
151
152             /* Load parameters for j particles */
153             jq0              = charge[jnr+0];
154             vdwjidx0         = 2*vdwtype[jnr+0];
155
156             /**************************
157              * CALCULATE INTERACTIONS *
158              **************************/
159
160             r00              = rsq00*rinv00;
161
162             qq00             = iq0*jq0;
163             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
164             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
165
166             /* Calculate table index by multiplying r with table scale and truncate to integer */
167             rt               = r00*vftabscale;
168             vfitab           = rt;
169             vfeps            = rt-vfitab;
170             vfitab           = 2*4*vfitab;
171
172             /* COULOMB ELECTROSTATICS */
173             velec            = qq00*rinv00;
174             felec            = velec*rinvsq00;
175
176             /* CUBIC SPLINE TABLE DISPERSION */
177             vfitab          += 0;
178             Y                = vftab[vfitab];
179             F                = vftab[vfitab+1];
180             Geps             = vfeps*vftab[vfitab+2];
181             Heps2            = vfeps*vfeps*vftab[vfitab+3];
182             Fp               = F+Geps+Heps2;
183             VV               = Y+vfeps*Fp;
184             vvdw6            = c6_00*VV;
185             FF               = Fp+Geps+2.0*Heps2;
186             fvdw6            = c6_00*FF;
187
188             /* CUBIC SPLINE TABLE REPULSION */
189             Y                = vftab[vfitab+4];
190             F                = vftab[vfitab+5];
191             Geps             = vfeps*vftab[vfitab+6];
192             Heps2            = vfeps*vfeps*vftab[vfitab+7];
193             Fp               = F+Geps+Heps2;
194             VV               = Y+vfeps*Fp;
195             vvdw12           = c12_00*VV;
196             FF               = Fp+Geps+2.0*Heps2;
197             fvdw12           = c12_00*FF;
198             vvdw             = vvdw12+vvdw6;
199             fvdw             = -(fvdw6+fvdw12)*vftabscale*rinv00;
200
201             /* Update potential sums from outer loop */
202             velecsum        += velec;
203             vvdwsum         += vvdw;
204
205             fscal            = felec+fvdw;
206
207             /* Calculate temporary vectorial force */
208             tx               = fscal*dx00;
209             ty               = fscal*dy00;
210             tz               = fscal*dz00;
211
212             /* Update vectorial force */
213             fix0            += tx;
214             fiy0            += ty;
215             fiz0            += tz;
216             f[j_coord_offset+DIM*0+XX] -= tx;
217             f[j_coord_offset+DIM*0+YY] -= ty;
218             f[j_coord_offset+DIM*0+ZZ] -= tz;
219
220             /* Inner loop uses 62 flops */
221         }
222         /* End of innermost loop */
223
224         tx = ty = tz = 0;
225         f[i_coord_offset+DIM*0+XX] += fix0;
226         f[i_coord_offset+DIM*0+YY] += fiy0;
227         f[i_coord_offset+DIM*0+ZZ] += fiz0;
228         tx                         += fix0;
229         ty                         += fiy0;
230         tz                         += fiz0;
231         fshift[i_shift_offset+XX]  += tx;
232         fshift[i_shift_offset+YY]  += ty;
233         fshift[i_shift_offset+ZZ]  += tz;
234
235         ggid                        = gid[iidx];
236         /* Update potential energies */
237         kernel_data->energygrp_elec[ggid] += velecsum;
238         kernel_data->energygrp_vdw[ggid] += vvdwsum;
239
240         /* Increment number of inner iterations */
241         inneriter                  += j_index_end - j_index_start;
242
243         /* Outer loop uses 15 flops */
244     }
245
246     /* Increment number of outer iterations */
247     outeriter        += nri;
248
249     /* Update outer/inner flops */
250
251     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*15 + inneriter*62);
252 }
253 /*
254  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwCSTab_GeomP1P1_F_c
255  * Electrostatics interaction: Coulomb
256  * VdW interaction:            CubicSplineTable
257  * Geometry:                   Particle-Particle
258  * Calculate force/pot:        Force
259  */
260 void
261 nb_kernel_ElecCoul_VdwCSTab_GeomP1P1_F_c
262                     (t_nblist * gmx_restrict                nlist,
263                      rvec * gmx_restrict                    xx,
264                      rvec * gmx_restrict                    ff,
265                      t_forcerec * gmx_restrict              fr,
266                      t_mdatoms * gmx_restrict               mdatoms,
267                      nb_kernel_data_t * gmx_restrict        kernel_data,
268                      t_nrnb * gmx_restrict                  nrnb)
269 {
270     int              i_shift_offset,i_coord_offset,j_coord_offset;
271     int              j_index_start,j_index_end;
272     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
273     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
274     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
275     real             *shiftvec,*fshift,*x,*f;
276     int              vdwioffset0;
277     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
278     int              vdwjidx0;
279     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
280     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
281     real             velec,felec,velecsum,facel,crf,krf,krf2;
282     real             *charge;
283     int              nvdwtype;
284     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
285     int              *vdwtype;
286     real             *vdwparam;
287     int              vfitab;
288     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
289     real             *vftab;
290
291     x                = xx[0];
292     f                = ff[0];
293
294     nri              = nlist->nri;
295     iinr             = nlist->iinr;
296     jindex           = nlist->jindex;
297     jjnr             = nlist->jjnr;
298     shiftidx         = nlist->shift;
299     gid              = nlist->gid;
300     shiftvec         = fr->shift_vec[0];
301     fshift           = fr->fshift[0];
302     facel            = fr->epsfac;
303     charge           = mdatoms->chargeA;
304     nvdwtype         = fr->ntype;
305     vdwparam         = fr->nbfp;
306     vdwtype          = mdatoms->typeA;
307
308     vftab            = kernel_data->table_vdw->data;
309     vftabscale       = kernel_data->table_vdw->scale;
310
311     outeriter        = 0;
312     inneriter        = 0;
313
314     /* Start outer loop over neighborlists */
315     for(iidx=0; iidx<nri; iidx++)
316     {
317         /* Load shift vector for this list */
318         i_shift_offset   = DIM*shiftidx[iidx];
319         shX              = shiftvec[i_shift_offset+XX];
320         shY              = shiftvec[i_shift_offset+YY];
321         shZ              = shiftvec[i_shift_offset+ZZ];
322
323         /* Load limits for loop over neighbors */
324         j_index_start    = jindex[iidx];
325         j_index_end      = jindex[iidx+1];
326
327         /* Get outer coordinate index */
328         inr              = iinr[iidx];
329         i_coord_offset   = DIM*inr;
330
331         /* Load i particle coords and add shift vector */
332         ix0              = shX + x[i_coord_offset+DIM*0+XX];
333         iy0              = shY + x[i_coord_offset+DIM*0+YY];
334         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
335
336         fix0             = 0.0;
337         fiy0             = 0.0;
338         fiz0             = 0.0;
339
340         /* Load parameters for i particles */
341         iq0              = facel*charge[inr+0];
342         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
343
344         /* Start inner kernel loop */
345         for(jidx=j_index_start; jidx<j_index_end; jidx++)
346         {
347             /* Get j neighbor index, and coordinate index */
348             jnr              = jjnr[jidx];
349             j_coord_offset   = DIM*jnr;
350
351             /* load j atom coordinates */
352             jx0              = x[j_coord_offset+DIM*0+XX];
353             jy0              = x[j_coord_offset+DIM*0+YY];
354             jz0              = x[j_coord_offset+DIM*0+ZZ];
355
356             /* Calculate displacement vector */
357             dx00             = ix0 - jx0;
358             dy00             = iy0 - jy0;
359             dz00             = iz0 - jz0;
360
361             /* Calculate squared distance and things based on it */
362             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
363
364             rinv00           = gmx_invsqrt(rsq00);
365
366             rinvsq00         = rinv00*rinv00;
367
368             /* Load parameters for j particles */
369             jq0              = charge[jnr+0];
370             vdwjidx0         = 2*vdwtype[jnr+0];
371
372             /**************************
373              * CALCULATE INTERACTIONS *
374              **************************/
375
376             r00              = rsq00*rinv00;
377
378             qq00             = iq0*jq0;
379             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
380             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
381
382             /* Calculate table index by multiplying r with table scale and truncate to integer */
383             rt               = r00*vftabscale;
384             vfitab           = rt;
385             vfeps            = rt-vfitab;
386             vfitab           = 2*4*vfitab;
387
388             /* COULOMB ELECTROSTATICS */
389             velec            = qq00*rinv00;
390             felec            = velec*rinvsq00;
391
392             /* CUBIC SPLINE TABLE DISPERSION */
393             vfitab          += 0;
394             F                = vftab[vfitab+1];
395             Geps             = vfeps*vftab[vfitab+2];
396             Heps2            = vfeps*vfeps*vftab[vfitab+3];
397             Fp               = F+Geps+Heps2;
398             FF               = Fp+Geps+2.0*Heps2;
399             fvdw6            = c6_00*FF;
400
401             /* CUBIC SPLINE TABLE REPULSION */
402             F                = vftab[vfitab+5];
403             Geps             = vfeps*vftab[vfitab+6];
404             Heps2            = vfeps*vfeps*vftab[vfitab+7];
405             Fp               = F+Geps+Heps2;
406             FF               = Fp+Geps+2.0*Heps2;
407             fvdw12           = c12_00*FF;
408             fvdw             = -(fvdw6+fvdw12)*vftabscale*rinv00;
409
410             fscal            = felec+fvdw;
411
412             /* Calculate temporary vectorial force */
413             tx               = fscal*dx00;
414             ty               = fscal*dy00;
415             tz               = fscal*dz00;
416
417             /* Update vectorial force */
418             fix0            += tx;
419             fiy0            += ty;
420             fiz0            += tz;
421             f[j_coord_offset+DIM*0+XX] -= tx;
422             f[j_coord_offset+DIM*0+YY] -= ty;
423             f[j_coord_offset+DIM*0+ZZ] -= tz;
424
425             /* Inner loop uses 53 flops */
426         }
427         /* End of innermost loop */
428
429         tx = ty = tz = 0;
430         f[i_coord_offset+DIM*0+XX] += fix0;
431         f[i_coord_offset+DIM*0+YY] += fiy0;
432         f[i_coord_offset+DIM*0+ZZ] += fiz0;
433         tx                         += fix0;
434         ty                         += fiy0;
435         tz                         += fiz0;
436         fshift[i_shift_offset+XX]  += tx;
437         fshift[i_shift_offset+YY]  += ty;
438         fshift[i_shift_offset+ZZ]  += tz;
439
440         /* Increment number of inner iterations */
441         inneriter                  += j_index_end - j_index_start;
442
443         /* Outer loop uses 13 flops */
444     }
445
446     /* Increment number of outer iterations */
447     outeriter        += nri;
448
449     /* Update outer/inner flops */
450
451     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*13 + inneriter*53);
452 }