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_ElecEwSh_VdwBhamSh_GeomW3P1_VF_c
49 * Electrostatics interaction: Ewald
50 * VdW interaction: Buckingham
51 * Geometry: Water3-Particle
52 * Calculate force/pot: PotentialAndForce
55 nb_kernel_ElecEwSh_VdwBhamSh_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;
88 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
96 jindex = nlist->jindex;
98 shiftidx = nlist->shift;
100 shiftvec = fr->shift_vec[0];
101 fshift = fr->fshift[0];
103 charge = mdatoms->chargeA;
104 nvdwtype = fr->ntype;
106 vdwtype = mdatoms->typeA;
108 sh_ewald = fr->ic->sh_ewald;
109 ewtab = fr->ic->tabq_coul_FDV0;
110 ewtabscale = fr->ic->tabq_scale;
111 ewtabhalfspace = 0.5/ewtabscale;
113 /* Setup water-specific parameters */
114 inr = nlist->iinr[0];
115 iq0 = facel*charge[inr+0];
116 iq1 = facel*charge[inr+1];
117 iq2 = facel*charge[inr+2];
118 vdwioffset0 = 3*nvdwtype*vdwtype[inr+0];
120 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
121 rcutoff = fr->rcoulomb;
122 rcutoff2 = rcutoff*rcutoff;
124 sh_vdw_invrcut6 = fr->ic->sh_invrc6;
130 /* Start outer loop over neighborlists */
131 for(iidx=0; iidx<nri; iidx++)
133 /* Load shift vector for this list */
134 i_shift_offset = DIM*shiftidx[iidx];
135 shX = shiftvec[i_shift_offset+XX];
136 shY = shiftvec[i_shift_offset+YY];
137 shZ = shiftvec[i_shift_offset+ZZ];
139 /* Load limits for loop over neighbors */
140 j_index_start = jindex[iidx];
141 j_index_end = jindex[iidx+1];
143 /* Get outer coordinate index */
145 i_coord_offset = DIM*inr;
147 /* Load i particle coords and add shift vector */
148 ix0 = shX + x[i_coord_offset+DIM*0+XX];
149 iy0 = shY + x[i_coord_offset+DIM*0+YY];
150 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
151 ix1 = shX + x[i_coord_offset+DIM*1+XX];
152 iy1 = shY + x[i_coord_offset+DIM*1+YY];
153 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
154 ix2 = shX + x[i_coord_offset+DIM*2+XX];
155 iy2 = shY + x[i_coord_offset+DIM*2+YY];
156 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
168 /* Reset potential sums */
172 /* Start inner kernel loop */
173 for(jidx=j_index_start; jidx<j_index_end; jidx++)
175 /* Get j neighbor index, and coordinate index */
177 j_coord_offset = DIM*jnr;
179 /* load j atom coordinates */
180 jx0 = x[j_coord_offset+DIM*0+XX];
181 jy0 = x[j_coord_offset+DIM*0+YY];
182 jz0 = x[j_coord_offset+DIM*0+ZZ];
184 /* Calculate displacement vector */
195 /* Calculate squared distance and things based on it */
196 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
197 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
198 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
200 rinv00 = gmx_invsqrt(rsq00);
201 rinv10 = gmx_invsqrt(rsq10);
202 rinv20 = gmx_invsqrt(rsq20);
204 rinvsq00 = rinv00*rinv00;
205 rinvsq10 = rinv10*rinv10;
206 rinvsq20 = rinv20*rinv20;
208 /* Load parameters for j particles */
210 vdwjidx0 = 3*vdwtype[jnr+0];
212 /**************************
213 * CALCULATE INTERACTIONS *
214 **************************/
222 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
223 cexp1_00 = vdwparam[vdwioffset0+vdwjidx0+1];
224 cexp2_00 = vdwparam[vdwioffset0+vdwjidx0+2];
226 /* EWALD ELECTROSTATICS */
228 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
229 ewrt = r00*ewtabscale;
233 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
234 velec = qq00*((rinv00-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
235 felec = qq00*rinv00*(rinvsq00-felec);
237 /* BUCKINGHAM DISPERSION/REPULSION */
238 rinvsix = rinvsq00*rinvsq00*rinvsq00;
239 vvdw6 = c6_00*rinvsix;
241 vvdwexp = cexp1_00*exp(-br);
242 vvdw = (vvdwexp-cexp1_00*exp(-cexp2_00*rvdw)) - (vvdw6 - c6_00*sh_vdw_invrcut6)*(1.0/6.0);
243 fvdw = (br*vvdwexp-vvdw6)*rinvsq00;
245 /* 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 /* Inner loop uses 195 flops */
352 /* End of innermost loop */
355 f[i_coord_offset+DIM*0+XX] += fix0;
356 f[i_coord_offset+DIM*0+YY] += fiy0;
357 f[i_coord_offset+DIM*0+ZZ] += fiz0;
361 f[i_coord_offset+DIM*1+XX] += fix1;
362 f[i_coord_offset+DIM*1+YY] += fiy1;
363 f[i_coord_offset+DIM*1+ZZ] += fiz1;
367 f[i_coord_offset+DIM*2+XX] += fix2;
368 f[i_coord_offset+DIM*2+YY] += fiy2;
369 f[i_coord_offset+DIM*2+ZZ] += fiz2;
373 fshift[i_shift_offset+XX] += tx;
374 fshift[i_shift_offset+YY] += ty;
375 fshift[i_shift_offset+ZZ] += tz;
378 /* Update potential energies */
379 kernel_data->energygrp_elec[ggid] += velecsum;
380 kernel_data->energygrp_vdw[ggid] += vvdwsum;
382 /* Increment number of inner iterations */
383 inneriter += j_index_end - j_index_start;
385 /* Outer loop uses 32 flops */
388 /* Increment number of outer iterations */
391 /* Update outer/inner flops */
393 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*32 + inneriter*195);
396 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwBhamSh_GeomW3P1_F_c
397 * Electrostatics interaction: Ewald
398 * VdW interaction: Buckingham
399 * Geometry: Water3-Particle
400 * Calculate force/pot: Force
403 nb_kernel_ElecEwSh_VdwBhamSh_GeomW3P1_F_c
404 (t_nblist * gmx_restrict nlist,
405 rvec * gmx_restrict xx,
406 rvec * gmx_restrict ff,
407 t_forcerec * gmx_restrict fr,
408 t_mdatoms * gmx_restrict mdatoms,
409 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
410 t_nrnb * gmx_restrict nrnb)
412 int i_shift_offset,i_coord_offset,j_coord_offset;
413 int j_index_start,j_index_end;
414 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
415 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
416 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
417 real *shiftvec,*fshift,*x,*f;
419 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
421 real ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
423 real ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
425 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
426 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
427 real dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
428 real dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
429 real velec,felec,velecsum,facel,crf,krf,krf2;
432 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
436 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
444 jindex = nlist->jindex;
446 shiftidx = nlist->shift;
448 shiftvec = fr->shift_vec[0];
449 fshift = fr->fshift[0];
451 charge = mdatoms->chargeA;
452 nvdwtype = fr->ntype;
454 vdwtype = mdatoms->typeA;
456 sh_ewald = fr->ic->sh_ewald;
457 ewtab = fr->ic->tabq_coul_F;
458 ewtabscale = fr->ic->tabq_scale;
459 ewtabhalfspace = 0.5/ewtabscale;
461 /* Setup water-specific parameters */
462 inr = nlist->iinr[0];
463 iq0 = facel*charge[inr+0];
464 iq1 = facel*charge[inr+1];
465 iq2 = facel*charge[inr+2];
466 vdwioffset0 = 3*nvdwtype*vdwtype[inr+0];
468 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
469 rcutoff = fr->rcoulomb;
470 rcutoff2 = rcutoff*rcutoff;
472 sh_vdw_invrcut6 = fr->ic->sh_invrc6;
478 /* Start outer loop over neighborlists */
479 for(iidx=0; iidx<nri; iidx++)
481 /* Load shift vector for this list */
482 i_shift_offset = DIM*shiftidx[iidx];
483 shX = shiftvec[i_shift_offset+XX];
484 shY = shiftvec[i_shift_offset+YY];
485 shZ = shiftvec[i_shift_offset+ZZ];
487 /* Load limits for loop over neighbors */
488 j_index_start = jindex[iidx];
489 j_index_end = jindex[iidx+1];
491 /* Get outer coordinate index */
493 i_coord_offset = DIM*inr;
495 /* Load i particle coords and add shift vector */
496 ix0 = shX + x[i_coord_offset+DIM*0+XX];
497 iy0 = shY + x[i_coord_offset+DIM*0+YY];
498 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
499 ix1 = shX + x[i_coord_offset+DIM*1+XX];
500 iy1 = shY + x[i_coord_offset+DIM*1+YY];
501 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
502 ix2 = shX + x[i_coord_offset+DIM*2+XX];
503 iy2 = shY + x[i_coord_offset+DIM*2+YY];
504 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
516 /* Start inner kernel loop */
517 for(jidx=j_index_start; jidx<j_index_end; jidx++)
519 /* Get j neighbor index, and coordinate index */
521 j_coord_offset = DIM*jnr;
523 /* load j atom coordinates */
524 jx0 = x[j_coord_offset+DIM*0+XX];
525 jy0 = x[j_coord_offset+DIM*0+YY];
526 jz0 = x[j_coord_offset+DIM*0+ZZ];
528 /* Calculate displacement vector */
539 /* Calculate squared distance and things based on it */
540 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
541 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
542 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
544 rinv00 = gmx_invsqrt(rsq00);
545 rinv10 = gmx_invsqrt(rsq10);
546 rinv20 = gmx_invsqrt(rsq20);
548 rinvsq00 = rinv00*rinv00;
549 rinvsq10 = rinv10*rinv10;
550 rinvsq20 = rinv20*rinv20;
552 /* Load parameters for j particles */
554 vdwjidx0 = 3*vdwtype[jnr+0];
556 /**************************
557 * CALCULATE INTERACTIONS *
558 **************************/
566 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
567 cexp1_00 = vdwparam[vdwioffset0+vdwjidx0+1];
568 cexp2_00 = vdwparam[vdwioffset0+vdwjidx0+2];
570 /* EWALD ELECTROSTATICS */
572 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
573 ewrt = r00*ewtabscale;
576 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
577 felec = qq00*rinv00*(rinvsq00-felec);
579 /* BUCKINGHAM DISPERSION/REPULSION */
580 rinvsix = rinvsq00*rinvsq00*rinvsq00;
581 vvdw6 = c6_00*rinvsix;
583 vvdwexp = cexp1_00*exp(-br);
584 fvdw = (br*vvdwexp-vvdw6)*rinvsq00;
588 /* Calculate temporary vectorial force */
593 /* Update vectorial force */
597 f[j_coord_offset+DIM*0+XX] -= tx;
598 f[j_coord_offset+DIM*0+YY] -= ty;
599 f[j_coord_offset+DIM*0+ZZ] -= tz;
603 /**************************
604 * CALCULATE INTERACTIONS *
605 **************************/
614 /* EWALD ELECTROSTATICS */
616 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
617 ewrt = r10*ewtabscale;
620 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
621 felec = qq10*rinv10*(rinvsq10-felec);
625 /* Calculate temporary vectorial force */
630 /* Update vectorial force */
634 f[j_coord_offset+DIM*0+XX] -= tx;
635 f[j_coord_offset+DIM*0+YY] -= ty;
636 f[j_coord_offset+DIM*0+ZZ] -= tz;
640 /**************************
641 * CALCULATE INTERACTIONS *
642 **************************/
651 /* EWALD ELECTROSTATICS */
653 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
654 ewrt = r20*ewtabscale;
657 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
658 felec = qq20*rinv20*(rinvsq20-felec);
662 /* Calculate temporary vectorial force */
667 /* Update vectorial force */
671 f[j_coord_offset+DIM*0+XX] -= tx;
672 f[j_coord_offset+DIM*0+YY] -= ty;
673 f[j_coord_offset+DIM*0+ZZ] -= tz;
677 /* Inner loop uses 137 flops */
679 /* End of innermost loop */
682 f[i_coord_offset+DIM*0+XX] += fix0;
683 f[i_coord_offset+DIM*0+YY] += fiy0;
684 f[i_coord_offset+DIM*0+ZZ] += fiz0;
688 f[i_coord_offset+DIM*1+XX] += fix1;
689 f[i_coord_offset+DIM*1+YY] += fiy1;
690 f[i_coord_offset+DIM*1+ZZ] += fiz1;
694 f[i_coord_offset+DIM*2+XX] += fix2;
695 f[i_coord_offset+DIM*2+YY] += fiy2;
696 f[i_coord_offset+DIM*2+ZZ] += fiz2;
700 fshift[i_shift_offset+XX] += tx;
701 fshift[i_shift_offset+YY] += ty;
702 fshift[i_shift_offset+ZZ] += tz;
704 /* Increment number of inner iterations */
705 inneriter += j_index_end - j_index_start;
707 /* Outer loop uses 30 flops */
710 /* Increment number of outer iterations */
713 /* Update outer/inner flops */
715 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*30 + inneriter*137);