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