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