Merge release-5-0 into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecGB_VdwCSTab_GeomP1P1_c.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS c kernel generator.
37  */
38 #include "gmxpre.h"
39
40 #include "config.h"
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
48
49 /*
50  * Gromacs nonbonded kernel:   nb_kernel_ElecGB_VdwCSTab_GeomP1P1_VF_c
51  * Electrostatics interaction: GeneralizedBorn
52  * VdW interaction:            CubicSplineTable
53  * Geometry:                   Particle-Particle
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecGB_VdwCSTab_GeomP1P1_VF_c
58                     (t_nblist                    * gmx_restrict       nlist,
59                      rvec                        * gmx_restrict          xx,
60                      rvec                        * gmx_restrict          ff,
61                      t_forcerec                  * gmx_restrict          fr,
62                      t_mdatoms                   * gmx_restrict     mdatoms,
63                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64                      t_nrnb                      * gmx_restrict        nrnb)
65 {
66     int              i_shift_offset,i_coord_offset,j_coord_offset;
67     int              j_index_start,j_index_end;
68     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
69     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
70     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
71     real             *shiftvec,*fshift,*x,*f;
72     int              vdwioffset0;
73     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
74     int              vdwjidx0;
75     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
76     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
77     real             velec,felec,velecsum,facel,crf,krf,krf2;
78     real             *charge;
79     int              gbitab;
80     real             vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,dvdaj,gbeps,dvdatmp;
81     real             *invsqrta,*dvda,*gbtab;
82     int              nvdwtype;
83     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
84     int              *vdwtype;
85     real             *vdwparam;
86     int              vfitab;
87     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
88     real             *vftab;
89
90     x                = xx[0];
91     f                = ff[0];
92
93     nri              = nlist->nri;
94     iinr             = nlist->iinr;
95     jindex           = nlist->jindex;
96     jjnr             = nlist->jjnr;
97     shiftidx         = nlist->shift;
98     gid              = nlist->gid;
99     shiftvec         = fr->shift_vec[0];
100     fshift           = fr->fshift[0];
101     facel            = fr->epsfac;
102     charge           = mdatoms->chargeA;
103     nvdwtype         = fr->ntype;
104     vdwparam         = fr->nbfp;
105     vdwtype          = mdatoms->typeA;
106
107     vftab            = kernel_data->table_vdw->data;
108     vftabscale       = kernel_data->table_vdw->scale;
109
110     invsqrta         = fr->invsqrta;
111     dvda             = fr->dvda;
112     gbtabscale       = fr->gbtab.scale;
113     gbtab            = fr->gbtab.data;
114     gbinvepsdiff     = (1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent);
115
116     outeriter        = 0;
117     inneriter        = 0;
118
119     /* Start outer loop over neighborlists */
120     for(iidx=0; iidx<nri; iidx++)
121     {
122         /* Load shift vector for this list */
123         i_shift_offset   = DIM*shiftidx[iidx];
124         shX              = shiftvec[i_shift_offset+XX];
125         shY              = shiftvec[i_shift_offset+YY];
126         shZ              = shiftvec[i_shift_offset+ZZ];
127
128         /* Load limits for loop over neighbors */
129         j_index_start    = jindex[iidx];
130         j_index_end      = jindex[iidx+1];
131
132         /* Get outer coordinate index */
133         inr              = iinr[iidx];
134         i_coord_offset   = DIM*inr;
135
136         /* Load i particle coords and add shift vector */
137         ix0              = shX + x[i_coord_offset+DIM*0+XX];
138         iy0              = shY + x[i_coord_offset+DIM*0+YY];
139         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
140
141         fix0             = 0.0;
142         fiy0             = 0.0;
143         fiz0             = 0.0;
144
145         /* Load parameters for i particles */
146         iq0              = facel*charge[inr+0];
147         isai0            = invsqrta[inr+0];
148         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
149
150         /* Reset potential sums */
151         velecsum         = 0.0;
152         vgbsum           = 0.0;
153         vvdwsum          = 0.0;
154         dvdasum          = 0.0;
155
156         /* Start inner kernel loop */
157         for(jidx=j_index_start; jidx<j_index_end; jidx++)
158         {
159             /* Get j neighbor index, and coordinate index */
160             jnr              = jjnr[jidx];
161             j_coord_offset   = DIM*jnr;
162
163             /* load j atom coordinates */
164             jx0              = x[j_coord_offset+DIM*0+XX];
165             jy0              = x[j_coord_offset+DIM*0+YY];
166             jz0              = x[j_coord_offset+DIM*0+ZZ];
167
168             /* Calculate displacement vector */
169             dx00             = ix0 - jx0;
170             dy00             = iy0 - jy0;
171             dz00             = iz0 - jz0;
172
173             /* Calculate squared distance and things based on it */
174             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
175
176             rinv00           = gmx_invsqrt(rsq00);
177
178             /* Load parameters for j particles */
179             jq0              = charge[jnr+0];
180             isaj0           = invsqrta[jnr+0];
181             vdwjidx0         = 2*vdwtype[jnr+0];
182
183             /**************************
184              * CALCULATE INTERACTIONS *
185              **************************/
186
187             r00              = rsq00*rinv00;
188
189             qq00             = iq0*jq0;
190             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
191             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
192
193             /* Calculate table index by multiplying r with table scale and truncate to integer */
194             rt               = r00*vftabscale;
195             vfitab           = rt;
196             vfeps            = rt-vfitab;
197             vfitab           = 2*4*vfitab;
198
199             /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
200             isaprod          = isai0*isaj0;
201             gbqqfactor       = isaprod*(-qq00)*gbinvepsdiff;
202             gbscale          = isaprod*gbtabscale;
203             dvdaj            = dvda[jnr+0];
204
205             /* Calculate generalized born table index - this is a separate table from the normal one,
206              * but we use the same procedure by multiplying r with scale and truncating to integer.
207              */
208             rt               = r00*gbscale;
209             gbitab           = rt;
210             gbeps            = rt-gbitab;
211             gbitab           = 4*gbitab;
212
213             Y                = gbtab[gbitab];
214             F                = gbtab[gbitab+1];
215             Geps             = gbeps*gbtab[gbitab+2];
216             Heps2            = gbeps*gbeps*gbtab[gbitab+3];
217             Fp               = F+Geps+Heps2;
218             VV               = Y+gbeps*Fp;
219             vgb              = gbqqfactor*VV;
220
221             FF               = Fp+Geps+2.0*Heps2;
222             fgb              = gbqqfactor*FF*gbscale;
223             dvdatmp          = -0.5*(vgb+fgb*r00);
224             dvdasum          = dvdasum + dvdatmp;
225             dvda[jnr]        = dvdaj+dvdatmp*isaj0*isaj0;
226             velec            = qq00*rinv00;
227             felec            = (velec*rinv00-fgb)*rinv00;
228
229             /* CUBIC SPLINE TABLE DISPERSION */
230             vfitab          += 0;
231             Y                = vftab[vfitab];
232             F                = vftab[vfitab+1];
233             Geps             = vfeps*vftab[vfitab+2];
234             Heps2            = vfeps*vfeps*vftab[vfitab+3];
235             Fp               = F+Geps+Heps2;
236             VV               = Y+vfeps*Fp;
237             vvdw6            = c6_00*VV;
238             FF               = Fp+Geps+2.0*Heps2;
239             fvdw6            = c6_00*FF;
240
241             /* CUBIC SPLINE TABLE REPULSION */
242             Y                = vftab[vfitab+4];
243             F                = vftab[vfitab+5];
244             Geps             = vfeps*vftab[vfitab+6];
245             Heps2            = vfeps*vfeps*vftab[vfitab+7];
246             Fp               = F+Geps+Heps2;
247             VV               = Y+vfeps*Fp;
248             vvdw12           = c12_00*VV;
249             FF               = Fp+Geps+2.0*Heps2;
250             fvdw12           = c12_00*FF;
251             vvdw             = vvdw12+vvdw6;
252             fvdw             = -(fvdw6+fvdw12)*vftabscale*rinv00;
253
254             /* Update potential sums from outer loop */
255             velecsum        += velec;
256             vgbsum          += vgb;
257             vvdwsum         += vvdw;
258
259             fscal            = felec+fvdw;
260
261             /* Calculate temporary vectorial force */
262             tx               = fscal*dx00;
263             ty               = fscal*dy00;
264             tz               = fscal*dz00;
265
266             /* Update vectorial force */
267             fix0            += tx;
268             fiy0            += ty;
269             fiz0            += tz;
270             f[j_coord_offset+DIM*0+XX] -= tx;
271             f[j_coord_offset+DIM*0+YY] -= ty;
272             f[j_coord_offset+DIM*0+ZZ] -= tz;
273
274             /* Inner loop uses 91 flops */
275         }
276         /* End of innermost loop */
277
278         tx = ty = tz = 0;
279         f[i_coord_offset+DIM*0+XX] += fix0;
280         f[i_coord_offset+DIM*0+YY] += fiy0;
281         f[i_coord_offset+DIM*0+ZZ] += fiz0;
282         tx                         += fix0;
283         ty                         += fiy0;
284         tz                         += fiz0;
285         fshift[i_shift_offset+XX]  += tx;
286         fshift[i_shift_offset+YY]  += ty;
287         fshift[i_shift_offset+ZZ]  += tz;
288
289         ggid                        = gid[iidx];
290         /* Update potential energies */
291         kernel_data->energygrp_elec[ggid] += velecsum;
292         kernel_data->energygrp_polarization[ggid] += vgbsum;
293         kernel_data->energygrp_vdw[ggid] += vvdwsum;
294         dvda[inr]                   = dvda[inr] + dvdasum*isai0*isai0;
295
296         /* Increment number of inner iterations */
297         inneriter                  += j_index_end - j_index_start;
298
299         /* Outer loop uses 16 flops */
300     }
301
302     /* Increment number of outer iterations */
303     outeriter        += nri;
304
305     /* Update outer/inner flops */
306
307     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*16 + inneriter*91);
308 }
309 /*
310  * Gromacs nonbonded kernel:   nb_kernel_ElecGB_VdwCSTab_GeomP1P1_F_c
311  * Electrostatics interaction: GeneralizedBorn
312  * VdW interaction:            CubicSplineTable
313  * Geometry:                   Particle-Particle
314  * Calculate force/pot:        Force
315  */
316 void
317 nb_kernel_ElecGB_VdwCSTab_GeomP1P1_F_c
318                     (t_nblist                    * gmx_restrict       nlist,
319                      rvec                        * gmx_restrict          xx,
320                      rvec                        * gmx_restrict          ff,
321                      t_forcerec                  * gmx_restrict          fr,
322                      t_mdatoms                   * gmx_restrict     mdatoms,
323                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
324                      t_nrnb                      * gmx_restrict        nrnb)
325 {
326     int              i_shift_offset,i_coord_offset,j_coord_offset;
327     int              j_index_start,j_index_end;
328     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
329     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
330     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
331     real             *shiftvec,*fshift,*x,*f;
332     int              vdwioffset0;
333     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
334     int              vdwjidx0;
335     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
336     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
337     real             velec,felec,velecsum,facel,crf,krf,krf2;
338     real             *charge;
339     int              gbitab;
340     real             vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,dvdaj,gbeps,dvdatmp;
341     real             *invsqrta,*dvda,*gbtab;
342     int              nvdwtype;
343     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
344     int              *vdwtype;
345     real             *vdwparam;
346     int              vfitab;
347     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
348     real             *vftab;
349
350     x                = xx[0];
351     f                = ff[0];
352
353     nri              = nlist->nri;
354     iinr             = nlist->iinr;
355     jindex           = nlist->jindex;
356     jjnr             = nlist->jjnr;
357     shiftidx         = nlist->shift;
358     gid              = nlist->gid;
359     shiftvec         = fr->shift_vec[0];
360     fshift           = fr->fshift[0];
361     facel            = fr->epsfac;
362     charge           = mdatoms->chargeA;
363     nvdwtype         = fr->ntype;
364     vdwparam         = fr->nbfp;
365     vdwtype          = mdatoms->typeA;
366
367     vftab            = kernel_data->table_vdw->data;
368     vftabscale       = kernel_data->table_vdw->scale;
369
370     invsqrta         = fr->invsqrta;
371     dvda             = fr->dvda;
372     gbtabscale       = fr->gbtab.scale;
373     gbtab            = fr->gbtab.data;
374     gbinvepsdiff     = (1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent);
375
376     outeriter        = 0;
377     inneriter        = 0;
378
379     /* Start outer loop over neighborlists */
380     for(iidx=0; iidx<nri; iidx++)
381     {
382         /* Load shift vector for this list */
383         i_shift_offset   = DIM*shiftidx[iidx];
384         shX              = shiftvec[i_shift_offset+XX];
385         shY              = shiftvec[i_shift_offset+YY];
386         shZ              = shiftvec[i_shift_offset+ZZ];
387
388         /* Load limits for loop over neighbors */
389         j_index_start    = jindex[iidx];
390         j_index_end      = jindex[iidx+1];
391
392         /* Get outer coordinate index */
393         inr              = iinr[iidx];
394         i_coord_offset   = DIM*inr;
395
396         /* Load i particle coords and add shift vector */
397         ix0              = shX + x[i_coord_offset+DIM*0+XX];
398         iy0              = shY + x[i_coord_offset+DIM*0+YY];
399         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
400
401         fix0             = 0.0;
402         fiy0             = 0.0;
403         fiz0             = 0.0;
404
405         /* Load parameters for i particles */
406         iq0              = facel*charge[inr+0];
407         isai0            = invsqrta[inr+0];
408         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
409
410         dvdasum          = 0.0;
411
412         /* Start inner kernel loop */
413         for(jidx=j_index_start; jidx<j_index_end; jidx++)
414         {
415             /* Get j neighbor index, and coordinate index */
416             jnr              = jjnr[jidx];
417             j_coord_offset   = DIM*jnr;
418
419             /* load j atom coordinates */
420             jx0              = x[j_coord_offset+DIM*0+XX];
421             jy0              = x[j_coord_offset+DIM*0+YY];
422             jz0              = x[j_coord_offset+DIM*0+ZZ];
423
424             /* Calculate displacement vector */
425             dx00             = ix0 - jx0;
426             dy00             = iy0 - jy0;
427             dz00             = iz0 - jz0;
428
429             /* Calculate squared distance and things based on it */
430             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
431
432             rinv00           = gmx_invsqrt(rsq00);
433
434             /* Load parameters for j particles */
435             jq0              = charge[jnr+0];
436             isaj0           = invsqrta[jnr+0];
437             vdwjidx0         = 2*vdwtype[jnr+0];
438
439             /**************************
440              * CALCULATE INTERACTIONS *
441              **************************/
442
443             r00              = rsq00*rinv00;
444
445             qq00             = iq0*jq0;
446             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
447             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
448
449             /* Calculate table index by multiplying r with table scale and truncate to integer */
450             rt               = r00*vftabscale;
451             vfitab           = rt;
452             vfeps            = rt-vfitab;
453             vfitab           = 2*4*vfitab;
454
455             /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
456             isaprod          = isai0*isaj0;
457             gbqqfactor       = isaprod*(-qq00)*gbinvepsdiff;
458             gbscale          = isaprod*gbtabscale;
459             dvdaj            = dvda[jnr+0];
460
461             /* Calculate generalized born table index - this is a separate table from the normal one,
462              * but we use the same procedure by multiplying r with scale and truncating to integer.
463              */
464             rt               = r00*gbscale;
465             gbitab           = rt;
466             gbeps            = rt-gbitab;
467             gbitab           = 4*gbitab;
468
469             Y                = gbtab[gbitab];
470             F                = gbtab[gbitab+1];
471             Geps             = gbeps*gbtab[gbitab+2];
472             Heps2            = gbeps*gbeps*gbtab[gbitab+3];
473             Fp               = F+Geps+Heps2;
474             VV               = Y+gbeps*Fp;
475             vgb              = gbqqfactor*VV;
476
477             FF               = Fp+Geps+2.0*Heps2;
478             fgb              = gbqqfactor*FF*gbscale;
479             dvdatmp          = -0.5*(vgb+fgb*r00);
480             dvdasum          = dvdasum + dvdatmp;
481             dvda[jnr]        = dvdaj+dvdatmp*isaj0*isaj0;
482             velec            = qq00*rinv00;
483             felec            = (velec*rinv00-fgb)*rinv00;
484
485             /* CUBIC SPLINE TABLE DISPERSION */
486             vfitab          += 0;
487             F                = vftab[vfitab+1];
488             Geps             = vfeps*vftab[vfitab+2];
489             Heps2            = vfeps*vfeps*vftab[vfitab+3];
490             Fp               = F+Geps+Heps2;
491             FF               = Fp+Geps+2.0*Heps2;
492             fvdw6            = c6_00*FF;
493
494             /* CUBIC SPLINE TABLE REPULSION */
495             F                = vftab[vfitab+5];
496             Geps             = vfeps*vftab[vfitab+6];
497             Heps2            = vfeps*vfeps*vftab[vfitab+7];
498             Fp               = F+Geps+Heps2;
499             FF               = Fp+Geps+2.0*Heps2;
500             fvdw12           = c12_00*FF;
501             fvdw             = -(fvdw6+fvdw12)*vftabscale*rinv00;
502
503             fscal            = felec+fvdw;
504
505             /* Calculate temporary vectorial force */
506             tx               = fscal*dx00;
507             ty               = fscal*dy00;
508             tz               = fscal*dz00;
509
510             /* Update vectorial force */
511             fix0            += tx;
512             fiy0            += ty;
513             fiz0            += tz;
514             f[j_coord_offset+DIM*0+XX] -= tx;
515             f[j_coord_offset+DIM*0+YY] -= ty;
516             f[j_coord_offset+DIM*0+ZZ] -= tz;
517
518             /* Inner loop uses 81 flops */
519         }
520         /* End of innermost loop */
521
522         tx = ty = tz = 0;
523         f[i_coord_offset+DIM*0+XX] += fix0;
524         f[i_coord_offset+DIM*0+YY] += fiy0;
525         f[i_coord_offset+DIM*0+ZZ] += fiz0;
526         tx                         += fix0;
527         ty                         += fiy0;
528         tz                         += fiz0;
529         fshift[i_shift_offset+XX]  += tx;
530         fshift[i_shift_offset+YY]  += ty;
531         fshift[i_shift_offset+ZZ]  += tz;
532
533         dvda[inr]                   = dvda[inr] + dvdasum*isai0*isai0;
534
535         /* Increment number of inner iterations */
536         inneriter                  += j_index_end - j_index_start;
537
538         /* Outer loop uses 13 flops */
539     }
540
541     /* Increment number of outer iterations */
542     outeriter        += nri;
543
544     /* Update outer/inner flops */
545
546     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*13 + inneriter*81);
547 }