2 * Note: this file was generated by the Gromacs c kernel generator.
4 * This source code is part of
8 * Copyright (c) 2001-2012, The GROMACS Development Team
10 * Gromacs is a library for molecular simulation and trajectory analysis,
11 * written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
12 * a full list of developers and information, check out http://www.gromacs.org
14 * This program is free software; you can redistribute it and/or modify it under
15 * the terms of the GNU Lesser General Public License as published by the Free
16 * Software Foundation; either version 2 of the License, or (at your option) any
19 * To help fund GROMACS development, we humbly ask that you cite
20 * the papers people have written on it - you can find them on the website.
28 #include "../nb_kernel.h"
29 #include "types/simple.h"
34 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomP1P1_VF_c
35 * Electrostatics interaction: ReactionField
36 * VdW interaction: LennardJones
37 * Geometry: Particle-Particle
38 * Calculate force/pot: PotentialAndForce
41 nb_kernel_ElecRFCut_VdwLJSw_GeomP1P1_VF_c
42 (t_nblist * gmx_restrict nlist,
43 rvec * gmx_restrict xx,
44 rvec * gmx_restrict ff,
45 t_forcerec * gmx_restrict fr,
46 t_mdatoms * gmx_restrict mdatoms,
47 nb_kernel_data_t * gmx_restrict kernel_data,
48 t_nrnb * gmx_restrict nrnb)
50 int i_shift_offset,i_coord_offset,j_coord_offset;
51 int j_index_start,j_index_end;
52 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
53 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
54 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
55 real *shiftvec,*fshift,*x,*f;
57 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
59 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
60 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
61 real velec,felec,velecsum,facel,crf,krf,krf2;
64 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
67 real rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
74 jindex = nlist->jindex;
76 shiftidx = nlist->shift;
78 shiftvec = fr->shift_vec[0];
79 fshift = fr->fshift[0];
81 charge = mdatoms->chargeA;
87 vdwtype = mdatoms->typeA;
89 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
90 rcutoff = fr->rcoulomb;
91 rcutoff2 = rcutoff*rcutoff;
93 rswitch = fr->rvdw_switch;
94 /* Setup switch parameters */
97 swV4 = 15.0/(d*d*d*d);
98 swV5 = -6.0/(d*d*d*d*d);
100 swF3 = 60.0/(d*d*d*d);
101 swF4 = -30.0/(d*d*d*d*d);
106 /* Start outer loop over neighborlists */
107 for(iidx=0; iidx<nri; iidx++)
109 /* Load shift vector for this list */
110 i_shift_offset = DIM*shiftidx[iidx];
111 shX = shiftvec[i_shift_offset+XX];
112 shY = shiftvec[i_shift_offset+YY];
113 shZ = shiftvec[i_shift_offset+ZZ];
115 /* Load limits for loop over neighbors */
116 j_index_start = jindex[iidx];
117 j_index_end = jindex[iidx+1];
119 /* Get outer coordinate index */
121 i_coord_offset = DIM*inr;
123 /* Load i particle coords and add shift vector */
124 ix0 = shX + x[i_coord_offset+DIM*0+XX];
125 iy0 = shY + x[i_coord_offset+DIM*0+YY];
126 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
132 /* Load parameters for i particles */
133 iq0 = facel*charge[inr+0];
134 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
136 /* Reset potential sums */
140 /* Start inner kernel loop */
141 for(jidx=j_index_start; jidx<j_index_end; jidx++)
143 /* Get j neighbor index, and coordinate index */
145 j_coord_offset = DIM*jnr;
147 /* load j atom coordinates */
148 jx0 = x[j_coord_offset+DIM*0+XX];
149 jy0 = x[j_coord_offset+DIM*0+YY];
150 jz0 = x[j_coord_offset+DIM*0+ZZ];
152 /* Calculate displacement vector */
157 /* Calculate squared distance and things based on it */
158 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
160 rinv00 = gmx_invsqrt(rsq00);
162 rinvsq00 = rinv00*rinv00;
164 /* Load parameters for j particles */
166 vdwjidx0 = 2*vdwtype[jnr+0];
168 /**************************
169 * CALCULATE INTERACTIONS *
170 **************************/
178 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
179 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
181 /* REACTION-FIELD ELECTROSTATICS */
182 velec = qq00*(rinv00+krf*rsq00-crf);
183 felec = qq00*(rinv00*rinvsq00-krf2);
185 /* LENNARD-JONES DISPERSION/REPULSION */
187 rinvsix = rinvsq00*rinvsq00*rinvsq00;
188 vvdw6 = c6_00*rinvsix;
189 vvdw12 = c12_00*rinvsix*rinvsix;
190 vvdw = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
191 fvdw = (vvdw12-vvdw6)*rinvsq00;
194 d = (d>0.0) ? d : 0.0;
196 sw = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
198 dsw = d2*(swF2+d*(swF3+d*swF4));
200 /* Evaluate switch function */
201 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
202 fvdw = fvdw*sw - rinv00*vvdw*dsw;
205 /* Update potential sums from outer loop */
211 /* Calculate temporary vectorial force */
216 /* Update vectorial force */
220 f[j_coord_offset+DIM*0+XX] -= tx;
221 f[j_coord_offset+DIM*0+YY] -= ty;
222 f[j_coord_offset+DIM*0+ZZ] -= tz;
226 /* Inner loop uses 63 flops */
228 /* End of innermost loop */
231 f[i_coord_offset+DIM*0+XX] += fix0;
232 f[i_coord_offset+DIM*0+YY] += fiy0;
233 f[i_coord_offset+DIM*0+ZZ] += fiz0;
237 fshift[i_shift_offset+XX] += tx;
238 fshift[i_shift_offset+YY] += ty;
239 fshift[i_shift_offset+ZZ] += tz;
242 /* Update potential energies */
243 kernel_data->energygrp_elec[ggid] += velecsum;
244 kernel_data->energygrp_vdw[ggid] += vvdwsum;
246 /* Increment number of inner iterations */
247 inneriter += j_index_end - j_index_start;
249 /* Outer loop uses 15 flops */
252 /* Increment number of outer iterations */
255 /* Update outer/inner flops */
257 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*15 + inneriter*63);
260 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomP1P1_F_c
261 * Electrostatics interaction: ReactionField
262 * VdW interaction: LennardJones
263 * Geometry: Particle-Particle
264 * Calculate force/pot: Force
267 nb_kernel_ElecRFCut_VdwLJSw_GeomP1P1_F_c
268 (t_nblist * gmx_restrict nlist,
269 rvec * gmx_restrict xx,
270 rvec * gmx_restrict ff,
271 t_forcerec * gmx_restrict fr,
272 t_mdatoms * gmx_restrict mdatoms,
273 nb_kernel_data_t * gmx_restrict kernel_data,
274 t_nrnb * gmx_restrict nrnb)
276 int i_shift_offset,i_coord_offset,j_coord_offset;
277 int j_index_start,j_index_end;
278 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
279 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
280 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
281 real *shiftvec,*fshift,*x,*f;
283 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
285 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
286 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
287 real velec,felec,velecsum,facel,crf,krf,krf2;
290 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
293 real rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
300 jindex = nlist->jindex;
302 shiftidx = nlist->shift;
304 shiftvec = fr->shift_vec[0];
305 fshift = fr->fshift[0];
307 charge = mdatoms->chargeA;
311 nvdwtype = fr->ntype;
313 vdwtype = mdatoms->typeA;
315 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
316 rcutoff = fr->rcoulomb;
317 rcutoff2 = rcutoff*rcutoff;
319 rswitch = fr->rvdw_switch;
320 /* Setup switch parameters */
322 swV3 = -10.0/(d*d*d);
323 swV4 = 15.0/(d*d*d*d);
324 swV5 = -6.0/(d*d*d*d*d);
325 swF2 = -30.0/(d*d*d);
326 swF3 = 60.0/(d*d*d*d);
327 swF4 = -30.0/(d*d*d*d*d);
332 /* Start outer loop over neighborlists */
333 for(iidx=0; iidx<nri; iidx++)
335 /* Load shift vector for this list */
336 i_shift_offset = DIM*shiftidx[iidx];
337 shX = shiftvec[i_shift_offset+XX];
338 shY = shiftvec[i_shift_offset+YY];
339 shZ = shiftvec[i_shift_offset+ZZ];
341 /* Load limits for loop over neighbors */
342 j_index_start = jindex[iidx];
343 j_index_end = jindex[iidx+1];
345 /* Get outer coordinate index */
347 i_coord_offset = DIM*inr;
349 /* Load i particle coords and add shift vector */
350 ix0 = shX + x[i_coord_offset+DIM*0+XX];
351 iy0 = shY + x[i_coord_offset+DIM*0+YY];
352 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
358 /* Load parameters for i particles */
359 iq0 = facel*charge[inr+0];
360 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
362 /* Start inner kernel loop */
363 for(jidx=j_index_start; jidx<j_index_end; jidx++)
365 /* Get j neighbor index, and coordinate index */
367 j_coord_offset = DIM*jnr;
369 /* load j atom coordinates */
370 jx0 = x[j_coord_offset+DIM*0+XX];
371 jy0 = x[j_coord_offset+DIM*0+YY];
372 jz0 = x[j_coord_offset+DIM*0+ZZ];
374 /* Calculate displacement vector */
379 /* Calculate squared distance and things based on it */
380 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
382 rinv00 = gmx_invsqrt(rsq00);
384 rinvsq00 = rinv00*rinv00;
386 /* Load parameters for j particles */
388 vdwjidx0 = 2*vdwtype[jnr+0];
390 /**************************
391 * CALCULATE INTERACTIONS *
392 **************************/
400 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
401 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
403 /* REACTION-FIELD ELECTROSTATICS */
404 felec = qq00*(rinv00*rinvsq00-krf2);
406 /* LENNARD-JONES DISPERSION/REPULSION */
408 rinvsix = rinvsq00*rinvsq00*rinvsq00;
409 vvdw6 = c6_00*rinvsix;
410 vvdw12 = c12_00*rinvsix*rinvsix;
411 vvdw = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
412 fvdw = (vvdw12-vvdw6)*rinvsq00;
415 d = (d>0.0) ? d : 0.0;
417 sw = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
419 dsw = d2*(swF2+d*(swF3+d*swF4));
421 /* Evaluate switch function */
422 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
423 fvdw = fvdw*sw - rinv00*vvdw*dsw;
427 /* Calculate temporary vectorial force */
432 /* Update vectorial force */
436 f[j_coord_offset+DIM*0+XX] -= tx;
437 f[j_coord_offset+DIM*0+YY] -= ty;
438 f[j_coord_offset+DIM*0+ZZ] -= tz;
442 /* Inner loop uses 56 flops */
444 /* End of innermost loop */
447 f[i_coord_offset+DIM*0+XX] += fix0;
448 f[i_coord_offset+DIM*0+YY] += fiy0;
449 f[i_coord_offset+DIM*0+ZZ] += fiz0;
453 fshift[i_shift_offset+XX] += tx;
454 fshift[i_shift_offset+YY] += ty;
455 fshift[i_shift_offset+ZZ] += tz;
457 /* Increment number of inner iterations */
458 inneriter += j_index_end - j_index_start;
460 /* Outer loop uses 13 flops */
463 /* Increment number of outer iterations */
466 /* Update outer/inner flops */
468 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*13 + inneriter*56);