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.
42 #include "../nb_kernel.h"
43 #include "gromacs/legacyheaders/types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "gromacs/legacyheaders/nrnb.h"
48 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomP1P1_VF_c
49 * Electrostatics interaction: ReactionField
50 * VdW interaction: LennardJones
51 * Geometry: Particle-Particle
52 * Calculate force/pot: PotentialAndForce
55 nb_kernel_ElecRFCut_VdwLJSw_GeomP1P1_VF_c
56 (t_nblist * gmx_restrict nlist,
57 rvec * gmx_restrict xx,
58 rvec * gmx_restrict ff,
59 t_forcerec * gmx_restrict fr,
60 t_mdatoms * gmx_restrict mdatoms,
61 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
62 t_nrnb * gmx_restrict nrnb)
64 int i_shift_offset,i_coord_offset,j_coord_offset;
65 int j_index_start,j_index_end;
66 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
67 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
68 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
69 real *shiftvec,*fshift,*x,*f;
71 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
73 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
74 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
75 real velec,felec,velecsum,facel,crf,krf,krf2;
78 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
81 real rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
88 jindex = nlist->jindex;
90 shiftidx = nlist->shift;
92 shiftvec = fr->shift_vec[0];
93 fshift = fr->fshift[0];
95 charge = mdatoms->chargeA;
101 vdwtype = mdatoms->typeA;
103 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
104 rcutoff = fr->rcoulomb;
105 rcutoff2 = rcutoff*rcutoff;
107 rswitch = fr->rvdw_switch;
108 /* Setup switch parameters */
110 swV3 = -10.0/(d*d*d);
111 swV4 = 15.0/(d*d*d*d);
112 swV5 = -6.0/(d*d*d*d*d);
113 swF2 = -30.0/(d*d*d);
114 swF3 = 60.0/(d*d*d*d);
115 swF4 = -30.0/(d*d*d*d*d);
120 /* Start outer loop over neighborlists */
121 for(iidx=0; iidx<nri; iidx++)
123 /* Load shift vector for this list */
124 i_shift_offset = DIM*shiftidx[iidx];
125 shX = shiftvec[i_shift_offset+XX];
126 shY = shiftvec[i_shift_offset+YY];
127 shZ = shiftvec[i_shift_offset+ZZ];
129 /* Load limits for loop over neighbors */
130 j_index_start = jindex[iidx];
131 j_index_end = jindex[iidx+1];
133 /* Get outer coordinate index */
135 i_coord_offset = DIM*inr;
137 /* Load i particle coords and add shift vector */
138 ix0 = shX + x[i_coord_offset+DIM*0+XX];
139 iy0 = shY + x[i_coord_offset+DIM*0+YY];
140 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
146 /* Load parameters for i particles */
147 iq0 = facel*charge[inr+0];
148 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
150 /* Reset potential sums */
154 /* Start inner kernel loop */
155 for(jidx=j_index_start; jidx<j_index_end; jidx++)
157 /* Get j neighbor index, and coordinate index */
159 j_coord_offset = DIM*jnr;
161 /* load j atom coordinates */
162 jx0 = x[j_coord_offset+DIM*0+XX];
163 jy0 = x[j_coord_offset+DIM*0+YY];
164 jz0 = x[j_coord_offset+DIM*0+ZZ];
166 /* Calculate displacement vector */
171 /* Calculate squared distance and things based on it */
172 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
174 rinv00 = gmx_invsqrt(rsq00);
176 rinvsq00 = rinv00*rinv00;
178 /* Load parameters for j particles */
180 vdwjidx0 = 2*vdwtype[jnr+0];
182 /**************************
183 * CALCULATE INTERACTIONS *
184 **************************/
192 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
193 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
195 /* REACTION-FIELD ELECTROSTATICS */
196 velec = qq00*(rinv00+krf*rsq00-crf);
197 felec = qq00*(rinv00*rinvsq00-krf2);
199 /* LENNARD-JONES DISPERSION/REPULSION */
201 rinvsix = rinvsq00*rinvsq00*rinvsq00;
202 vvdw6 = c6_00*rinvsix;
203 vvdw12 = c12_00*rinvsix*rinvsix;
204 vvdw = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
205 fvdw = (vvdw12-vvdw6)*rinvsq00;
208 d = (d>0.0) ? d : 0.0;
210 sw = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
212 dsw = d2*(swF2+d*(swF3+d*swF4));
214 /* Evaluate switch function */
215 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
216 fvdw = fvdw*sw - rinv00*vvdw*dsw;
219 /* Update potential sums from outer loop */
225 /* Calculate temporary vectorial force */
230 /* Update vectorial force */
234 f[j_coord_offset+DIM*0+XX] -= tx;
235 f[j_coord_offset+DIM*0+YY] -= ty;
236 f[j_coord_offset+DIM*0+ZZ] -= tz;
240 /* Inner loop uses 63 flops */
242 /* End of innermost loop */
245 f[i_coord_offset+DIM*0+XX] += fix0;
246 f[i_coord_offset+DIM*0+YY] += fiy0;
247 f[i_coord_offset+DIM*0+ZZ] += fiz0;
251 fshift[i_shift_offset+XX] += tx;
252 fshift[i_shift_offset+YY] += ty;
253 fshift[i_shift_offset+ZZ] += tz;
256 /* Update potential energies */
257 kernel_data->energygrp_elec[ggid] += velecsum;
258 kernel_data->energygrp_vdw[ggid] += vvdwsum;
260 /* Increment number of inner iterations */
261 inneriter += j_index_end - j_index_start;
263 /* Outer loop uses 15 flops */
266 /* Increment number of outer iterations */
269 /* Update outer/inner flops */
271 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*15 + inneriter*63);
274 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomP1P1_F_c
275 * Electrostatics interaction: ReactionField
276 * VdW interaction: LennardJones
277 * Geometry: Particle-Particle
278 * Calculate force/pot: Force
281 nb_kernel_ElecRFCut_VdwLJSw_GeomP1P1_F_c
282 (t_nblist * gmx_restrict nlist,
283 rvec * gmx_restrict xx,
284 rvec * gmx_restrict ff,
285 t_forcerec * gmx_restrict fr,
286 t_mdatoms * gmx_restrict mdatoms,
287 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
288 t_nrnb * gmx_restrict nrnb)
290 int i_shift_offset,i_coord_offset,j_coord_offset;
291 int j_index_start,j_index_end;
292 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
293 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
294 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
295 real *shiftvec,*fshift,*x,*f;
297 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
299 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
300 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
301 real velec,felec,velecsum,facel,crf,krf,krf2;
304 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
307 real rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
314 jindex = nlist->jindex;
316 shiftidx = nlist->shift;
318 shiftvec = fr->shift_vec[0];
319 fshift = fr->fshift[0];
321 charge = mdatoms->chargeA;
325 nvdwtype = fr->ntype;
327 vdwtype = mdatoms->typeA;
329 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
330 rcutoff = fr->rcoulomb;
331 rcutoff2 = rcutoff*rcutoff;
333 rswitch = fr->rvdw_switch;
334 /* Setup switch parameters */
336 swV3 = -10.0/(d*d*d);
337 swV4 = 15.0/(d*d*d*d);
338 swV5 = -6.0/(d*d*d*d*d);
339 swF2 = -30.0/(d*d*d);
340 swF3 = 60.0/(d*d*d*d);
341 swF4 = -30.0/(d*d*d*d*d);
346 /* Start outer loop over neighborlists */
347 for(iidx=0; iidx<nri; iidx++)
349 /* Load shift vector for this list */
350 i_shift_offset = DIM*shiftidx[iidx];
351 shX = shiftvec[i_shift_offset+XX];
352 shY = shiftvec[i_shift_offset+YY];
353 shZ = shiftvec[i_shift_offset+ZZ];
355 /* Load limits for loop over neighbors */
356 j_index_start = jindex[iidx];
357 j_index_end = jindex[iidx+1];
359 /* Get outer coordinate index */
361 i_coord_offset = DIM*inr;
363 /* Load i particle coords and add shift vector */
364 ix0 = shX + x[i_coord_offset+DIM*0+XX];
365 iy0 = shY + x[i_coord_offset+DIM*0+YY];
366 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
372 /* Load parameters for i particles */
373 iq0 = facel*charge[inr+0];
374 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
376 /* Start inner kernel loop */
377 for(jidx=j_index_start; jidx<j_index_end; jidx++)
379 /* Get j neighbor index, and coordinate index */
381 j_coord_offset = DIM*jnr;
383 /* load j atom coordinates */
384 jx0 = x[j_coord_offset+DIM*0+XX];
385 jy0 = x[j_coord_offset+DIM*0+YY];
386 jz0 = x[j_coord_offset+DIM*0+ZZ];
388 /* Calculate displacement vector */
393 /* Calculate squared distance and things based on it */
394 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
396 rinv00 = gmx_invsqrt(rsq00);
398 rinvsq00 = rinv00*rinv00;
400 /* Load parameters for j particles */
402 vdwjidx0 = 2*vdwtype[jnr+0];
404 /**************************
405 * CALCULATE INTERACTIONS *
406 **************************/
414 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
415 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
417 /* REACTION-FIELD ELECTROSTATICS */
418 felec = qq00*(rinv00*rinvsq00-krf2);
420 /* LENNARD-JONES DISPERSION/REPULSION */
422 rinvsix = rinvsq00*rinvsq00*rinvsq00;
423 vvdw6 = c6_00*rinvsix;
424 vvdw12 = c12_00*rinvsix*rinvsix;
425 vvdw = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
426 fvdw = (vvdw12-vvdw6)*rinvsq00;
429 d = (d>0.0) ? d : 0.0;
431 sw = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
433 dsw = d2*(swF2+d*(swF3+d*swF4));
435 /* Evaluate switch function */
436 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
437 fvdw = fvdw*sw - rinv00*vvdw*dsw;
441 /* Calculate temporary vectorial force */
446 /* Update vectorial force */
450 f[j_coord_offset+DIM*0+XX] -= tx;
451 f[j_coord_offset+DIM*0+YY] -= ty;
452 f[j_coord_offset+DIM*0+ZZ] -= tz;
456 /* Inner loop uses 56 flops */
458 /* End of innermost loop */
461 f[i_coord_offset+DIM*0+XX] += fix0;
462 f[i_coord_offset+DIM*0+YY] += fiy0;
463 f[i_coord_offset+DIM*0+ZZ] += fiz0;
467 fshift[i_shift_offset+XX] += tx;
468 fshift[i_shift_offset+YY] += ty;
469 fshift[i_shift_offset+ZZ] += tz;
471 /* Increment number of inner iterations */
472 inneriter += j_index_end - j_index_start;
474 /* Outer loop uses 13 flops */
477 /* Increment number of outer iterations */
480 /* Update outer/inner flops */
482 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*13 + inneriter*56);