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