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