2 * This file is part of the GROMACS molecular simulation package.
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.
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.
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.
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.
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.
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.
36 * Note: this file was generated by the GROMACS c kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
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
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)
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;
73 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
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;
80 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
83 real rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
90 jindex = nlist->jindex;
92 shiftidx = nlist->shift;
94 shiftvec = fr->shift_vec[0];
95 fshift = fr->fshift[0];
97 charge = mdatoms->chargeA;
101 nvdwtype = fr->ntype;
103 vdwtype = mdatoms->typeA;
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;
109 rswitch = fr->rvdw_switch;
110 /* Setup switch parameters */
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);
122 /* Start outer loop over neighborlists */
123 for(iidx=0; iidx<nri; iidx++)
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];
131 /* Load limits for loop over neighbors */
132 j_index_start = jindex[iidx];
133 j_index_end = jindex[iidx+1];
135 /* Get outer coordinate index */
137 i_coord_offset = DIM*inr;
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];
148 /* Load parameters for i particles */
149 iq0 = facel*charge[inr+0];
150 vdwioffset0 = 3*nvdwtype*vdwtype[inr+0];
152 /* Reset potential sums */
156 /* Start inner kernel loop */
157 for(jidx=j_index_start; jidx<j_index_end; jidx++)
159 /* Get j neighbor index, and coordinate index */
161 j_coord_offset = DIM*jnr;
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];
168 /* Calculate displacement vector */
173 /* Calculate squared distance and things based on it */
174 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
176 rinv00 = gmx_invsqrt(rsq00);
178 rinvsq00 = rinv00*rinv00;
180 /* Load parameters for j particles */
182 vdwjidx0 = 3*vdwtype[jnr+0];
184 /**************************
185 * CALCULATE INTERACTIONS *
186 **************************/
194 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
195 cexp1_00 = vdwparam[vdwioffset0+vdwjidx0+1];
196 cexp2_00 = vdwparam[vdwioffset0+vdwjidx0+2];
198 /* REACTION-FIELD ELECTROSTATICS */
199 velec = qq00*(rinv00+krf*rsq00-crf);
200 felec = qq00*(rinv00*rinvsq00-krf2);
202 /* BUCKINGHAM DISPERSION/REPULSION */
203 rinvsix = rinvsq00*rinvsq00*rinvsq00;
204 vvdw6 = c6_00*rinvsix;
206 vvdwexp = cexp1_00*exp(-br);
207 vvdw = vvdwexp - vvdw6*(1.0/6.0);
208 fvdw = (br*vvdwexp-vvdw6)*rinvsq00;
211 d = (d>0.0) ? d : 0.0;
213 sw = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
215 dsw = d2*(swF2+d*(swF3+d*swF4));
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;
222 /* Update potential sums from outer loop */
228 /* Calculate temporary vectorial force */
233 /* Update vectorial force */
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;
243 /* Inner loop uses 89 flops */
245 /* End of innermost loop */
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;
254 fshift[i_shift_offset+XX] += tx;
255 fshift[i_shift_offset+YY] += ty;
256 fshift[i_shift_offset+ZZ] += tz;
259 /* Update potential energies */
260 kernel_data->energygrp_elec[ggid] += velecsum;
261 kernel_data->energygrp_vdw[ggid] += vvdwsum;
263 /* Increment number of inner iterations */
264 inneriter += j_index_end - j_index_start;
266 /* Outer loop uses 15 flops */
269 /* Increment number of outer iterations */
272 /* Update outer/inner flops */
274 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*15 + inneriter*89);
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
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)
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;
300 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
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;
307 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
310 real rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
317 jindex = nlist->jindex;
319 shiftidx = nlist->shift;
321 shiftvec = fr->shift_vec[0];
322 fshift = fr->fshift[0];
324 charge = mdatoms->chargeA;
328 nvdwtype = fr->ntype;
330 vdwtype = mdatoms->typeA;
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;
336 rswitch = fr->rvdw_switch;
337 /* Setup switch parameters */
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);
349 /* Start outer loop over neighborlists */
350 for(iidx=0; iidx<nri; iidx++)
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];
358 /* Load limits for loop over neighbors */
359 j_index_start = jindex[iidx];
360 j_index_end = jindex[iidx+1];
362 /* Get outer coordinate index */
364 i_coord_offset = DIM*inr;
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];
375 /* Load parameters for i particles */
376 iq0 = facel*charge[inr+0];
377 vdwioffset0 = 3*nvdwtype*vdwtype[inr+0];
379 /* Start inner kernel loop */
380 for(jidx=j_index_start; jidx<j_index_end; jidx++)
382 /* Get j neighbor index, and coordinate index */
384 j_coord_offset = DIM*jnr;
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];
391 /* Calculate displacement vector */
396 /* Calculate squared distance and things based on it */
397 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
399 rinv00 = gmx_invsqrt(rsq00);
401 rinvsq00 = rinv00*rinv00;
403 /* Load parameters for j particles */
405 vdwjidx0 = 3*vdwtype[jnr+0];
407 /**************************
408 * CALCULATE INTERACTIONS *
409 **************************/
417 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
418 cexp1_00 = vdwparam[vdwioffset0+vdwjidx0+1];
419 cexp2_00 = vdwparam[vdwioffset0+vdwjidx0+2];
421 /* REACTION-FIELD ELECTROSTATICS */
422 felec = qq00*(rinv00*rinvsq00-krf2);
424 /* BUCKINGHAM DISPERSION/REPULSION */
425 rinvsix = rinvsq00*rinvsq00*rinvsq00;
426 vvdw6 = c6_00*rinvsix;
428 vvdwexp = cexp1_00*exp(-br);
429 vvdw = vvdwexp - vvdw6*(1.0/6.0);
430 fvdw = (br*vvdwexp-vvdw6)*rinvsq00;
433 d = (d>0.0) ? d : 0.0;
435 sw = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
437 dsw = d2*(swF2+d*(swF3+d*swF4));
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;
445 /* Calculate temporary vectorial force */
450 /* Update vectorial force */
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;
460 /* Inner loop uses 82 flops */
462 /* End of innermost loop */
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;
471 fshift[i_shift_offset+XX] += tx;
472 fshift[i_shift_offset+YY] += ty;
473 fshift[i_shift_offset+ZZ] += tz;
475 /* Increment number of inner iterations */
476 inneriter += j_index_end - j_index_start;
478 /* Outer loop uses 13 flops */
481 /* Increment number of outer iterations */
484 /* Update outer/inner flops */
486 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*13 + inneriter*82);