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.
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_VF_c
51 * Electrostatics interaction: Ewald
52 * VdW interaction: LennardJones
53 * Geometry: Water4-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_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 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
77 real ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
79 real ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
81 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
82 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
83 real dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
84 real dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
85 real dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
86 real velec,felec,velecsum,facel,crf,krf,krf2;
89 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
93 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
101 jindex = nlist->jindex;
103 shiftidx = nlist->shift;
105 shiftvec = fr->shift_vec[0];
106 fshift = fr->fshift[0];
108 charge = mdatoms->chargeA;
109 nvdwtype = fr->ntype;
111 vdwtype = mdatoms->typeA;
113 sh_ewald = fr->ic->sh_ewald;
114 ewtab = fr->ic->tabq_coul_FDV0;
115 ewtabscale = fr->ic->tabq_scale;
116 ewtabhalfspace = 0.5/ewtabscale;
118 /* Setup water-specific parameters */
119 inr = nlist->iinr[0];
120 iq1 = facel*charge[inr+1];
121 iq2 = facel*charge[inr+2];
122 iq3 = facel*charge[inr+3];
123 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
125 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
126 rcutoff = fr->rcoulomb;
127 rcutoff2 = rcutoff*rcutoff;
129 sh_vdw_invrcut6 = fr->ic->sh_invrc6;
135 /* Start outer loop over neighborlists */
136 for(iidx=0; iidx<nri; iidx++)
138 /* Load shift vector for this list */
139 i_shift_offset = DIM*shiftidx[iidx];
140 shX = shiftvec[i_shift_offset+XX];
141 shY = shiftvec[i_shift_offset+YY];
142 shZ = shiftvec[i_shift_offset+ZZ];
144 /* Load limits for loop over neighbors */
145 j_index_start = jindex[iidx];
146 j_index_end = jindex[iidx+1];
148 /* Get outer coordinate index */
150 i_coord_offset = DIM*inr;
152 /* Load i particle coords and add shift vector */
153 ix0 = shX + x[i_coord_offset+DIM*0+XX];
154 iy0 = shY + x[i_coord_offset+DIM*0+YY];
155 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
156 ix1 = shX + x[i_coord_offset+DIM*1+XX];
157 iy1 = shY + x[i_coord_offset+DIM*1+YY];
158 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
159 ix2 = shX + x[i_coord_offset+DIM*2+XX];
160 iy2 = shY + x[i_coord_offset+DIM*2+YY];
161 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
162 ix3 = shX + x[i_coord_offset+DIM*3+XX];
163 iy3 = shY + x[i_coord_offset+DIM*3+YY];
164 iz3 = shZ + x[i_coord_offset+DIM*3+ZZ];
179 /* Reset potential sums */
183 /* Start inner kernel loop */
184 for(jidx=j_index_start; jidx<j_index_end; jidx++)
186 /* Get j neighbor index, and coordinate index */
188 j_coord_offset = DIM*jnr;
190 /* load j atom coordinates */
191 jx0 = x[j_coord_offset+DIM*0+XX];
192 jy0 = x[j_coord_offset+DIM*0+YY];
193 jz0 = x[j_coord_offset+DIM*0+ZZ];
195 /* Calculate displacement vector */
209 /* Calculate squared distance and things based on it */
210 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
211 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
212 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
213 rsq30 = dx30*dx30+dy30*dy30+dz30*dz30;
215 rinv10 = gmx_invsqrt(rsq10);
216 rinv20 = gmx_invsqrt(rsq20);
217 rinv30 = gmx_invsqrt(rsq30);
219 rinvsq00 = 1.0/rsq00;
220 rinvsq10 = rinv10*rinv10;
221 rinvsq20 = rinv20*rinv20;
222 rinvsq30 = rinv30*rinv30;
224 /* Load parameters for j particles */
226 vdwjidx0 = 2*vdwtype[jnr+0];
228 /**************************
229 * CALCULATE INTERACTIONS *
230 **************************/
235 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
236 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
238 /* LENNARD-JONES DISPERSION/REPULSION */
240 rinvsix = rinvsq00*rinvsq00*rinvsq00;
241 vvdw6 = c6_00*rinvsix;
242 vvdw12 = c12_00*rinvsix*rinvsix;
243 vvdw = (vvdw12 - c12_00*sh_vdw_invrcut6*sh_vdw_invrcut6)*(1.0/12.0) - (vvdw6 - c6_00*sh_vdw_invrcut6)*(1.0/6.0);
244 fvdw = (vvdw12-vvdw6)*rinvsq00;
246 /* Update potential sums from outer loop */
251 /* Calculate temporary vectorial force */
256 /* Update vectorial force */
260 f[j_coord_offset+DIM*0+XX] -= tx;
261 f[j_coord_offset+DIM*0+YY] -= ty;
262 f[j_coord_offset+DIM*0+ZZ] -= tz;
266 /**************************
267 * CALCULATE INTERACTIONS *
268 **************************/
277 /* EWALD ELECTROSTATICS */
279 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
280 ewrt = r10*ewtabscale;
284 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
285 velec = qq10*((rinv10-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
286 felec = qq10*rinv10*(rinvsq10-felec);
288 /* Update potential sums from outer loop */
293 /* Calculate temporary vectorial force */
298 /* Update vectorial force */
302 f[j_coord_offset+DIM*0+XX] -= tx;
303 f[j_coord_offset+DIM*0+YY] -= ty;
304 f[j_coord_offset+DIM*0+ZZ] -= tz;
308 /**************************
309 * CALCULATE INTERACTIONS *
310 **************************/
319 /* EWALD ELECTROSTATICS */
321 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
322 ewrt = r20*ewtabscale;
326 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
327 velec = qq20*((rinv20-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
328 felec = qq20*rinv20*(rinvsq20-felec);
330 /* Update potential sums from outer loop */
335 /* Calculate temporary vectorial force */
340 /* Update vectorial force */
344 f[j_coord_offset+DIM*0+XX] -= tx;
345 f[j_coord_offset+DIM*0+YY] -= ty;
346 f[j_coord_offset+DIM*0+ZZ] -= tz;
350 /**************************
351 * CALCULATE INTERACTIONS *
352 **************************/
361 /* EWALD ELECTROSTATICS */
363 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
364 ewrt = r30*ewtabscale;
368 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
369 velec = qq30*((rinv30-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
370 felec = qq30*rinv30*(rinvsq30-felec);
372 /* Update potential sums from outer loop */
377 /* Calculate temporary vectorial force */
382 /* Update vectorial force */
386 f[j_coord_offset+DIM*0+XX] -= tx;
387 f[j_coord_offset+DIM*0+YY] -= ty;
388 f[j_coord_offset+DIM*0+ZZ] -= tz;
392 /* Inner loop uses 163 flops */
394 /* End of innermost loop */
397 f[i_coord_offset+DIM*0+XX] += fix0;
398 f[i_coord_offset+DIM*0+YY] += fiy0;
399 f[i_coord_offset+DIM*0+ZZ] += fiz0;
403 f[i_coord_offset+DIM*1+XX] += fix1;
404 f[i_coord_offset+DIM*1+YY] += fiy1;
405 f[i_coord_offset+DIM*1+ZZ] += fiz1;
409 f[i_coord_offset+DIM*2+XX] += fix2;
410 f[i_coord_offset+DIM*2+YY] += fiy2;
411 f[i_coord_offset+DIM*2+ZZ] += fiz2;
415 f[i_coord_offset+DIM*3+XX] += fix3;
416 f[i_coord_offset+DIM*3+YY] += fiy3;
417 f[i_coord_offset+DIM*3+ZZ] += fiz3;
421 fshift[i_shift_offset+XX] += tx;
422 fshift[i_shift_offset+YY] += ty;
423 fshift[i_shift_offset+ZZ] += tz;
426 /* Update potential energies */
427 kernel_data->energygrp_elec[ggid] += velecsum;
428 kernel_data->energygrp_vdw[ggid] += vvdwsum;
430 /* Increment number of inner iterations */
431 inneriter += j_index_end - j_index_start;
433 /* Outer loop uses 41 flops */
436 /* Increment number of outer iterations */
439 /* Update outer/inner flops */
441 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*41 + inneriter*163);
444 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_F_c
445 * Electrostatics interaction: Ewald
446 * VdW interaction: LennardJones
447 * Geometry: Water4-Particle
448 * Calculate force/pot: Force
451 nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_F_c
452 (t_nblist * gmx_restrict nlist,
453 rvec * gmx_restrict xx,
454 rvec * gmx_restrict ff,
455 t_forcerec * gmx_restrict fr,
456 t_mdatoms * gmx_restrict mdatoms,
457 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
458 t_nrnb * gmx_restrict nrnb)
460 int i_shift_offset,i_coord_offset,j_coord_offset;
461 int j_index_start,j_index_end;
462 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
463 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
464 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
465 real *shiftvec,*fshift,*x,*f;
467 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
469 real ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
471 real ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
473 real ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
475 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
476 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
477 real dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
478 real dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
479 real dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
480 real velec,felec,velecsum,facel,crf,krf,krf2;
483 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
487 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
495 jindex = nlist->jindex;
497 shiftidx = nlist->shift;
499 shiftvec = fr->shift_vec[0];
500 fshift = fr->fshift[0];
502 charge = mdatoms->chargeA;
503 nvdwtype = fr->ntype;
505 vdwtype = mdatoms->typeA;
507 sh_ewald = fr->ic->sh_ewald;
508 ewtab = fr->ic->tabq_coul_F;
509 ewtabscale = fr->ic->tabq_scale;
510 ewtabhalfspace = 0.5/ewtabscale;
512 /* Setup water-specific parameters */
513 inr = nlist->iinr[0];
514 iq1 = facel*charge[inr+1];
515 iq2 = facel*charge[inr+2];
516 iq3 = facel*charge[inr+3];
517 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
519 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
520 rcutoff = fr->rcoulomb;
521 rcutoff2 = rcutoff*rcutoff;
523 sh_vdw_invrcut6 = fr->ic->sh_invrc6;
529 /* Start outer loop over neighborlists */
530 for(iidx=0; iidx<nri; iidx++)
532 /* Load shift vector for this list */
533 i_shift_offset = DIM*shiftidx[iidx];
534 shX = shiftvec[i_shift_offset+XX];
535 shY = shiftvec[i_shift_offset+YY];
536 shZ = shiftvec[i_shift_offset+ZZ];
538 /* Load limits for loop over neighbors */
539 j_index_start = jindex[iidx];
540 j_index_end = jindex[iidx+1];
542 /* Get outer coordinate index */
544 i_coord_offset = DIM*inr;
546 /* Load i particle coords and add shift vector */
547 ix0 = shX + x[i_coord_offset+DIM*0+XX];
548 iy0 = shY + x[i_coord_offset+DIM*0+YY];
549 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
550 ix1 = shX + x[i_coord_offset+DIM*1+XX];
551 iy1 = shY + x[i_coord_offset+DIM*1+YY];
552 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
553 ix2 = shX + x[i_coord_offset+DIM*2+XX];
554 iy2 = shY + x[i_coord_offset+DIM*2+YY];
555 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
556 ix3 = shX + x[i_coord_offset+DIM*3+XX];
557 iy3 = shY + x[i_coord_offset+DIM*3+YY];
558 iz3 = shZ + x[i_coord_offset+DIM*3+ZZ];
573 /* Start inner kernel loop */
574 for(jidx=j_index_start; jidx<j_index_end; jidx++)
576 /* Get j neighbor index, and coordinate index */
578 j_coord_offset = DIM*jnr;
580 /* load j atom coordinates */
581 jx0 = x[j_coord_offset+DIM*0+XX];
582 jy0 = x[j_coord_offset+DIM*0+YY];
583 jz0 = x[j_coord_offset+DIM*0+ZZ];
585 /* Calculate displacement vector */
599 /* Calculate squared distance and things based on it */
600 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
601 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
602 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
603 rsq30 = dx30*dx30+dy30*dy30+dz30*dz30;
605 rinv10 = gmx_invsqrt(rsq10);
606 rinv20 = gmx_invsqrt(rsq20);
607 rinv30 = gmx_invsqrt(rsq30);
609 rinvsq00 = 1.0/rsq00;
610 rinvsq10 = rinv10*rinv10;
611 rinvsq20 = rinv20*rinv20;
612 rinvsq30 = rinv30*rinv30;
614 /* Load parameters for j particles */
616 vdwjidx0 = 2*vdwtype[jnr+0];
618 /**************************
619 * CALCULATE INTERACTIONS *
620 **************************/
625 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
626 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
628 /* LENNARD-JONES DISPERSION/REPULSION */
630 rinvsix = rinvsq00*rinvsq00*rinvsq00;
631 fvdw = (c12_00*rinvsix-c6_00)*rinvsix*rinvsq00;
635 /* Calculate temporary vectorial force */
640 /* Update vectorial force */
644 f[j_coord_offset+DIM*0+XX] -= tx;
645 f[j_coord_offset+DIM*0+YY] -= ty;
646 f[j_coord_offset+DIM*0+ZZ] -= tz;
650 /**************************
651 * CALCULATE INTERACTIONS *
652 **************************/
661 /* EWALD ELECTROSTATICS */
663 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
664 ewrt = r10*ewtabscale;
667 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
668 felec = qq10*rinv10*(rinvsq10-felec);
672 /* Calculate temporary vectorial force */
677 /* Update vectorial force */
681 f[j_coord_offset+DIM*0+XX] -= tx;
682 f[j_coord_offset+DIM*0+YY] -= ty;
683 f[j_coord_offset+DIM*0+ZZ] -= tz;
687 /**************************
688 * CALCULATE INTERACTIONS *
689 **************************/
698 /* EWALD ELECTROSTATICS */
700 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
701 ewrt = r20*ewtabscale;
704 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
705 felec = qq20*rinv20*(rinvsq20-felec);
709 /* Calculate temporary vectorial force */
714 /* Update vectorial force */
718 f[j_coord_offset+DIM*0+XX] -= tx;
719 f[j_coord_offset+DIM*0+YY] -= ty;
720 f[j_coord_offset+DIM*0+ZZ] -= tz;
724 /**************************
725 * CALCULATE INTERACTIONS *
726 **************************/
735 /* EWALD ELECTROSTATICS */
737 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
738 ewrt = r30*ewtabscale;
741 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
742 felec = qq30*rinv30*(rinvsq30-felec);
746 /* Calculate temporary vectorial force */
751 /* Update vectorial force */
755 f[j_coord_offset+DIM*0+XX] -= tx;
756 f[j_coord_offset+DIM*0+YY] -= ty;
757 f[j_coord_offset+DIM*0+ZZ] -= tz;
761 /* Inner loop uses 129 flops */
763 /* End of innermost loop */
766 f[i_coord_offset+DIM*0+XX] += fix0;
767 f[i_coord_offset+DIM*0+YY] += fiy0;
768 f[i_coord_offset+DIM*0+ZZ] += fiz0;
772 f[i_coord_offset+DIM*1+XX] += fix1;
773 f[i_coord_offset+DIM*1+YY] += fiy1;
774 f[i_coord_offset+DIM*1+ZZ] += fiz1;
778 f[i_coord_offset+DIM*2+XX] += fix2;
779 f[i_coord_offset+DIM*2+YY] += fiy2;
780 f[i_coord_offset+DIM*2+ZZ] += fiz2;
784 f[i_coord_offset+DIM*3+XX] += fix3;
785 f[i_coord_offset+DIM*3+YY] += fiy3;
786 f[i_coord_offset+DIM*3+ZZ] += fiz3;
790 fshift[i_shift_offset+XX] += tx;
791 fshift[i_shift_offset+YY] += ty;
792 fshift[i_shift_offset+ZZ] += tz;
794 /* Increment number of inner iterations */
795 inneriter += j_index_end - j_index_start;
797 /* Outer loop uses 39 flops */
800 /* Increment number of outer iterations */
803 /* Update outer/inner flops */
805 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*39 + inneriter*129);