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