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