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_ElecEw_VdwLJ_GeomW3P1_VF_c
49 * Electrostatics interaction: Ewald
50 * VdW interaction: LennardJones
51 * Geometry: Water3-Particle
52 * Calculate force/pot: PotentialAndForce
55 nb_kernel_ElecEw_VdwLJ_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;
88 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
96 jindex = nlist->jindex;
98 shiftidx = nlist->shift;
100 shiftvec = fr->shift_vec[0];
101 fshift = fr->fshift[0];
103 charge = mdatoms->chargeA;
104 nvdwtype = fr->ntype;
106 vdwtype = mdatoms->typeA;
108 sh_ewald = fr->ic->sh_ewald;
109 ewtab = fr->ic->tabq_coul_FDV0;
110 ewtabscale = fr->ic->tabq_scale;
111 ewtabhalfspace = 0.5/ewtabscale;
113 /* Setup water-specific parameters */
114 inr = nlist->iinr[0];
115 iq0 = facel*charge[inr+0];
116 iq1 = facel*charge[inr+1];
117 iq2 = facel*charge[inr+2];
118 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
123 /* Start outer loop over neighborlists */
124 for(iidx=0; iidx<nri; iidx++)
126 /* Load shift vector for this list */
127 i_shift_offset = DIM*shiftidx[iidx];
128 shX = shiftvec[i_shift_offset+XX];
129 shY = shiftvec[i_shift_offset+YY];
130 shZ = shiftvec[i_shift_offset+ZZ];
132 /* Load limits for loop over neighbors */
133 j_index_start = jindex[iidx];
134 j_index_end = jindex[iidx+1];
136 /* Get outer coordinate index */
138 i_coord_offset = DIM*inr;
140 /* Load i particle coords and add shift vector */
141 ix0 = shX + x[i_coord_offset+DIM*0+XX];
142 iy0 = shY + x[i_coord_offset+DIM*0+YY];
143 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
144 ix1 = shX + x[i_coord_offset+DIM*1+XX];
145 iy1 = shY + x[i_coord_offset+DIM*1+YY];
146 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
147 ix2 = shX + x[i_coord_offset+DIM*2+XX];
148 iy2 = shY + x[i_coord_offset+DIM*2+YY];
149 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
161 /* Reset potential sums */
165 /* Start inner kernel loop */
166 for(jidx=j_index_start; jidx<j_index_end; jidx++)
168 /* Get j neighbor index, and coordinate index */
170 j_coord_offset = DIM*jnr;
172 /* load j atom coordinates */
173 jx0 = x[j_coord_offset+DIM*0+XX];
174 jy0 = x[j_coord_offset+DIM*0+YY];
175 jz0 = x[j_coord_offset+DIM*0+ZZ];
177 /* Calculate displacement vector */
188 /* Calculate squared distance and things based on it */
189 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
190 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
191 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
193 rinv00 = gmx_invsqrt(rsq00);
194 rinv10 = gmx_invsqrt(rsq10);
195 rinv20 = gmx_invsqrt(rsq20);
197 rinvsq00 = rinv00*rinv00;
198 rinvsq10 = rinv10*rinv10;
199 rinvsq20 = rinv20*rinv20;
201 /* Load parameters for j particles */
203 vdwjidx0 = 2*vdwtype[jnr+0];
205 /**************************
206 * CALCULATE INTERACTIONS *
207 **************************/
212 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
213 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
215 /* EWALD ELECTROSTATICS */
217 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
218 ewrt = r00*ewtabscale;
222 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
223 velec = qq00*(rinv00-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
224 felec = qq00*rinv00*(rinvsq00-felec);
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 */
240 /* Calculate temporary vectorial force */
245 /* Update vectorial force */
249 f[j_coord_offset+DIM*0+XX] -= tx;
250 f[j_coord_offset+DIM*0+YY] -= ty;
251 f[j_coord_offset+DIM*0+ZZ] -= tz;
253 /**************************
254 * CALCULATE INTERACTIONS *
255 **************************/
261 /* EWALD ELECTROSTATICS */
263 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
264 ewrt = r10*ewtabscale;
268 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
269 velec = qq10*(rinv10-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
270 felec = qq10*rinv10*(rinvsq10-felec);
272 /* Update potential sums from outer loop */
277 /* Calculate temporary vectorial force */
282 /* Update vectorial force */
286 f[j_coord_offset+DIM*0+XX] -= tx;
287 f[j_coord_offset+DIM*0+YY] -= ty;
288 f[j_coord_offset+DIM*0+ZZ] -= tz;
290 /**************************
291 * CALCULATE INTERACTIONS *
292 **************************/
298 /* EWALD ELECTROSTATICS */
300 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
301 ewrt = r20*ewtabscale;
305 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
306 velec = qq20*(rinv20-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
307 felec = qq20*rinv20*(rinvsq20-felec);
309 /* Update potential sums from outer loop */
314 /* Calculate temporary vectorial force */
319 /* Update vectorial force */
323 f[j_coord_offset+DIM*0+XX] -= tx;
324 f[j_coord_offset+DIM*0+YY] -= ty;
325 f[j_coord_offset+DIM*0+ZZ] -= tz;
327 /* Inner loop uses 135 flops */
329 /* End of innermost loop */
332 f[i_coord_offset+DIM*0+XX] += fix0;
333 f[i_coord_offset+DIM*0+YY] += fiy0;
334 f[i_coord_offset+DIM*0+ZZ] += fiz0;
338 f[i_coord_offset+DIM*1+XX] += fix1;
339 f[i_coord_offset+DIM*1+YY] += fiy1;
340 f[i_coord_offset+DIM*1+ZZ] += fiz1;
344 f[i_coord_offset+DIM*2+XX] += fix2;
345 f[i_coord_offset+DIM*2+YY] += fiy2;
346 f[i_coord_offset+DIM*2+ZZ] += fiz2;
350 fshift[i_shift_offset+XX] += tx;
351 fshift[i_shift_offset+YY] += ty;
352 fshift[i_shift_offset+ZZ] += tz;
355 /* Update potential energies */
356 kernel_data->energygrp_elec[ggid] += velecsum;
357 kernel_data->energygrp_vdw[ggid] += vvdwsum;
359 /* Increment number of inner iterations */
360 inneriter += j_index_end - j_index_start;
362 /* Outer loop uses 32 flops */
365 /* Increment number of outer iterations */
368 /* Update outer/inner flops */
370 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*32 + inneriter*135);
373 * Gromacs nonbonded kernel: nb_kernel_ElecEw_VdwLJ_GeomW3P1_F_c
374 * Electrostatics interaction: Ewald
375 * VdW interaction: LennardJones
376 * Geometry: Water3-Particle
377 * Calculate force/pot: Force
380 nb_kernel_ElecEw_VdwLJ_GeomW3P1_F_c
381 (t_nblist * gmx_restrict nlist,
382 rvec * gmx_restrict xx,
383 rvec * gmx_restrict ff,
384 t_forcerec * gmx_restrict fr,
385 t_mdatoms * gmx_restrict mdatoms,
386 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
387 t_nrnb * gmx_restrict nrnb)
389 int i_shift_offset,i_coord_offset,j_coord_offset;
390 int j_index_start,j_index_end;
391 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
392 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
393 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
394 real *shiftvec,*fshift,*x,*f;
396 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
398 real ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
400 real ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
402 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
403 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
404 real dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
405 real dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
406 real velec,felec,velecsum,facel,crf,krf,krf2;
409 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
413 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
421 jindex = nlist->jindex;
423 shiftidx = nlist->shift;
425 shiftvec = fr->shift_vec[0];
426 fshift = fr->fshift[0];
428 charge = mdatoms->chargeA;
429 nvdwtype = fr->ntype;
431 vdwtype = mdatoms->typeA;
433 sh_ewald = fr->ic->sh_ewald;
434 ewtab = fr->ic->tabq_coul_F;
435 ewtabscale = fr->ic->tabq_scale;
436 ewtabhalfspace = 0.5/ewtabscale;
438 /* Setup water-specific parameters */
439 inr = nlist->iinr[0];
440 iq0 = facel*charge[inr+0];
441 iq1 = facel*charge[inr+1];
442 iq2 = facel*charge[inr+2];
443 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
448 /* Start outer loop over neighborlists */
449 for(iidx=0; iidx<nri; iidx++)
451 /* Load shift vector for this list */
452 i_shift_offset = DIM*shiftidx[iidx];
453 shX = shiftvec[i_shift_offset+XX];
454 shY = shiftvec[i_shift_offset+YY];
455 shZ = shiftvec[i_shift_offset+ZZ];
457 /* Load limits for loop over neighbors */
458 j_index_start = jindex[iidx];
459 j_index_end = jindex[iidx+1];
461 /* Get outer coordinate index */
463 i_coord_offset = DIM*inr;
465 /* Load i particle coords and add shift vector */
466 ix0 = shX + x[i_coord_offset+DIM*0+XX];
467 iy0 = shY + x[i_coord_offset+DIM*0+YY];
468 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
469 ix1 = shX + x[i_coord_offset+DIM*1+XX];
470 iy1 = shY + x[i_coord_offset+DIM*1+YY];
471 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
472 ix2 = shX + x[i_coord_offset+DIM*2+XX];
473 iy2 = shY + x[i_coord_offset+DIM*2+YY];
474 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
486 /* Start inner kernel loop */
487 for(jidx=j_index_start; jidx<j_index_end; jidx++)
489 /* Get j neighbor index, and coordinate index */
491 j_coord_offset = DIM*jnr;
493 /* load j atom coordinates */
494 jx0 = x[j_coord_offset+DIM*0+XX];
495 jy0 = x[j_coord_offset+DIM*0+YY];
496 jz0 = x[j_coord_offset+DIM*0+ZZ];
498 /* Calculate displacement vector */
509 /* Calculate squared distance and things based on it */
510 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
511 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
512 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
514 rinv00 = gmx_invsqrt(rsq00);
515 rinv10 = gmx_invsqrt(rsq10);
516 rinv20 = gmx_invsqrt(rsq20);
518 rinvsq00 = rinv00*rinv00;
519 rinvsq10 = rinv10*rinv10;
520 rinvsq20 = rinv20*rinv20;
522 /* Load parameters for j particles */
524 vdwjidx0 = 2*vdwtype[jnr+0];
526 /**************************
527 * CALCULATE INTERACTIONS *
528 **************************/
533 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
534 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
536 /* EWALD ELECTROSTATICS */
538 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
539 ewrt = r00*ewtabscale;
542 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
543 felec = qq00*rinv00*(rinvsq00-felec);
545 /* LENNARD-JONES DISPERSION/REPULSION */
547 rinvsix = rinvsq00*rinvsq00*rinvsq00;
548 fvdw = (c12_00*rinvsix-c6_00)*rinvsix*rinvsq00;
552 /* Calculate temporary vectorial force */
557 /* Update vectorial force */
561 f[j_coord_offset+DIM*0+XX] -= tx;
562 f[j_coord_offset+DIM*0+YY] -= ty;
563 f[j_coord_offset+DIM*0+ZZ] -= tz;
565 /**************************
566 * CALCULATE INTERACTIONS *
567 **************************/
573 /* EWALD ELECTROSTATICS */
575 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
576 ewrt = r10*ewtabscale;
579 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
580 felec = qq10*rinv10*(rinvsq10-felec);
584 /* Calculate temporary vectorial force */
589 /* Update vectorial force */
593 f[j_coord_offset+DIM*0+XX] -= tx;
594 f[j_coord_offset+DIM*0+YY] -= ty;
595 f[j_coord_offset+DIM*0+ZZ] -= tz;
597 /**************************
598 * CALCULATE INTERACTIONS *
599 **************************/
605 /* EWALD ELECTROSTATICS */
607 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
608 ewrt = r20*ewtabscale;
611 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
612 felec = qq20*rinv20*(rinvsq20-felec);
616 /* Calculate temporary vectorial force */
621 /* Update vectorial force */
625 f[j_coord_offset+DIM*0+XX] -= tx;
626 f[j_coord_offset+DIM*0+YY] -= ty;
627 f[j_coord_offset+DIM*0+ZZ] -= tz;
629 /* Inner loop uses 109 flops */
631 /* End of innermost loop */
634 f[i_coord_offset+DIM*0+XX] += fix0;
635 f[i_coord_offset+DIM*0+YY] += fiy0;
636 f[i_coord_offset+DIM*0+ZZ] += fiz0;
640 f[i_coord_offset+DIM*1+XX] += fix1;
641 f[i_coord_offset+DIM*1+YY] += fiy1;
642 f[i_coord_offset+DIM*1+ZZ] += fiz1;
646 f[i_coord_offset+DIM*2+XX] += fix2;
647 f[i_coord_offset+DIM*2+YY] += fiy2;
648 f[i_coord_offset+DIM*2+ZZ] += fiz2;
652 fshift[i_shift_offset+XX] += tx;
653 fshift[i_shift_offset+YY] += ty;
654 fshift[i_shift_offset+ZZ] += tz;
656 /* Increment number of inner iterations */
657 inneriter += j_index_end - j_index_start;
659 /* Outer loop uses 30 flops */
662 /* Increment number of outer iterations */
665 /* Update outer/inner flops */
667 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*30 + inneriter*109);