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 "gromacs/legacyheaders/types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "gromacs/legacyheaders/nrnb.h"
48 * Gromacs nonbonded kernel: nb_kernel_ElecEw_VdwLJ_GeomW4P1_VF_c
49 * Electrostatics interaction: Ewald
50 * VdW interaction: LennardJones
51 * Geometry: Water4-Particle
52 * Calculate force/pot: PotentialAndForce
55 nb_kernel_ElecEw_VdwLJ_GeomW4P1_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 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
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 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
84 real velec,felec,velecsum,facel,crf,krf,krf2;
87 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
91 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
99 jindex = nlist->jindex;
101 shiftidx = nlist->shift;
103 shiftvec = fr->shift_vec[0];
104 fshift = fr->fshift[0];
106 charge = mdatoms->chargeA;
107 nvdwtype = fr->ntype;
109 vdwtype = mdatoms->typeA;
111 sh_ewald = fr->ic->sh_ewald;
112 ewtab = fr->ic->tabq_coul_FDV0;
113 ewtabscale = fr->ic->tabq_scale;
114 ewtabhalfspace = 0.5/ewtabscale;
116 /* Setup water-specific parameters */
117 inr = nlist->iinr[0];
118 iq1 = facel*charge[inr+1];
119 iq2 = facel*charge[inr+2];
120 iq3 = facel*charge[inr+3];
121 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
126 /* Start outer loop over neighborlists */
127 for(iidx=0; iidx<nri; iidx++)
129 /* Load shift vector for this list */
130 i_shift_offset = DIM*shiftidx[iidx];
131 shX = shiftvec[i_shift_offset+XX];
132 shY = shiftvec[i_shift_offset+YY];
133 shZ = shiftvec[i_shift_offset+ZZ];
135 /* Load limits for loop over neighbors */
136 j_index_start = jindex[iidx];
137 j_index_end = jindex[iidx+1];
139 /* Get outer coordinate index */
141 i_coord_offset = DIM*inr;
143 /* Load i particle coords and add shift vector */
144 ix0 = shX + x[i_coord_offset+DIM*0+XX];
145 iy0 = shY + x[i_coord_offset+DIM*0+YY];
146 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
147 ix1 = shX + x[i_coord_offset+DIM*1+XX];
148 iy1 = shY + x[i_coord_offset+DIM*1+YY];
149 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
150 ix2 = shX + x[i_coord_offset+DIM*2+XX];
151 iy2 = shY + x[i_coord_offset+DIM*2+YY];
152 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
153 ix3 = shX + x[i_coord_offset+DIM*3+XX];
154 iy3 = shY + x[i_coord_offset+DIM*3+YY];
155 iz3 = shZ + x[i_coord_offset+DIM*3+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 */
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;
204 rsq30 = dx30*dx30+dy30*dy30+dz30*dz30;
206 rinv10 = gmx_invsqrt(rsq10);
207 rinv20 = gmx_invsqrt(rsq20);
208 rinv30 = gmx_invsqrt(rsq30);
210 rinvsq00 = 1.0/rsq00;
211 rinvsq10 = rinv10*rinv10;
212 rinvsq20 = rinv20*rinv20;
213 rinvsq30 = rinv30*rinv30;
215 /* Load parameters for j particles */
217 vdwjidx0 = 2*vdwtype[jnr+0];
219 /**************************
220 * CALCULATE INTERACTIONS *
221 **************************/
223 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
224 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
226 /* LENNARD-JONES DISPERSION/REPULSION */
228 rinvsix = rinvsq00*rinvsq00*rinvsq00;
229 vvdw6 = c6_00*rinvsix;
230 vvdw12 = c12_00*rinvsix*rinvsix;
231 vvdw = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
232 fvdw = (vvdw12-vvdw6)*rinvsq00;
234 /* Update potential sums from outer loop */
239 /* Calculate temporary vectorial force */
244 /* Update vectorial force */
248 f[j_coord_offset+DIM*0+XX] -= tx;
249 f[j_coord_offset+DIM*0+YY] -= ty;
250 f[j_coord_offset+DIM*0+ZZ] -= tz;
252 /**************************
253 * CALCULATE INTERACTIONS *
254 **************************/
260 /* EWALD ELECTROSTATICS */
262 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
263 ewrt = r10*ewtabscale;
267 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
268 velec = qq10*(rinv10-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
269 felec = qq10*rinv10*(rinvsq10-felec);
271 /* Update potential sums from outer loop */
276 /* Calculate temporary vectorial force */
281 /* Update vectorial force */
285 f[j_coord_offset+DIM*0+XX] -= tx;
286 f[j_coord_offset+DIM*0+YY] -= ty;
287 f[j_coord_offset+DIM*0+ZZ] -= tz;
289 /**************************
290 * CALCULATE INTERACTIONS *
291 **************************/
297 /* EWALD ELECTROSTATICS */
299 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
300 ewrt = r20*ewtabscale;
304 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
305 velec = qq20*(rinv20-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
306 felec = qq20*rinv20*(rinvsq20-felec);
308 /* Update potential sums from outer loop */
313 /* Calculate temporary vectorial force */
318 /* Update vectorial force */
322 f[j_coord_offset+DIM*0+XX] -= tx;
323 f[j_coord_offset+DIM*0+YY] -= ty;
324 f[j_coord_offset+DIM*0+ZZ] -= tz;
326 /**************************
327 * CALCULATE INTERACTIONS *
328 **************************/
334 /* EWALD ELECTROSTATICS */
336 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
337 ewrt = r30*ewtabscale;
341 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
342 velec = qq30*(rinv30-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
343 felec = qq30*rinv30*(rinvsq30-felec);
345 /* Update potential sums from outer loop */
350 /* Calculate temporary vectorial force */
355 /* Update vectorial force */
359 f[j_coord_offset+DIM*0+XX] -= tx;
360 f[j_coord_offset+DIM*0+YY] -= ty;
361 f[j_coord_offset+DIM*0+ZZ] -= tz;
363 /* Inner loop uses 155 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 f[i_coord_offset+DIM*3+XX] += fix3;
387 f[i_coord_offset+DIM*3+YY] += fiy3;
388 f[i_coord_offset+DIM*3+ZZ] += fiz3;
392 fshift[i_shift_offset+XX] += tx;
393 fshift[i_shift_offset+YY] += ty;
394 fshift[i_shift_offset+ZZ] += tz;
397 /* Update potential energies */
398 kernel_data->energygrp_elec[ggid] += velecsum;
399 kernel_data->energygrp_vdw[ggid] += vvdwsum;
401 /* Increment number of inner iterations */
402 inneriter += j_index_end - j_index_start;
404 /* Outer loop uses 41 flops */
407 /* Increment number of outer iterations */
410 /* Update outer/inner flops */
412 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*41 + inneriter*155);
415 * Gromacs nonbonded kernel: nb_kernel_ElecEw_VdwLJ_GeomW4P1_F_c
416 * Electrostatics interaction: Ewald
417 * VdW interaction: LennardJones
418 * Geometry: Water4-Particle
419 * Calculate force/pot: Force
422 nb_kernel_ElecEw_VdwLJ_GeomW4P1_F_c
423 (t_nblist * gmx_restrict nlist,
424 rvec * gmx_restrict xx,
425 rvec * gmx_restrict ff,
426 t_forcerec * gmx_restrict fr,
427 t_mdatoms * gmx_restrict mdatoms,
428 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
429 t_nrnb * gmx_restrict nrnb)
431 int i_shift_offset,i_coord_offset,j_coord_offset;
432 int j_index_start,j_index_end;
433 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
434 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
435 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
436 real *shiftvec,*fshift,*x,*f;
438 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
440 real ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
442 real ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
444 real ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
446 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
447 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
448 real dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
449 real dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
450 real dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
451 real velec,felec,velecsum,facel,crf,krf,krf2;
454 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
458 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
466 jindex = nlist->jindex;
468 shiftidx = nlist->shift;
470 shiftvec = fr->shift_vec[0];
471 fshift = fr->fshift[0];
473 charge = mdatoms->chargeA;
474 nvdwtype = fr->ntype;
476 vdwtype = mdatoms->typeA;
478 sh_ewald = fr->ic->sh_ewald;
479 ewtab = fr->ic->tabq_coul_F;
480 ewtabscale = fr->ic->tabq_scale;
481 ewtabhalfspace = 0.5/ewtabscale;
483 /* Setup water-specific parameters */
484 inr = nlist->iinr[0];
485 iq1 = facel*charge[inr+1];
486 iq2 = facel*charge[inr+2];
487 iq3 = facel*charge[inr+3];
488 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
493 /* Start outer loop over neighborlists */
494 for(iidx=0; iidx<nri; iidx++)
496 /* Load shift vector for this list */
497 i_shift_offset = DIM*shiftidx[iidx];
498 shX = shiftvec[i_shift_offset+XX];
499 shY = shiftvec[i_shift_offset+YY];
500 shZ = shiftvec[i_shift_offset+ZZ];
502 /* Load limits for loop over neighbors */
503 j_index_start = jindex[iidx];
504 j_index_end = jindex[iidx+1];
506 /* Get outer coordinate index */
508 i_coord_offset = DIM*inr;
510 /* Load i particle coords and add shift vector */
511 ix0 = shX + x[i_coord_offset+DIM*0+XX];
512 iy0 = shY + x[i_coord_offset+DIM*0+YY];
513 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
514 ix1 = shX + x[i_coord_offset+DIM*1+XX];
515 iy1 = shY + x[i_coord_offset+DIM*1+YY];
516 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
517 ix2 = shX + x[i_coord_offset+DIM*2+XX];
518 iy2 = shY + x[i_coord_offset+DIM*2+YY];
519 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
520 ix3 = shX + x[i_coord_offset+DIM*3+XX];
521 iy3 = shY + x[i_coord_offset+DIM*3+YY];
522 iz3 = shZ + x[i_coord_offset+DIM*3+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 */
563 /* Calculate squared distance and things based on it */
564 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
565 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
566 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
567 rsq30 = dx30*dx30+dy30*dy30+dz30*dz30;
569 rinv10 = gmx_invsqrt(rsq10);
570 rinv20 = gmx_invsqrt(rsq20);
571 rinv30 = gmx_invsqrt(rsq30);
573 rinvsq00 = 1.0/rsq00;
574 rinvsq10 = rinv10*rinv10;
575 rinvsq20 = rinv20*rinv20;
576 rinvsq30 = rinv30*rinv30;
578 /* Load parameters for j particles */
580 vdwjidx0 = 2*vdwtype[jnr+0];
582 /**************************
583 * CALCULATE INTERACTIONS *
584 **************************/
586 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
587 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
589 /* LENNARD-JONES DISPERSION/REPULSION */
591 rinvsix = rinvsq00*rinvsq00*rinvsq00;
592 fvdw = (c12_00*rinvsix-c6_00)*rinvsix*rinvsq00;
596 /* Calculate temporary vectorial force */
601 /* Update vectorial force */
605 f[j_coord_offset+DIM*0+XX] -= tx;
606 f[j_coord_offset+DIM*0+YY] -= ty;
607 f[j_coord_offset+DIM*0+ZZ] -= tz;
609 /**************************
610 * CALCULATE INTERACTIONS *
611 **************************/
617 /* EWALD ELECTROSTATICS */
619 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
620 ewrt = r10*ewtabscale;
623 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
624 felec = qq10*rinv10*(rinvsq10-felec);
628 /* Calculate temporary vectorial force */
633 /* Update vectorial force */
637 f[j_coord_offset+DIM*0+XX] -= tx;
638 f[j_coord_offset+DIM*0+YY] -= ty;
639 f[j_coord_offset+DIM*0+ZZ] -= tz;
641 /**************************
642 * CALCULATE INTERACTIONS *
643 **************************/
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;
673 /**************************
674 * CALCULATE INTERACTIONS *
675 **************************/
681 /* EWALD ELECTROSTATICS */
683 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
684 ewrt = r30*ewtabscale;
687 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
688 felec = qq30*rinv30*(rinvsq30-felec);
692 /* Calculate temporary vectorial force */
697 /* Update vectorial force */
701 f[j_coord_offset+DIM*0+XX] -= tx;
702 f[j_coord_offset+DIM*0+YY] -= ty;
703 f[j_coord_offset+DIM*0+ZZ] -= tz;
705 /* Inner loop uses 129 flops */
707 /* End of innermost loop */
710 f[i_coord_offset+DIM*0+XX] += fix0;
711 f[i_coord_offset+DIM*0+YY] += fiy0;
712 f[i_coord_offset+DIM*0+ZZ] += fiz0;
716 f[i_coord_offset+DIM*1+XX] += fix1;
717 f[i_coord_offset+DIM*1+YY] += fiy1;
718 f[i_coord_offset+DIM*1+ZZ] += fiz1;
722 f[i_coord_offset+DIM*2+XX] += fix2;
723 f[i_coord_offset+DIM*2+YY] += fiy2;
724 f[i_coord_offset+DIM*2+ZZ] += fiz2;
728 f[i_coord_offset+DIM*3+XX] += fix3;
729 f[i_coord_offset+DIM*3+YY] += fiy3;
730 f[i_coord_offset+DIM*3+ZZ] += fiz3;
734 fshift[i_shift_offset+XX] += tx;
735 fshift[i_shift_offset+YY] += ty;
736 fshift[i_shift_offset+ZZ] += tz;
738 /* Increment number of inner iterations */
739 inneriter += j_index_end - j_index_start;
741 /* Outer loop uses 39 flops */
744 /* Increment number of outer iterations */
747 /* Update outer/inner flops */
749 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*39 + inneriter*129);