d0935afdcc42691118c831a559335a87452f1bbf
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecRF_VdwCSTab_GeomP1P1_c.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS c kernel generator.
37  */
38 #include "config.h"
39
40 #include <math.h>
41
42 #include "../nb_kernel.h"
43 #include "gromacs/legacyheaders/types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "gromacs/legacyheaders/nrnb.h"
46
47 /*
48  * Gromacs nonbonded kernel:   nb_kernel_ElecRF_VdwCSTab_GeomP1P1_VF_c
49  * Electrostatics interaction: ReactionField
50  * VdW interaction:            CubicSplineTable
51  * Geometry:                   Particle-Particle
52  * Calculate force/pot:        PotentialAndForce
53  */
54 void
55 nb_kernel_ElecRF_VdwCSTab_GeomP1P1_VF_c
56                     (t_nblist                    * gmx_restrict       nlist,
57                      rvec                        * gmx_restrict          xx,
58                      rvec                        * gmx_restrict          ff,
59                      t_forcerec                  * gmx_restrict          fr,
60                      t_mdatoms                   * gmx_restrict     mdatoms,
61                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
62                      t_nrnb                      * gmx_restrict        nrnb)
63 {
64     int              i_shift_offset,i_coord_offset,j_coord_offset;
65     int              j_index_start,j_index_end;
66     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
67     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
68     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
69     real             *shiftvec,*fshift,*x,*f;
70     int              vdwioffset0;
71     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
72     int              vdwjidx0;
73     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
74     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
75     real             velec,felec,velecsum,facel,crf,krf,krf2;
76     real             *charge;
77     int              nvdwtype;
78     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
79     int              *vdwtype;
80     real             *vdwparam;
81     int              vfitab;
82     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
83     real             *vftab;
84
85     x                = xx[0];
86     f                = ff[0];
87
88     nri              = nlist->nri;
89     iinr             = nlist->iinr;
90     jindex           = nlist->jindex;
91     jjnr             = nlist->jjnr;
92     shiftidx         = nlist->shift;
93     gid              = nlist->gid;
94     shiftvec         = fr->shift_vec[0];
95     fshift           = fr->fshift[0];
96     facel            = fr->epsfac;
97     charge           = mdatoms->chargeA;
98     krf              = fr->ic->k_rf;
99     krf2             = krf*2.0;
100     crf              = fr->ic->c_rf;
101     nvdwtype         = fr->ntype;
102     vdwparam         = fr->nbfp;
103     vdwtype          = mdatoms->typeA;
104
105     vftab            = kernel_data->table_vdw->data;
106     vftabscale       = kernel_data->table_vdw->scale;
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             r00              = rsq00*rinv00;
178
179             qq00             = iq0*jq0;
180             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
181             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
182
183             /* Calculate table index by multiplying r with table scale and truncate to integer */
184             rt               = r00*vftabscale;
185             vfitab           = rt;
186             vfeps            = rt-vfitab;
187             vfitab           = 2*4*vfitab;
188
189             /* REACTION-FIELD ELECTROSTATICS */
190             velec            = qq00*(rinv00+krf*rsq00-crf);
191             felec            = qq00*(rinv00*rinvsq00-krf2);
192
193             /* CUBIC SPLINE TABLE DISPERSION */
194             vfitab          += 0;
195             Y                = vftab[vfitab];
196             F                = vftab[vfitab+1];
197             Geps             = vfeps*vftab[vfitab+2];
198             Heps2            = vfeps*vfeps*vftab[vfitab+3];
199             Fp               = F+Geps+Heps2;
200             VV               = Y+vfeps*Fp;
201             vvdw6            = c6_00*VV;
202             FF               = Fp+Geps+2.0*Heps2;
203             fvdw6            = c6_00*FF;
204
205             /* CUBIC SPLINE TABLE REPULSION */
206             Y                = vftab[vfitab+4];
207             F                = vftab[vfitab+5];
208             Geps             = vfeps*vftab[vfitab+6];
209             Heps2            = vfeps*vfeps*vftab[vfitab+7];
210             Fp               = F+Geps+Heps2;
211             VV               = Y+vfeps*Fp;
212             vvdw12           = c12_00*VV;
213             FF               = Fp+Geps+2.0*Heps2;
214             fvdw12           = c12_00*FF;
215             vvdw             = vvdw12+vvdw6;
216             fvdw             = -(fvdw6+fvdw12)*vftabscale*rinv00;
217
218             /* Update potential sums from outer loop */
219             velecsum        += velec;
220             vvdwsum         += vvdw;
221
222             fscal            = felec+fvdw;
223
224             /* Calculate temporary vectorial force */
225             tx               = fscal*dx00;
226             ty               = fscal*dy00;
227             tz               = fscal*dz00;
228
229             /* Update vectorial force */
230             fix0            += tx;
231             fiy0            += ty;
232             fiz0            += tz;
233             f[j_coord_offset+DIM*0+XX] -= tx;
234             f[j_coord_offset+DIM*0+YY] -= ty;
235             f[j_coord_offset+DIM*0+ZZ] -= tz;
236
237             /* Inner loop uses 66 flops */
238         }
239         /* End of innermost loop */
240
241         tx = ty = tz = 0;
242         f[i_coord_offset+DIM*0+XX] += fix0;
243         f[i_coord_offset+DIM*0+YY] += fiy0;
244         f[i_coord_offset+DIM*0+ZZ] += fiz0;
245         tx                         += fix0;
246         ty                         += fiy0;
247         tz                         += fiz0;
248         fshift[i_shift_offset+XX]  += tx;
249         fshift[i_shift_offset+YY]  += ty;
250         fshift[i_shift_offset+ZZ]  += tz;
251
252         ggid                        = gid[iidx];
253         /* Update potential energies */
254         kernel_data->energygrp_elec[ggid] += velecsum;
255         kernel_data->energygrp_vdw[ggid] += vvdwsum;
256
257         /* Increment number of inner iterations */
258         inneriter                  += j_index_end - j_index_start;
259
260         /* Outer loop uses 15 flops */
261     }
262
263     /* Increment number of outer iterations */
264     outeriter        += nri;
265
266     /* Update outer/inner flops */
267
268     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*15 + inneriter*66);
269 }
270 /*
271  * Gromacs nonbonded kernel:   nb_kernel_ElecRF_VdwCSTab_GeomP1P1_F_c
272  * Electrostatics interaction: ReactionField
273  * VdW interaction:            CubicSplineTable
274  * Geometry:                   Particle-Particle
275  * Calculate force/pot:        Force
276  */
277 void
278 nb_kernel_ElecRF_VdwCSTab_GeomP1P1_F_c
279                     (t_nblist                    * gmx_restrict       nlist,
280                      rvec                        * gmx_restrict          xx,
281                      rvec                        * gmx_restrict          ff,
282                      t_forcerec                  * gmx_restrict          fr,
283                      t_mdatoms                   * gmx_restrict     mdatoms,
284                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
285                      t_nrnb                      * gmx_restrict        nrnb)
286 {
287     int              i_shift_offset,i_coord_offset,j_coord_offset;
288     int              j_index_start,j_index_end;
289     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
290     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
291     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
292     real             *shiftvec,*fshift,*x,*f;
293     int              vdwioffset0;
294     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
295     int              vdwjidx0;
296     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
297     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
298     real             velec,felec,velecsum,facel,crf,krf,krf2;
299     real             *charge;
300     int              nvdwtype;
301     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
302     int              *vdwtype;
303     real             *vdwparam;
304     int              vfitab;
305     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
306     real             *vftab;
307
308     x                = xx[0];
309     f                = ff[0];
310
311     nri              = nlist->nri;
312     iinr             = nlist->iinr;
313     jindex           = nlist->jindex;
314     jjnr             = nlist->jjnr;
315     shiftidx         = nlist->shift;
316     gid              = nlist->gid;
317     shiftvec         = fr->shift_vec[0];
318     fshift           = fr->fshift[0];
319     facel            = fr->epsfac;
320     charge           = mdatoms->chargeA;
321     krf              = fr->ic->k_rf;
322     krf2             = krf*2.0;
323     crf              = fr->ic->c_rf;
324     nvdwtype         = fr->ntype;
325     vdwparam         = fr->nbfp;
326     vdwtype          = mdatoms->typeA;
327
328     vftab            = kernel_data->table_vdw->data;
329     vftabscale       = kernel_data->table_vdw->scale;
330
331     outeriter        = 0;
332     inneriter        = 0;
333
334     /* Start outer loop over neighborlists */
335     for(iidx=0; iidx<nri; iidx++)
336     {
337         /* Load shift vector for this list */
338         i_shift_offset   = DIM*shiftidx[iidx];
339         shX              = shiftvec[i_shift_offset+XX];
340         shY              = shiftvec[i_shift_offset+YY];
341         shZ              = shiftvec[i_shift_offset+ZZ];
342
343         /* Load limits for loop over neighbors */
344         j_index_start    = jindex[iidx];
345         j_index_end      = jindex[iidx+1];
346
347         /* Get outer coordinate index */
348         inr              = iinr[iidx];
349         i_coord_offset   = DIM*inr;
350
351         /* Load i particle coords and add shift vector */
352         ix0              = shX + x[i_coord_offset+DIM*0+XX];
353         iy0              = shY + x[i_coord_offset+DIM*0+YY];
354         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
355
356         fix0             = 0.0;
357         fiy0             = 0.0;
358         fiz0             = 0.0;
359
360         /* Load parameters for i particles */
361         iq0              = facel*charge[inr+0];
362         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
363
364         /* Start inner kernel loop */
365         for(jidx=j_index_start; jidx<j_index_end; jidx++)
366         {
367             /* Get j neighbor index, and coordinate index */
368             jnr              = jjnr[jidx];
369             j_coord_offset   = DIM*jnr;
370
371             /* load j atom coordinates */
372             jx0              = x[j_coord_offset+DIM*0+XX];
373             jy0              = x[j_coord_offset+DIM*0+YY];
374             jz0              = x[j_coord_offset+DIM*0+ZZ];
375
376             /* Calculate displacement vector */
377             dx00             = ix0 - jx0;
378             dy00             = iy0 - jy0;
379             dz00             = iz0 - jz0;
380
381             /* Calculate squared distance and things based on it */
382             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
383
384             rinv00           = gmx_invsqrt(rsq00);
385
386             rinvsq00         = rinv00*rinv00;
387
388             /* Load parameters for j particles */
389             jq0              = charge[jnr+0];
390             vdwjidx0         = 2*vdwtype[jnr+0];
391
392             /**************************
393              * CALCULATE INTERACTIONS *
394              **************************/
395
396             r00              = rsq00*rinv00;
397
398             qq00             = iq0*jq0;
399             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
400             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
401
402             /* Calculate table index by multiplying r with table scale and truncate to integer */
403             rt               = r00*vftabscale;
404             vfitab           = rt;
405             vfeps            = rt-vfitab;
406             vfitab           = 2*4*vfitab;
407
408             /* REACTION-FIELD ELECTROSTATICS */
409             felec            = qq00*(rinv00*rinvsq00-krf2);
410
411             /* CUBIC SPLINE TABLE DISPERSION */
412             vfitab          += 0;
413             F                = vftab[vfitab+1];
414             Geps             = vfeps*vftab[vfitab+2];
415             Heps2            = vfeps*vfeps*vftab[vfitab+3];
416             Fp               = F+Geps+Heps2;
417             FF               = Fp+Geps+2.0*Heps2;
418             fvdw6            = c6_00*FF;
419
420             /* CUBIC SPLINE TABLE REPULSION */
421             F                = vftab[vfitab+5];
422             Geps             = vfeps*vftab[vfitab+6];
423             Heps2            = vfeps*vfeps*vftab[vfitab+7];
424             Fp               = F+Geps+Heps2;
425             FF               = Fp+Geps+2.0*Heps2;
426             fvdw12           = c12_00*FF;
427             fvdw             = -(fvdw6+fvdw12)*vftabscale*rinv00;
428
429             fscal            = felec+fvdw;
430
431             /* Calculate temporary vectorial force */
432             tx               = fscal*dx00;
433             ty               = fscal*dy00;
434             tz               = fscal*dz00;
435
436             /* Update vectorial force */
437             fix0            += tx;
438             fiy0            += ty;
439             fiz0            += tz;
440             f[j_coord_offset+DIM*0+XX] -= tx;
441             f[j_coord_offset+DIM*0+YY] -= ty;
442             f[j_coord_offset+DIM*0+ZZ] -= tz;
443
444             /* Inner loop uses 53 flops */
445         }
446         /* End of innermost loop */
447
448         tx = ty = tz = 0;
449         f[i_coord_offset+DIM*0+XX] += fix0;
450         f[i_coord_offset+DIM*0+YY] += fiy0;
451         f[i_coord_offset+DIM*0+ZZ] += fiz0;
452         tx                         += fix0;
453         ty                         += fiy0;
454         tz                         += fiz0;
455         fshift[i_shift_offset+XX]  += tx;
456         fshift[i_shift_offset+YY]  += ty;
457         fshift[i_shift_offset+ZZ]  += tz;
458
459         /* Increment number of inner iterations */
460         inneriter                  += j_index_end - j_index_start;
461
462         /* Outer loop uses 13 flops */
463     }
464
465     /* Increment number of outer iterations */
466     outeriter        += nri;
467
468     /* Update outer/inner flops */
469
470     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*13 + inneriter*53);
471 }