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