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