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