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 "types/simple.h"
44 #include "gromacs/math/vec.h"
48 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomW3P1_VF_c
49 * Electrostatics interaction: ReactionField
50 * VdW interaction: LennardJones
51 * Geometry: Water3-Particle
52 * Calculate force/pot: PotentialAndForce
55 nb_kernel_ElecRFCut_VdwLJSw_GeomW3P1_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 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
75 real ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
77 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
78 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
79 real dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
80 real dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
81 real velec,felec,velecsum,facel,crf,krf,krf2;
84 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
87 real rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
94 jindex = nlist->jindex;
96 shiftidx = nlist->shift;
98 shiftvec = fr->shift_vec[0];
99 fshift = fr->fshift[0];
101 charge = mdatoms->chargeA;
105 nvdwtype = fr->ntype;
107 vdwtype = mdatoms->typeA;
109 /* Setup water-specific parameters */
110 inr = nlist->iinr[0];
111 iq0 = facel*charge[inr+0];
112 iq1 = facel*charge[inr+1];
113 iq2 = facel*charge[inr+2];
114 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
116 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
117 rcutoff = fr->rcoulomb;
118 rcutoff2 = rcutoff*rcutoff;
120 rswitch = fr->rvdw_switch;
121 /* Setup switch parameters */
123 swV3 = -10.0/(d*d*d);
124 swV4 = 15.0/(d*d*d*d);
125 swV5 = -6.0/(d*d*d*d*d);
126 swF2 = -30.0/(d*d*d);
127 swF3 = 60.0/(d*d*d*d);
128 swF4 = -30.0/(d*d*d*d*d);
133 /* Start outer loop over neighborlists */
134 for(iidx=0; iidx<nri; iidx++)
136 /* Load shift vector for this list */
137 i_shift_offset = DIM*shiftidx[iidx];
138 shX = shiftvec[i_shift_offset+XX];
139 shY = shiftvec[i_shift_offset+YY];
140 shZ = shiftvec[i_shift_offset+ZZ];
142 /* Load limits for loop over neighbors */
143 j_index_start = jindex[iidx];
144 j_index_end = jindex[iidx+1];
146 /* Get outer coordinate index */
148 i_coord_offset = DIM*inr;
150 /* Load i particle coords and add shift vector */
151 ix0 = shX + x[i_coord_offset+DIM*0+XX];
152 iy0 = shY + x[i_coord_offset+DIM*0+YY];
153 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
154 ix1 = shX + x[i_coord_offset+DIM*1+XX];
155 iy1 = shY + x[i_coord_offset+DIM*1+YY];
156 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
157 ix2 = shX + x[i_coord_offset+DIM*2+XX];
158 iy2 = shY + x[i_coord_offset+DIM*2+YY];
159 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
171 /* Reset potential sums */
175 /* Start inner kernel loop */
176 for(jidx=j_index_start; jidx<j_index_end; jidx++)
178 /* Get j neighbor index, and coordinate index */
180 j_coord_offset = DIM*jnr;
182 /* load j atom coordinates */
183 jx0 = x[j_coord_offset+DIM*0+XX];
184 jy0 = x[j_coord_offset+DIM*0+YY];
185 jz0 = x[j_coord_offset+DIM*0+ZZ];
187 /* Calculate displacement vector */
198 /* Calculate squared distance and things based on it */
199 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
200 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
201 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
203 rinv00 = gmx_invsqrt(rsq00);
204 rinv10 = gmx_invsqrt(rsq10);
205 rinv20 = gmx_invsqrt(rsq20);
207 rinvsq00 = rinv00*rinv00;
208 rinvsq10 = rinv10*rinv10;
209 rinvsq20 = rinv20*rinv20;
211 /* Load parameters for j particles */
213 vdwjidx0 = 2*vdwtype[jnr+0];
215 /**************************
216 * CALCULATE INTERACTIONS *
217 **************************/
225 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
226 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
228 /* REACTION-FIELD ELECTROSTATICS */
229 velec = qq00*(rinv00+krf*rsq00-crf);
230 felec = qq00*(rinv00*rinvsq00-krf2);
232 /* LENNARD-JONES DISPERSION/REPULSION */
234 rinvsix = rinvsq00*rinvsq00*rinvsq00;
235 vvdw6 = c6_00*rinvsix;
236 vvdw12 = c12_00*rinvsix*rinvsix;
237 vvdw = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
238 fvdw = (vvdw12-vvdw6)*rinvsq00;
241 d = (d>0.0) ? d : 0.0;
243 sw = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
245 dsw = d2*(swF2+d*(swF3+d*swF4));
247 /* Evaluate switch function */
248 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
249 fvdw = fvdw*sw - rinv00*vvdw*dsw;
252 /* Update potential sums from outer loop */
258 /* Calculate temporary vectorial force */
263 /* Update vectorial force */
267 f[j_coord_offset+DIM*0+XX] -= tx;
268 f[j_coord_offset+DIM*0+YY] -= ty;
269 f[j_coord_offset+DIM*0+ZZ] -= tz;
273 /**************************
274 * CALCULATE INTERACTIONS *
275 **************************/
282 /* REACTION-FIELD ELECTROSTATICS */
283 velec = qq10*(rinv10+krf*rsq10-crf);
284 felec = qq10*(rinv10*rinvsq10-krf2);
286 /* Update potential sums from outer loop */
291 /* Calculate temporary vectorial force */
296 /* Update vectorial force */
300 f[j_coord_offset+DIM*0+XX] -= tx;
301 f[j_coord_offset+DIM*0+YY] -= ty;
302 f[j_coord_offset+DIM*0+ZZ] -= tz;
306 /**************************
307 * CALCULATE INTERACTIONS *
308 **************************/
315 /* REACTION-FIELD ELECTROSTATICS */
316 velec = qq20*(rinv20+krf*rsq20-crf);
317 felec = qq20*(rinv20*rinvsq20-krf2);
319 /* Update potential sums from outer loop */
324 /* Calculate temporary vectorial force */
329 /* Update vectorial force */
333 f[j_coord_offset+DIM*0+XX] -= tx;
334 f[j_coord_offset+DIM*0+YY] -= ty;
335 f[j_coord_offset+DIM*0+ZZ] -= tz;
339 /* Inner loop uses 127 flops */
341 /* End of innermost loop */
344 f[i_coord_offset+DIM*0+XX] += fix0;
345 f[i_coord_offset+DIM*0+YY] += fiy0;
346 f[i_coord_offset+DIM*0+ZZ] += fiz0;
350 f[i_coord_offset+DIM*1+XX] += fix1;
351 f[i_coord_offset+DIM*1+YY] += fiy1;
352 f[i_coord_offset+DIM*1+ZZ] += fiz1;
356 f[i_coord_offset+DIM*2+XX] += fix2;
357 f[i_coord_offset+DIM*2+YY] += fiy2;
358 f[i_coord_offset+DIM*2+ZZ] += fiz2;
362 fshift[i_shift_offset+XX] += tx;
363 fshift[i_shift_offset+YY] += ty;
364 fshift[i_shift_offset+ZZ] += tz;
367 /* Update potential energies */
368 kernel_data->energygrp_elec[ggid] += velecsum;
369 kernel_data->energygrp_vdw[ggid] += vvdwsum;
371 /* Increment number of inner iterations */
372 inneriter += j_index_end - j_index_start;
374 /* Outer loop uses 32 flops */
377 /* Increment number of outer iterations */
380 /* Update outer/inner flops */
382 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*32 + inneriter*127);
385 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomW3P1_F_c
386 * Electrostatics interaction: ReactionField
387 * VdW interaction: LennardJones
388 * Geometry: Water3-Particle
389 * Calculate force/pot: Force
392 nb_kernel_ElecRFCut_VdwLJSw_GeomW3P1_F_c
393 (t_nblist * gmx_restrict nlist,
394 rvec * gmx_restrict xx,
395 rvec * gmx_restrict ff,
396 t_forcerec * gmx_restrict fr,
397 t_mdatoms * gmx_restrict mdatoms,
398 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
399 t_nrnb * gmx_restrict nrnb)
401 int i_shift_offset,i_coord_offset,j_coord_offset;
402 int j_index_start,j_index_end;
403 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
404 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
405 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
406 real *shiftvec,*fshift,*x,*f;
408 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
410 real ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
412 real ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
414 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
415 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
416 real dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
417 real dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
418 real velec,felec,velecsum,facel,crf,krf,krf2;
421 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
424 real rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
431 jindex = nlist->jindex;
433 shiftidx = nlist->shift;
435 shiftvec = fr->shift_vec[0];
436 fshift = fr->fshift[0];
438 charge = mdatoms->chargeA;
442 nvdwtype = fr->ntype;
444 vdwtype = mdatoms->typeA;
446 /* Setup water-specific parameters */
447 inr = nlist->iinr[0];
448 iq0 = facel*charge[inr+0];
449 iq1 = facel*charge[inr+1];
450 iq2 = facel*charge[inr+2];
451 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
453 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
454 rcutoff = fr->rcoulomb;
455 rcutoff2 = rcutoff*rcutoff;
457 rswitch = fr->rvdw_switch;
458 /* Setup switch parameters */
460 swV3 = -10.0/(d*d*d);
461 swV4 = 15.0/(d*d*d*d);
462 swV5 = -6.0/(d*d*d*d*d);
463 swF2 = -30.0/(d*d*d);
464 swF3 = 60.0/(d*d*d*d);
465 swF4 = -30.0/(d*d*d*d*d);
470 /* Start outer loop over neighborlists */
471 for(iidx=0; iidx<nri; iidx++)
473 /* Load shift vector for this list */
474 i_shift_offset = DIM*shiftidx[iidx];
475 shX = shiftvec[i_shift_offset+XX];
476 shY = shiftvec[i_shift_offset+YY];
477 shZ = shiftvec[i_shift_offset+ZZ];
479 /* Load limits for loop over neighbors */
480 j_index_start = jindex[iidx];
481 j_index_end = jindex[iidx+1];
483 /* Get outer coordinate index */
485 i_coord_offset = DIM*inr;
487 /* Load i particle coords and add shift vector */
488 ix0 = shX + x[i_coord_offset+DIM*0+XX];
489 iy0 = shY + x[i_coord_offset+DIM*0+YY];
490 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
491 ix1 = shX + x[i_coord_offset+DIM*1+XX];
492 iy1 = shY + x[i_coord_offset+DIM*1+YY];
493 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
494 ix2 = shX + x[i_coord_offset+DIM*2+XX];
495 iy2 = shY + x[i_coord_offset+DIM*2+YY];
496 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
508 /* Start inner kernel loop */
509 for(jidx=j_index_start; jidx<j_index_end; jidx++)
511 /* Get j neighbor index, and coordinate index */
513 j_coord_offset = DIM*jnr;
515 /* load j atom coordinates */
516 jx0 = x[j_coord_offset+DIM*0+XX];
517 jy0 = x[j_coord_offset+DIM*0+YY];
518 jz0 = x[j_coord_offset+DIM*0+ZZ];
520 /* Calculate displacement vector */
531 /* Calculate squared distance and things based on it */
532 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
533 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
534 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
536 rinv00 = gmx_invsqrt(rsq00);
537 rinv10 = gmx_invsqrt(rsq10);
538 rinv20 = gmx_invsqrt(rsq20);
540 rinvsq00 = rinv00*rinv00;
541 rinvsq10 = rinv10*rinv10;
542 rinvsq20 = rinv20*rinv20;
544 /* Load parameters for j particles */
546 vdwjidx0 = 2*vdwtype[jnr+0];
548 /**************************
549 * CALCULATE INTERACTIONS *
550 **************************/
558 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
559 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
561 /* REACTION-FIELD ELECTROSTATICS */
562 felec = qq00*(rinv00*rinvsq00-krf2);
564 /* LENNARD-JONES DISPERSION/REPULSION */
566 rinvsix = rinvsq00*rinvsq00*rinvsq00;
567 vvdw6 = c6_00*rinvsix;
568 vvdw12 = c12_00*rinvsix*rinvsix;
569 vvdw = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
570 fvdw = (vvdw12-vvdw6)*rinvsq00;
573 d = (d>0.0) ? d : 0.0;
575 sw = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
577 dsw = d2*(swF2+d*(swF3+d*swF4));
579 /* Evaluate switch function */
580 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
581 fvdw = fvdw*sw - rinv00*vvdw*dsw;
585 /* Calculate temporary vectorial force */
590 /* Update vectorial force */
594 f[j_coord_offset+DIM*0+XX] -= tx;
595 f[j_coord_offset+DIM*0+YY] -= ty;
596 f[j_coord_offset+DIM*0+ZZ] -= tz;
600 /**************************
601 * CALCULATE INTERACTIONS *
602 **************************/
609 /* REACTION-FIELD ELECTROSTATICS */
610 felec = qq10*(rinv10*rinvsq10-krf2);
614 /* Calculate temporary vectorial force */
619 /* Update vectorial force */
623 f[j_coord_offset+DIM*0+XX] -= tx;
624 f[j_coord_offset+DIM*0+YY] -= ty;
625 f[j_coord_offset+DIM*0+ZZ] -= tz;
629 /**************************
630 * CALCULATE INTERACTIONS *
631 **************************/
638 /* REACTION-FIELD ELECTROSTATICS */
639 felec = qq20*(rinv20*rinvsq20-krf2);
643 /* Calculate temporary vectorial force */
648 /* Update vectorial force */
652 f[j_coord_offset+DIM*0+XX] -= tx;
653 f[j_coord_offset+DIM*0+YY] -= ty;
654 f[j_coord_offset+DIM*0+ZZ] -= tz;
658 /* Inner loop uses 110 flops */
660 /* End of innermost loop */
663 f[i_coord_offset+DIM*0+XX] += fix0;
664 f[i_coord_offset+DIM*0+YY] += fiy0;
665 f[i_coord_offset+DIM*0+ZZ] += fiz0;
669 f[i_coord_offset+DIM*1+XX] += fix1;
670 f[i_coord_offset+DIM*1+YY] += fiy1;
671 f[i_coord_offset+DIM*1+ZZ] += fiz1;
675 f[i_coord_offset+DIM*2+XX] += fix2;
676 f[i_coord_offset+DIM*2+YY] += fiy2;
677 f[i_coord_offset+DIM*2+ZZ] += fiz2;
681 fshift[i_shift_offset+XX] += tx;
682 fshift[i_shift_offset+YY] += ty;
683 fshift[i_shift_offset+ZZ] += tz;
685 /* Increment number of inner iterations */
686 inneriter += j_index_end - j_index_start;
688 /* Outer loop uses 30 flops */
691 /* Increment number of outer iterations */
694 /* Update outer/inner flops */
696 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*30 + inneriter*110);