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_GeomW3P1_VF_c
51 * Electrostatics interaction: Ewald
52 * VdW interaction: LennardJones
53 * Geometry: Water3-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecEw_VdwLJ_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];
125 /* Start outer loop over neighborlists */
126 for(iidx=0; iidx<nri; iidx++)
128 /* Load shift vector for this list */
129 i_shift_offset = DIM*shiftidx[iidx];
130 shX = shiftvec[i_shift_offset+XX];
131 shY = shiftvec[i_shift_offset+YY];
132 shZ = shiftvec[i_shift_offset+ZZ];
134 /* Load limits for loop over neighbors */
135 j_index_start = jindex[iidx];
136 j_index_end = jindex[iidx+1];
138 /* Get outer coordinate index */
140 i_coord_offset = DIM*inr;
142 /* Load i particle coords and add shift vector */
143 ix0 = shX + x[i_coord_offset+DIM*0+XX];
144 iy0 = shY + x[i_coord_offset+DIM*0+YY];
145 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
146 ix1 = shX + x[i_coord_offset+DIM*1+XX];
147 iy1 = shY + x[i_coord_offset+DIM*1+YY];
148 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
149 ix2 = shX + x[i_coord_offset+DIM*2+XX];
150 iy2 = shY + x[i_coord_offset+DIM*2+YY];
151 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
163 /* Reset potential sums */
167 /* Start inner kernel loop */
168 for(jidx=j_index_start; jidx<j_index_end; jidx++)
170 /* Get j neighbor index, and coordinate index */
172 j_coord_offset = DIM*jnr;
174 /* load j atom coordinates */
175 jx0 = x[j_coord_offset+DIM*0+XX];
176 jy0 = x[j_coord_offset+DIM*0+YY];
177 jz0 = x[j_coord_offset+DIM*0+ZZ];
179 /* Calculate displacement vector */
190 /* Calculate squared distance and things based on it */
191 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
192 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
193 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
195 rinv00 = gmx_invsqrt(rsq00);
196 rinv10 = gmx_invsqrt(rsq10);
197 rinv20 = gmx_invsqrt(rsq20);
199 rinvsq00 = rinv00*rinv00;
200 rinvsq10 = rinv10*rinv10;
201 rinvsq20 = rinv20*rinv20;
203 /* Load parameters for j particles */
205 vdwjidx0 = 2*vdwtype[jnr+0];
207 /**************************
208 * CALCULATE INTERACTIONS *
209 **************************/
214 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
215 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
217 /* EWALD ELECTROSTATICS */
219 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
220 ewrt = r00*ewtabscale;
224 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
225 velec = qq00*(rinv00-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
226 felec = qq00*rinv00*(rinvsq00-felec);
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 */
242 /* Calculate temporary vectorial force */
247 /* Update vectorial force */
251 f[j_coord_offset+DIM*0+XX] -= tx;
252 f[j_coord_offset+DIM*0+YY] -= ty;
253 f[j_coord_offset+DIM*0+ZZ] -= tz;
255 /**************************
256 * CALCULATE INTERACTIONS *
257 **************************/
263 /* EWALD ELECTROSTATICS */
265 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
266 ewrt = r10*ewtabscale;
270 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
271 velec = qq10*(rinv10-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
272 felec = qq10*rinv10*(rinvsq10-felec);
274 /* Update potential sums from outer loop */
279 /* Calculate temporary vectorial force */
284 /* Update vectorial force */
288 f[j_coord_offset+DIM*0+XX] -= tx;
289 f[j_coord_offset+DIM*0+YY] -= ty;
290 f[j_coord_offset+DIM*0+ZZ] -= tz;
292 /**************************
293 * CALCULATE INTERACTIONS *
294 **************************/
300 /* EWALD ELECTROSTATICS */
302 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
303 ewrt = r20*ewtabscale;
307 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
308 velec = qq20*(rinv20-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
309 felec = qq20*rinv20*(rinvsq20-felec);
311 /* Update potential sums from outer loop */
316 /* Calculate temporary vectorial force */
321 /* Update vectorial force */
325 f[j_coord_offset+DIM*0+XX] -= tx;
326 f[j_coord_offset+DIM*0+YY] -= ty;
327 f[j_coord_offset+DIM*0+ZZ] -= tz;
329 /* Inner loop uses 135 flops */
331 /* End of innermost loop */
334 f[i_coord_offset+DIM*0+XX] += fix0;
335 f[i_coord_offset+DIM*0+YY] += fiy0;
336 f[i_coord_offset+DIM*0+ZZ] += fiz0;
340 f[i_coord_offset+DIM*1+XX] += fix1;
341 f[i_coord_offset+DIM*1+YY] += fiy1;
342 f[i_coord_offset+DIM*1+ZZ] += fiz1;
346 f[i_coord_offset+DIM*2+XX] += fix2;
347 f[i_coord_offset+DIM*2+YY] += fiy2;
348 f[i_coord_offset+DIM*2+ZZ] += fiz2;
352 fshift[i_shift_offset+XX] += tx;
353 fshift[i_shift_offset+YY] += ty;
354 fshift[i_shift_offset+ZZ] += tz;
357 /* Update potential energies */
358 kernel_data->energygrp_elec[ggid] += velecsum;
359 kernel_data->energygrp_vdw[ggid] += vvdwsum;
361 /* Increment number of inner iterations */
362 inneriter += j_index_end - j_index_start;
364 /* Outer loop uses 32 flops */
367 /* Increment number of outer iterations */
370 /* Update outer/inner flops */
372 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*32 + inneriter*135);
375 * Gromacs nonbonded kernel: nb_kernel_ElecEw_VdwLJ_GeomW3P1_F_c
376 * Electrostatics interaction: Ewald
377 * VdW interaction: LennardJones
378 * Geometry: Water3-Particle
379 * Calculate force/pot: Force
382 nb_kernel_ElecEw_VdwLJ_GeomW3P1_F_c
383 (t_nblist * gmx_restrict nlist,
384 rvec * gmx_restrict xx,
385 rvec * gmx_restrict ff,
386 t_forcerec * gmx_restrict fr,
387 t_mdatoms * gmx_restrict mdatoms,
388 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
389 t_nrnb * gmx_restrict nrnb)
391 int i_shift_offset,i_coord_offset,j_coord_offset;
392 int j_index_start,j_index_end;
393 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
394 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
395 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
396 real *shiftvec,*fshift,*x,*f;
398 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
400 real ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
402 real ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
404 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
405 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
406 real dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
407 real dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
408 real velec,felec,velecsum,facel,crf,krf,krf2;
411 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
415 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
423 jindex = nlist->jindex;
425 shiftidx = nlist->shift;
427 shiftvec = fr->shift_vec[0];
428 fshift = fr->fshift[0];
430 charge = mdatoms->chargeA;
431 nvdwtype = fr->ntype;
433 vdwtype = mdatoms->typeA;
435 sh_ewald = fr->ic->sh_ewald;
436 ewtab = fr->ic->tabq_coul_F;
437 ewtabscale = fr->ic->tabq_scale;
438 ewtabhalfspace = 0.5/ewtabscale;
440 /* Setup water-specific parameters */
441 inr = nlist->iinr[0];
442 iq0 = facel*charge[inr+0];
443 iq1 = facel*charge[inr+1];
444 iq2 = facel*charge[inr+2];
445 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
450 /* Start outer loop over neighborlists */
451 for(iidx=0; iidx<nri; iidx++)
453 /* Load shift vector for this list */
454 i_shift_offset = DIM*shiftidx[iidx];
455 shX = shiftvec[i_shift_offset+XX];
456 shY = shiftvec[i_shift_offset+YY];
457 shZ = shiftvec[i_shift_offset+ZZ];
459 /* Load limits for loop over neighbors */
460 j_index_start = jindex[iidx];
461 j_index_end = jindex[iidx+1];
463 /* Get outer coordinate index */
465 i_coord_offset = DIM*inr;
467 /* Load i particle coords and add shift vector */
468 ix0 = shX + x[i_coord_offset+DIM*0+XX];
469 iy0 = shY + x[i_coord_offset+DIM*0+YY];
470 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
471 ix1 = shX + x[i_coord_offset+DIM*1+XX];
472 iy1 = shY + x[i_coord_offset+DIM*1+YY];
473 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
474 ix2 = shX + x[i_coord_offset+DIM*2+XX];
475 iy2 = shY + x[i_coord_offset+DIM*2+YY];
476 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
488 /* Start inner kernel loop */
489 for(jidx=j_index_start; jidx<j_index_end; jidx++)
491 /* Get j neighbor index, and coordinate index */
493 j_coord_offset = DIM*jnr;
495 /* load j atom coordinates */
496 jx0 = x[j_coord_offset+DIM*0+XX];
497 jy0 = x[j_coord_offset+DIM*0+YY];
498 jz0 = x[j_coord_offset+DIM*0+ZZ];
500 /* Calculate displacement vector */
511 /* Calculate squared distance and things based on it */
512 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
513 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
514 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
516 rinv00 = gmx_invsqrt(rsq00);
517 rinv10 = gmx_invsqrt(rsq10);
518 rinv20 = gmx_invsqrt(rsq20);
520 rinvsq00 = rinv00*rinv00;
521 rinvsq10 = rinv10*rinv10;
522 rinvsq20 = rinv20*rinv20;
524 /* Load parameters for j particles */
526 vdwjidx0 = 2*vdwtype[jnr+0];
528 /**************************
529 * CALCULATE INTERACTIONS *
530 **************************/
535 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
536 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
538 /* EWALD ELECTROSTATICS */
540 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
541 ewrt = r00*ewtabscale;
544 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
545 felec = qq00*rinv00*(rinvsq00-felec);
547 /* LENNARD-JONES DISPERSION/REPULSION */
549 rinvsix = rinvsq00*rinvsq00*rinvsq00;
550 fvdw = (c12_00*rinvsix-c6_00)*rinvsix*rinvsq00;
554 /* Calculate temporary vectorial force */
559 /* Update vectorial force */
563 f[j_coord_offset+DIM*0+XX] -= tx;
564 f[j_coord_offset+DIM*0+YY] -= ty;
565 f[j_coord_offset+DIM*0+ZZ] -= tz;
567 /**************************
568 * CALCULATE INTERACTIONS *
569 **************************/
575 /* EWALD ELECTROSTATICS */
577 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
578 ewrt = r10*ewtabscale;
581 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
582 felec = qq10*rinv10*(rinvsq10-felec);
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;
599 /**************************
600 * CALCULATE INTERACTIONS *
601 **************************/
607 /* EWALD ELECTROSTATICS */
609 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
610 ewrt = r20*ewtabscale;
613 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
614 felec = qq20*rinv20*(rinvsq20-felec);
618 /* Calculate temporary vectorial force */
623 /* Update vectorial force */
627 f[j_coord_offset+DIM*0+XX] -= tx;
628 f[j_coord_offset+DIM*0+YY] -= ty;
629 f[j_coord_offset+DIM*0+ZZ] -= tz;
631 /* Inner loop uses 109 flops */
633 /* End of innermost loop */
636 f[i_coord_offset+DIM*0+XX] += fix0;
637 f[i_coord_offset+DIM*0+YY] += fiy0;
638 f[i_coord_offset+DIM*0+ZZ] += fiz0;
642 f[i_coord_offset+DIM*1+XX] += fix1;
643 f[i_coord_offset+DIM*1+YY] += fiy1;
644 f[i_coord_offset+DIM*1+ZZ] += fiz1;
648 f[i_coord_offset+DIM*2+XX] += fix2;
649 f[i_coord_offset+DIM*2+YY] += fiy2;
650 f[i_coord_offset+DIM*2+ZZ] += fiz2;
654 fshift[i_shift_offset+XX] += tx;
655 fshift[i_shift_offset+YY] += ty;
656 fshift[i_shift_offset+ZZ] += tz;
658 /* Increment number of inner iterations */
659 inneriter += j_index_end - j_index_start;
661 /* Outer loop uses 30 flops */
664 /* Increment number of outer iterations */
667 /* Update outer/inner flops */
669 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*30 + inneriter*109);