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_VdwLJEwSh_GeomW3P1_VF_c
49 * Electrostatics interaction: Ewald
50 * VdW interaction: LJEwald
51 * Geometry: Water3-Particle
52 * Calculate force/pot: PotentialAndForce
55 nb_kernel_ElecEwSh_VdwLJEwSh_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;
90 real ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,sh_lj_ewald;
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;
112 vdwgridparam = fr->ljpme_c6grid;
113 ewclj = fr->ewaldcoeff_lj;
114 sh_lj_ewald = fr->ic->sh_lj_ewald;
115 ewclj2 = ewclj*ewclj;
116 ewclj6 = ewclj2*ewclj2*ewclj2;
118 sh_ewald = fr->ic->sh_ewald;
119 ewtab = fr->ic->tabq_coul_FDV0;
120 ewtabscale = fr->ic->tabq_scale;
121 ewtabhalfspace = 0.5/ewtabscale;
123 /* Setup water-specific parameters */
124 inr = nlist->iinr[0];
125 iq0 = facel*charge[inr+0];
126 iq1 = facel*charge[inr+1];
127 iq2 = facel*charge[inr+2];
128 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
130 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
131 rcutoff = fr->rcoulomb;
132 rcutoff2 = rcutoff*rcutoff;
134 sh_vdw_invrcut6 = fr->ic->sh_invrc6;
140 /* Start outer loop over neighborlists */
141 for(iidx=0; iidx<nri; iidx++)
143 /* Load shift vector for this list */
144 i_shift_offset = DIM*shiftidx[iidx];
145 shX = shiftvec[i_shift_offset+XX];
146 shY = shiftvec[i_shift_offset+YY];
147 shZ = shiftvec[i_shift_offset+ZZ];
149 /* Load limits for loop over neighbors */
150 j_index_start = jindex[iidx];
151 j_index_end = jindex[iidx+1];
153 /* Get outer coordinate index */
155 i_coord_offset = DIM*inr;
157 /* Load i particle coords and add shift vector */
158 ix0 = shX + x[i_coord_offset+DIM*0+XX];
159 iy0 = shY + x[i_coord_offset+DIM*0+YY];
160 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
161 ix1 = shX + x[i_coord_offset+DIM*1+XX];
162 iy1 = shY + x[i_coord_offset+DIM*1+YY];
163 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
164 ix2 = shX + x[i_coord_offset+DIM*2+XX];
165 iy2 = shY + x[i_coord_offset+DIM*2+YY];
166 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
178 /* Reset potential sums */
182 /* Start inner kernel loop */
183 for(jidx=j_index_start; jidx<j_index_end; jidx++)
185 /* Get j neighbor index, and coordinate index */
187 j_coord_offset = DIM*jnr;
189 /* load j atom coordinates */
190 jx0 = x[j_coord_offset+DIM*0+XX];
191 jy0 = x[j_coord_offset+DIM*0+YY];
192 jz0 = x[j_coord_offset+DIM*0+ZZ];
194 /* Calculate displacement vector */
205 /* Calculate squared distance and things based on it */
206 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
207 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
208 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
210 rinv00 = gmx_invsqrt(rsq00);
211 rinv10 = gmx_invsqrt(rsq10);
212 rinv20 = gmx_invsqrt(rsq20);
214 rinvsq00 = rinv00*rinv00;
215 rinvsq10 = rinv10*rinv10;
216 rinvsq20 = rinv20*rinv20;
218 /* Load parameters for j particles */
220 vdwjidx0 = 2*vdwtype[jnr+0];
222 /**************************
223 * CALCULATE INTERACTIONS *
224 **************************/
232 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
233 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
234 c6grid_00 = vdwgridparam[vdwioffset0+vdwjidx0];
236 /* EWALD ELECTROSTATICS */
238 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
239 ewrt = r00*ewtabscale;
243 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
244 velec = qq00*((rinv00-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
245 felec = qq00*rinv00*(rinvsq00-felec);
247 rinvsix = rinvsq00*rinvsq00*rinvsq00;
248 ewcljrsq = ewclj2*rsq00;
249 exponent = exp(-ewcljrsq);
250 poly = exponent*(1.0 + ewcljrsq + ewcljrsq*ewcljrsq*0.5);
251 vvdw6 = (c6_00-c6grid_00*(1.0-poly))*rinvsix;
252 vvdw12 = c12_00*rinvsix*rinvsix;
253 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);
254 fvdw = (vvdw12 - vvdw6 - c6grid_00*(1.0/6.0)*exponent*ewclj6)*rinvsq00;
256 /* Update potential sums from outer loop */
262 /* Calculate temporary vectorial force */
267 /* Update vectorial force */
271 f[j_coord_offset+DIM*0+XX] -= tx;
272 f[j_coord_offset+DIM*0+YY] -= ty;
273 f[j_coord_offset+DIM*0+ZZ] -= tz;
277 /**************************
278 * CALCULATE INTERACTIONS *
279 **************************/
288 /* EWALD ELECTROSTATICS */
290 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
291 ewrt = r10*ewtabscale;
295 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
296 velec = qq10*((rinv10-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
297 felec = qq10*rinv10*(rinvsq10-felec);
299 /* Update potential sums from outer loop */
304 /* Calculate temporary vectorial force */
309 /* Update vectorial force */
313 f[j_coord_offset+DIM*0+XX] -= tx;
314 f[j_coord_offset+DIM*0+YY] -= ty;
315 f[j_coord_offset+DIM*0+ZZ] -= tz;
319 /**************************
320 * CALCULATE INTERACTIONS *
321 **************************/
330 /* EWALD ELECTROSTATICS */
332 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
333 ewrt = r20*ewtabscale;
337 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
338 velec = qq20*((rinv20-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
339 felec = qq20*rinv20*(rinvsq20-felec);
341 /* Update potential sums from outer loop */
346 /* Calculate temporary vectorial force */
351 /* Update vectorial force */
355 f[j_coord_offset+DIM*0+XX] -= tx;
356 f[j_coord_offset+DIM*0+YY] -= ty;
357 f[j_coord_offset+DIM*0+ZZ] -= tz;
361 /* Inner loop uses 158 flops */
363 /* End of innermost loop */
366 f[i_coord_offset+DIM*0+XX] += fix0;
367 f[i_coord_offset+DIM*0+YY] += fiy0;
368 f[i_coord_offset+DIM*0+ZZ] += fiz0;
372 f[i_coord_offset+DIM*1+XX] += fix1;
373 f[i_coord_offset+DIM*1+YY] += fiy1;
374 f[i_coord_offset+DIM*1+ZZ] += fiz1;
378 f[i_coord_offset+DIM*2+XX] += fix2;
379 f[i_coord_offset+DIM*2+YY] += fiy2;
380 f[i_coord_offset+DIM*2+ZZ] += fiz2;
384 fshift[i_shift_offset+XX] += tx;
385 fshift[i_shift_offset+YY] += ty;
386 fshift[i_shift_offset+ZZ] += tz;
389 /* Update potential energies */
390 kernel_data->energygrp_elec[ggid] += velecsum;
391 kernel_data->energygrp_vdw[ggid] += vvdwsum;
393 /* Increment number of inner iterations */
394 inneriter += j_index_end - j_index_start;
396 /* Outer loop uses 32 flops */
399 /* Increment number of outer iterations */
402 /* Update outer/inner flops */
404 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*32 + inneriter*158);
407 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJEwSh_GeomW3P1_F_c
408 * Electrostatics interaction: Ewald
409 * VdW interaction: LJEwald
410 * Geometry: Water3-Particle
411 * Calculate force/pot: Force
414 nb_kernel_ElecEwSh_VdwLJEwSh_GeomW3P1_F_c
415 (t_nblist * gmx_restrict nlist,
416 rvec * gmx_restrict xx,
417 rvec * gmx_restrict ff,
418 t_forcerec * gmx_restrict fr,
419 t_mdatoms * gmx_restrict mdatoms,
420 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
421 t_nrnb * gmx_restrict nrnb)
423 int i_shift_offset,i_coord_offset,j_coord_offset;
424 int j_index_start,j_index_end;
425 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
426 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
427 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
428 real *shiftvec,*fshift,*x,*f;
430 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
432 real ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
434 real ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
436 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
437 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
438 real dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
439 real dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
440 real velec,felec,velecsum,facel,crf,krf,krf2;
443 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
449 real ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,sh_lj_ewald;
452 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
460 jindex = nlist->jindex;
462 shiftidx = nlist->shift;
464 shiftvec = fr->shift_vec[0];
465 fshift = fr->fshift[0];
467 charge = mdatoms->chargeA;
468 nvdwtype = fr->ntype;
470 vdwtype = mdatoms->typeA;
471 vdwgridparam = fr->ljpme_c6grid;
472 ewclj = fr->ewaldcoeff_lj;
473 sh_lj_ewald = fr->ic->sh_lj_ewald;
474 ewclj2 = ewclj*ewclj;
475 ewclj6 = ewclj2*ewclj2*ewclj2;
477 sh_ewald = fr->ic->sh_ewald;
478 ewtab = fr->ic->tabq_coul_F;
479 ewtabscale = fr->ic->tabq_scale;
480 ewtabhalfspace = 0.5/ewtabscale;
482 /* Setup water-specific parameters */
483 inr = nlist->iinr[0];
484 iq0 = facel*charge[inr+0];
485 iq1 = facel*charge[inr+1];
486 iq2 = facel*charge[inr+2];
487 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
489 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
490 rcutoff = fr->rcoulomb;
491 rcutoff2 = rcutoff*rcutoff;
493 sh_vdw_invrcut6 = fr->ic->sh_invrc6;
499 /* Start outer loop over neighborlists */
500 for(iidx=0; iidx<nri; iidx++)
502 /* Load shift vector for this list */
503 i_shift_offset = DIM*shiftidx[iidx];
504 shX = shiftvec[i_shift_offset+XX];
505 shY = shiftvec[i_shift_offset+YY];
506 shZ = shiftvec[i_shift_offset+ZZ];
508 /* Load limits for loop over neighbors */
509 j_index_start = jindex[iidx];
510 j_index_end = jindex[iidx+1];
512 /* Get outer coordinate index */
514 i_coord_offset = DIM*inr;
516 /* Load i particle coords and add shift vector */
517 ix0 = shX + x[i_coord_offset+DIM*0+XX];
518 iy0 = shY + x[i_coord_offset+DIM*0+YY];
519 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
520 ix1 = shX + x[i_coord_offset+DIM*1+XX];
521 iy1 = shY + x[i_coord_offset+DIM*1+YY];
522 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
523 ix2 = shX + x[i_coord_offset+DIM*2+XX];
524 iy2 = shY + x[i_coord_offset+DIM*2+YY];
525 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
537 /* Start inner kernel loop */
538 for(jidx=j_index_start; jidx<j_index_end; jidx++)
540 /* Get j neighbor index, and coordinate index */
542 j_coord_offset = DIM*jnr;
544 /* load j atom coordinates */
545 jx0 = x[j_coord_offset+DIM*0+XX];
546 jy0 = x[j_coord_offset+DIM*0+YY];
547 jz0 = x[j_coord_offset+DIM*0+ZZ];
549 /* Calculate displacement vector */
560 /* Calculate squared distance and things based on it */
561 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
562 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
563 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
565 rinv00 = gmx_invsqrt(rsq00);
566 rinv10 = gmx_invsqrt(rsq10);
567 rinv20 = gmx_invsqrt(rsq20);
569 rinvsq00 = rinv00*rinv00;
570 rinvsq10 = rinv10*rinv10;
571 rinvsq20 = rinv20*rinv20;
573 /* Load parameters for j particles */
575 vdwjidx0 = 2*vdwtype[jnr+0];
577 /**************************
578 * CALCULATE INTERACTIONS *
579 **************************/
587 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
588 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
589 c6grid_00 = vdwgridparam[vdwioffset0+vdwjidx0];
591 /* EWALD ELECTROSTATICS */
593 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
594 ewrt = r00*ewtabscale;
597 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
598 felec = qq00*rinv00*(rinvsq00-felec);
600 rinvsix = rinvsq00*rinvsq00*rinvsq00;
601 ewcljrsq = ewclj2*rsq00;
602 exponent = exp(-ewcljrsq);
603 poly = exponent*(1.0 + ewcljrsq + ewcljrsq*ewcljrsq*0.5);
604 fvdw = (((c12_00*rinvsix - c6_00 + c6grid_00*(1.0-poly))*rinvsix) - c6grid_00*(1.0/6.0)*exponent*ewclj6)*rinvsq00;
608 /* Calculate temporary vectorial force */
613 /* Update vectorial force */
617 f[j_coord_offset+DIM*0+XX] -= tx;
618 f[j_coord_offset+DIM*0+YY] -= ty;
619 f[j_coord_offset+DIM*0+ZZ] -= tz;
623 /**************************
624 * CALCULATE INTERACTIONS *
625 **************************/
634 /* EWALD ELECTROSTATICS */
636 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
637 ewrt = r10*ewtabscale;
640 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
641 felec = qq10*rinv10*(rinvsq10-felec);
645 /* Calculate temporary vectorial force */
650 /* Update vectorial force */
654 f[j_coord_offset+DIM*0+XX] -= tx;
655 f[j_coord_offset+DIM*0+YY] -= ty;
656 f[j_coord_offset+DIM*0+ZZ] -= tz;
660 /**************************
661 * CALCULATE INTERACTIONS *
662 **************************/
671 /* EWALD ELECTROSTATICS */
673 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
674 ewrt = r20*ewtabscale;
677 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
678 felec = qq20*rinv20*(rinvsq20-felec);
682 /* Calculate temporary vectorial force */
687 /* Update vectorial force */
691 f[j_coord_offset+DIM*0+XX] -= tx;
692 f[j_coord_offset+DIM*0+YY] -= ty;
693 f[j_coord_offset+DIM*0+ZZ] -= tz;
697 /* Inner loop uses 123 flops */
699 /* End of innermost loop */
702 f[i_coord_offset+DIM*0+XX] += fix0;
703 f[i_coord_offset+DIM*0+YY] += fiy0;
704 f[i_coord_offset+DIM*0+ZZ] += fiz0;
708 f[i_coord_offset+DIM*1+XX] += fix1;
709 f[i_coord_offset+DIM*1+YY] += fiy1;
710 f[i_coord_offset+DIM*1+ZZ] += fiz1;
714 f[i_coord_offset+DIM*2+XX] += fix2;
715 f[i_coord_offset+DIM*2+YY] += fiy2;
716 f[i_coord_offset+DIM*2+ZZ] += fiz2;
720 fshift[i_shift_offset+XX] += tx;
721 fshift[i_shift_offset+YY] += ty;
722 fshift[i_shift_offset+ZZ] += tz;
724 /* Increment number of inner iterations */
725 inneriter += j_index_end - j_index_start;
727 /* Outer loop uses 30 flops */
730 /* Increment number of outer iterations */
733 /* Update outer/inner flops */
735 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*30 + inneriter*123);