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