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