2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013, 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 "types/simple.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomP1P1_VF_c
51 * Electrostatics interaction: ReactionField
52 * VdW interaction: LennardJones
53 * Geometry: Particle-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecRFCut_VdwLJSw_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;
83 real rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
90 jindex = nlist->jindex;
92 shiftidx = nlist->shift;
94 shiftvec = fr->shift_vec[0];
95 fshift = fr->fshift[0];
97 charge = mdatoms->chargeA;
101 nvdwtype = fr->ntype;
103 vdwtype = mdatoms->typeA;
105 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
106 rcutoff = fr->rcoulomb;
107 rcutoff2 = rcutoff*rcutoff;
109 rswitch = fr->rvdw_switch;
110 /* Setup switch parameters */
112 swV3 = -10.0/(d*d*d);
113 swV4 = 15.0/(d*d*d*d);
114 swV5 = -6.0/(d*d*d*d*d);
115 swF2 = -30.0/(d*d*d);
116 swF3 = 60.0/(d*d*d*d);
117 swF4 = -30.0/(d*d*d*d*d);
122 /* Start outer loop over neighborlists */
123 for(iidx=0; iidx<nri; iidx++)
125 /* Load shift vector for this list */
126 i_shift_offset = DIM*shiftidx[iidx];
127 shX = shiftvec[i_shift_offset+XX];
128 shY = shiftvec[i_shift_offset+YY];
129 shZ = shiftvec[i_shift_offset+ZZ];
131 /* Load limits for loop over neighbors */
132 j_index_start = jindex[iidx];
133 j_index_end = jindex[iidx+1];
135 /* Get outer coordinate index */
137 i_coord_offset = DIM*inr;
139 /* Load i particle coords and add shift vector */
140 ix0 = shX + x[i_coord_offset+DIM*0+XX];
141 iy0 = shY + x[i_coord_offset+DIM*0+YY];
142 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
148 /* Load parameters for i particles */
149 iq0 = facel*charge[inr+0];
150 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
152 /* Reset potential sums */
156 /* Start inner kernel loop */
157 for(jidx=j_index_start; jidx<j_index_end; jidx++)
159 /* Get j neighbor index, and coordinate index */
161 j_coord_offset = DIM*jnr;
163 /* load j atom coordinates */
164 jx0 = x[j_coord_offset+DIM*0+XX];
165 jy0 = x[j_coord_offset+DIM*0+YY];
166 jz0 = x[j_coord_offset+DIM*0+ZZ];
168 /* Calculate displacement vector */
173 /* Calculate squared distance and things based on it */
174 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
176 rinv00 = gmx_invsqrt(rsq00);
178 rinvsq00 = rinv00*rinv00;
180 /* Load parameters for j particles */
182 vdwjidx0 = 2*vdwtype[jnr+0];
184 /**************************
185 * CALCULATE INTERACTIONS *
186 **************************/
194 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
195 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
197 /* REACTION-FIELD ELECTROSTATICS */
198 velec = qq00*(rinv00+krf*rsq00-crf);
199 felec = qq00*(rinv00*rinvsq00-krf2);
201 /* LENNARD-JONES DISPERSION/REPULSION */
203 rinvsix = rinvsq00*rinvsq00*rinvsq00;
204 vvdw6 = c6_00*rinvsix;
205 vvdw12 = c12_00*rinvsix*rinvsix;
206 vvdw = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
207 fvdw = (vvdw12-vvdw6)*rinvsq00;
210 d = (d>0.0) ? d : 0.0;
212 sw = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
214 dsw = d2*(swF2+d*(swF3+d*swF4));
216 /* Evaluate switch function */
217 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
218 fvdw = fvdw*sw - rinv00*vvdw*dsw;
221 /* Update potential sums from outer loop */
227 /* Calculate temporary vectorial force */
232 /* Update vectorial force */
236 f[j_coord_offset+DIM*0+XX] -= tx;
237 f[j_coord_offset+DIM*0+YY] -= ty;
238 f[j_coord_offset+DIM*0+ZZ] -= tz;
242 /* Inner loop uses 63 flops */
244 /* End of innermost loop */
247 f[i_coord_offset+DIM*0+XX] += fix0;
248 f[i_coord_offset+DIM*0+YY] += fiy0;
249 f[i_coord_offset+DIM*0+ZZ] += fiz0;
253 fshift[i_shift_offset+XX] += tx;
254 fshift[i_shift_offset+YY] += ty;
255 fshift[i_shift_offset+ZZ] += tz;
258 /* Update potential energies */
259 kernel_data->energygrp_elec[ggid] += velecsum;
260 kernel_data->energygrp_vdw[ggid] += vvdwsum;
262 /* Increment number of inner iterations */
263 inneriter += j_index_end - j_index_start;
265 /* Outer loop uses 15 flops */
268 /* Increment number of outer iterations */
271 /* Update outer/inner flops */
273 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*15 + inneriter*63);
276 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomP1P1_F_c
277 * Electrostatics interaction: ReactionField
278 * VdW interaction: LennardJones
279 * Geometry: Particle-Particle
280 * Calculate force/pot: Force
283 nb_kernel_ElecRFCut_VdwLJSw_GeomP1P1_F_c
284 (t_nblist * gmx_restrict nlist,
285 rvec * gmx_restrict xx,
286 rvec * gmx_restrict ff,
287 t_forcerec * gmx_restrict fr,
288 t_mdatoms * gmx_restrict mdatoms,
289 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
290 t_nrnb * gmx_restrict nrnb)
292 int i_shift_offset,i_coord_offset,j_coord_offset;
293 int j_index_start,j_index_end;
294 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
295 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
296 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
297 real *shiftvec,*fshift,*x,*f;
299 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
301 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
302 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
303 real velec,felec,velecsum,facel,crf,krf,krf2;
306 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
309 real rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
316 jindex = nlist->jindex;
318 shiftidx = nlist->shift;
320 shiftvec = fr->shift_vec[0];
321 fshift = fr->fshift[0];
323 charge = mdatoms->chargeA;
327 nvdwtype = fr->ntype;
329 vdwtype = mdatoms->typeA;
331 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
332 rcutoff = fr->rcoulomb;
333 rcutoff2 = rcutoff*rcutoff;
335 rswitch = fr->rvdw_switch;
336 /* Setup switch parameters */
338 swV3 = -10.0/(d*d*d);
339 swV4 = 15.0/(d*d*d*d);
340 swV5 = -6.0/(d*d*d*d*d);
341 swF2 = -30.0/(d*d*d);
342 swF3 = 60.0/(d*d*d*d);
343 swF4 = -30.0/(d*d*d*d*d);
348 /* Start outer loop over neighborlists */
349 for(iidx=0; iidx<nri; iidx++)
351 /* Load shift vector for this list */
352 i_shift_offset = DIM*shiftidx[iidx];
353 shX = shiftvec[i_shift_offset+XX];
354 shY = shiftvec[i_shift_offset+YY];
355 shZ = shiftvec[i_shift_offset+ZZ];
357 /* Load limits for loop over neighbors */
358 j_index_start = jindex[iidx];
359 j_index_end = jindex[iidx+1];
361 /* Get outer coordinate index */
363 i_coord_offset = DIM*inr;
365 /* Load i particle coords and add shift vector */
366 ix0 = shX + x[i_coord_offset+DIM*0+XX];
367 iy0 = shY + x[i_coord_offset+DIM*0+YY];
368 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
374 /* Load parameters for i particles */
375 iq0 = facel*charge[inr+0];
376 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
378 /* Start inner kernel loop */
379 for(jidx=j_index_start; jidx<j_index_end; jidx++)
381 /* Get j neighbor index, and coordinate index */
383 j_coord_offset = DIM*jnr;
385 /* load j atom coordinates */
386 jx0 = x[j_coord_offset+DIM*0+XX];
387 jy0 = x[j_coord_offset+DIM*0+YY];
388 jz0 = x[j_coord_offset+DIM*0+ZZ];
390 /* Calculate displacement vector */
395 /* Calculate squared distance and things based on it */
396 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
398 rinv00 = gmx_invsqrt(rsq00);
400 rinvsq00 = rinv00*rinv00;
402 /* Load parameters for j particles */
404 vdwjidx0 = 2*vdwtype[jnr+0];
406 /**************************
407 * CALCULATE INTERACTIONS *
408 **************************/
416 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
417 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
419 /* REACTION-FIELD ELECTROSTATICS */
420 felec = qq00*(rinv00*rinvsq00-krf2);
422 /* LENNARD-JONES DISPERSION/REPULSION */
424 rinvsix = rinvsq00*rinvsq00*rinvsq00;
425 vvdw6 = c6_00*rinvsix;
426 vvdw12 = c12_00*rinvsix*rinvsix;
427 vvdw = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
428 fvdw = (vvdw12-vvdw6)*rinvsq00;
431 d = (d>0.0) ? d : 0.0;
433 sw = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
435 dsw = d2*(swF2+d*(swF3+d*swF4));
437 /* Evaluate switch function */
438 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
439 fvdw = fvdw*sw - rinv00*vvdw*dsw;
443 /* Calculate temporary vectorial force */
448 /* Update vectorial force */
452 f[j_coord_offset+DIM*0+XX] -= tx;
453 f[j_coord_offset+DIM*0+YY] -= ty;
454 f[j_coord_offset+DIM*0+ZZ] -= tz;
458 /* Inner loop uses 56 flops */
460 /* End of innermost loop */
463 f[i_coord_offset+DIM*0+XX] += fix0;
464 f[i_coord_offset+DIM*0+YY] += fiy0;
465 f[i_coord_offset+DIM*0+ZZ] += fiz0;
469 fshift[i_shift_offset+XX] += tx;
470 fshift[i_shift_offset+YY] += ty;
471 fshift[i_shift_offset+ZZ] += tz;
473 /* Increment number of inner iterations */
474 inneriter += j_index_end - j_index_start;
476 /* Outer loop uses 13 flops */
479 /* Increment number of outer iterations */
482 /* Update outer/inner flops */
484 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*13 + inneriter*56);