396f264b55c6528c80a68092dc64ac582e418355
[alexxy/gromacs.git] / src / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecRFCut_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_ElecRFCut_VdwLJSh_GeomP1P1_VF_c
35  * Electrostatics interaction: ReactionField
36  * VdW interaction:            LennardJones
37  * Geometry:                   Particle-Particle
38  * Calculate force/pot:        PotentialAndForce
39  */
40 void
41 nb_kernel_ElecRFCut_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
68     x                = xx[0];
69     f                = ff[0];
70
71     nri              = nlist->nri;
72     iinr             = nlist->iinr;
73     jindex           = nlist->jindex;
74     jjnr             = nlist->jjnr;
75     shiftidx         = nlist->shift;
76     gid              = nlist->gid;
77     shiftvec         = fr->shift_vec[0];
78     fshift           = fr->fshift[0];
79     facel            = fr->epsfac;
80     charge           = mdatoms->chargeA;
81     krf              = fr->ic->k_rf;
82     krf2             = krf*2.0;
83     crf              = fr->ic->c_rf;
84     nvdwtype         = fr->ntype;
85     vdwparam         = fr->nbfp;
86     vdwtype          = mdatoms->typeA;
87
88     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
89     rcutoff          = fr->rcoulomb;
90     rcutoff2         = rcutoff*rcutoff;
91
92     sh_vdw_invrcut6  = fr->ic->sh_invrc6;
93     rvdw             = fr->rvdw;
94
95     outeriter        = 0;
96     inneriter        = 0;
97
98     /* Start outer loop over neighborlists */
99     for(iidx=0; iidx<nri; iidx++)
100     {
101         /* Load shift vector for this list */
102         i_shift_offset   = DIM*shiftidx[iidx];
103         shX              = shiftvec[i_shift_offset+XX];
104         shY              = shiftvec[i_shift_offset+YY];
105         shZ              = shiftvec[i_shift_offset+ZZ];
106
107         /* Load limits for loop over neighbors */
108         j_index_start    = jindex[iidx];
109         j_index_end      = jindex[iidx+1];
110
111         /* Get outer coordinate index */
112         inr              = iinr[iidx];
113         i_coord_offset   = DIM*inr;
114
115         /* Load i particle coords and add shift vector */
116         ix0              = shX + x[i_coord_offset+DIM*0+XX];
117         iy0              = shY + x[i_coord_offset+DIM*0+YY];
118         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
119
120         fix0             = 0.0;
121         fiy0             = 0.0;
122         fiz0             = 0.0;
123
124         /* Load parameters for i particles */
125         iq0              = facel*charge[inr+0];
126         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
127
128         /* Reset potential sums */
129         velecsum         = 0.0;
130         vvdwsum          = 0.0;
131
132         /* Start inner kernel loop */
133         for(jidx=j_index_start; jidx<j_index_end; jidx++)
134         {
135             /* Get j neighbor index, and coordinate index */
136             jnr              = jjnr[jidx];
137             j_coord_offset   = DIM*jnr;
138
139             /* load j atom coordinates */
140             jx0              = x[j_coord_offset+DIM*0+XX];
141             jy0              = x[j_coord_offset+DIM*0+YY];
142             jz0              = x[j_coord_offset+DIM*0+ZZ];
143
144             /* Calculate displacement vector */
145             dx00             = ix0 - jx0;
146             dy00             = iy0 - jy0;
147             dz00             = iz0 - jz0;
148
149             /* Calculate squared distance and things based on it */
150             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
151
152             rinv00           = gmx_invsqrt(rsq00);
153
154             rinvsq00         = rinv00*rinv00;
155
156             /* Load parameters for j particles */
157             jq0              = charge[jnr+0];
158             vdwjidx0         = 2*vdwtype[jnr+0];
159
160             /**************************
161              * CALCULATE INTERACTIONS *
162              **************************/
163
164             if (rsq00<rcutoff2)
165             {
166
167             qq00             = iq0*jq0;
168             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
169             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
170
171             /* REACTION-FIELD ELECTROSTATICS */
172             velec            = qq00*(rinv00+krf*rsq00-crf);
173             felec            = qq00*(rinv00*rinvsq00-krf2);
174
175             /* LENNARD-JONES DISPERSION/REPULSION */
176
177             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
178             vvdw6            = c6_00*rinvsix;
179             vvdw12           = c12_00*rinvsix*rinvsix;
180             vvdw             = (vvdw12 - c12_00*sh_vdw_invrcut6*sh_vdw_invrcut6)*(1.0/12.0) - (vvdw6 - c6_00*sh_vdw_invrcut6)*(1.0/6.0);
181             fvdw             = (vvdw12-vvdw6)*rinvsq00;
182
183             /* Update potential sums from outer loop */
184             velecsum        += velec;
185             vvdwsum         += vvdw;
186
187             fscal            = felec+fvdw;
188
189             /* Calculate temporary vectorial force */
190             tx               = fscal*dx00;
191             ty               = fscal*dy00;
192             tz               = fscal*dz00;
193
194             /* Update vectorial force */
195             fix0            += tx;
196             fiy0            += ty;
197             fiz0            += tz;
198             f[j_coord_offset+DIM*0+XX] -= tx;
199             f[j_coord_offset+DIM*0+YY] -= ty;
200             f[j_coord_offset+DIM*0+ZZ] -= tz;
201
202             }
203
204             /* Inner loop uses 49 flops */
205         }
206         /* End of innermost loop */
207
208         tx = ty = tz = 0;
209         f[i_coord_offset+DIM*0+XX] += fix0;
210         f[i_coord_offset+DIM*0+YY] += fiy0;
211         f[i_coord_offset+DIM*0+ZZ] += fiz0;
212         tx                         += fix0;
213         ty                         += fiy0;
214         tz                         += fiz0;
215         fshift[i_shift_offset+XX]  += tx;
216         fshift[i_shift_offset+YY]  += ty;
217         fshift[i_shift_offset+ZZ]  += tz;
218
219         ggid                        = gid[iidx];
220         /* Update potential energies */
221         kernel_data->energygrp_elec[ggid] += velecsum;
222         kernel_data->energygrp_vdw[ggid] += vvdwsum;
223
224         /* Increment number of inner iterations */
225         inneriter                  += j_index_end - j_index_start;
226
227         /* Outer loop uses 15 flops */
228     }
229
230     /* Increment number of outer iterations */
231     outeriter        += nri;
232
233     /* Update outer/inner flops */
234
235     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*15 + inneriter*49);
236 }
237 /*
238  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwLJSh_GeomP1P1_F_c
239  * Electrostatics interaction: ReactionField
240  * VdW interaction:            LennardJones
241  * Geometry:                   Particle-Particle
242  * Calculate force/pot:        Force
243  */
244 void
245 nb_kernel_ElecRFCut_VdwLJSh_GeomP1P1_F_c
246                     (t_nblist * gmx_restrict                nlist,
247                      rvec * gmx_restrict                    xx,
248                      rvec * gmx_restrict                    ff,
249                      t_forcerec * gmx_restrict              fr,
250                      t_mdatoms * gmx_restrict               mdatoms,
251                      nb_kernel_data_t * gmx_restrict        kernel_data,
252                      t_nrnb * gmx_restrict                  nrnb)
253 {
254     int              i_shift_offset,i_coord_offset,j_coord_offset;
255     int              j_index_start,j_index_end;
256     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
257     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
258     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
259     real             *shiftvec,*fshift,*x,*f;
260     int              vdwioffset0;
261     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
262     int              vdwjidx0;
263     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
264     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
265     real             velec,felec,velecsum,facel,crf,krf,krf2;
266     real             *charge;
267     int              nvdwtype;
268     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
269     int              *vdwtype;
270     real             *vdwparam;
271
272     x                = xx[0];
273     f                = ff[0];
274
275     nri              = nlist->nri;
276     iinr             = nlist->iinr;
277     jindex           = nlist->jindex;
278     jjnr             = nlist->jjnr;
279     shiftidx         = nlist->shift;
280     gid              = nlist->gid;
281     shiftvec         = fr->shift_vec[0];
282     fshift           = fr->fshift[0];
283     facel            = fr->epsfac;
284     charge           = mdatoms->chargeA;
285     krf              = fr->ic->k_rf;
286     krf2             = krf*2.0;
287     crf              = fr->ic->c_rf;
288     nvdwtype         = fr->ntype;
289     vdwparam         = fr->nbfp;
290     vdwtype          = mdatoms->typeA;
291
292     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
293     rcutoff          = fr->rcoulomb;
294     rcutoff2         = rcutoff*rcutoff;
295
296     sh_vdw_invrcut6  = fr->ic->sh_invrc6;
297     rvdw             = fr->rvdw;
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             if (rsq00<rcutoff2)
365             {
366
367             qq00             = iq0*jq0;
368             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
369             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
370
371             /* REACTION-FIELD ELECTROSTATICS */
372             felec            = qq00*(rinv00*rinvsq00-krf2);
373
374             /* LENNARD-JONES DISPERSION/REPULSION */
375
376             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
377             fvdw             = (c12_00*rinvsix-c6_00)*rinvsix*rinvsq00;
378
379             fscal            = felec+fvdw;
380
381             /* Calculate temporary vectorial force */
382             tx               = fscal*dx00;
383             ty               = fscal*dy00;
384             tz               = fscal*dz00;
385
386             /* Update vectorial force */
387             fix0            += tx;
388             fiy0            += ty;
389             fiz0            += tz;
390             f[j_coord_offset+DIM*0+XX] -= tx;
391             f[j_coord_offset+DIM*0+YY] -= ty;
392             f[j_coord_offset+DIM*0+ZZ] -= tz;
393
394             }
395
396             /* Inner loop uses 34 flops */
397         }
398         /* End of innermost loop */
399
400         tx = ty = tz = 0;
401         f[i_coord_offset+DIM*0+XX] += fix0;
402         f[i_coord_offset+DIM*0+YY] += fiy0;
403         f[i_coord_offset+DIM*0+ZZ] += fiz0;
404         tx                         += fix0;
405         ty                         += fiy0;
406         tz                         += fiz0;
407         fshift[i_shift_offset+XX]  += tx;
408         fshift[i_shift_offset+YY]  += ty;
409         fshift[i_shift_offset+ZZ]  += tz;
410
411         /* Increment number of inner iterations */
412         inneriter                  += j_index_end - j_index_start;
413
414         /* Outer loop uses 13 flops */
415     }
416
417     /* Increment number of outer iterations */
418     outeriter        += nri;
419
420     /* Update outer/inner flops */
421
422     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*13 + inneriter*34);
423 }