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_VdwLJEwSh_GeomW3P1_VF_c
51 * Electrostatics interaction: Ewald
52 * VdW interaction: LJEwald
53 * Geometry: Water3-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecEwSh_VdwLJEwSh_GeomW3P1_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 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 velec,felec,velecsum,facel,crf,krf,krf2;
86 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
92 real ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,sh_lj_ewald;
95 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
103 jindex = nlist->jindex;
105 shiftidx = nlist->shift;
107 shiftvec = fr->shift_vec[0];
108 fshift = fr->fshift[0];
110 charge = mdatoms->chargeA;
111 nvdwtype = fr->ntype;
113 vdwtype = mdatoms->typeA;
114 vdwgridparam = fr->ljpme_c6grid;
115 ewclj = fr->ewaldcoeff_lj;
116 sh_lj_ewald = fr->ic->sh_lj_ewald;
117 ewclj2 = ewclj*ewclj;
118 ewclj6 = ewclj2*ewclj2*ewclj2;
120 sh_ewald = fr->ic->sh_ewald;
121 ewtab = fr->ic->tabq_coul_FDV0;
122 ewtabscale = fr->ic->tabq_scale;
123 ewtabhalfspace = 0.5/ewtabscale;
125 /* Setup water-specific parameters */
126 inr = nlist->iinr[0];
127 iq0 = facel*charge[inr+0];
128 iq1 = facel*charge[inr+1];
129 iq2 = facel*charge[inr+2];
130 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
132 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
133 rcutoff = fr->rcoulomb;
134 rcutoff2 = rcutoff*rcutoff;
136 sh_vdw_invrcut6 = fr->ic->sh_invrc6;
142 /* Start outer loop over neighborlists */
143 for(iidx=0; iidx<nri; iidx++)
145 /* Load shift vector for this list */
146 i_shift_offset = DIM*shiftidx[iidx];
147 shX = shiftvec[i_shift_offset+XX];
148 shY = shiftvec[i_shift_offset+YY];
149 shZ = shiftvec[i_shift_offset+ZZ];
151 /* Load limits for loop over neighbors */
152 j_index_start = jindex[iidx];
153 j_index_end = jindex[iidx+1];
155 /* Get outer coordinate index */
157 i_coord_offset = DIM*inr;
159 /* Load i particle coords and add shift vector */
160 ix0 = shX + x[i_coord_offset+DIM*0+XX];
161 iy0 = shY + x[i_coord_offset+DIM*0+YY];
162 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
163 ix1 = shX + x[i_coord_offset+DIM*1+XX];
164 iy1 = shY + x[i_coord_offset+DIM*1+YY];
165 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
166 ix2 = shX + x[i_coord_offset+DIM*2+XX];
167 iy2 = shY + x[i_coord_offset+DIM*2+YY];
168 iz2 = shZ + x[i_coord_offset+DIM*2+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 */
207 /* Calculate squared distance and things based on it */
208 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
209 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
210 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
212 rinv00 = gmx_invsqrt(rsq00);
213 rinv10 = gmx_invsqrt(rsq10);
214 rinv20 = gmx_invsqrt(rsq20);
216 rinvsq00 = rinv00*rinv00;
217 rinvsq10 = rinv10*rinv10;
218 rinvsq20 = rinv20*rinv20;
220 /* Load parameters for j particles */
222 vdwjidx0 = 2*vdwtype[jnr+0];
224 /**************************
225 * CALCULATE INTERACTIONS *
226 **************************/
234 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
235 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
236 c6grid_00 = vdwgridparam[vdwioffset0+vdwjidx0];
238 /* EWALD ELECTROSTATICS */
240 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
241 ewrt = r00*ewtabscale;
245 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
246 velec = qq00*((rinv00-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
247 felec = qq00*rinv00*(rinvsq00-felec);
249 rinvsix = rinvsq00*rinvsq00*rinvsq00;
250 ewcljrsq = ewclj2*rsq00;
251 exponent = exp(-ewcljrsq);
252 poly = exponent*(1.0 + ewcljrsq + ewcljrsq*ewcljrsq*0.5);
253 vvdw6 = (c6_00-c6grid_00*(1.0-poly))*rinvsix;
254 vvdw12 = c12_00*rinvsix*rinvsix;
255 vvdw = (vvdw12 - c12_00*sh_vdw_invrcut6*sh_vdw_invrcut6)*(1.0/12.0) - (vvdw6 - c6_00*sh_vdw_invrcut6 - c6grid_00*sh_lj_ewald)*(1.0/6.0);
256 fvdw = (vvdw12 - vvdw6 - c6grid_00*(1.0/6.0)*exponent*ewclj6)*rinvsq00;
258 /* Update potential sums from outer loop */
264 /* Calculate temporary vectorial force */
269 /* Update vectorial force */
273 f[j_coord_offset+DIM*0+XX] -= tx;
274 f[j_coord_offset+DIM*0+YY] -= ty;
275 f[j_coord_offset+DIM*0+ZZ] -= tz;
279 /**************************
280 * CALCULATE INTERACTIONS *
281 **************************/
290 /* EWALD ELECTROSTATICS */
292 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
293 ewrt = r10*ewtabscale;
297 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
298 velec = qq10*((rinv10-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
299 felec = qq10*rinv10*(rinvsq10-felec);
301 /* Update potential sums from outer loop */
306 /* Calculate temporary vectorial force */
311 /* Update vectorial force */
315 f[j_coord_offset+DIM*0+XX] -= tx;
316 f[j_coord_offset+DIM*0+YY] -= ty;
317 f[j_coord_offset+DIM*0+ZZ] -= tz;
321 /**************************
322 * CALCULATE INTERACTIONS *
323 **************************/
332 /* EWALD ELECTROSTATICS */
334 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
335 ewrt = r20*ewtabscale;
339 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
340 velec = qq20*((rinv20-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
341 felec = qq20*rinv20*(rinvsq20-felec);
343 /* Update potential sums from outer loop */
348 /* Calculate temporary vectorial force */
353 /* Update vectorial force */
357 f[j_coord_offset+DIM*0+XX] -= tx;
358 f[j_coord_offset+DIM*0+YY] -= ty;
359 f[j_coord_offset+DIM*0+ZZ] -= tz;
363 /* Inner loop uses 158 flops */
365 /* End of innermost loop */
368 f[i_coord_offset+DIM*0+XX] += fix0;
369 f[i_coord_offset+DIM*0+YY] += fiy0;
370 f[i_coord_offset+DIM*0+ZZ] += fiz0;
374 f[i_coord_offset+DIM*1+XX] += fix1;
375 f[i_coord_offset+DIM*1+YY] += fiy1;
376 f[i_coord_offset+DIM*1+ZZ] += fiz1;
380 f[i_coord_offset+DIM*2+XX] += fix2;
381 f[i_coord_offset+DIM*2+YY] += fiy2;
382 f[i_coord_offset+DIM*2+ZZ] += fiz2;
386 fshift[i_shift_offset+XX] += tx;
387 fshift[i_shift_offset+YY] += ty;
388 fshift[i_shift_offset+ZZ] += tz;
391 /* Update potential energies */
392 kernel_data->energygrp_elec[ggid] += velecsum;
393 kernel_data->energygrp_vdw[ggid] += vvdwsum;
395 /* Increment number of inner iterations */
396 inneriter += j_index_end - j_index_start;
398 /* Outer loop uses 32 flops */
401 /* Increment number of outer iterations */
404 /* Update outer/inner flops */
406 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*32 + inneriter*158);
409 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJEwSh_GeomW3P1_F_c
410 * Electrostatics interaction: Ewald
411 * VdW interaction: LJEwald
412 * Geometry: Water3-Particle
413 * Calculate force/pot: Force
416 nb_kernel_ElecEwSh_VdwLJEwSh_GeomW3P1_F_c
417 (t_nblist * gmx_restrict nlist,
418 rvec * gmx_restrict xx,
419 rvec * gmx_restrict ff,
420 t_forcerec * gmx_restrict fr,
421 t_mdatoms * gmx_restrict mdatoms,
422 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
423 t_nrnb * gmx_restrict nrnb)
425 int i_shift_offset,i_coord_offset,j_coord_offset;
426 int j_index_start,j_index_end;
427 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
428 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
429 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
430 real *shiftvec,*fshift,*x,*f;
432 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
434 real ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
436 real ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
438 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
439 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
440 real dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
441 real dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
442 real velec,felec,velecsum,facel,crf,krf,krf2;
445 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
451 real ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,sh_lj_ewald;
454 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
462 jindex = nlist->jindex;
464 shiftidx = nlist->shift;
466 shiftvec = fr->shift_vec[0];
467 fshift = fr->fshift[0];
469 charge = mdatoms->chargeA;
470 nvdwtype = fr->ntype;
472 vdwtype = mdatoms->typeA;
473 vdwgridparam = fr->ljpme_c6grid;
474 ewclj = fr->ewaldcoeff_lj;
475 sh_lj_ewald = fr->ic->sh_lj_ewald;
476 ewclj2 = ewclj*ewclj;
477 ewclj6 = ewclj2*ewclj2*ewclj2;
479 sh_ewald = fr->ic->sh_ewald;
480 ewtab = fr->ic->tabq_coul_F;
481 ewtabscale = fr->ic->tabq_scale;
482 ewtabhalfspace = 0.5/ewtabscale;
484 /* Setup water-specific parameters */
485 inr = nlist->iinr[0];
486 iq0 = facel*charge[inr+0];
487 iq1 = facel*charge[inr+1];
488 iq2 = facel*charge[inr+2];
489 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
491 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
492 rcutoff = fr->rcoulomb;
493 rcutoff2 = rcutoff*rcutoff;
495 sh_vdw_invrcut6 = fr->ic->sh_invrc6;
501 /* Start outer loop over neighborlists */
502 for(iidx=0; iidx<nri; iidx++)
504 /* Load shift vector for this list */
505 i_shift_offset = DIM*shiftidx[iidx];
506 shX = shiftvec[i_shift_offset+XX];
507 shY = shiftvec[i_shift_offset+YY];
508 shZ = shiftvec[i_shift_offset+ZZ];
510 /* Load limits for loop over neighbors */
511 j_index_start = jindex[iidx];
512 j_index_end = jindex[iidx+1];
514 /* Get outer coordinate index */
516 i_coord_offset = DIM*inr;
518 /* Load i particle coords and add shift vector */
519 ix0 = shX + x[i_coord_offset+DIM*0+XX];
520 iy0 = shY + x[i_coord_offset+DIM*0+YY];
521 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
522 ix1 = shX + x[i_coord_offset+DIM*1+XX];
523 iy1 = shY + x[i_coord_offset+DIM*1+YY];
524 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
525 ix2 = shX + x[i_coord_offset+DIM*2+XX];
526 iy2 = shY + x[i_coord_offset+DIM*2+YY];
527 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
539 /* Start inner kernel loop */
540 for(jidx=j_index_start; jidx<j_index_end; jidx++)
542 /* Get j neighbor index, and coordinate index */
544 j_coord_offset = DIM*jnr;
546 /* load j atom coordinates */
547 jx0 = x[j_coord_offset+DIM*0+XX];
548 jy0 = x[j_coord_offset+DIM*0+YY];
549 jz0 = x[j_coord_offset+DIM*0+ZZ];
551 /* Calculate displacement vector */
562 /* Calculate squared distance and things based on it */
563 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
564 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
565 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
567 rinv00 = gmx_invsqrt(rsq00);
568 rinv10 = gmx_invsqrt(rsq10);
569 rinv20 = gmx_invsqrt(rsq20);
571 rinvsq00 = rinv00*rinv00;
572 rinvsq10 = rinv10*rinv10;
573 rinvsq20 = rinv20*rinv20;
575 /* Load parameters for j particles */
577 vdwjidx0 = 2*vdwtype[jnr+0];
579 /**************************
580 * CALCULATE INTERACTIONS *
581 **************************/
589 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
590 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
591 c6grid_00 = vdwgridparam[vdwioffset0+vdwjidx0];
593 /* EWALD ELECTROSTATICS */
595 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
596 ewrt = r00*ewtabscale;
599 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
600 felec = qq00*rinv00*(rinvsq00-felec);
602 rinvsix = rinvsq00*rinvsq00*rinvsq00;
603 ewcljrsq = ewclj2*rsq00;
604 exponent = exp(-ewcljrsq);
605 poly = exponent*(1.0 + ewcljrsq + ewcljrsq*ewcljrsq*0.5);
606 fvdw = (((c12_00*rinvsix - c6_00 + c6grid_00*(1.0-poly))*rinvsix) - c6grid_00*(1.0/6.0)*exponent*ewclj6)*rinvsq00;
610 /* Calculate temporary vectorial force */
615 /* Update vectorial force */
619 f[j_coord_offset+DIM*0+XX] -= tx;
620 f[j_coord_offset+DIM*0+YY] -= ty;
621 f[j_coord_offset+DIM*0+ZZ] -= tz;
625 /**************************
626 * CALCULATE INTERACTIONS *
627 **************************/
636 /* EWALD ELECTROSTATICS */
638 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
639 ewrt = r10*ewtabscale;
642 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
643 felec = qq10*rinv10*(rinvsq10-felec);
647 /* Calculate temporary vectorial force */
652 /* Update vectorial force */
656 f[j_coord_offset+DIM*0+XX] -= tx;
657 f[j_coord_offset+DIM*0+YY] -= ty;
658 f[j_coord_offset+DIM*0+ZZ] -= tz;
662 /**************************
663 * CALCULATE INTERACTIONS *
664 **************************/
673 /* EWALD ELECTROSTATICS */
675 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
676 ewrt = r20*ewtabscale;
679 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
680 felec = qq20*rinv20*(rinvsq20-felec);
684 /* Calculate temporary vectorial force */
689 /* Update vectorial force */
693 f[j_coord_offset+DIM*0+XX] -= tx;
694 f[j_coord_offset+DIM*0+YY] -= ty;
695 f[j_coord_offset+DIM*0+ZZ] -= tz;
699 /* Inner loop uses 123 flops */
701 /* End of innermost loop */
704 f[i_coord_offset+DIM*0+XX] += fix0;
705 f[i_coord_offset+DIM*0+YY] += fiy0;
706 f[i_coord_offset+DIM*0+ZZ] += fiz0;
710 f[i_coord_offset+DIM*1+XX] += fix1;
711 f[i_coord_offset+DIM*1+YY] += fiy1;
712 f[i_coord_offset+DIM*1+ZZ] += fiz1;
716 f[i_coord_offset+DIM*2+XX] += fix2;
717 f[i_coord_offset+DIM*2+YY] += fiy2;
718 f[i_coord_offset+DIM*2+ZZ] += fiz2;
722 fshift[i_shift_offset+XX] += tx;
723 fshift[i_shift_offset+YY] += ty;
724 fshift[i_shift_offset+ZZ] += tz;
726 /* Increment number of inner iterations */
727 inneriter += j_index_end - j_index_start;
729 /* Outer loop uses 30 flops */
732 /* Increment number of outer iterations */
735 /* Update outer/inner flops */
737 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*30 + inneriter*123);