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_ElecEwSh_VdwLJSh_GeomP1P1_VF_c
35 * Electrostatics interaction: Ewald
36 * VdW interaction: LennardJones
37 * Geometry: Particle-Particle
38 * Calculate force/pot: PotentialAndForce
41 nb_kernel_ElecEwSh_VdwLJSh_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;
68 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
76 jindex = nlist->jindex;
78 shiftidx = nlist->shift;
80 shiftvec = fr->shift_vec[0];
81 fshift = fr->fshift[0];
83 charge = mdatoms->chargeA;
86 vdwtype = mdatoms->typeA;
88 sh_ewald = fr->ic->sh_ewald;
89 ewtab = fr->ic->tabq_coul_FDV0;
90 ewtabscale = fr->ic->tabq_scale;
91 ewtabhalfspace = 0.5/ewtabscale;
93 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
94 rcutoff = fr->rcoulomb;
95 rcutoff2 = rcutoff*rcutoff;
97 sh_vdw_invrcut6 = fr->ic->sh_invrc6;
103 /* Start outer loop over neighborlists */
104 for(iidx=0; iidx<nri; iidx++)
106 /* Load shift vector for this list */
107 i_shift_offset = DIM*shiftidx[iidx];
108 shX = shiftvec[i_shift_offset+XX];
109 shY = shiftvec[i_shift_offset+YY];
110 shZ = shiftvec[i_shift_offset+ZZ];
112 /* Load limits for loop over neighbors */
113 j_index_start = jindex[iidx];
114 j_index_end = jindex[iidx+1];
116 /* Get outer coordinate index */
118 i_coord_offset = DIM*inr;
120 /* Load i particle coords and add shift vector */
121 ix0 = shX + x[i_coord_offset+DIM*0+XX];
122 iy0 = shY + x[i_coord_offset+DIM*0+YY];
123 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
129 /* Load parameters for i particles */
130 iq0 = facel*charge[inr+0];
131 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
133 /* Reset potential sums */
137 /* Start inner kernel loop */
138 for(jidx=j_index_start; jidx<j_index_end; jidx++)
140 /* Get j neighbor index, and coordinate index */
142 j_coord_offset = DIM*jnr;
144 /* load j atom coordinates */
145 jx0 = x[j_coord_offset+DIM*0+XX];
146 jy0 = x[j_coord_offset+DIM*0+YY];
147 jz0 = x[j_coord_offset+DIM*0+ZZ];
149 /* Calculate displacement vector */
154 /* Calculate squared distance and things based on it */
155 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
157 rinv00 = gmx_invsqrt(rsq00);
159 rinvsq00 = rinv00*rinv00;
161 /* Load parameters for j particles */
163 vdwjidx0 = 2*vdwtype[jnr+0];
165 /**************************
166 * CALCULATE INTERACTIONS *
167 **************************/
175 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
176 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
178 /* EWALD ELECTROSTATICS */
180 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
181 ewrt = r00*ewtabscale;
185 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
186 velec = qq00*((rinv00-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
187 felec = qq00*rinv00*(rinvsq00-felec);
189 /* LENNARD-JONES DISPERSION/REPULSION */
191 rinvsix = rinvsq00*rinvsq00*rinvsq00;
192 vvdw6 = c6_00*rinvsix;
193 vvdw12 = c12_00*rinvsix*rinvsix;
194 vvdw = (vvdw12 - c12_00*sh_vdw_invrcut6*sh_vdw_invrcut6)*(1.0/12.0) - (vvdw6 - c6_00*sh_vdw_invrcut6)*(1.0/6.0);
195 fvdw = (vvdw12-vvdw6)*rinvsq00;
197 /* Update potential sums from outer loop */
203 /* Calculate temporary vectorial force */
208 /* Update vectorial force */
212 f[j_coord_offset+DIM*0+XX] -= tx;
213 f[j_coord_offset+DIM*0+YY] -= ty;
214 f[j_coord_offset+DIM*0+ZZ] -= tz;
218 /* Inner loop uses 59 flops */
220 /* End of innermost loop */
223 f[i_coord_offset+DIM*0+XX] += fix0;
224 f[i_coord_offset+DIM*0+YY] += fiy0;
225 f[i_coord_offset+DIM*0+ZZ] += fiz0;
229 fshift[i_shift_offset+XX] += tx;
230 fshift[i_shift_offset+YY] += ty;
231 fshift[i_shift_offset+ZZ] += tz;
234 /* Update potential energies */
235 kernel_data->energygrp_elec[ggid] += velecsum;
236 kernel_data->energygrp_vdw[ggid] += vvdwsum;
238 /* Increment number of inner iterations */
239 inneriter += j_index_end - j_index_start;
241 /* Outer loop uses 15 flops */
244 /* Increment number of outer iterations */
247 /* Update outer/inner flops */
249 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*15 + inneriter*59);
252 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_F_c
253 * Electrostatics interaction: Ewald
254 * VdW interaction: LennardJones
255 * Geometry: Particle-Particle
256 * Calculate force/pot: Force
259 nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_F_c
260 (t_nblist * gmx_restrict nlist,
261 rvec * gmx_restrict xx,
262 rvec * gmx_restrict ff,
263 t_forcerec * gmx_restrict fr,
264 t_mdatoms * gmx_restrict mdatoms,
265 nb_kernel_data_t * gmx_restrict kernel_data,
266 t_nrnb * gmx_restrict nrnb)
268 int i_shift_offset,i_coord_offset,j_coord_offset;
269 int j_index_start,j_index_end;
270 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
271 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
272 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
273 real *shiftvec,*fshift,*x,*f;
275 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
277 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
278 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
279 real velec,felec,velecsum,facel,crf,krf,krf2;
282 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
286 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
294 jindex = nlist->jindex;
296 shiftidx = nlist->shift;
298 shiftvec = fr->shift_vec[0];
299 fshift = fr->fshift[0];
301 charge = mdatoms->chargeA;
302 nvdwtype = fr->ntype;
304 vdwtype = mdatoms->typeA;
306 sh_ewald = fr->ic->sh_ewald;
307 ewtab = fr->ic->tabq_coul_F;
308 ewtabscale = fr->ic->tabq_scale;
309 ewtabhalfspace = 0.5/ewtabscale;
311 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
312 rcutoff = fr->rcoulomb;
313 rcutoff2 = rcutoff*rcutoff;
315 sh_vdw_invrcut6 = fr->ic->sh_invrc6;
321 /* Start outer loop over neighborlists */
322 for(iidx=0; iidx<nri; iidx++)
324 /* Load shift vector for this list */
325 i_shift_offset = DIM*shiftidx[iidx];
326 shX = shiftvec[i_shift_offset+XX];
327 shY = shiftvec[i_shift_offset+YY];
328 shZ = shiftvec[i_shift_offset+ZZ];
330 /* Load limits for loop over neighbors */
331 j_index_start = jindex[iidx];
332 j_index_end = jindex[iidx+1];
334 /* Get outer coordinate index */
336 i_coord_offset = DIM*inr;
338 /* Load i particle coords and add shift vector */
339 ix0 = shX + x[i_coord_offset+DIM*0+XX];
340 iy0 = shY + x[i_coord_offset+DIM*0+YY];
341 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
347 /* Load parameters for i particles */
348 iq0 = facel*charge[inr+0];
349 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
351 /* Start inner kernel loop */
352 for(jidx=j_index_start; jidx<j_index_end; jidx++)
354 /* Get j neighbor index, and coordinate index */
356 j_coord_offset = DIM*jnr;
358 /* load j atom coordinates */
359 jx0 = x[j_coord_offset+DIM*0+XX];
360 jy0 = x[j_coord_offset+DIM*0+YY];
361 jz0 = x[j_coord_offset+DIM*0+ZZ];
363 /* Calculate displacement vector */
368 /* Calculate squared distance and things based on it */
369 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
371 rinv00 = gmx_invsqrt(rsq00);
373 rinvsq00 = rinv00*rinv00;
375 /* Load parameters for j particles */
377 vdwjidx0 = 2*vdwtype[jnr+0];
379 /**************************
380 * CALCULATE INTERACTIONS *
381 **************************/
389 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
390 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
392 /* EWALD ELECTROSTATICS */
394 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
395 ewrt = r00*ewtabscale;
398 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
399 felec = qq00*rinv00*(rinvsq00-felec);
401 /* LENNARD-JONES DISPERSION/REPULSION */
403 rinvsix = rinvsq00*rinvsq00*rinvsq00;
404 fvdw = (c12_00*rinvsix-c6_00)*rinvsix*rinvsq00;
408 /* Calculate temporary vectorial force */
413 /* Update vectorial force */
417 f[j_coord_offset+DIM*0+XX] -= tx;
418 f[j_coord_offset+DIM*0+YY] -= ty;
419 f[j_coord_offset+DIM*0+ZZ] -= tz;
423 /* Inner loop uses 41 flops */
425 /* End of innermost loop */
428 f[i_coord_offset+DIM*0+XX] += fix0;
429 f[i_coord_offset+DIM*0+YY] += fiy0;
430 f[i_coord_offset+DIM*0+ZZ] += fiz0;
434 fshift[i_shift_offset+XX] += tx;
435 fshift[i_shift_offset+YY] += ty;
436 fshift[i_shift_offset+ZZ] += tz;
438 /* Increment number of inner iterations */
439 inneriter += j_index_end - j_index_start;
441 /* Outer loop uses 13 flops */
444 /* Increment number of outer iterations */
447 /* Update outer/inner flops */
449 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*13 + inneriter*41);