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