7a88d5250a87398032c05159e0b0988983babfa0
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecNone_VdwBhamSw_GeomP1P1_c.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS c kernel generator.
37  */
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "nrnb.h"
48
49 /*
50  * Gromacs nonbonded kernel:   nb_kernel_ElecNone_VdwBhamSw_GeomP1P1_VF_c
51  * Electrostatics interaction: None
52  * VdW interaction:            Buckingham
53  * Geometry:                   Particle-Particle
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecNone_VdwBhamSw_GeomP1P1_VF_c
58                     (t_nblist                    * gmx_restrict       nlist,
59                      rvec                        * gmx_restrict          xx,
60                      rvec                        * gmx_restrict          ff,
61                      t_forcerec                  * gmx_restrict          fr,
62                      t_mdatoms                   * gmx_restrict     mdatoms,
63                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64                      t_nrnb                      * gmx_restrict        nrnb)
65 {
66     int              i_shift_offset,i_coord_offset,j_coord_offset;
67     int              j_index_start,j_index_end;
68     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
69     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
70     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
71     real             *shiftvec,*fshift,*x,*f;
72     int              vdwioffset0;
73     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
74     int              vdwjidx0;
75     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
76     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
77     int              nvdwtype;
78     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
79     int              *vdwtype;
80     real             *vdwparam;
81     real             rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
82
83     x                = xx[0];
84     f                = ff[0];
85
86     nri              = nlist->nri;
87     iinr             = nlist->iinr;
88     jindex           = nlist->jindex;
89     jjnr             = nlist->jjnr;
90     shiftidx         = nlist->shift;
91     gid              = nlist->gid;
92     shiftvec         = fr->shift_vec[0];
93     fshift           = fr->fshift[0];
94     nvdwtype         = fr->ntype;
95     vdwparam         = fr->nbfp;
96     vdwtype          = mdatoms->typeA;
97
98     rcutoff          = fr->rvdw;
99     rcutoff2         = rcutoff*rcutoff;
100
101     rswitch          = fr->rvdw_switch;
102     /* Setup switch parameters */
103     d                = rcutoff-rswitch;
104     swV3             = -10.0/(d*d*d);
105     swV4             =  15.0/(d*d*d*d);
106     swV5             =  -6.0/(d*d*d*d*d);
107     swF2             = -30.0/(d*d*d);
108     swF3             =  60.0/(d*d*d*d);
109     swF4             = -30.0/(d*d*d*d*d);
110
111     outeriter        = 0;
112     inneriter        = 0;
113
114     /* Start outer loop over neighborlists */
115     for(iidx=0; iidx<nri; iidx++)
116     {
117         /* Load shift vector for this list */
118         i_shift_offset   = DIM*shiftidx[iidx];
119         shX              = shiftvec[i_shift_offset+XX];
120         shY              = shiftvec[i_shift_offset+YY];
121         shZ              = shiftvec[i_shift_offset+ZZ];
122
123         /* Load limits for loop over neighbors */
124         j_index_start    = jindex[iidx];
125         j_index_end      = jindex[iidx+1];
126
127         /* Get outer coordinate index */
128         inr              = iinr[iidx];
129         i_coord_offset   = DIM*inr;
130
131         /* Load i particle coords and add shift vector */
132         ix0              = shX + x[i_coord_offset+DIM*0+XX];
133         iy0              = shY + x[i_coord_offset+DIM*0+YY];
134         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
135
136         fix0             = 0.0;
137         fiy0             = 0.0;
138         fiz0             = 0.0;
139
140         /* Load parameters for i particles */
141         vdwioffset0      = 3*nvdwtype*vdwtype[inr+0];
142
143         /* Reset potential sums */
144         vvdwsum          = 0.0;
145
146         /* Start inner kernel loop */
147         for(jidx=j_index_start; jidx<j_index_end; jidx++)
148         {
149             /* Get j neighbor index, and coordinate index */
150             jnr              = jjnr[jidx];
151             j_coord_offset   = DIM*jnr;
152
153             /* load j atom coordinates */
154             jx0              = x[j_coord_offset+DIM*0+XX];
155             jy0              = x[j_coord_offset+DIM*0+YY];
156             jz0              = x[j_coord_offset+DIM*0+ZZ];
157
158             /* Calculate displacement vector */
159             dx00             = ix0 - jx0;
160             dy00             = iy0 - jy0;
161             dz00             = iz0 - jz0;
162
163             /* Calculate squared distance and things based on it */
164             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
165
166             rinv00           = gmx_invsqrt(rsq00);
167
168             rinvsq00         = rinv00*rinv00;
169
170             /* Load parameters for j particles */
171             vdwjidx0         = 3*vdwtype[jnr+0];
172
173             /**************************
174              * CALCULATE INTERACTIONS *
175              **************************/
176
177             if (rsq00<rcutoff2)
178             {
179
180             r00              = rsq00*rinv00;
181
182             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
183             cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
184             cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
185
186             /* BUCKINGHAM DISPERSION/REPULSION */
187             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
188             vvdw6            = c6_00*rinvsix;
189             br               = cexp2_00*r00;
190             vvdwexp          = cexp1_00*exp(-br);
191             vvdw             = vvdwexp - vvdw6*(1.0/6.0);
192             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
193
194             d                = r00-rswitch;
195             d                = (d>0.0) ? d : 0.0;
196             d2               = d*d;
197             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
198
199             dsw              = d2*(swF2+d*(swF3+d*swF4));
200
201             /* Evaluate switch function */
202             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
203             fvdw             = fvdw*sw - rinv00*vvdw*dsw;
204             vvdw            *= sw;
205
206             /* Update potential sums from outer loop */
207             vvdwsum         += vvdw;
208
209             fscal            = fvdw;
210
211             /* Calculate temporary vectorial force */
212             tx               = fscal*dx00;
213             ty               = fscal*dy00;
214             tz               = fscal*dz00;
215
216             /* Update vectorial force */
217             fix0            += tx;
218             fiy0            += ty;
219             fiz0            += tz;
220             f[j_coord_offset+DIM*0+XX] -= tx;
221             f[j_coord_offset+DIM*0+YY] -= ty;
222             f[j_coord_offset+DIM*0+ZZ] -= tz;
223
224             }
225
226             /* Inner loop uses 79 flops */
227         }
228         /* End of innermost loop */
229
230         tx = ty = tz = 0;
231         f[i_coord_offset+DIM*0+XX] += fix0;
232         f[i_coord_offset+DIM*0+YY] += fiy0;
233         f[i_coord_offset+DIM*0+ZZ] += fiz0;
234         tx                         += fix0;
235         ty                         += fiy0;
236         tz                         += fiz0;
237         fshift[i_shift_offset+XX]  += tx;
238         fshift[i_shift_offset+YY]  += ty;
239         fshift[i_shift_offset+ZZ]  += tz;
240
241         ggid                        = gid[iidx];
242         /* Update potential energies */
243         kernel_data->energygrp_vdw[ggid] += vvdwsum;
244
245         /* Increment number of inner iterations */
246         inneriter                  += j_index_end - j_index_start;
247
248         /* Outer loop uses 13 flops */
249     }
250
251     /* Increment number of outer iterations */
252     outeriter        += nri;
253
254     /* Update outer/inner flops */
255
256     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_VF,outeriter*13 + inneriter*79);
257 }
258 /*
259  * Gromacs nonbonded kernel:   nb_kernel_ElecNone_VdwBhamSw_GeomP1P1_F_c
260  * Electrostatics interaction: None
261  * VdW interaction:            Buckingham
262  * Geometry:                   Particle-Particle
263  * Calculate force/pot:        Force
264  */
265 void
266 nb_kernel_ElecNone_VdwBhamSw_GeomP1P1_F_c
267                     (t_nblist                    * gmx_restrict       nlist,
268                      rvec                        * gmx_restrict          xx,
269                      rvec                        * gmx_restrict          ff,
270                      t_forcerec                  * gmx_restrict          fr,
271                      t_mdatoms                   * gmx_restrict     mdatoms,
272                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
273                      t_nrnb                      * gmx_restrict        nrnb)
274 {
275     int              i_shift_offset,i_coord_offset,j_coord_offset;
276     int              j_index_start,j_index_end;
277     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
278     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
279     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
280     real             *shiftvec,*fshift,*x,*f;
281     int              vdwioffset0;
282     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
283     int              vdwjidx0;
284     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
285     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
286     int              nvdwtype;
287     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
288     int              *vdwtype;
289     real             *vdwparam;
290     real             rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
291
292     x                = xx[0];
293     f                = ff[0];
294
295     nri              = nlist->nri;
296     iinr             = nlist->iinr;
297     jindex           = nlist->jindex;
298     jjnr             = nlist->jjnr;
299     shiftidx         = nlist->shift;
300     gid              = nlist->gid;
301     shiftvec         = fr->shift_vec[0];
302     fshift           = fr->fshift[0];
303     nvdwtype         = fr->ntype;
304     vdwparam         = fr->nbfp;
305     vdwtype          = mdatoms->typeA;
306
307     rcutoff          = fr->rvdw;
308     rcutoff2         = rcutoff*rcutoff;
309
310     rswitch          = fr->rvdw_switch;
311     /* Setup switch parameters */
312     d                = rcutoff-rswitch;
313     swV3             = -10.0/(d*d*d);
314     swV4             =  15.0/(d*d*d*d);
315     swV5             =  -6.0/(d*d*d*d*d);
316     swF2             = -30.0/(d*d*d);
317     swF3             =  60.0/(d*d*d*d);
318     swF4             = -30.0/(d*d*d*d*d);
319
320     outeriter        = 0;
321     inneriter        = 0;
322
323     /* Start outer loop over neighborlists */
324     for(iidx=0; iidx<nri; iidx++)
325     {
326         /* Load shift vector for this list */
327         i_shift_offset   = DIM*shiftidx[iidx];
328         shX              = shiftvec[i_shift_offset+XX];
329         shY              = shiftvec[i_shift_offset+YY];
330         shZ              = shiftvec[i_shift_offset+ZZ];
331
332         /* Load limits for loop over neighbors */
333         j_index_start    = jindex[iidx];
334         j_index_end      = jindex[iidx+1];
335
336         /* Get outer coordinate index */
337         inr              = iinr[iidx];
338         i_coord_offset   = DIM*inr;
339
340         /* Load i particle coords and add shift vector */
341         ix0              = shX + x[i_coord_offset+DIM*0+XX];
342         iy0              = shY + x[i_coord_offset+DIM*0+YY];
343         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
344
345         fix0             = 0.0;
346         fiy0             = 0.0;
347         fiz0             = 0.0;
348
349         /* Load parameters for i particles */
350         vdwioffset0      = 3*nvdwtype*vdwtype[inr+0];
351
352         /* Start inner kernel loop */
353         for(jidx=j_index_start; jidx<j_index_end; jidx++)
354         {
355             /* Get j neighbor index, and coordinate index */
356             jnr              = jjnr[jidx];
357             j_coord_offset   = DIM*jnr;
358
359             /* load j atom coordinates */
360             jx0              = x[j_coord_offset+DIM*0+XX];
361             jy0              = x[j_coord_offset+DIM*0+YY];
362             jz0              = x[j_coord_offset+DIM*0+ZZ];
363
364             /* Calculate displacement vector */
365             dx00             = ix0 - jx0;
366             dy00             = iy0 - jy0;
367             dz00             = iz0 - jz0;
368
369             /* Calculate squared distance and things based on it */
370             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
371
372             rinv00           = gmx_invsqrt(rsq00);
373
374             rinvsq00         = rinv00*rinv00;
375
376             /* Load parameters for j particles */
377             vdwjidx0         = 3*vdwtype[jnr+0];
378
379             /**************************
380              * CALCULATE INTERACTIONS *
381              **************************/
382
383             if (rsq00<rcutoff2)
384             {
385
386             r00              = rsq00*rinv00;
387
388             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
389             cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
390             cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
391
392             /* BUCKINGHAM DISPERSION/REPULSION */
393             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
394             vvdw6            = c6_00*rinvsix;
395             br               = cexp2_00*r00;
396             vvdwexp          = cexp1_00*exp(-br);
397             vvdw             = vvdwexp - vvdw6*(1.0/6.0);
398             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
399
400             d                = r00-rswitch;
401             d                = (d>0.0) ? d : 0.0;
402             d2               = d*d;
403             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
404
405             dsw              = d2*(swF2+d*(swF3+d*swF4));
406
407             /* Evaluate switch function */
408             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
409             fvdw             = fvdw*sw - rinv00*vvdw*dsw;
410
411             fscal            = fvdw;
412
413             /* Calculate temporary vectorial force */
414             tx               = fscal*dx00;
415             ty               = fscal*dy00;
416             tz               = fscal*dz00;
417
418             /* Update vectorial force */
419             fix0            += tx;
420             fiy0            += ty;
421             fiz0            += tz;
422             f[j_coord_offset+DIM*0+XX] -= tx;
423             f[j_coord_offset+DIM*0+YY] -= ty;
424             f[j_coord_offset+DIM*0+ZZ] -= tz;
425
426             }
427
428             /* Inner loop uses 77 flops */
429         }
430         /* End of innermost loop */
431
432         tx = ty = tz = 0;
433         f[i_coord_offset+DIM*0+XX] += fix0;
434         f[i_coord_offset+DIM*0+YY] += fiy0;
435         f[i_coord_offset+DIM*0+ZZ] += fiz0;
436         tx                         += fix0;
437         ty                         += fiy0;
438         tz                         += fiz0;
439         fshift[i_shift_offset+XX]  += tx;
440         fshift[i_shift_offset+YY]  += ty;
441         fshift[i_shift_offset+ZZ]  += tz;
442
443         /* Increment number of inner iterations */
444         inneriter                  += j_index_end - j_index_start;
445
446         /* Outer loop uses 12 flops */
447     }
448
449     /* Increment number of outer iterations */
450     outeriter        += nri;
451
452     /* Update outer/inner flops */
453
454     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_F,outeriter*12 + inneriter*77);
455 }