434429e51930bd68e02a6374fbd025f7c97938b5
[alexxy/gromacs.git] / src / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecNone_VdwBham_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_ElecNone_VdwBham_GeomP1P1_VF_c
35  * Electrostatics interaction: None
36  * VdW interaction:            Buckingham
37  * Geometry:                   Particle-Particle
38  * Calculate force/pot:        PotentialAndForce
39  */
40 void
41 nb_kernel_ElecNone_VdwBham_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     int              nvdwtype;
62     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
63     int              *vdwtype;
64     real             *vdwparam;
65
66     x                = xx[0];
67     f                = ff[0];
68
69     nri              = nlist->nri;
70     iinr             = nlist->iinr;
71     jindex           = nlist->jindex;
72     jjnr             = nlist->jjnr;
73     shiftidx         = nlist->shift;
74     gid              = nlist->gid;
75     shiftvec         = fr->shift_vec[0];
76     fshift           = fr->fshift[0];
77     nvdwtype         = fr->ntype;
78     vdwparam         = fr->nbfp;
79     vdwtype          = mdatoms->typeA;
80
81     outeriter        = 0;
82     inneriter        = 0;
83
84     /* Start outer loop over neighborlists */
85     for(iidx=0; iidx<nri; iidx++)
86     {
87         /* Load shift vector for this list */
88         i_shift_offset   = DIM*shiftidx[iidx];
89         shX              = shiftvec[i_shift_offset+XX];
90         shY              = shiftvec[i_shift_offset+YY];
91         shZ              = shiftvec[i_shift_offset+ZZ];
92
93         /* Load limits for loop over neighbors */
94         j_index_start    = jindex[iidx];
95         j_index_end      = jindex[iidx+1];
96
97         /* Get outer coordinate index */
98         inr              = iinr[iidx];
99         i_coord_offset   = DIM*inr;
100
101         /* Load i particle coords and add shift vector */
102         ix0              = shX + x[i_coord_offset+DIM*0+XX];
103         iy0              = shY + x[i_coord_offset+DIM*0+YY];
104         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
105
106         fix0             = 0.0;
107         fiy0             = 0.0;
108         fiz0             = 0.0;
109
110         /* Load parameters for i particles */
111         vdwioffset0      = 3*nvdwtype*vdwtype[inr+0];
112
113         /* Reset potential sums */
114         vvdwsum          = 0.0;
115
116         /* Start inner kernel loop */
117         for(jidx=j_index_start; jidx<j_index_end; jidx++)
118         {
119             /* Get j neighbor index, and coordinate index */
120             jnr              = jjnr[jidx];
121             j_coord_offset   = DIM*jnr;
122
123             /* load j atom coordinates */
124             jx0              = x[j_coord_offset+DIM*0+XX];
125             jy0              = x[j_coord_offset+DIM*0+YY];
126             jz0              = x[j_coord_offset+DIM*0+ZZ];
127
128             /* Calculate displacement vector */
129             dx00             = ix0 - jx0;
130             dy00             = iy0 - jy0;
131             dz00             = iz0 - jz0;
132
133             /* Calculate squared distance and things based on it */
134             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
135
136             rinv00           = gmx_invsqrt(rsq00);
137
138             rinvsq00         = rinv00*rinv00;
139
140             /* Load parameters for j particles */
141             vdwjidx0         = 3*vdwtype[jnr+0];
142
143             /**************************
144              * CALCULATE INTERACTIONS *
145              **************************/
146
147             r00              = rsq00*rinv00;
148
149             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
150             cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
151             cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
152
153             /* BUCKINGHAM DISPERSION/REPULSION */
154             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
155             vvdw6            = c6_00*rinvsix;
156             br               = cexp2_00*r00;
157             vvdwexp          = cexp1_00*exp(-br);
158             vvdw             = vvdwexp - vvdw6*(1.0/6.0);
159             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
160
161             /* Update potential sums from outer loop */
162             vvdwsum         += vvdw;
163
164             fscal            = fvdw;
165
166             /* Calculate temporary vectorial force */
167             tx               = fscal*dx00;
168             ty               = fscal*dy00;
169             tz               = fscal*dz00;
170
171             /* Update vectorial force */
172             fix0            += tx;
173             fiy0            += ty;
174             fiz0            += tz;
175             f[j_coord_offset+DIM*0+XX] -= tx;
176             f[j_coord_offset+DIM*0+YY] -= ty;
177             f[j_coord_offset+DIM*0+ZZ] -= tz;
178
179             /* Inner loop uses 61 flops */
180         }
181         /* End of innermost loop */
182
183         tx = ty = tz = 0;
184         f[i_coord_offset+DIM*0+XX] += fix0;
185         f[i_coord_offset+DIM*0+YY] += fiy0;
186         f[i_coord_offset+DIM*0+ZZ] += fiz0;
187         tx                         += fix0;
188         ty                         += fiy0;
189         tz                         += fiz0;
190         fshift[i_shift_offset+XX]  += tx;
191         fshift[i_shift_offset+YY]  += ty;
192         fshift[i_shift_offset+ZZ]  += tz;
193
194         ggid                        = gid[iidx];
195         /* Update potential energies */
196         kernel_data->energygrp_vdw[ggid] += vvdwsum;
197
198         /* Increment number of inner iterations */
199         inneriter                  += j_index_end - j_index_start;
200
201         /* Outer loop uses 13 flops */
202     }
203
204     /* Increment number of outer iterations */
205     outeriter        += nri;
206
207     /* Update outer/inner flops */
208
209     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_VF,outeriter*13 + inneriter*61);
210 }
211 /*
212  * Gromacs nonbonded kernel:   nb_kernel_ElecNone_VdwBham_GeomP1P1_F_c
213  * Electrostatics interaction: None
214  * VdW interaction:            Buckingham
215  * Geometry:                   Particle-Particle
216  * Calculate force/pot:        Force
217  */
218 void
219 nb_kernel_ElecNone_VdwBham_GeomP1P1_F_c
220                     (t_nblist * gmx_restrict                nlist,
221                      rvec * gmx_restrict                    xx,
222                      rvec * gmx_restrict                    ff,
223                      t_forcerec * gmx_restrict              fr,
224                      t_mdatoms * gmx_restrict               mdatoms,
225                      nb_kernel_data_t * gmx_restrict        kernel_data,
226                      t_nrnb * gmx_restrict                  nrnb)
227 {
228     int              i_shift_offset,i_coord_offset,j_coord_offset;
229     int              j_index_start,j_index_end;
230     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
231     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
232     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
233     real             *shiftvec,*fshift,*x,*f;
234     int              vdwioffset0;
235     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
236     int              vdwjidx0;
237     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
238     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
239     int              nvdwtype;
240     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
241     int              *vdwtype;
242     real             *vdwparam;
243
244     x                = xx[0];
245     f                = ff[0];
246
247     nri              = nlist->nri;
248     iinr             = nlist->iinr;
249     jindex           = nlist->jindex;
250     jjnr             = nlist->jjnr;
251     shiftidx         = nlist->shift;
252     gid              = nlist->gid;
253     shiftvec         = fr->shift_vec[0];
254     fshift           = fr->fshift[0];
255     nvdwtype         = fr->ntype;
256     vdwparam         = fr->nbfp;
257     vdwtype          = mdatoms->typeA;
258
259     outeriter        = 0;
260     inneriter        = 0;
261
262     /* Start outer loop over neighborlists */
263     for(iidx=0; iidx<nri; iidx++)
264     {
265         /* Load shift vector for this list */
266         i_shift_offset   = DIM*shiftidx[iidx];
267         shX              = shiftvec[i_shift_offset+XX];
268         shY              = shiftvec[i_shift_offset+YY];
269         shZ              = shiftvec[i_shift_offset+ZZ];
270
271         /* Load limits for loop over neighbors */
272         j_index_start    = jindex[iidx];
273         j_index_end      = jindex[iidx+1];
274
275         /* Get outer coordinate index */
276         inr              = iinr[iidx];
277         i_coord_offset   = DIM*inr;
278
279         /* Load i particle coords and add shift vector */
280         ix0              = shX + x[i_coord_offset+DIM*0+XX];
281         iy0              = shY + x[i_coord_offset+DIM*0+YY];
282         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
283
284         fix0             = 0.0;
285         fiy0             = 0.0;
286         fiz0             = 0.0;
287
288         /* Load parameters for i particles */
289         vdwioffset0      = 3*nvdwtype*vdwtype[inr+0];
290
291         /* Start inner kernel loop */
292         for(jidx=j_index_start; jidx<j_index_end; jidx++)
293         {
294             /* Get j neighbor index, and coordinate index */
295             jnr              = jjnr[jidx];
296             j_coord_offset   = DIM*jnr;
297
298             /* load j atom coordinates */
299             jx0              = x[j_coord_offset+DIM*0+XX];
300             jy0              = x[j_coord_offset+DIM*0+YY];
301             jz0              = x[j_coord_offset+DIM*0+ZZ];
302
303             /* Calculate displacement vector */
304             dx00             = ix0 - jx0;
305             dy00             = iy0 - jy0;
306             dz00             = iz0 - jz0;
307
308             /* Calculate squared distance and things based on it */
309             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
310
311             rinv00           = gmx_invsqrt(rsq00);
312
313             rinvsq00         = rinv00*rinv00;
314
315             /* Load parameters for j particles */
316             vdwjidx0         = 3*vdwtype[jnr+0];
317
318             /**************************
319              * CALCULATE INTERACTIONS *
320              **************************/
321
322             r00              = rsq00*rinv00;
323
324             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
325             cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
326             cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
327
328             /* BUCKINGHAM DISPERSION/REPULSION */
329             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
330             vvdw6            = c6_00*rinvsix;
331             br               = cexp2_00*r00;
332             vvdwexp          = cexp1_00*exp(-br);
333             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
334
335             fscal            = fvdw;
336
337             /* Calculate temporary vectorial force */
338             tx               = fscal*dx00;
339             ty               = fscal*dy00;
340             tz               = fscal*dz00;
341
342             /* Update vectorial force */
343             fix0            += tx;
344             fiy0            += ty;
345             fiz0            += tz;
346             f[j_coord_offset+DIM*0+XX] -= tx;
347             f[j_coord_offset+DIM*0+YY] -= ty;
348             f[j_coord_offset+DIM*0+ZZ] -= tz;
349
350             /* Inner loop uses 58 flops */
351         }
352         /* End of innermost loop */
353
354         tx = ty = tz = 0;
355         f[i_coord_offset+DIM*0+XX] += fix0;
356         f[i_coord_offset+DIM*0+YY] += fiy0;
357         f[i_coord_offset+DIM*0+ZZ] += fiz0;
358         tx                         += fix0;
359         ty                         += fiy0;
360         tz                         += fiz0;
361         fshift[i_shift_offset+XX]  += tx;
362         fshift[i_shift_offset+YY]  += ty;
363         fshift[i_shift_offset+ZZ]  += tz;
364
365         /* Increment number of inner iterations */
366         inneriter                  += j_index_end - j_index_start;
367
368         /* Outer loop uses 12 flops */
369     }
370
371     /* Increment number of outer iterations */
372     outeriter        += nri;
373
374     /* Update outer/inner flops */
375
376     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_F,outeriter*12 + inneriter*58);
377 }