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