a04671ae8731abcbeabda89c9a597c309af23e7f
[alexxy/gromacs.git] / src / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecEw_VdwBham_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_ElecEw_VdwBham_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_ElecEw_VdwBham_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     outeriter        = 0;
94     inneriter        = 0;
95
96     /* Start outer loop over neighborlists */
97     for(iidx=0; iidx<nri; iidx++)
98     {
99         /* Load shift vector for this list */
100         i_shift_offset   = DIM*shiftidx[iidx];
101         shX              = shiftvec[i_shift_offset+XX];
102         shY              = shiftvec[i_shift_offset+YY];
103         shZ              = shiftvec[i_shift_offset+ZZ];
104
105         /* Load limits for loop over neighbors */
106         j_index_start    = jindex[iidx];
107         j_index_end      = jindex[iidx+1];
108
109         /* Get outer coordinate index */
110         inr              = iinr[iidx];
111         i_coord_offset   = DIM*inr;
112
113         /* Load i particle coords and add shift vector */
114         ix0              = shX + x[i_coord_offset+DIM*0+XX];
115         iy0              = shY + x[i_coord_offset+DIM*0+YY];
116         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
117
118         fix0             = 0.0;
119         fiy0             = 0.0;
120         fiz0             = 0.0;
121
122         /* Load parameters for i particles */
123         iq0              = facel*charge[inr+0];
124         vdwioffset0      = 3*nvdwtype*vdwtype[inr+0];
125
126         /* Reset potential sums */
127         velecsum         = 0.0;
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             jq0              = charge[jnr+0];
156             vdwjidx0         = 3*vdwtype[jnr+0];
157
158             /**************************
159              * CALCULATE INTERACTIONS *
160              **************************/
161
162             r00              = rsq00*rinv00;
163
164             qq00             = iq0*jq0;
165             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
166             cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
167             cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
168
169             /* EWALD ELECTROSTATICS */
170
171             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
172             ewrt             = r00*ewtabscale;
173             ewitab           = ewrt;
174             eweps            = ewrt-ewitab;
175             ewitab           = 4*ewitab;
176             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
177             velec            = qq00*(rinv00-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
178             felec            = qq00*rinv00*(rinvsq00-felec);
179
180             /* BUCKINGHAM DISPERSION/REPULSION */
181             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
182             vvdw6            = c6_00*rinvsix;
183             br               = cexp2_00*r00;
184             vvdwexp          = cexp1_00*exp(-br);
185             vvdw             = vvdwexp - vvdw6*(1.0/6.0);
186             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
187
188             /* Update potential sums from outer loop */
189             velecsum        += velec;
190             vvdwsum         += vvdw;
191
192             fscal            = felec+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             /* Inner loop uses 79 flops */
208         }
209         /* End of innermost loop */
210
211         tx = ty = tz = 0;
212         f[i_coord_offset+DIM*0+XX] += fix0;
213         f[i_coord_offset+DIM*0+YY] += fiy0;
214         f[i_coord_offset+DIM*0+ZZ] += fiz0;
215         tx                         += fix0;
216         ty                         += fiy0;
217         tz                         += fiz0;
218         fshift[i_shift_offset+XX]  += tx;
219         fshift[i_shift_offset+YY]  += ty;
220         fshift[i_shift_offset+ZZ]  += tz;
221
222         ggid                        = gid[iidx];
223         /* Update potential energies */
224         kernel_data->energygrp_elec[ggid] += velecsum;
225         kernel_data->energygrp_vdw[ggid] += vvdwsum;
226
227         /* Increment number of inner iterations */
228         inneriter                  += j_index_end - j_index_start;
229
230         /* Outer loop uses 15 flops */
231     }
232
233     /* Increment number of outer iterations */
234     outeriter        += nri;
235
236     /* Update outer/inner flops */
237
238     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*15 + inneriter*79);
239 }
240 /*
241  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwBham_GeomP1P1_F_c
242  * Electrostatics interaction: Ewald
243  * VdW interaction:            Buckingham
244  * Geometry:                   Particle-Particle
245  * Calculate force/pot:        Force
246  */
247 void
248 nb_kernel_ElecEw_VdwBham_GeomP1P1_F_c
249                     (t_nblist * gmx_restrict                nlist,
250                      rvec * gmx_restrict                    xx,
251                      rvec * gmx_restrict                    ff,
252                      t_forcerec * gmx_restrict              fr,
253                      t_mdatoms * gmx_restrict               mdatoms,
254                      nb_kernel_data_t * gmx_restrict        kernel_data,
255                      t_nrnb * gmx_restrict                  nrnb)
256 {
257     int              i_shift_offset,i_coord_offset,j_coord_offset;
258     int              j_index_start,j_index_end;
259     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
260     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
261     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
262     real             *shiftvec,*fshift,*x,*f;
263     int              vdwioffset0;
264     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
265     int              vdwjidx0;
266     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
267     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
268     real             velec,felec,velecsum,facel,crf,krf,krf2;
269     real             *charge;
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     int              ewitab;
275     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
276     real             *ewtab;
277
278     x                = xx[0];
279     f                = ff[0];
280
281     nri              = nlist->nri;
282     iinr             = nlist->iinr;
283     jindex           = nlist->jindex;
284     jjnr             = nlist->jjnr;
285     shiftidx         = nlist->shift;
286     gid              = nlist->gid;
287     shiftvec         = fr->shift_vec[0];
288     fshift           = fr->fshift[0];
289     facel            = fr->epsfac;
290     charge           = mdatoms->chargeA;
291     nvdwtype         = fr->ntype;
292     vdwparam         = fr->nbfp;
293     vdwtype          = mdatoms->typeA;
294
295     sh_ewald         = fr->ic->sh_ewald;
296     ewtab            = fr->ic->tabq_coul_F;
297     ewtabscale       = fr->ic->tabq_scale;
298     ewtabhalfspace   = 0.5/ewtabscale;
299
300     outeriter        = 0;
301     inneriter        = 0;
302
303     /* Start outer loop over neighborlists */
304     for(iidx=0; iidx<nri; iidx++)
305     {
306         /* Load shift vector for this list */
307         i_shift_offset   = DIM*shiftidx[iidx];
308         shX              = shiftvec[i_shift_offset+XX];
309         shY              = shiftvec[i_shift_offset+YY];
310         shZ              = shiftvec[i_shift_offset+ZZ];
311
312         /* Load limits for loop over neighbors */
313         j_index_start    = jindex[iidx];
314         j_index_end      = jindex[iidx+1];
315
316         /* Get outer coordinate index */
317         inr              = iinr[iidx];
318         i_coord_offset   = DIM*inr;
319
320         /* Load i particle coords and add shift vector */
321         ix0              = shX + x[i_coord_offset+DIM*0+XX];
322         iy0              = shY + x[i_coord_offset+DIM*0+YY];
323         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
324
325         fix0             = 0.0;
326         fiy0             = 0.0;
327         fiz0             = 0.0;
328
329         /* Load parameters for i particles */
330         iq0              = facel*charge[inr+0];
331         vdwioffset0      = 3*nvdwtype*vdwtype[inr+0];
332
333         /* Start inner kernel loop */
334         for(jidx=j_index_start; jidx<j_index_end; jidx++)
335         {
336             /* Get j neighbor index, and coordinate index */
337             jnr              = jjnr[jidx];
338             j_coord_offset   = DIM*jnr;
339
340             /* load j atom coordinates */
341             jx0              = x[j_coord_offset+DIM*0+XX];
342             jy0              = x[j_coord_offset+DIM*0+YY];
343             jz0              = x[j_coord_offset+DIM*0+ZZ];
344
345             /* Calculate displacement vector */
346             dx00             = ix0 - jx0;
347             dy00             = iy0 - jy0;
348             dz00             = iz0 - jz0;
349
350             /* Calculate squared distance and things based on it */
351             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
352
353             rinv00           = gmx_invsqrt(rsq00);
354
355             rinvsq00         = rinv00*rinv00;
356
357             /* Load parameters for j particles */
358             jq0              = charge[jnr+0];
359             vdwjidx0         = 3*vdwtype[jnr+0];
360
361             /**************************
362              * CALCULATE INTERACTIONS *
363              **************************/
364
365             r00              = rsq00*rinv00;
366
367             qq00             = iq0*jq0;
368             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
369             cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
370             cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
371
372             /* EWALD ELECTROSTATICS */
373
374             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
375             ewrt             = r00*ewtabscale;
376             ewitab           = ewrt;
377             eweps            = ewrt-ewitab;
378             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
379             felec            = qq00*rinv00*(rinvsq00-felec);
380
381             /* BUCKINGHAM DISPERSION/REPULSION */
382             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
383             vvdw6            = c6_00*rinvsix;
384             br               = cexp2_00*r00;
385             vvdwexp          = cexp1_00*exp(-br);
386             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
387
388             fscal            = felec+fvdw;
389
390             /* Calculate temporary vectorial force */
391             tx               = fscal*dx00;
392             ty               = fscal*dy00;
393             tz               = fscal*dz00;
394
395             /* Update vectorial force */
396             fix0            += tx;
397             fiy0            += ty;
398             fiz0            += tz;
399             f[j_coord_offset+DIM*0+XX] -= tx;
400             f[j_coord_offset+DIM*0+YY] -= ty;
401             f[j_coord_offset+DIM*0+ZZ] -= tz;
402
403             /* Inner loop uses 69 flops */
404         }
405         /* End of innermost loop */
406
407         tx = ty = tz = 0;
408         f[i_coord_offset+DIM*0+XX] += fix0;
409         f[i_coord_offset+DIM*0+YY] += fiy0;
410         f[i_coord_offset+DIM*0+ZZ] += fiz0;
411         tx                         += fix0;
412         ty                         += fiy0;
413         tz                         += fiz0;
414         fshift[i_shift_offset+XX]  += tx;
415         fshift[i_shift_offset+YY]  += ty;
416         fshift[i_shift_offset+ZZ]  += tz;
417
418         /* Increment number of inner iterations */
419         inneriter                  += j_index_end - j_index_start;
420
421         /* Outer loop uses 13 flops */
422     }
423
424     /* Increment number of outer iterations */
425     outeriter        += nri;
426
427     /* Update outer/inner flops */
428
429     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*13 + inneriter*69);
430 }