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_VdwLJ_GeomW4P1_VF_c
51 * Electrostatics interaction: Ewald
52 * VdW interaction: LennardJones
53 * Geometry: Water4-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecEw_VdwLJ_GeomW4P1_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 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
81 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
82 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
83 real dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
84 real dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
85 real dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
86 real velec,felec,velecsum,facel,crf,krf,krf2;
89 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
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;
113 sh_ewald = fr->ic->sh_ewald;
114 ewtab = fr->ic->tabq_coul_FDV0;
115 ewtabscale = fr->ic->tabq_scale;
116 ewtabhalfspace = 0.5/ewtabscale;
118 /* Setup water-specific parameters */
119 inr = nlist->iinr[0];
120 iq1 = facel*charge[inr+1];
121 iq2 = facel*charge[inr+2];
122 iq3 = facel*charge[inr+3];
123 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
128 /* Start outer loop over neighborlists */
129 for(iidx=0; iidx<nri; iidx++)
131 /* Load shift vector for this list */
132 i_shift_offset = DIM*shiftidx[iidx];
133 shX = shiftvec[i_shift_offset+XX];
134 shY = shiftvec[i_shift_offset+YY];
135 shZ = shiftvec[i_shift_offset+ZZ];
137 /* Load limits for loop over neighbors */
138 j_index_start = jindex[iidx];
139 j_index_end = jindex[iidx+1];
141 /* Get outer coordinate index */
143 i_coord_offset = DIM*inr;
145 /* Load i particle coords and add shift vector */
146 ix0 = shX + x[i_coord_offset+DIM*0+XX];
147 iy0 = shY + x[i_coord_offset+DIM*0+YY];
148 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
149 ix1 = shX + x[i_coord_offset+DIM*1+XX];
150 iy1 = shY + x[i_coord_offset+DIM*1+YY];
151 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
152 ix2 = shX + x[i_coord_offset+DIM*2+XX];
153 iy2 = shY + x[i_coord_offset+DIM*2+YY];
154 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
155 ix3 = shX + x[i_coord_offset+DIM*3+XX];
156 iy3 = shY + x[i_coord_offset+DIM*3+YY];
157 iz3 = shZ + x[i_coord_offset+DIM*3+ZZ];
172 /* Reset potential sums */
176 /* Start inner kernel loop */
177 for(jidx=j_index_start; jidx<j_index_end; jidx++)
179 /* Get j neighbor index, and coordinate index */
181 j_coord_offset = DIM*jnr;
183 /* load j atom coordinates */
184 jx0 = x[j_coord_offset+DIM*0+XX];
185 jy0 = x[j_coord_offset+DIM*0+YY];
186 jz0 = x[j_coord_offset+DIM*0+ZZ];
188 /* Calculate displacement vector */
202 /* Calculate squared distance and things based on it */
203 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
204 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
205 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
206 rsq30 = dx30*dx30+dy30*dy30+dz30*dz30;
208 rinv10 = gmx_invsqrt(rsq10);
209 rinv20 = gmx_invsqrt(rsq20);
210 rinv30 = gmx_invsqrt(rsq30);
212 rinvsq00 = 1.0/rsq00;
213 rinvsq10 = rinv10*rinv10;
214 rinvsq20 = rinv20*rinv20;
215 rinvsq30 = rinv30*rinv30;
217 /* Load parameters for j particles */
219 vdwjidx0 = 2*vdwtype[jnr+0];
221 /**************************
222 * CALCULATE INTERACTIONS *
223 **************************/
225 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
226 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
228 /* LENNARD-JONES DISPERSION/REPULSION */
230 rinvsix = rinvsq00*rinvsq00*rinvsq00;
231 vvdw6 = c6_00*rinvsix;
232 vvdw12 = c12_00*rinvsix*rinvsix;
233 vvdw = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
234 fvdw = (vvdw12-vvdw6)*rinvsq00;
236 /* Update potential sums from outer loop */
241 /* Calculate temporary vectorial force */
246 /* Update vectorial force */
250 f[j_coord_offset+DIM*0+XX] -= tx;
251 f[j_coord_offset+DIM*0+YY] -= ty;
252 f[j_coord_offset+DIM*0+ZZ] -= tz;
254 /**************************
255 * CALCULATE INTERACTIONS *
256 **************************/
262 /* EWALD ELECTROSTATICS */
264 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
265 ewrt = r10*ewtabscale;
269 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
270 velec = qq10*(rinv10-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
271 felec = qq10*rinv10*(rinvsq10-felec);
273 /* Update potential sums from outer loop */
278 /* Calculate temporary vectorial force */
283 /* Update vectorial force */
287 f[j_coord_offset+DIM*0+XX] -= tx;
288 f[j_coord_offset+DIM*0+YY] -= ty;
289 f[j_coord_offset+DIM*0+ZZ] -= tz;
291 /**************************
292 * CALCULATE INTERACTIONS *
293 **************************/
299 /* EWALD ELECTROSTATICS */
301 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
302 ewrt = r20*ewtabscale;
306 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
307 velec = qq20*(rinv20-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
308 felec = qq20*rinv20*(rinvsq20-felec);
310 /* Update potential sums from outer loop */
315 /* Calculate temporary vectorial force */
320 /* Update vectorial force */
324 f[j_coord_offset+DIM*0+XX] -= tx;
325 f[j_coord_offset+DIM*0+YY] -= ty;
326 f[j_coord_offset+DIM*0+ZZ] -= tz;
328 /**************************
329 * CALCULATE INTERACTIONS *
330 **************************/
336 /* EWALD ELECTROSTATICS */
338 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
339 ewrt = r30*ewtabscale;
343 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
344 velec = qq30*(rinv30-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
345 felec = qq30*rinv30*(rinvsq30-felec);
347 /* Update potential sums from outer loop */
352 /* Calculate temporary vectorial force */
357 /* Update vectorial force */
361 f[j_coord_offset+DIM*0+XX] -= tx;
362 f[j_coord_offset+DIM*0+YY] -= ty;
363 f[j_coord_offset+DIM*0+ZZ] -= tz;
365 /* Inner loop uses 155 flops */
367 /* End of innermost loop */
370 f[i_coord_offset+DIM*0+XX] += fix0;
371 f[i_coord_offset+DIM*0+YY] += fiy0;
372 f[i_coord_offset+DIM*0+ZZ] += fiz0;
376 f[i_coord_offset+DIM*1+XX] += fix1;
377 f[i_coord_offset+DIM*1+YY] += fiy1;
378 f[i_coord_offset+DIM*1+ZZ] += fiz1;
382 f[i_coord_offset+DIM*2+XX] += fix2;
383 f[i_coord_offset+DIM*2+YY] += fiy2;
384 f[i_coord_offset+DIM*2+ZZ] += fiz2;
388 f[i_coord_offset+DIM*3+XX] += fix3;
389 f[i_coord_offset+DIM*3+YY] += fiy3;
390 f[i_coord_offset+DIM*3+ZZ] += fiz3;
394 fshift[i_shift_offset+XX] += tx;
395 fshift[i_shift_offset+YY] += ty;
396 fshift[i_shift_offset+ZZ] += tz;
399 /* Update potential energies */
400 kernel_data->energygrp_elec[ggid] += velecsum;
401 kernel_data->energygrp_vdw[ggid] += vvdwsum;
403 /* Increment number of inner iterations */
404 inneriter += j_index_end - j_index_start;
406 /* Outer loop uses 41 flops */
409 /* Increment number of outer iterations */
412 /* Update outer/inner flops */
414 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*41 + inneriter*155);
417 * Gromacs nonbonded kernel: nb_kernel_ElecEw_VdwLJ_GeomW4P1_F_c
418 * Electrostatics interaction: Ewald
419 * VdW interaction: LennardJones
420 * Geometry: Water4-Particle
421 * Calculate force/pot: Force
424 nb_kernel_ElecEw_VdwLJ_GeomW4P1_F_c
425 (t_nblist * gmx_restrict nlist,
426 rvec * gmx_restrict xx,
427 rvec * gmx_restrict ff,
428 t_forcerec * gmx_restrict fr,
429 t_mdatoms * gmx_restrict mdatoms,
430 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
431 t_nrnb * gmx_restrict nrnb)
433 int i_shift_offset,i_coord_offset,j_coord_offset;
434 int j_index_start,j_index_end;
435 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
436 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
437 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
438 real *shiftvec,*fshift,*x,*f;
440 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
442 real ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
444 real ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
446 real ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
448 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
449 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
450 real dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
451 real dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
452 real dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
453 real velec,felec,velecsum,facel,crf,krf,krf2;
456 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
460 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
468 jindex = nlist->jindex;
470 shiftidx = nlist->shift;
472 shiftvec = fr->shift_vec[0];
473 fshift = fr->fshift[0];
475 charge = mdatoms->chargeA;
476 nvdwtype = fr->ntype;
478 vdwtype = mdatoms->typeA;
480 sh_ewald = fr->ic->sh_ewald;
481 ewtab = fr->ic->tabq_coul_F;
482 ewtabscale = fr->ic->tabq_scale;
483 ewtabhalfspace = 0.5/ewtabscale;
485 /* Setup water-specific parameters */
486 inr = nlist->iinr[0];
487 iq1 = facel*charge[inr+1];
488 iq2 = facel*charge[inr+2];
489 iq3 = facel*charge[inr+3];
490 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
495 /* Start outer loop over neighborlists */
496 for(iidx=0; iidx<nri; iidx++)
498 /* Load shift vector for this list */
499 i_shift_offset = DIM*shiftidx[iidx];
500 shX = shiftvec[i_shift_offset+XX];
501 shY = shiftvec[i_shift_offset+YY];
502 shZ = shiftvec[i_shift_offset+ZZ];
504 /* Load limits for loop over neighbors */
505 j_index_start = jindex[iidx];
506 j_index_end = jindex[iidx+1];
508 /* Get outer coordinate index */
510 i_coord_offset = DIM*inr;
512 /* Load i particle coords and add shift vector */
513 ix0 = shX + x[i_coord_offset+DIM*0+XX];
514 iy0 = shY + x[i_coord_offset+DIM*0+YY];
515 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
516 ix1 = shX + x[i_coord_offset+DIM*1+XX];
517 iy1 = shY + x[i_coord_offset+DIM*1+YY];
518 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
519 ix2 = shX + x[i_coord_offset+DIM*2+XX];
520 iy2 = shY + x[i_coord_offset+DIM*2+YY];
521 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
522 ix3 = shX + x[i_coord_offset+DIM*3+XX];
523 iy3 = shY + x[i_coord_offset+DIM*3+YY];
524 iz3 = shZ + x[i_coord_offset+DIM*3+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 */
565 /* Calculate squared distance and things based on it */
566 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
567 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
568 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
569 rsq30 = dx30*dx30+dy30*dy30+dz30*dz30;
571 rinv10 = gmx_invsqrt(rsq10);
572 rinv20 = gmx_invsqrt(rsq20);
573 rinv30 = gmx_invsqrt(rsq30);
575 rinvsq00 = 1.0/rsq00;
576 rinvsq10 = rinv10*rinv10;
577 rinvsq20 = rinv20*rinv20;
578 rinvsq30 = rinv30*rinv30;
580 /* Load parameters for j particles */
582 vdwjidx0 = 2*vdwtype[jnr+0];
584 /**************************
585 * CALCULATE INTERACTIONS *
586 **************************/
588 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
589 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
591 /* LENNARD-JONES DISPERSION/REPULSION */
593 rinvsix = rinvsq00*rinvsq00*rinvsq00;
594 fvdw = (c12_00*rinvsix-c6_00)*rinvsix*rinvsq00;
598 /* Calculate temporary vectorial force */
603 /* Update vectorial force */
607 f[j_coord_offset+DIM*0+XX] -= tx;
608 f[j_coord_offset+DIM*0+YY] -= ty;
609 f[j_coord_offset+DIM*0+ZZ] -= tz;
611 /**************************
612 * CALCULATE INTERACTIONS *
613 **************************/
619 /* EWALD ELECTROSTATICS */
621 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
622 ewrt = r10*ewtabscale;
625 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
626 felec = qq10*rinv10*(rinvsq10-felec);
630 /* Calculate temporary vectorial force */
635 /* Update vectorial force */
639 f[j_coord_offset+DIM*0+XX] -= tx;
640 f[j_coord_offset+DIM*0+YY] -= ty;
641 f[j_coord_offset+DIM*0+ZZ] -= tz;
643 /**************************
644 * CALCULATE INTERACTIONS *
645 **************************/
651 /* EWALD ELECTROSTATICS */
653 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
654 ewrt = r20*ewtabscale;
657 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
658 felec = qq20*rinv20*(rinvsq20-felec);
662 /* Calculate temporary vectorial force */
667 /* Update vectorial force */
671 f[j_coord_offset+DIM*0+XX] -= tx;
672 f[j_coord_offset+DIM*0+YY] -= ty;
673 f[j_coord_offset+DIM*0+ZZ] -= tz;
675 /**************************
676 * CALCULATE INTERACTIONS *
677 **************************/
683 /* EWALD ELECTROSTATICS */
685 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
686 ewrt = r30*ewtabscale;
689 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
690 felec = qq30*rinv30*(rinvsq30-felec);
694 /* Calculate temporary vectorial force */
699 /* Update vectorial force */
703 f[j_coord_offset+DIM*0+XX] -= tx;
704 f[j_coord_offset+DIM*0+YY] -= ty;
705 f[j_coord_offset+DIM*0+ZZ] -= tz;
707 /* Inner loop uses 129 flops */
709 /* End of innermost loop */
712 f[i_coord_offset+DIM*0+XX] += fix0;
713 f[i_coord_offset+DIM*0+YY] += fiy0;
714 f[i_coord_offset+DIM*0+ZZ] += fiz0;
718 f[i_coord_offset+DIM*1+XX] += fix1;
719 f[i_coord_offset+DIM*1+YY] += fiy1;
720 f[i_coord_offset+DIM*1+ZZ] += fiz1;
724 f[i_coord_offset+DIM*2+XX] += fix2;
725 f[i_coord_offset+DIM*2+YY] += fiy2;
726 f[i_coord_offset+DIM*2+ZZ] += fiz2;
730 f[i_coord_offset+DIM*3+XX] += fix3;
731 f[i_coord_offset+DIM*3+YY] += fiy3;
732 f[i_coord_offset+DIM*3+ZZ] += fiz3;
736 fshift[i_shift_offset+XX] += tx;
737 fshift[i_shift_offset+YY] += ty;
738 fshift[i_shift_offset+ZZ] += tz;
740 /* Increment number of inner iterations */
741 inneriter += j_index_end - j_index_start;
743 /* Outer loop uses 39 flops */
746 /* Increment number of outer iterations */
749 /* Update outer/inner flops */
751 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*39 + inneriter*129);