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