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_GeomW3P1_VF_c
51 * Electrostatics interaction: Ewald
52 * VdW interaction: LennardJones
53 * Geometry: Water3-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecEwSh_VdwLJSh_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;
90 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
98 jindex = nlist->jindex;
100 shiftidx = nlist->shift;
102 shiftvec = fr->shift_vec[0];
103 fshift = fr->fshift[0];
105 charge = mdatoms->chargeA;
106 nvdwtype = fr->ntype;
108 vdwtype = mdatoms->typeA;
110 sh_ewald = fr->ic->sh_ewald;
111 ewtab = fr->ic->tabq_coul_FDV0;
112 ewtabscale = fr->ic->tabq_scale;
113 ewtabhalfspace = 0.5/ewtabscale;
115 /* Setup water-specific parameters */
116 inr = nlist->iinr[0];
117 iq0 = facel*charge[inr+0];
118 iq1 = facel*charge[inr+1];
119 iq2 = facel*charge[inr+2];
120 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
122 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
123 rcutoff = fr->rcoulomb;
124 rcutoff2 = rcutoff*rcutoff;
126 sh_vdw_invrcut6 = fr->ic->sh_invrc6;
132 /* Start outer loop over neighborlists */
133 for(iidx=0; iidx<nri; iidx++)
135 /* Load shift vector for this list */
136 i_shift_offset = DIM*shiftidx[iidx];
137 shX = shiftvec[i_shift_offset+XX];
138 shY = shiftvec[i_shift_offset+YY];
139 shZ = shiftvec[i_shift_offset+ZZ];
141 /* Load limits for loop over neighbors */
142 j_index_start = jindex[iidx];
143 j_index_end = jindex[iidx+1];
145 /* Get outer coordinate index */
147 i_coord_offset = DIM*inr;
149 /* Load i particle coords and add shift vector */
150 ix0 = shX + x[i_coord_offset+DIM*0+XX];
151 iy0 = shY + x[i_coord_offset+DIM*0+YY];
152 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
153 ix1 = shX + x[i_coord_offset+DIM*1+XX];
154 iy1 = shY + x[i_coord_offset+DIM*1+YY];
155 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
156 ix2 = shX + x[i_coord_offset+DIM*2+XX];
157 iy2 = shY + x[i_coord_offset+DIM*2+YY];
158 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
170 /* Reset potential sums */
174 /* Start inner kernel loop */
175 for(jidx=j_index_start; jidx<j_index_end; jidx++)
177 /* Get j neighbor index, and coordinate index */
179 j_coord_offset = DIM*jnr;
181 /* load j atom coordinates */
182 jx0 = x[j_coord_offset+DIM*0+XX];
183 jy0 = x[j_coord_offset+DIM*0+YY];
184 jz0 = x[j_coord_offset+DIM*0+ZZ];
186 /* Calculate displacement vector */
197 /* Calculate squared distance and things based on it */
198 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
199 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
200 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
202 rinv00 = gmx_invsqrt(rsq00);
203 rinv10 = gmx_invsqrt(rsq10);
204 rinv20 = gmx_invsqrt(rsq20);
206 rinvsq00 = rinv00*rinv00;
207 rinvsq10 = rinv10*rinv10;
208 rinvsq20 = rinv20*rinv20;
210 /* Load parameters for j particles */
212 vdwjidx0 = 2*vdwtype[jnr+0];
214 /**************************
215 * CALCULATE INTERACTIONS *
216 **************************/
224 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
225 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
227 /* EWALD ELECTROSTATICS */
229 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
230 ewrt = r00*ewtabscale;
234 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
235 velec = qq00*((rinv00-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
236 felec = qq00*rinv00*(rinvsq00-felec);
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 */
252 /* Calculate temporary vectorial force */
257 /* Update vectorial force */
261 f[j_coord_offset+DIM*0+XX] -= tx;
262 f[j_coord_offset+DIM*0+YY] -= ty;
263 f[j_coord_offset+DIM*0+ZZ] -= tz;
267 /**************************
268 * CALCULATE INTERACTIONS *
269 **************************/
278 /* EWALD ELECTROSTATICS */
280 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
281 ewrt = r10*ewtabscale;
285 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
286 velec = qq10*((rinv10-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
287 felec = qq10*rinv10*(rinvsq10-felec);
289 /* Update potential sums from outer loop */
294 /* Calculate temporary vectorial force */
299 /* Update vectorial force */
303 f[j_coord_offset+DIM*0+XX] -= tx;
304 f[j_coord_offset+DIM*0+YY] -= ty;
305 f[j_coord_offset+DIM*0+ZZ] -= tz;
309 /**************************
310 * CALCULATE INTERACTIONS *
311 **************************/
320 /* EWALD ELECTROSTATICS */
322 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
323 ewrt = r20*ewtabscale;
327 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
328 velec = qq20*((rinv20-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
329 felec = qq20*rinv20*(rinvsq20-felec);
331 /* Update potential sums from outer loop */
336 /* Calculate temporary vectorial force */
341 /* Update vectorial force */
345 f[j_coord_offset+DIM*0+XX] -= tx;
346 f[j_coord_offset+DIM*0+YY] -= ty;
347 f[j_coord_offset+DIM*0+ZZ] -= tz;
351 /* Inner loop uses 143 flops */
353 /* End of innermost loop */
356 f[i_coord_offset+DIM*0+XX] += fix0;
357 f[i_coord_offset+DIM*0+YY] += fiy0;
358 f[i_coord_offset+DIM*0+ZZ] += fiz0;
362 f[i_coord_offset+DIM*1+XX] += fix1;
363 f[i_coord_offset+DIM*1+YY] += fiy1;
364 f[i_coord_offset+DIM*1+ZZ] += fiz1;
368 f[i_coord_offset+DIM*2+XX] += fix2;
369 f[i_coord_offset+DIM*2+YY] += fiy2;
370 f[i_coord_offset+DIM*2+ZZ] += fiz2;
374 fshift[i_shift_offset+XX] += tx;
375 fshift[i_shift_offset+YY] += ty;
376 fshift[i_shift_offset+ZZ] += tz;
379 /* Update potential energies */
380 kernel_data->energygrp_elec[ggid] += velecsum;
381 kernel_data->energygrp_vdw[ggid] += vvdwsum;
383 /* Increment number of inner iterations */
384 inneriter += j_index_end - j_index_start;
386 /* Outer loop uses 32 flops */
389 /* Increment number of outer iterations */
392 /* Update outer/inner flops */
394 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*32 + inneriter*143);
397 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomW3P1_F_c
398 * Electrostatics interaction: Ewald
399 * VdW interaction: LennardJones
400 * Geometry: Water3-Particle
401 * Calculate force/pot: Force
404 nb_kernel_ElecEwSh_VdwLJSh_GeomW3P1_F_c
405 (t_nblist * gmx_restrict nlist,
406 rvec * gmx_restrict xx,
407 rvec * gmx_restrict ff,
408 t_forcerec * gmx_restrict fr,
409 t_mdatoms * gmx_restrict mdatoms,
410 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
411 t_nrnb * gmx_restrict nrnb)
413 int i_shift_offset,i_coord_offset,j_coord_offset;
414 int j_index_start,j_index_end;
415 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
416 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
417 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
418 real *shiftvec,*fshift,*x,*f;
420 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
422 real ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
424 real ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
426 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
427 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
428 real dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
429 real dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
430 real velec,felec,velecsum,facel,crf,krf,krf2;
433 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
437 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
445 jindex = nlist->jindex;
447 shiftidx = nlist->shift;
449 shiftvec = fr->shift_vec[0];
450 fshift = fr->fshift[0];
452 charge = mdatoms->chargeA;
453 nvdwtype = fr->ntype;
455 vdwtype = mdatoms->typeA;
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];
469 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
470 rcutoff = fr->rcoulomb;
471 rcutoff2 = rcutoff*rcutoff;
473 sh_vdw_invrcut6 = fr->ic->sh_invrc6;
479 /* Start outer loop over neighborlists */
480 for(iidx=0; iidx<nri; iidx++)
482 /* Load shift vector for this list */
483 i_shift_offset = DIM*shiftidx[iidx];
484 shX = shiftvec[i_shift_offset+XX];
485 shY = shiftvec[i_shift_offset+YY];
486 shZ = shiftvec[i_shift_offset+ZZ];
488 /* Load limits for loop over neighbors */
489 j_index_start = jindex[iidx];
490 j_index_end = jindex[iidx+1];
492 /* Get outer coordinate index */
494 i_coord_offset = DIM*inr;
496 /* Load i particle coords and add shift vector */
497 ix0 = shX + x[i_coord_offset+DIM*0+XX];
498 iy0 = shY + x[i_coord_offset+DIM*0+YY];
499 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
500 ix1 = shX + x[i_coord_offset+DIM*1+XX];
501 iy1 = shY + x[i_coord_offset+DIM*1+YY];
502 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
503 ix2 = shX + x[i_coord_offset+DIM*2+XX];
504 iy2 = shY + x[i_coord_offset+DIM*2+YY];
505 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
517 /* Start inner kernel loop */
518 for(jidx=j_index_start; jidx<j_index_end; jidx++)
520 /* Get j neighbor index, and coordinate index */
522 j_coord_offset = DIM*jnr;
524 /* load j atom coordinates */
525 jx0 = x[j_coord_offset+DIM*0+XX];
526 jy0 = x[j_coord_offset+DIM*0+YY];
527 jz0 = x[j_coord_offset+DIM*0+ZZ];
529 /* Calculate displacement vector */
540 /* Calculate squared distance and things based on it */
541 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
542 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
543 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
545 rinv00 = gmx_invsqrt(rsq00);
546 rinv10 = gmx_invsqrt(rsq10);
547 rinv20 = gmx_invsqrt(rsq20);
549 rinvsq00 = rinv00*rinv00;
550 rinvsq10 = rinv10*rinv10;
551 rinvsq20 = rinv20*rinv20;
553 /* Load parameters for j particles */
555 vdwjidx0 = 2*vdwtype[jnr+0];
557 /**************************
558 * CALCULATE INTERACTIONS *
559 **************************/
567 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
568 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
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 /* LENNARD-JONES DISPERSION/REPULSION */
581 rinvsix = rinvsq00*rinvsq00*rinvsq00;
582 fvdw = (c12_00*rinvsix-c6_00)*rinvsix*rinvsq00;
586 /* Calculate temporary vectorial force */
591 /* Update vectorial force */
595 f[j_coord_offset+DIM*0+XX] -= tx;
596 f[j_coord_offset+DIM*0+YY] -= ty;
597 f[j_coord_offset+DIM*0+ZZ] -= tz;
601 /**************************
602 * CALCULATE INTERACTIONS *
603 **************************/
612 /* EWALD ELECTROSTATICS */
614 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
615 ewrt = r10*ewtabscale;
618 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
619 felec = qq10*rinv10*(rinvsq10-felec);
623 /* Calculate temporary vectorial force */
628 /* Update vectorial force */
632 f[j_coord_offset+DIM*0+XX] -= tx;
633 f[j_coord_offset+DIM*0+YY] -= ty;
634 f[j_coord_offset+DIM*0+ZZ] -= tz;
638 /**************************
639 * CALCULATE INTERACTIONS *
640 **************************/
649 /* EWALD ELECTROSTATICS */
651 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
652 ewrt = r20*ewtabscale;
655 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
656 felec = qq20*rinv20*(rinvsq20-felec);
660 /* Calculate temporary vectorial force */
665 /* Update vectorial force */
669 f[j_coord_offset+DIM*0+XX] -= tx;
670 f[j_coord_offset+DIM*0+YY] -= ty;
671 f[j_coord_offset+DIM*0+ZZ] -= tz;
675 /* Inner loop uses 109 flops */
677 /* End of innermost loop */
680 f[i_coord_offset+DIM*0+XX] += fix0;
681 f[i_coord_offset+DIM*0+YY] += fiy0;
682 f[i_coord_offset+DIM*0+ZZ] += fiz0;
686 f[i_coord_offset+DIM*1+XX] += fix1;
687 f[i_coord_offset+DIM*1+YY] += fiy1;
688 f[i_coord_offset+DIM*1+ZZ] += fiz1;
692 f[i_coord_offset+DIM*2+XX] += fix2;
693 f[i_coord_offset+DIM*2+YY] += fiy2;
694 f[i_coord_offset+DIM*2+ZZ] += fiz2;
698 fshift[i_shift_offset+XX] += tx;
699 fshift[i_shift_offset+YY] += ty;
700 fshift[i_shift_offset+ZZ] += tz;
702 /* Increment number of inner iterations */
703 inneriter += j_index_end - j_index_start;
705 /* Outer loop uses 30 flops */
708 /* Increment number of outer iterations */
711 /* Update outer/inner flops */
713 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*30 + inneriter*109);