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