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_ElecEw_VdwLJEw_GeomW3P1_VF_c
51 * Electrostatics interaction: Ewald
52 * VdW interaction: LJEwald
53 * Geometry: Water3-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecEw_VdwLJEw_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];
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];
173 /* Reset potential sums */
177 /* Start inner kernel loop */
178 for(jidx=j_index_start; jidx<j_index_end; jidx++)
180 /* Get j neighbor index, and coordinate index */
182 j_coord_offset = DIM*jnr;
184 /* load j atom coordinates */
185 jx0 = x[j_coord_offset+DIM*0+XX];
186 jy0 = x[j_coord_offset+DIM*0+YY];
187 jz0 = x[j_coord_offset+DIM*0+ZZ];
189 /* Calculate displacement vector */
200 /* Calculate squared distance and things based on it */
201 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
202 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
203 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
205 rinv00 = gmx_invsqrt(rsq00);
206 rinv10 = gmx_invsqrt(rsq10);
207 rinv20 = gmx_invsqrt(rsq20);
209 rinvsq00 = rinv00*rinv00;
210 rinvsq10 = rinv10*rinv10;
211 rinvsq20 = rinv20*rinv20;
213 /* Load parameters for j particles */
215 vdwjidx0 = 2*vdwtype[jnr+0];
217 /**************************
218 * CALCULATE INTERACTIONS *
219 **************************/
224 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
225 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
226 c6grid_00 = vdwgridparam[vdwioffset0+vdwjidx0];
228 /* EWALD ELECTROSTATICS */
230 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
231 ewrt = r00*ewtabscale;
235 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
236 velec = qq00*(rinv00-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
237 felec = qq00*rinv00*(rinvsq00-felec);
239 rinvsix = rinvsq00*rinvsq00*rinvsq00;
240 ewcljrsq = ewclj2*rsq00;
241 exponent = exp(-ewcljrsq);
242 poly = exponent*(1.0 + ewcljrsq + ewcljrsq*ewcljrsq*0.5);
243 vvdw6 = (c6_00-c6grid_00*(1.0-poly))*rinvsix;
244 vvdw12 = c12_00*rinvsix*rinvsix;
245 vvdw = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
246 fvdw = (vvdw12 - vvdw6 - c6grid_00*(1.0/6.0)*exponent*ewclj6)*rinvsq00;
248 /* Update potential sums from outer loop */
254 /* Calculate temporary vectorial force */
259 /* Update vectorial force */
263 f[j_coord_offset+DIM*0+XX] -= tx;
264 f[j_coord_offset+DIM*0+YY] -= ty;
265 f[j_coord_offset+DIM*0+ZZ] -= tz;
267 /**************************
268 * CALCULATE INTERACTIONS *
269 **************************/
275 /* EWALD ELECTROSTATICS */
277 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
278 ewrt = r10*ewtabscale;
282 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
283 velec = qq10*(rinv10-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
284 felec = qq10*rinv10*(rinvsq10-felec);
286 /* Update potential sums from outer loop */
291 /* Calculate temporary vectorial force */
296 /* Update vectorial force */
300 f[j_coord_offset+DIM*0+XX] -= tx;
301 f[j_coord_offset+DIM*0+YY] -= ty;
302 f[j_coord_offset+DIM*0+ZZ] -= tz;
304 /**************************
305 * CALCULATE INTERACTIONS *
306 **************************/
312 /* EWALD ELECTROSTATICS */
314 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
315 ewrt = r20*ewtabscale;
319 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
320 velec = qq20*(rinv20-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
321 felec = qq20*rinv20*(rinvsq20-felec);
323 /* Update potential sums from outer loop */
328 /* Calculate temporary vectorial force */
333 /* Update vectorial force */
337 f[j_coord_offset+DIM*0+XX] -= tx;
338 f[j_coord_offset+DIM*0+YY] -= ty;
339 f[j_coord_offset+DIM*0+ZZ] -= tz;
341 /* Inner loop uses 149 flops */
343 /* End of innermost loop */
346 f[i_coord_offset+DIM*0+XX] += fix0;
347 f[i_coord_offset+DIM*0+YY] += fiy0;
348 f[i_coord_offset+DIM*0+ZZ] += fiz0;
352 f[i_coord_offset+DIM*1+XX] += fix1;
353 f[i_coord_offset+DIM*1+YY] += fiy1;
354 f[i_coord_offset+DIM*1+ZZ] += fiz1;
358 f[i_coord_offset+DIM*2+XX] += fix2;
359 f[i_coord_offset+DIM*2+YY] += fiy2;
360 f[i_coord_offset+DIM*2+ZZ] += fiz2;
364 fshift[i_shift_offset+XX] += tx;
365 fshift[i_shift_offset+YY] += ty;
366 fshift[i_shift_offset+ZZ] += tz;
369 /* Update potential energies */
370 kernel_data->energygrp_elec[ggid] += velecsum;
371 kernel_data->energygrp_vdw[ggid] += vvdwsum;
373 /* Increment number of inner iterations */
374 inneriter += j_index_end - j_index_start;
376 /* Outer loop uses 32 flops */
379 /* Increment number of outer iterations */
382 /* Update outer/inner flops */
384 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*32 + inneriter*149);
387 * Gromacs nonbonded kernel: nb_kernel_ElecEw_VdwLJEw_GeomW3P1_F_c
388 * Electrostatics interaction: Ewald
389 * VdW interaction: LJEwald
390 * Geometry: Water3-Particle
391 * Calculate force/pot: Force
394 nb_kernel_ElecEw_VdwLJEw_GeomW3P1_F_c
395 (t_nblist * gmx_restrict nlist,
396 rvec * gmx_restrict xx,
397 rvec * gmx_restrict ff,
398 t_forcerec * gmx_restrict fr,
399 t_mdatoms * gmx_restrict mdatoms,
400 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
401 t_nrnb * gmx_restrict nrnb)
403 int i_shift_offset,i_coord_offset,j_coord_offset;
404 int j_index_start,j_index_end;
405 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
406 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
407 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
408 real *shiftvec,*fshift,*x,*f;
410 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
412 real ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
414 real ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
416 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
417 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
418 real dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
419 real dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
420 real velec,felec,velecsum,facel,crf,krf,krf2;
423 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
429 real ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,sh_lj_ewald;
432 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
440 jindex = nlist->jindex;
442 shiftidx = nlist->shift;
444 shiftvec = fr->shift_vec[0];
445 fshift = fr->fshift[0];
447 charge = mdatoms->chargeA;
448 nvdwtype = fr->ntype;
450 vdwtype = mdatoms->typeA;
451 vdwgridparam = fr->ljpme_c6grid;
452 ewclj = fr->ewaldcoeff_lj;
453 sh_lj_ewald = fr->ic->sh_lj_ewald;
454 ewclj2 = ewclj*ewclj;
455 ewclj6 = ewclj2*ewclj2*ewclj2;
457 sh_ewald = fr->ic->sh_ewald;
458 ewtab = fr->ic->tabq_coul_F;
459 ewtabscale = fr->ic->tabq_scale;
460 ewtabhalfspace = 0.5/ewtabscale;
462 /* Setup water-specific parameters */
463 inr = nlist->iinr[0];
464 iq0 = facel*charge[inr+0];
465 iq1 = facel*charge[inr+1];
466 iq2 = facel*charge[inr+2];
467 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
472 /* Start outer loop over neighborlists */
473 for(iidx=0; iidx<nri; iidx++)
475 /* Load shift vector for this list */
476 i_shift_offset = DIM*shiftidx[iidx];
477 shX = shiftvec[i_shift_offset+XX];
478 shY = shiftvec[i_shift_offset+YY];
479 shZ = shiftvec[i_shift_offset+ZZ];
481 /* Load limits for loop over neighbors */
482 j_index_start = jindex[iidx];
483 j_index_end = jindex[iidx+1];
485 /* Get outer coordinate index */
487 i_coord_offset = DIM*inr;
489 /* Load i particle coords and add shift vector */
490 ix0 = shX + x[i_coord_offset+DIM*0+XX];
491 iy0 = shY + x[i_coord_offset+DIM*0+YY];
492 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
493 ix1 = shX + x[i_coord_offset+DIM*1+XX];
494 iy1 = shY + x[i_coord_offset+DIM*1+YY];
495 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
496 ix2 = shX + x[i_coord_offset+DIM*2+XX];
497 iy2 = shY + x[i_coord_offset+DIM*2+YY];
498 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
510 /* Start inner kernel loop */
511 for(jidx=j_index_start; jidx<j_index_end; jidx++)
513 /* Get j neighbor index, and coordinate index */
515 j_coord_offset = DIM*jnr;
517 /* load j atom coordinates */
518 jx0 = x[j_coord_offset+DIM*0+XX];
519 jy0 = x[j_coord_offset+DIM*0+YY];
520 jz0 = x[j_coord_offset+DIM*0+ZZ];
522 /* Calculate displacement vector */
533 /* Calculate squared distance and things based on it */
534 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
535 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
536 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
538 rinv00 = gmx_invsqrt(rsq00);
539 rinv10 = gmx_invsqrt(rsq10);
540 rinv20 = gmx_invsqrt(rsq20);
542 rinvsq00 = rinv00*rinv00;
543 rinvsq10 = rinv10*rinv10;
544 rinvsq20 = rinv20*rinv20;
546 /* Load parameters for j particles */
548 vdwjidx0 = 2*vdwtype[jnr+0];
550 /**************************
551 * CALCULATE INTERACTIONS *
552 **************************/
557 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
558 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
559 c6grid_00 = vdwgridparam[vdwioffset0+vdwjidx0];
561 /* EWALD ELECTROSTATICS */
563 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
564 ewrt = r00*ewtabscale;
567 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
568 felec = qq00*rinv00*(rinvsq00-felec);
570 rinvsix = rinvsq00*rinvsq00*rinvsq00;
571 ewcljrsq = ewclj2*rsq00;
572 exponent = exp(-ewcljrsq);
573 poly = exponent*(1.0 + ewcljrsq + ewcljrsq*ewcljrsq*0.5);
574 fvdw = (((c12_00*rinvsix - c6_00 + c6grid_00*(1.0-poly))*rinvsix) - c6grid_00*(1.0/6.0)*exponent*ewclj6)*rinvsq00;
578 /* Calculate temporary vectorial force */
583 /* Update vectorial force */
587 f[j_coord_offset+DIM*0+XX] -= tx;
588 f[j_coord_offset+DIM*0+YY] -= ty;
589 f[j_coord_offset+DIM*0+ZZ] -= tz;
591 /**************************
592 * CALCULATE INTERACTIONS *
593 **************************/
599 /* EWALD ELECTROSTATICS */
601 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
602 ewrt = r10*ewtabscale;
605 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
606 felec = qq10*rinv10*(rinvsq10-felec);
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;
623 /**************************
624 * CALCULATE INTERACTIONS *
625 **************************/
631 /* EWALD ELECTROSTATICS */
633 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
634 ewrt = r20*ewtabscale;
637 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
638 felec = qq20*rinv20*(rinvsq20-felec);
642 /* Calculate temporary vectorial force */
647 /* Update vectorial force */
651 f[j_coord_offset+DIM*0+XX] -= tx;
652 f[j_coord_offset+DIM*0+YY] -= ty;
653 f[j_coord_offset+DIM*0+ZZ] -= tz;
655 /* Inner loop uses 123 flops */
657 /* End of innermost loop */
660 f[i_coord_offset+DIM*0+XX] += fix0;
661 f[i_coord_offset+DIM*0+YY] += fiy0;
662 f[i_coord_offset+DIM*0+ZZ] += fiz0;
666 f[i_coord_offset+DIM*1+XX] += fix1;
667 f[i_coord_offset+DIM*1+YY] += fiy1;
668 f[i_coord_offset+DIM*1+ZZ] += fiz1;
672 f[i_coord_offset+DIM*2+XX] += fix2;
673 f[i_coord_offset+DIM*2+YY] += fiy2;
674 f[i_coord_offset+DIM*2+ZZ] += fiz2;
678 fshift[i_shift_offset+XX] += tx;
679 fshift[i_shift_offset+YY] += ty;
680 fshift[i_shift_offset+ZZ] += tz;
682 /* Increment number of inner iterations */
683 inneriter += j_index_end - j_index_start;
685 /* Outer loop uses 30 flops */
688 /* Increment number of outer iterations */
691 /* Update outer/inner flops */
693 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*30 + inneriter*123);