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_ElecEwSw_VdwBhamSw_GeomP1P1_VF_c
51 * Electrostatics interaction: Ewald
52 * VdW interaction: Buckingham
53 * Geometry: Particle-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecEwSw_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;
84 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
86 real rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
93 jindex = nlist->jindex;
95 shiftidx = nlist->shift;
97 shiftvec = fr->shift_vec[0];
98 fshift = fr->fshift[0];
100 charge = mdatoms->chargeA;
101 nvdwtype = fr->ntype;
103 vdwtype = mdatoms->typeA;
105 sh_ewald = fr->ic->sh_ewald;
106 ewtab = fr->ic->tabq_coul_FDV0;
107 ewtabscale = fr->ic->tabq_scale;
108 ewtabhalfspace = 0.5/ewtabscale;
110 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
111 rcutoff = fr->rcoulomb;
112 rcutoff2 = rcutoff*rcutoff;
114 rswitch = fr->rcoulomb_switch;
115 /* Setup switch parameters */
117 swV3 = -10.0/(d*d*d);
118 swV4 = 15.0/(d*d*d*d);
119 swV5 = -6.0/(d*d*d*d*d);
120 swF2 = -30.0/(d*d*d);
121 swF3 = 60.0/(d*d*d*d);
122 swF4 = -30.0/(d*d*d*d*d);
127 /* Start outer loop over neighborlists */
128 for(iidx=0; iidx<nri; iidx++)
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];
136 /* Load limits for loop over neighbors */
137 j_index_start = jindex[iidx];
138 j_index_end = jindex[iidx+1];
140 /* Get outer coordinate index */
142 i_coord_offset = DIM*inr;
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];
153 /* Load parameters for i particles */
154 iq0 = facel*charge[inr+0];
155 vdwioffset0 = 3*nvdwtype*vdwtype[inr+0];
157 /* Reset potential sums */
161 /* Start inner kernel loop */
162 for(jidx=j_index_start; jidx<j_index_end; jidx++)
164 /* Get j neighbor index, and coordinate index */
166 j_coord_offset = DIM*jnr;
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];
173 /* Calculate displacement vector */
178 /* Calculate squared distance and things based on it */
179 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
181 rinv00 = gmx_invsqrt(rsq00);
183 rinvsq00 = rinv00*rinv00;
185 /* Load parameters for j particles */
187 vdwjidx0 = 3*vdwtype[jnr+0];
189 /**************************
190 * CALCULATE INTERACTIONS *
191 **************************/
199 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
200 cexp1_00 = vdwparam[vdwioffset0+vdwjidx0+1];
201 cexp2_00 = vdwparam[vdwioffset0+vdwjidx0+2];
203 /* EWALD ELECTROSTATICS */
205 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
206 ewrt = r00*ewtabscale;
210 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
211 velec = qq00*(rinv00-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
212 felec = qq00*rinv00*(rinvsq00-felec);
214 /* BUCKINGHAM DISPERSION/REPULSION */
215 rinvsix = rinvsq00*rinvsq00*rinvsq00;
216 vvdw6 = c6_00*rinvsix;
218 vvdwexp = cexp1_00*exp(-br);
219 vvdw = vvdwexp - vvdw6*(1.0/6.0);
220 fvdw = (br*vvdwexp-vvdw6)*rinvsq00;
223 d = (d>0.0) ? d : 0.0;
225 sw = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
227 dsw = d2*(swF2+d*(swF3+d*swF4));
229 /* Evaluate switch function */
230 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
231 felec = felec*sw - rinv00*velec*dsw;
232 fvdw = fvdw*sw - rinv00*vvdw*dsw;
236 /* Update potential sums from outer loop */
242 /* Calculate temporary vectorial force */
247 /* Update vectorial force */
251 f[j_coord_offset+DIM*0+XX] -= tx;
252 f[j_coord_offset+DIM*0+YY] -= ty;
253 f[j_coord_offset+DIM*0+ZZ] -= tz;
257 /* Inner loop uses 101 flops */
259 /* End of innermost loop */
262 f[i_coord_offset+DIM*0+XX] += fix0;
263 f[i_coord_offset+DIM*0+YY] += fiy0;
264 f[i_coord_offset+DIM*0+ZZ] += fiz0;
268 fshift[i_shift_offset+XX] += tx;
269 fshift[i_shift_offset+YY] += ty;
270 fshift[i_shift_offset+ZZ] += tz;
273 /* Update potential energies */
274 kernel_data->energygrp_elec[ggid] += velecsum;
275 kernel_data->energygrp_vdw[ggid] += vvdwsum;
277 /* Increment number of inner iterations */
278 inneriter += j_index_end - j_index_start;
280 /* Outer loop uses 15 flops */
283 /* Increment number of outer iterations */
286 /* Update outer/inner flops */
288 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*15 + inneriter*101);
291 * Gromacs nonbonded kernel: nb_kernel_ElecEwSw_VdwBhamSw_GeomP1P1_F_c
292 * Electrostatics interaction: Ewald
293 * VdW interaction: Buckingham
294 * Geometry: Particle-Particle
295 * Calculate force/pot: Force
298 nb_kernel_ElecEwSw_VdwBhamSw_GeomP1P1_F_c
299 (t_nblist * gmx_restrict nlist,
300 rvec * gmx_restrict xx,
301 rvec * gmx_restrict ff,
302 t_forcerec * gmx_restrict fr,
303 t_mdatoms * gmx_restrict mdatoms,
304 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
305 t_nrnb * gmx_restrict nrnb)
307 int i_shift_offset,i_coord_offset,j_coord_offset;
308 int j_index_start,j_index_end;
309 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
310 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
311 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
312 real *shiftvec,*fshift,*x,*f;
314 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
316 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
317 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
318 real velec,felec,velecsum,facel,crf,krf,krf2;
321 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
325 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
327 real rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
334 jindex = nlist->jindex;
336 shiftidx = nlist->shift;
338 shiftvec = fr->shift_vec[0];
339 fshift = fr->fshift[0];
341 charge = mdatoms->chargeA;
342 nvdwtype = fr->ntype;
344 vdwtype = mdatoms->typeA;
346 sh_ewald = fr->ic->sh_ewald;
347 ewtab = fr->ic->tabq_coul_FDV0;
348 ewtabscale = fr->ic->tabq_scale;
349 ewtabhalfspace = 0.5/ewtabscale;
351 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
352 rcutoff = fr->rcoulomb;
353 rcutoff2 = rcutoff*rcutoff;
355 rswitch = fr->rcoulomb_switch;
356 /* Setup switch parameters */
358 swV3 = -10.0/(d*d*d);
359 swV4 = 15.0/(d*d*d*d);
360 swV5 = -6.0/(d*d*d*d*d);
361 swF2 = -30.0/(d*d*d);
362 swF3 = 60.0/(d*d*d*d);
363 swF4 = -30.0/(d*d*d*d*d);
368 /* Start outer loop over neighborlists */
369 for(iidx=0; iidx<nri; iidx++)
371 /* Load shift vector for this list */
372 i_shift_offset = DIM*shiftidx[iidx];
373 shX = shiftvec[i_shift_offset+XX];
374 shY = shiftvec[i_shift_offset+YY];
375 shZ = shiftvec[i_shift_offset+ZZ];
377 /* Load limits for loop over neighbors */
378 j_index_start = jindex[iidx];
379 j_index_end = jindex[iidx+1];
381 /* Get outer coordinate index */
383 i_coord_offset = DIM*inr;
385 /* Load i particle coords and add shift vector */
386 ix0 = shX + x[i_coord_offset+DIM*0+XX];
387 iy0 = shY + x[i_coord_offset+DIM*0+YY];
388 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
394 /* Load parameters for i particles */
395 iq0 = facel*charge[inr+0];
396 vdwioffset0 = 3*nvdwtype*vdwtype[inr+0];
398 /* Start inner kernel loop */
399 for(jidx=j_index_start; jidx<j_index_end; jidx++)
401 /* Get j neighbor index, and coordinate index */
403 j_coord_offset = DIM*jnr;
405 /* load j atom coordinates */
406 jx0 = x[j_coord_offset+DIM*0+XX];
407 jy0 = x[j_coord_offset+DIM*0+YY];
408 jz0 = x[j_coord_offset+DIM*0+ZZ];
410 /* Calculate displacement vector */
415 /* Calculate squared distance and things based on it */
416 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
418 rinv00 = gmx_invsqrt(rsq00);
420 rinvsq00 = rinv00*rinv00;
422 /* Load parameters for j particles */
424 vdwjidx0 = 3*vdwtype[jnr+0];
426 /**************************
427 * CALCULATE INTERACTIONS *
428 **************************/
436 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
437 cexp1_00 = vdwparam[vdwioffset0+vdwjidx0+1];
438 cexp2_00 = vdwparam[vdwioffset0+vdwjidx0+2];
440 /* EWALD ELECTROSTATICS */
442 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
443 ewrt = r00*ewtabscale;
447 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
448 velec = qq00*(rinv00-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
449 felec = qq00*rinv00*(rinvsq00-felec);
451 /* BUCKINGHAM DISPERSION/REPULSION */
452 rinvsix = rinvsq00*rinvsq00*rinvsq00;
453 vvdw6 = c6_00*rinvsix;
455 vvdwexp = cexp1_00*exp(-br);
456 vvdw = vvdwexp - vvdw6*(1.0/6.0);
457 fvdw = (br*vvdwexp-vvdw6)*rinvsq00;
460 d = (d>0.0) ? d : 0.0;
462 sw = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
464 dsw = d2*(swF2+d*(swF3+d*swF4));
466 /* Evaluate switch function */
467 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
468 felec = felec*sw - rinv00*velec*dsw;
469 fvdw = fvdw*sw - rinv00*vvdw*dsw;
473 /* Calculate temporary vectorial force */
478 /* Update vectorial force */
482 f[j_coord_offset+DIM*0+XX] -= tx;
483 f[j_coord_offset+DIM*0+YY] -= ty;
484 f[j_coord_offset+DIM*0+ZZ] -= tz;
488 /* Inner loop uses 97 flops */
490 /* End of innermost loop */
493 f[i_coord_offset+DIM*0+XX] += fix0;
494 f[i_coord_offset+DIM*0+YY] += fiy0;
495 f[i_coord_offset+DIM*0+ZZ] += fiz0;
499 fshift[i_shift_offset+XX] += tx;
500 fshift[i_shift_offset+YY] += ty;
501 fshift[i_shift_offset+ZZ] += tz;
503 /* Increment number of inner iterations */
504 inneriter += j_index_end - j_index_start;
506 /* Outer loop uses 13 flops */
509 /* Increment number of outer iterations */
512 /* Update outer/inner flops */
514 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*13 + inneriter*97);