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