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