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