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_ElecEwSw_VdwNone_GeomP1P1_VF_c
35 * Electrostatics interaction: Ewald
36 * VdW interaction: None
37 * Geometry: Particle-Particle
38 * Calculate force/pot: PotentialAndForce
41 nb_kernel_ElecEwSw_VdwNone_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 ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
66 real rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
73 jindex = nlist->jindex;
75 shiftidx = nlist->shift;
77 shiftvec = fr->shift_vec[0];
78 fshift = fr->fshift[0];
80 charge = mdatoms->chargeA;
82 sh_ewald = fr->ic->sh_ewald;
83 ewtab = fr->ic->tabq_coul_FDV0;
84 ewtabscale = fr->ic->tabq_scale;
85 ewtabhalfspace = 0.5/ewtabscale;
87 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
88 rcutoff = fr->rcoulomb;
89 rcutoff2 = rcutoff*rcutoff;
91 rswitch = fr->rcoulomb_switch;
92 /* Setup switch parameters */
95 swV4 = 15.0/(d*d*d*d);
96 swV5 = -6.0/(d*d*d*d*d);
98 swF3 = 60.0/(d*d*d*d);
99 swF4 = -30.0/(d*d*d*d*d);
104 /* Start outer loop over neighborlists */
105 for(iidx=0; iidx<nri; iidx++)
107 /* Load shift vector for this list */
108 i_shift_offset = DIM*shiftidx[iidx];
109 shX = shiftvec[i_shift_offset+XX];
110 shY = shiftvec[i_shift_offset+YY];
111 shZ = shiftvec[i_shift_offset+ZZ];
113 /* Load limits for loop over neighbors */
114 j_index_start = jindex[iidx];
115 j_index_end = jindex[iidx+1];
117 /* Get outer coordinate index */
119 i_coord_offset = DIM*inr;
121 /* Load i particle coords and add shift vector */
122 ix0 = shX + x[i_coord_offset+DIM*0+XX];
123 iy0 = shY + x[i_coord_offset+DIM*0+YY];
124 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
130 /* Load parameters for i particles */
131 iq0 = facel*charge[inr+0];
133 /* Reset potential sums */
136 /* Start inner kernel loop */
137 for(jidx=j_index_start; jidx<j_index_end; jidx++)
139 /* Get j neighbor index, and coordinate index */
141 j_coord_offset = DIM*jnr;
143 /* load j atom coordinates */
144 jx0 = x[j_coord_offset+DIM*0+XX];
145 jy0 = x[j_coord_offset+DIM*0+YY];
146 jz0 = x[j_coord_offset+DIM*0+ZZ];
148 /* Calculate displacement vector */
153 /* Calculate squared distance and things based on it */
154 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
156 rinv00 = gmx_invsqrt(rsq00);
158 rinvsq00 = rinv00*rinv00;
160 /* Load parameters for j particles */
163 /**************************
164 * CALCULATE INTERACTIONS *
165 **************************/
174 /* EWALD ELECTROSTATICS */
176 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
177 ewrt = r00*ewtabscale;
181 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
182 velec = qq00*(rinv00-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
183 felec = qq00*rinv00*(rinvsq00-felec);
186 d = (d>0.0) ? d : 0.0;
188 sw = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
190 dsw = d2*(swF2+d*(swF3+d*swF4));
192 /* Evaluate switch function */
193 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
194 felec = felec*sw - rinv00*velec*dsw;
197 /* Update potential sums from outer loop */
202 /* Calculate temporary vectorial force */
207 /* Update vectorial force */
211 f[j_coord_offset+DIM*0+XX] -= tx;
212 f[j_coord_offset+DIM*0+YY] -= ty;
213 f[j_coord_offset+DIM*0+ZZ] -= tz;
217 /* Inner loop uses 59 flops */
219 /* End of innermost loop */
222 f[i_coord_offset+DIM*0+XX] += fix0;
223 f[i_coord_offset+DIM*0+YY] += fiy0;
224 f[i_coord_offset+DIM*0+ZZ] += fiz0;
228 fshift[i_shift_offset+XX] += tx;
229 fshift[i_shift_offset+YY] += ty;
230 fshift[i_shift_offset+ZZ] += tz;
233 /* Update potential energies */
234 kernel_data->energygrp_elec[ggid] += velecsum;
236 /* Increment number of inner iterations */
237 inneriter += j_index_end - j_index_start;
239 /* Outer loop uses 14 flops */
242 /* Increment number of outer iterations */
245 /* Update outer/inner flops */
247 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*14 + inneriter*59);
250 * Gromacs nonbonded kernel: nb_kernel_ElecEwSw_VdwNone_GeomP1P1_F_c
251 * Electrostatics interaction: Ewald
252 * VdW interaction: None
253 * Geometry: Particle-Particle
254 * Calculate force/pot: Force
257 nb_kernel_ElecEwSw_VdwNone_GeomP1P1_F_c
258 (t_nblist * gmx_restrict nlist,
259 rvec * gmx_restrict xx,
260 rvec * gmx_restrict ff,
261 t_forcerec * gmx_restrict fr,
262 t_mdatoms * gmx_restrict mdatoms,
263 nb_kernel_data_t * gmx_restrict kernel_data,
264 t_nrnb * gmx_restrict nrnb)
266 int i_shift_offset,i_coord_offset,j_coord_offset;
267 int j_index_start,j_index_end;
268 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
269 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
270 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
271 real *shiftvec,*fshift,*x,*f;
273 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
275 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
276 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
277 real velec,felec,velecsum,facel,crf,krf,krf2;
280 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
282 real rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
289 jindex = nlist->jindex;
291 shiftidx = nlist->shift;
293 shiftvec = fr->shift_vec[0];
294 fshift = fr->fshift[0];
296 charge = mdatoms->chargeA;
298 sh_ewald = fr->ic->sh_ewald;
299 ewtab = fr->ic->tabq_coul_FDV0;
300 ewtabscale = fr->ic->tabq_scale;
301 ewtabhalfspace = 0.5/ewtabscale;
303 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
304 rcutoff = fr->rcoulomb;
305 rcutoff2 = rcutoff*rcutoff;
307 rswitch = fr->rcoulomb_switch;
308 /* Setup switch parameters */
310 swV3 = -10.0/(d*d*d);
311 swV4 = 15.0/(d*d*d*d);
312 swV5 = -6.0/(d*d*d*d*d);
313 swF2 = -30.0/(d*d*d);
314 swF3 = 60.0/(d*d*d*d);
315 swF4 = -30.0/(d*d*d*d*d);
320 /* Start outer loop over neighborlists */
321 for(iidx=0; iidx<nri; iidx++)
323 /* Load shift vector for this list */
324 i_shift_offset = DIM*shiftidx[iidx];
325 shX = shiftvec[i_shift_offset+XX];
326 shY = shiftvec[i_shift_offset+YY];
327 shZ = shiftvec[i_shift_offset+ZZ];
329 /* Load limits for loop over neighbors */
330 j_index_start = jindex[iidx];
331 j_index_end = jindex[iidx+1];
333 /* Get outer coordinate index */
335 i_coord_offset = DIM*inr;
337 /* Load i particle coords and add shift vector */
338 ix0 = shX + x[i_coord_offset+DIM*0+XX];
339 iy0 = shY + x[i_coord_offset+DIM*0+YY];
340 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
346 /* Load parameters for i particles */
347 iq0 = facel*charge[inr+0];
349 /* Start inner kernel loop */
350 for(jidx=j_index_start; jidx<j_index_end; jidx++)
352 /* Get j neighbor index, and coordinate index */
354 j_coord_offset = DIM*jnr;
356 /* load j atom coordinates */
357 jx0 = x[j_coord_offset+DIM*0+XX];
358 jy0 = x[j_coord_offset+DIM*0+YY];
359 jz0 = x[j_coord_offset+DIM*0+ZZ];
361 /* Calculate displacement vector */
366 /* Calculate squared distance and things based on it */
367 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
369 rinv00 = gmx_invsqrt(rsq00);
371 rinvsq00 = rinv00*rinv00;
373 /* Load parameters for j particles */
376 /**************************
377 * CALCULATE INTERACTIONS *
378 **************************/
387 /* EWALD ELECTROSTATICS */
389 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
390 ewrt = r00*ewtabscale;
394 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
395 velec = qq00*(rinv00-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
396 felec = qq00*rinv00*(rinvsq00-felec);
399 d = (d>0.0) ? d : 0.0;
401 sw = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
403 dsw = d2*(swF2+d*(swF3+d*swF4));
405 /* Evaluate switch function */
406 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
407 felec = felec*sw - rinv00*velec*dsw;
411 /* Calculate temporary vectorial force */
416 /* Update vectorial force */
420 f[j_coord_offset+DIM*0+XX] -= tx;
421 f[j_coord_offset+DIM*0+YY] -= ty;
422 f[j_coord_offset+DIM*0+ZZ] -= tz;
426 /* Inner loop uses 57 flops */
428 /* End of innermost loop */
431 f[i_coord_offset+DIM*0+XX] += fix0;
432 f[i_coord_offset+DIM*0+YY] += fiy0;
433 f[i_coord_offset+DIM*0+ZZ] += fiz0;
437 fshift[i_shift_offset+XX] += tx;
438 fshift[i_shift_offset+YY] += ty;
439 fshift[i_shift_offset+ZZ] += tz;
441 /* Increment number of inner iterations */
442 inneriter += j_index_end - j_index_start;
444 /* Outer loop uses 13 flops */
447 /* Increment number of outer iterations */
450 /* Update outer/inner flops */
452 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*13 + inneriter*57);