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