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