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_GeomW4P1_VF_c
49 * Electrostatics interaction: ReactionField
50 * VdW interaction: LennardJones
51 * Geometry: Water4-Particle
52 * Calculate force/pot: PotentialAndForce
55 nb_kernel_ElecRFCut_VdwLJSw_GeomW4P1_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 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
79 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
80 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
81 real dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
82 real dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
83 real dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
84 real velec,felec,velecsum,facel,crf,krf,krf2;
87 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
90 real rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
97 jindex = nlist->jindex;
99 shiftidx = nlist->shift;
101 shiftvec = fr->shift_vec[0];
102 fshift = fr->fshift[0];
104 charge = mdatoms->chargeA;
108 nvdwtype = fr->ntype;
110 vdwtype = mdatoms->typeA;
112 /* Setup water-specific parameters */
113 inr = nlist->iinr[0];
114 iq1 = facel*charge[inr+1];
115 iq2 = facel*charge[inr+2];
116 iq3 = facel*charge[inr+3];
117 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
119 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
120 rcutoff = fr->rcoulomb;
121 rcutoff2 = rcutoff*rcutoff;
123 rswitch = fr->rvdw_switch;
124 /* Setup switch parameters */
126 swV3 = -10.0/(d*d*d);
127 swV4 = 15.0/(d*d*d*d);
128 swV5 = -6.0/(d*d*d*d*d);
129 swF2 = -30.0/(d*d*d);
130 swF3 = 60.0/(d*d*d*d);
131 swF4 = -30.0/(d*d*d*d*d);
136 /* Start outer loop over neighborlists */
137 for(iidx=0; iidx<nri; iidx++)
139 /* Load shift vector for this list */
140 i_shift_offset = DIM*shiftidx[iidx];
141 shX = shiftvec[i_shift_offset+XX];
142 shY = shiftvec[i_shift_offset+YY];
143 shZ = shiftvec[i_shift_offset+ZZ];
145 /* Load limits for loop over neighbors */
146 j_index_start = jindex[iidx];
147 j_index_end = jindex[iidx+1];
149 /* Get outer coordinate index */
151 i_coord_offset = DIM*inr;
153 /* Load i particle coords and add shift vector */
154 ix0 = shX + x[i_coord_offset+DIM*0+XX];
155 iy0 = shY + x[i_coord_offset+DIM*0+YY];
156 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
157 ix1 = shX + x[i_coord_offset+DIM*1+XX];
158 iy1 = shY + x[i_coord_offset+DIM*1+YY];
159 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
160 ix2 = shX + x[i_coord_offset+DIM*2+XX];
161 iy2 = shY + x[i_coord_offset+DIM*2+YY];
162 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
163 ix3 = shX + x[i_coord_offset+DIM*3+XX];
164 iy3 = shY + x[i_coord_offset+DIM*3+YY];
165 iz3 = shZ + x[i_coord_offset+DIM*3+ZZ];
180 /* Reset potential sums */
184 /* Start inner kernel loop */
185 for(jidx=j_index_start; jidx<j_index_end; jidx++)
187 /* Get j neighbor index, and coordinate index */
189 j_coord_offset = DIM*jnr;
191 /* load j atom coordinates */
192 jx0 = x[j_coord_offset+DIM*0+XX];
193 jy0 = x[j_coord_offset+DIM*0+YY];
194 jz0 = x[j_coord_offset+DIM*0+ZZ];
196 /* Calculate displacement vector */
210 /* Calculate squared distance and things based on it */
211 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
212 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
213 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
214 rsq30 = dx30*dx30+dy30*dy30+dz30*dz30;
216 rinv00 = gmx_invsqrt(rsq00);
217 rinv10 = gmx_invsqrt(rsq10);
218 rinv20 = gmx_invsqrt(rsq20);
219 rinv30 = gmx_invsqrt(rsq30);
221 rinvsq00 = rinv00*rinv00;
222 rinvsq10 = rinv10*rinv10;
223 rinvsq20 = rinv20*rinv20;
224 rinvsq30 = rinv30*rinv30;
226 /* Load parameters for j particles */
228 vdwjidx0 = 2*vdwtype[jnr+0];
230 /**************************
231 * CALCULATE INTERACTIONS *
232 **************************/
239 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
240 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
242 /* LENNARD-JONES DISPERSION/REPULSION */
244 rinvsix = rinvsq00*rinvsq00*rinvsq00;
245 vvdw6 = c6_00*rinvsix;
246 vvdw12 = c12_00*rinvsix*rinvsix;
247 vvdw = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
248 fvdw = (vvdw12-vvdw6)*rinvsq00;
251 d = (d>0.0) ? d : 0.0;
253 sw = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
255 dsw = d2*(swF2+d*(swF3+d*swF4));
257 /* Evaluate switch function */
258 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
259 fvdw = fvdw*sw - rinv00*vvdw*dsw;
262 /* Update potential sums from outer loop */
267 /* Calculate temporary vectorial force */
272 /* Update vectorial force */
276 f[j_coord_offset+DIM*0+XX] -= tx;
277 f[j_coord_offset+DIM*0+YY] -= ty;
278 f[j_coord_offset+DIM*0+ZZ] -= tz;
282 /**************************
283 * CALCULATE INTERACTIONS *
284 **************************/
291 /* REACTION-FIELD ELECTROSTATICS */
292 velec = qq10*(rinv10+krf*rsq10-crf);
293 felec = qq10*(rinv10*rinvsq10-krf2);
295 /* Update potential sums from outer loop */
300 /* Calculate temporary vectorial force */
305 /* Update vectorial force */
309 f[j_coord_offset+DIM*0+XX] -= tx;
310 f[j_coord_offset+DIM*0+YY] -= ty;
311 f[j_coord_offset+DIM*0+ZZ] -= tz;
315 /**************************
316 * CALCULATE INTERACTIONS *
317 **************************/
324 /* REACTION-FIELD ELECTROSTATICS */
325 velec = qq20*(rinv20+krf*rsq20-crf);
326 felec = qq20*(rinv20*rinvsq20-krf2);
328 /* Update potential sums from outer loop */
333 /* Calculate temporary vectorial force */
338 /* Update vectorial force */
342 f[j_coord_offset+DIM*0+XX] -= tx;
343 f[j_coord_offset+DIM*0+YY] -= ty;
344 f[j_coord_offset+DIM*0+ZZ] -= tz;
348 /**************************
349 * CALCULATE INTERACTIONS *
350 **************************/
357 /* REACTION-FIELD ELECTROSTATICS */
358 velec = qq30*(rinv30+krf*rsq30-crf);
359 felec = qq30*(rinv30*rinvsq30-krf2);
361 /* Update potential sums from outer loop */
366 /* Calculate temporary vectorial force */
371 /* Update vectorial force */
375 f[j_coord_offset+DIM*0+XX] -= tx;
376 f[j_coord_offset+DIM*0+YY] -= ty;
377 f[j_coord_offset+DIM*0+ZZ] -= tz;
381 /* Inner loop uses 149 flops */
383 /* End of innermost loop */
386 f[i_coord_offset+DIM*0+XX] += fix0;
387 f[i_coord_offset+DIM*0+YY] += fiy0;
388 f[i_coord_offset+DIM*0+ZZ] += fiz0;
392 f[i_coord_offset+DIM*1+XX] += fix1;
393 f[i_coord_offset+DIM*1+YY] += fiy1;
394 f[i_coord_offset+DIM*1+ZZ] += fiz1;
398 f[i_coord_offset+DIM*2+XX] += fix2;
399 f[i_coord_offset+DIM*2+YY] += fiy2;
400 f[i_coord_offset+DIM*2+ZZ] += fiz2;
404 f[i_coord_offset+DIM*3+XX] += fix3;
405 f[i_coord_offset+DIM*3+YY] += fiy3;
406 f[i_coord_offset+DIM*3+ZZ] += fiz3;
410 fshift[i_shift_offset+XX] += tx;
411 fshift[i_shift_offset+YY] += ty;
412 fshift[i_shift_offset+ZZ] += tz;
415 /* Update potential energies */
416 kernel_data->energygrp_elec[ggid] += velecsum;
417 kernel_data->energygrp_vdw[ggid] += vvdwsum;
419 /* Increment number of inner iterations */
420 inneriter += j_index_end - j_index_start;
422 /* Outer loop uses 41 flops */
425 /* Increment number of outer iterations */
428 /* Update outer/inner flops */
430 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*41 + inneriter*149);
433 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomW4P1_F_c
434 * Electrostatics interaction: ReactionField
435 * VdW interaction: LennardJones
436 * Geometry: Water4-Particle
437 * Calculate force/pot: Force
440 nb_kernel_ElecRFCut_VdwLJSw_GeomW4P1_F_c
441 (t_nblist * gmx_restrict nlist,
442 rvec * gmx_restrict xx,
443 rvec * gmx_restrict ff,
444 t_forcerec * gmx_restrict fr,
445 t_mdatoms * gmx_restrict mdatoms,
446 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
447 t_nrnb * gmx_restrict nrnb)
449 int i_shift_offset,i_coord_offset,j_coord_offset;
450 int j_index_start,j_index_end;
451 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
452 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
453 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
454 real *shiftvec,*fshift,*x,*f;
456 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
458 real ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
460 real ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
462 real ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
464 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
465 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
466 real dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
467 real dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
468 real dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
469 real velec,felec,velecsum,facel,crf,krf,krf2;
472 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
475 real rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
482 jindex = nlist->jindex;
484 shiftidx = nlist->shift;
486 shiftvec = fr->shift_vec[0];
487 fshift = fr->fshift[0];
489 charge = mdatoms->chargeA;
493 nvdwtype = fr->ntype;
495 vdwtype = mdatoms->typeA;
497 /* Setup water-specific parameters */
498 inr = nlist->iinr[0];
499 iq1 = facel*charge[inr+1];
500 iq2 = facel*charge[inr+2];
501 iq3 = facel*charge[inr+3];
502 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
504 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
505 rcutoff = fr->rcoulomb;
506 rcutoff2 = rcutoff*rcutoff;
508 rswitch = fr->rvdw_switch;
509 /* Setup switch parameters */
511 swV3 = -10.0/(d*d*d);
512 swV4 = 15.0/(d*d*d*d);
513 swV5 = -6.0/(d*d*d*d*d);
514 swF2 = -30.0/(d*d*d);
515 swF3 = 60.0/(d*d*d*d);
516 swF4 = -30.0/(d*d*d*d*d);
521 /* Start outer loop over neighborlists */
522 for(iidx=0; iidx<nri; iidx++)
524 /* Load shift vector for this list */
525 i_shift_offset = DIM*shiftidx[iidx];
526 shX = shiftvec[i_shift_offset+XX];
527 shY = shiftvec[i_shift_offset+YY];
528 shZ = shiftvec[i_shift_offset+ZZ];
530 /* Load limits for loop over neighbors */
531 j_index_start = jindex[iidx];
532 j_index_end = jindex[iidx+1];
534 /* Get outer coordinate index */
536 i_coord_offset = DIM*inr;
538 /* Load i particle coords and add shift vector */
539 ix0 = shX + x[i_coord_offset+DIM*0+XX];
540 iy0 = shY + x[i_coord_offset+DIM*0+YY];
541 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
542 ix1 = shX + x[i_coord_offset+DIM*1+XX];
543 iy1 = shY + x[i_coord_offset+DIM*1+YY];
544 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
545 ix2 = shX + x[i_coord_offset+DIM*2+XX];
546 iy2 = shY + x[i_coord_offset+DIM*2+YY];
547 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
548 ix3 = shX + x[i_coord_offset+DIM*3+XX];
549 iy3 = shY + x[i_coord_offset+DIM*3+YY];
550 iz3 = shZ + x[i_coord_offset+DIM*3+ZZ];
565 /* Start inner kernel loop */
566 for(jidx=j_index_start; jidx<j_index_end; jidx++)
568 /* Get j neighbor index, and coordinate index */
570 j_coord_offset = DIM*jnr;
572 /* load j atom coordinates */
573 jx0 = x[j_coord_offset+DIM*0+XX];
574 jy0 = x[j_coord_offset+DIM*0+YY];
575 jz0 = x[j_coord_offset+DIM*0+ZZ];
577 /* Calculate displacement vector */
591 /* Calculate squared distance and things based on it */
592 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
593 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
594 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
595 rsq30 = dx30*dx30+dy30*dy30+dz30*dz30;
597 rinv00 = gmx_invsqrt(rsq00);
598 rinv10 = gmx_invsqrt(rsq10);
599 rinv20 = gmx_invsqrt(rsq20);
600 rinv30 = gmx_invsqrt(rsq30);
602 rinvsq00 = rinv00*rinv00;
603 rinvsq10 = rinv10*rinv10;
604 rinvsq20 = rinv20*rinv20;
605 rinvsq30 = rinv30*rinv30;
607 /* Load parameters for j particles */
609 vdwjidx0 = 2*vdwtype[jnr+0];
611 /**************************
612 * CALCULATE INTERACTIONS *
613 **************************/
620 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
621 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
623 /* LENNARD-JONES DISPERSION/REPULSION */
625 rinvsix = rinvsq00*rinvsq00*rinvsq00;
626 vvdw6 = c6_00*rinvsix;
627 vvdw12 = c12_00*rinvsix*rinvsix;
628 vvdw = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
629 fvdw = (vvdw12-vvdw6)*rinvsq00;
632 d = (d>0.0) ? d : 0.0;
634 sw = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
636 dsw = d2*(swF2+d*(swF3+d*swF4));
638 /* Evaluate switch function */
639 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
640 fvdw = fvdw*sw - rinv00*vvdw*dsw;
644 /* Calculate temporary vectorial force */
649 /* Update vectorial force */
653 f[j_coord_offset+DIM*0+XX] -= tx;
654 f[j_coord_offset+DIM*0+YY] -= ty;
655 f[j_coord_offset+DIM*0+ZZ] -= tz;
659 /**************************
660 * CALCULATE INTERACTIONS *
661 **************************/
668 /* REACTION-FIELD ELECTROSTATICS */
669 felec = qq10*(rinv10*rinvsq10-krf2);
673 /* Calculate temporary vectorial force */
678 /* Update vectorial force */
682 f[j_coord_offset+DIM*0+XX] -= tx;
683 f[j_coord_offset+DIM*0+YY] -= ty;
684 f[j_coord_offset+DIM*0+ZZ] -= tz;
688 /**************************
689 * CALCULATE INTERACTIONS *
690 **************************/
697 /* REACTION-FIELD ELECTROSTATICS */
698 felec = qq20*(rinv20*rinvsq20-krf2);
702 /* Calculate temporary vectorial force */
707 /* Update vectorial force */
711 f[j_coord_offset+DIM*0+XX] -= tx;
712 f[j_coord_offset+DIM*0+YY] -= ty;
713 f[j_coord_offset+DIM*0+ZZ] -= tz;
717 /**************************
718 * CALCULATE INTERACTIONS *
719 **************************/
726 /* REACTION-FIELD ELECTROSTATICS */
727 felec = qq30*(rinv30*rinvsq30-krf2);
731 /* Calculate temporary vectorial force */
736 /* Update vectorial force */
740 f[j_coord_offset+DIM*0+XX] -= tx;
741 f[j_coord_offset+DIM*0+YY] -= ty;
742 f[j_coord_offset+DIM*0+ZZ] -= tz;
746 /* Inner loop uses 132 flops */
748 /* End of innermost loop */
751 f[i_coord_offset+DIM*0+XX] += fix0;
752 f[i_coord_offset+DIM*0+YY] += fiy0;
753 f[i_coord_offset+DIM*0+ZZ] += fiz0;
757 f[i_coord_offset+DIM*1+XX] += fix1;
758 f[i_coord_offset+DIM*1+YY] += fiy1;
759 f[i_coord_offset+DIM*1+ZZ] += fiz1;
763 f[i_coord_offset+DIM*2+XX] += fix2;
764 f[i_coord_offset+DIM*2+YY] += fiy2;
765 f[i_coord_offset+DIM*2+ZZ] += fiz2;
769 f[i_coord_offset+DIM*3+XX] += fix3;
770 f[i_coord_offset+DIM*3+YY] += fiy3;
771 f[i_coord_offset+DIM*3+ZZ] += fiz3;
775 fshift[i_shift_offset+XX] += tx;
776 fshift[i_shift_offset+YY] += ty;
777 fshift[i_shift_offset+ZZ] += tz;
779 /* Increment number of inner iterations */
780 inneriter += j_index_end - j_index_start;
782 /* Outer loop uses 39 flops */
785 /* Increment number of outer iterations */
788 /* Update outer/inner flops */
790 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*39 + inneriter*132);