Merge release-5-0 into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecNone_VdwLJEw_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_ElecNone_VdwLJEw_GeomP1P1_VF_c
51  * Electrostatics interaction: None
52  * VdW interaction:            LJEwald
53  * Geometry:                   Particle-Particle
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecNone_VdwLJEw_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     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     real             c6grid_00;
82     real             ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,sh_lj_ewald;
83     real             *vdwgridparam;
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     nvdwtype         = fr->ntype;
97     vdwparam         = fr->nbfp;
98     vdwtype          = mdatoms->typeA;
99     vdwgridparam     = fr->ljpme_c6grid;
100     ewclj            = fr->ewaldcoeff_lj;
101     sh_lj_ewald      = fr->ic->sh_lj_ewald;
102     ewclj2           = ewclj*ewclj;
103     ewclj6           = ewclj2*ewclj2*ewclj2;
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         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
136
137         /* Reset potential sums */
138         vvdwsum          = 0.0;
139
140         /* Start inner kernel loop */
141         for(jidx=j_index_start; jidx<j_index_end; jidx++)
142         {
143             /* Get j neighbor index, and coordinate index */
144             jnr              = jjnr[jidx];
145             j_coord_offset   = DIM*jnr;
146
147             /* load j atom coordinates */
148             jx0              = x[j_coord_offset+DIM*0+XX];
149             jy0              = x[j_coord_offset+DIM*0+YY];
150             jz0              = x[j_coord_offset+DIM*0+ZZ];
151
152             /* Calculate displacement vector */
153             dx00             = ix0 - jx0;
154             dy00             = iy0 - jy0;
155             dz00             = iz0 - jz0;
156
157             /* Calculate squared distance and things based on it */
158             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
159
160             rinv00           = gmx_invsqrt(rsq00);
161
162             rinvsq00         = rinv00*rinv00;
163
164             /* Load parameters for j particles */
165             vdwjidx0         = 2*vdwtype[jnr+0];
166
167             /**************************
168              * CALCULATE INTERACTIONS *
169              **************************/
170
171             r00              = rsq00*rinv00;
172
173             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
174             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
175             c6grid_00        = vdwgridparam[vdwioffset0+vdwjidx0];
176
177             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
178             ewcljrsq         = ewclj2*rsq00;
179             exponent         = exp(-ewcljrsq);
180             poly             = exponent*(1.0 + ewcljrsq + ewcljrsq*ewcljrsq*0.5);
181             vvdw6            = (c6_00-c6grid_00*(1.0-poly))*rinvsix;
182             vvdw12           = c12_00*rinvsix*rinvsix;
183             vvdw             = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
184             fvdw             = (vvdw12 - vvdw6 - c6grid_00*(1.0/6.0)*exponent*ewclj6)*rinvsq00;
185
186             /* Update potential sums from outer loop */
187             vvdwsum         += vvdw;
188
189             fscal            = fvdw;
190
191             /* Calculate temporary vectorial force */
192             tx               = fscal*dx00;
193             ty               = fscal*dy00;
194             tz               = fscal*dz00;
195
196             /* Update vectorial force */
197             fix0            += tx;
198             fiy0            += ty;
199             fiz0            += tz;
200             f[j_coord_offset+DIM*0+XX] -= tx;
201             f[j_coord_offset+DIM*0+YY] -= ty;
202             f[j_coord_offset+DIM*0+ZZ] -= tz;
203
204             /* Inner loop uses 49 flops */
205         }
206         /* End of innermost loop */
207
208         tx = ty = tz = 0;
209         f[i_coord_offset+DIM*0+XX] += fix0;
210         f[i_coord_offset+DIM*0+YY] += fiy0;
211         f[i_coord_offset+DIM*0+ZZ] += fiz0;
212         tx                         += fix0;
213         ty                         += fiy0;
214         tz                         += fiz0;
215         fshift[i_shift_offset+XX]  += tx;
216         fshift[i_shift_offset+YY]  += ty;
217         fshift[i_shift_offset+ZZ]  += tz;
218
219         ggid                        = gid[iidx];
220         /* Update potential energies */
221         kernel_data->energygrp_vdw[ggid] += vvdwsum;
222
223         /* Increment number of inner iterations */
224         inneriter                  += j_index_end - j_index_start;
225
226         /* Outer loop uses 13 flops */
227     }
228
229     /* Increment number of outer iterations */
230     outeriter        += nri;
231
232     /* Update outer/inner flops */
233
234     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_VF,outeriter*13 + inneriter*49);
235 }
236 /*
237  * Gromacs nonbonded kernel:   nb_kernel_ElecNone_VdwLJEw_GeomP1P1_F_c
238  * Electrostatics interaction: None
239  * VdW interaction:            LJEwald
240  * Geometry:                   Particle-Particle
241  * Calculate force/pot:        Force
242  */
243 void
244 nb_kernel_ElecNone_VdwLJEw_GeomP1P1_F_c
245                     (t_nblist                    * gmx_restrict       nlist,
246                      rvec                        * gmx_restrict          xx,
247                      rvec                        * gmx_restrict          ff,
248                      t_forcerec                  * gmx_restrict          fr,
249                      t_mdatoms                   * gmx_restrict     mdatoms,
250                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
251                      t_nrnb                      * gmx_restrict        nrnb)
252 {
253     int              i_shift_offset,i_coord_offset,j_coord_offset;
254     int              j_index_start,j_index_end;
255     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
256     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
257     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
258     real             *shiftvec,*fshift,*x,*f;
259     int              vdwioffset0;
260     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
261     int              vdwjidx0;
262     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
263     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
264     int              nvdwtype;
265     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
266     int              *vdwtype;
267     real             *vdwparam;
268     real             c6grid_00;
269     real             ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,sh_lj_ewald;
270     real             *vdwgridparam;
271
272     x                = xx[0];
273     f                = ff[0];
274
275     nri              = nlist->nri;
276     iinr             = nlist->iinr;
277     jindex           = nlist->jindex;
278     jjnr             = nlist->jjnr;
279     shiftidx         = nlist->shift;
280     gid              = nlist->gid;
281     shiftvec         = fr->shift_vec[0];
282     fshift           = fr->fshift[0];
283     nvdwtype         = fr->ntype;
284     vdwparam         = fr->nbfp;
285     vdwtype          = mdatoms->typeA;
286     vdwgridparam     = fr->ljpme_c6grid;
287     ewclj            = fr->ewaldcoeff_lj;
288     sh_lj_ewald      = fr->ic->sh_lj_ewald;
289     ewclj2           = ewclj*ewclj;
290     ewclj6           = ewclj2*ewclj2*ewclj2;
291
292     outeriter        = 0;
293     inneriter        = 0;
294
295     /* Start outer loop over neighborlists */
296     for(iidx=0; iidx<nri; iidx++)
297     {
298         /* Load shift vector for this list */
299         i_shift_offset   = DIM*shiftidx[iidx];
300         shX              = shiftvec[i_shift_offset+XX];
301         shY              = shiftvec[i_shift_offset+YY];
302         shZ              = shiftvec[i_shift_offset+ZZ];
303
304         /* Load limits for loop over neighbors */
305         j_index_start    = jindex[iidx];
306         j_index_end      = jindex[iidx+1];
307
308         /* Get outer coordinate index */
309         inr              = iinr[iidx];
310         i_coord_offset   = DIM*inr;
311
312         /* Load i particle coords and add shift vector */
313         ix0              = shX + x[i_coord_offset+DIM*0+XX];
314         iy0              = shY + x[i_coord_offset+DIM*0+YY];
315         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
316
317         fix0             = 0.0;
318         fiy0             = 0.0;
319         fiz0             = 0.0;
320
321         /* Load parameters for i particles */
322         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
323
324         /* Start inner kernel loop */
325         for(jidx=j_index_start; jidx<j_index_end; jidx++)
326         {
327             /* Get j neighbor index, and coordinate index */
328             jnr              = jjnr[jidx];
329             j_coord_offset   = DIM*jnr;
330
331             /* load j atom coordinates */
332             jx0              = x[j_coord_offset+DIM*0+XX];
333             jy0              = x[j_coord_offset+DIM*0+YY];
334             jz0              = x[j_coord_offset+DIM*0+ZZ];
335
336             /* Calculate displacement vector */
337             dx00             = ix0 - jx0;
338             dy00             = iy0 - jy0;
339             dz00             = iz0 - jz0;
340
341             /* Calculate squared distance and things based on it */
342             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
343
344             rinv00           = gmx_invsqrt(rsq00);
345
346             rinvsq00         = rinv00*rinv00;
347
348             /* Load parameters for j particles */
349             vdwjidx0         = 2*vdwtype[jnr+0];
350
351             /**************************
352              * CALCULATE INTERACTIONS *
353              **************************/
354
355             r00              = rsq00*rinv00;
356
357             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
358             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
359             c6grid_00        = vdwgridparam[vdwioffset0+vdwjidx0];
360
361             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
362             ewcljrsq         = ewclj2*rsq00;
363             exponent         = exp(-ewcljrsq);
364             poly             = exponent*(1.0 + ewcljrsq + ewcljrsq*ewcljrsq*0.5);
365             fvdw             = (((c12_00*rinvsix - c6_00 + c6grid_00*(1.0-poly))*rinvsix) - c6grid_00*(1.0/6.0)*exponent*ewclj6)*rinvsq00;
366
367             fscal            = fvdw;
368
369             /* Calculate temporary vectorial force */
370             tx               = fscal*dx00;
371             ty               = fscal*dy00;
372             tz               = fscal*dz00;
373
374             /* Update vectorial force */
375             fix0            += tx;
376             fiy0            += ty;
377             fiz0            += tz;
378             f[j_coord_offset+DIM*0+XX] -= tx;
379             f[j_coord_offset+DIM*0+YY] -= ty;
380             f[j_coord_offset+DIM*0+ZZ] -= tz;
381
382             /* Inner loop uses 44 flops */
383         }
384         /* End of innermost loop */
385
386         tx = ty = tz = 0;
387         f[i_coord_offset+DIM*0+XX] += fix0;
388         f[i_coord_offset+DIM*0+YY] += fiy0;
389         f[i_coord_offset+DIM*0+ZZ] += fiz0;
390         tx                         += fix0;
391         ty                         += fiy0;
392         tz                         += fiz0;
393         fshift[i_shift_offset+XX]  += tx;
394         fshift[i_shift_offset+YY]  += ty;
395         fshift[i_shift_offset+ZZ]  += tz;
396
397         /* Increment number of inner iterations */
398         inneriter                  += j_index_end - j_index_start;
399
400         /* Outer loop uses 12 flops */
401     }
402
403     /* Increment number of outer iterations */
404     outeriter        += nri;
405
406     /* Update outer/inner flops */
407
408     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_F,outeriter*12 + inneriter*44);
409 }