Remove all unnecessary HAVE_CONFIG_H
[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,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_ElecEw_VdwCSTab_GeomP1P1_VF_c
49  * Electrostatics interaction: Ewald
50  * VdW interaction:            CubicSplineTable
51  * Geometry:                   Particle-Particle
52  * Calculate force/pot:        PotentialAndForce
53  */
54 void
55 nb_kernel_ElecEw_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     int              ewitab;
85     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
86     real             *ewtab;
87
88     x                = xx[0];
89     f                = ff[0];
90
91     nri              = nlist->nri;
92     iinr             = nlist->iinr;
93     jindex           = nlist->jindex;
94     jjnr             = nlist->jjnr;
95     shiftidx         = nlist->shift;
96     gid              = nlist->gid;
97     shiftvec         = fr->shift_vec[0];
98     fshift           = fr->fshift[0];
99     facel            = fr->epsfac;
100     charge           = mdatoms->chargeA;
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     sh_ewald         = fr->ic->sh_ewald;
109     ewtab            = fr->ic->tabq_coul_FDV0;
110     ewtabscale       = fr->ic->tabq_scale;
111     ewtabhalfspace   = 0.5/ewtabscale;
112
113     outeriter        = 0;
114     inneriter        = 0;
115
116     /* Start outer loop over neighborlists */
117     for(iidx=0; iidx<nri; iidx++)
118     {
119         /* Load shift vector for this list */
120         i_shift_offset   = DIM*shiftidx[iidx];
121         shX              = shiftvec[i_shift_offset+XX];
122         shY              = shiftvec[i_shift_offset+YY];
123         shZ              = shiftvec[i_shift_offset+ZZ];
124
125         /* Load limits for loop over neighbors */
126         j_index_start    = jindex[iidx];
127         j_index_end      = jindex[iidx+1];
128
129         /* Get outer coordinate index */
130         inr              = iinr[iidx];
131         i_coord_offset   = DIM*inr;
132
133         /* Load i particle coords and add shift vector */
134         ix0              = shX + x[i_coord_offset+DIM*0+XX];
135         iy0              = shY + x[i_coord_offset+DIM*0+YY];
136         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
137
138         fix0             = 0.0;
139         fiy0             = 0.0;
140         fiz0             = 0.0;
141
142         /* Load parameters for i particles */
143         iq0              = facel*charge[inr+0];
144         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
145
146         /* Reset potential sums */
147         velecsum         = 0.0;
148         vvdwsum          = 0.0;
149
150         /* Start inner kernel loop */
151         for(jidx=j_index_start; jidx<j_index_end; jidx++)
152         {
153             /* Get j neighbor index, and coordinate index */
154             jnr              = jjnr[jidx];
155             j_coord_offset   = DIM*jnr;
156
157             /* load j atom coordinates */
158             jx0              = x[j_coord_offset+DIM*0+XX];
159             jy0              = x[j_coord_offset+DIM*0+YY];
160             jz0              = x[j_coord_offset+DIM*0+ZZ];
161
162             /* Calculate displacement vector */
163             dx00             = ix0 - jx0;
164             dy00             = iy0 - jy0;
165             dz00             = iz0 - jz0;
166
167             /* Calculate squared distance and things based on it */
168             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
169
170             rinv00           = gmx_invsqrt(rsq00);
171
172             rinvsq00         = rinv00*rinv00;
173
174             /* Load parameters for j particles */
175             jq0              = charge[jnr+0];
176             vdwjidx0         = 2*vdwtype[jnr+0];
177
178             /**************************
179              * CALCULATE INTERACTIONS *
180              **************************/
181
182             r00              = rsq00*rinv00;
183
184             qq00             = iq0*jq0;
185             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
186             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
187
188             /* Calculate table index by multiplying r with table scale and truncate to integer */
189             rt               = r00*vftabscale;
190             vfitab           = rt;
191             vfeps            = rt-vfitab;
192             vfitab           = 2*4*vfitab;
193
194             /* EWALD ELECTROSTATICS */
195
196             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
197             ewrt             = r00*ewtabscale;
198             ewitab           = ewrt;
199             eweps            = ewrt-ewitab;
200             ewitab           = 4*ewitab;
201             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
202             velec            = qq00*(rinv00-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
203             felec            = qq00*rinv00*(rinvsq00-felec);
204
205             /* CUBIC SPLINE TABLE DISPERSION */
206             vfitab          += 0;
207             Y                = vftab[vfitab];
208             F                = vftab[vfitab+1];
209             Geps             = vfeps*vftab[vfitab+2];
210             Heps2            = vfeps*vfeps*vftab[vfitab+3];
211             Fp               = F+Geps+Heps2;
212             VV               = Y+vfeps*Fp;
213             vvdw6            = c6_00*VV;
214             FF               = Fp+Geps+2.0*Heps2;
215             fvdw6            = c6_00*FF;
216
217             /* CUBIC SPLINE TABLE REPULSION */
218             Y                = vftab[vfitab+4];
219             F                = vftab[vfitab+5];
220             Geps             = vfeps*vftab[vfitab+6];
221             Heps2            = vfeps*vfeps*vftab[vfitab+7];
222             Fp               = F+Geps+Heps2;
223             VV               = Y+vfeps*Fp;
224             vvdw12           = c12_00*VV;
225             FF               = Fp+Geps+2.0*Heps2;
226             fvdw12           = c12_00*FF;
227             vvdw             = vvdw12+vvdw6;
228             fvdw             = -(fvdw6+fvdw12)*vftabscale*rinv00;
229
230             /* Update potential sums from outer loop */
231             velecsum        += velec;
232             vvdwsum         += vvdw;
233
234             fscal            = felec+fvdw;
235
236             /* Calculate temporary vectorial force */
237             tx               = fscal*dx00;
238             ty               = fscal*dy00;
239             tz               = fscal*dz00;
240
241             /* Update vectorial force */
242             fix0            += tx;
243             fiy0            += ty;
244             fiz0            += tz;
245             f[j_coord_offset+DIM*0+XX] -= tx;
246             f[j_coord_offset+DIM*0+YY] -= ty;
247             f[j_coord_offset+DIM*0+ZZ] -= tz;
248
249             /* Inner loop uses 74 flops */
250         }
251         /* End of innermost loop */
252
253         tx = ty = tz = 0;
254         f[i_coord_offset+DIM*0+XX] += fix0;
255         f[i_coord_offset+DIM*0+YY] += fiy0;
256         f[i_coord_offset+DIM*0+ZZ] += fiz0;
257         tx                         += fix0;
258         ty                         += fiy0;
259         tz                         += fiz0;
260         fshift[i_shift_offset+XX]  += tx;
261         fshift[i_shift_offset+YY]  += ty;
262         fshift[i_shift_offset+ZZ]  += tz;
263
264         ggid                        = gid[iidx];
265         /* Update potential energies */
266         kernel_data->energygrp_elec[ggid] += velecsum;
267         kernel_data->energygrp_vdw[ggid] += vvdwsum;
268
269         /* Increment number of inner iterations */
270         inneriter                  += j_index_end - j_index_start;
271
272         /* Outer loop uses 15 flops */
273     }
274
275     /* Increment number of outer iterations */
276     outeriter        += nri;
277
278     /* Update outer/inner flops */
279
280     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*15 + inneriter*74);
281 }
282 /*
283  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwCSTab_GeomP1P1_F_c
284  * Electrostatics interaction: Ewald
285  * VdW interaction:            CubicSplineTable
286  * Geometry:                   Particle-Particle
287  * Calculate force/pot:        Force
288  */
289 void
290 nb_kernel_ElecEw_VdwCSTab_GeomP1P1_F_c
291                     (t_nblist                    * gmx_restrict       nlist,
292                      rvec                        * gmx_restrict          xx,
293                      rvec                        * gmx_restrict          ff,
294                      t_forcerec                  * gmx_restrict          fr,
295                      t_mdatoms                   * gmx_restrict     mdatoms,
296                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
297                      t_nrnb                      * gmx_restrict        nrnb)
298 {
299     int              i_shift_offset,i_coord_offset,j_coord_offset;
300     int              j_index_start,j_index_end;
301     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
302     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
303     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
304     real             *shiftvec,*fshift,*x,*f;
305     int              vdwioffset0;
306     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
307     int              vdwjidx0;
308     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
309     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
310     real             velec,felec,velecsum,facel,crf,krf,krf2;
311     real             *charge;
312     int              nvdwtype;
313     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
314     int              *vdwtype;
315     real             *vdwparam;
316     int              vfitab;
317     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
318     real             *vftab;
319     int              ewitab;
320     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
321     real             *ewtab;
322
323     x                = xx[0];
324     f                = ff[0];
325
326     nri              = nlist->nri;
327     iinr             = nlist->iinr;
328     jindex           = nlist->jindex;
329     jjnr             = nlist->jjnr;
330     shiftidx         = nlist->shift;
331     gid              = nlist->gid;
332     shiftvec         = fr->shift_vec[0];
333     fshift           = fr->fshift[0];
334     facel            = fr->epsfac;
335     charge           = mdatoms->chargeA;
336     nvdwtype         = fr->ntype;
337     vdwparam         = fr->nbfp;
338     vdwtype          = mdatoms->typeA;
339
340     vftab            = kernel_data->table_vdw->data;
341     vftabscale       = kernel_data->table_vdw->scale;
342
343     sh_ewald         = fr->ic->sh_ewald;
344     ewtab            = fr->ic->tabq_coul_F;
345     ewtabscale       = fr->ic->tabq_scale;
346     ewtabhalfspace   = 0.5/ewtabscale;
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             r00              = rsq00*rinv00;
414
415             qq00             = iq0*jq0;
416             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
417             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
418
419             /* Calculate table index by multiplying r with table scale and truncate to integer */
420             rt               = r00*vftabscale;
421             vfitab           = rt;
422             vfeps            = rt-vfitab;
423             vfitab           = 2*4*vfitab;
424
425             /* EWALD ELECTROSTATICS */
426
427             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
428             ewrt             = r00*ewtabscale;
429             ewitab           = ewrt;
430             eweps            = ewrt-ewitab;
431             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
432             felec            = qq00*rinv00*(rinvsq00-felec);
433
434             /* CUBIC SPLINE TABLE DISPERSION */
435             vfitab          += 0;
436             F                = vftab[vfitab+1];
437             Geps             = vfeps*vftab[vfitab+2];
438             Heps2            = vfeps*vfeps*vftab[vfitab+3];
439             Fp               = F+Geps+Heps2;
440             FF               = Fp+Geps+2.0*Heps2;
441             fvdw6            = c6_00*FF;
442
443             /* CUBIC SPLINE TABLE REPULSION */
444             F                = vftab[vfitab+5];
445             Geps             = vfeps*vftab[vfitab+6];
446             Heps2            = vfeps*vfeps*vftab[vfitab+7];
447             Fp               = F+Geps+Heps2;
448             FF               = Fp+Geps+2.0*Heps2;
449             fvdw12           = c12_00*FF;
450             fvdw             = -(fvdw6+fvdw12)*vftabscale*rinv00;
451
452             fscal            = felec+fvdw;
453
454             /* Calculate temporary vectorial force */
455             tx               = fscal*dx00;
456             ty               = fscal*dy00;
457             tz               = fscal*dz00;
458
459             /* Update vectorial force */
460             fix0            += tx;
461             fiy0            += ty;
462             fiz0            += tz;
463             f[j_coord_offset+DIM*0+XX] -= tx;
464             f[j_coord_offset+DIM*0+YY] -= ty;
465             f[j_coord_offset+DIM*0+ZZ] -= tz;
466
467             /* Inner loop uses 59 flops */
468         }
469         /* End of innermost loop */
470
471         tx = ty = tz = 0;
472         f[i_coord_offset+DIM*0+XX] += fix0;
473         f[i_coord_offset+DIM*0+YY] += fiy0;
474         f[i_coord_offset+DIM*0+ZZ] += fiz0;
475         tx                         += fix0;
476         ty                         += fiy0;
477         tz                         += fiz0;
478         fshift[i_shift_offset+XX]  += tx;
479         fshift[i_shift_offset+YY]  += ty;
480         fshift[i_shift_offset+ZZ]  += tz;
481
482         /* Increment number of inner iterations */
483         inneriter                  += j_index_end - j_index_start;
484
485         /* Outer loop uses 13 flops */
486     }
487
488     /* Increment number of outer iterations */
489     outeriter        += nri;
490
491     /* Update outer/inner flops */
492
493     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*13 + inneriter*59);
494 }