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