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_VdwBhamSh_GeomW3P1_VF_c
51 * Electrostatics interaction: Ewald
52 * VdW interaction: Buckingham
53 * Geometry: Water3-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecEwSh_VdwBhamSh_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 = 3*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 = 3*vdwtype[jnr+0];
214 /**************************
215 * CALCULATE INTERACTIONS *
216 **************************/
224 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
225 cexp1_00 = vdwparam[vdwioffset0+vdwjidx0+1];
226 cexp2_00 = vdwparam[vdwioffset0+vdwjidx0+2];
228 /* EWALD ELECTROSTATICS */
230 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
231 ewrt = r00*ewtabscale;
235 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
236 velec = qq00*((rinv00-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
237 felec = qq00*rinv00*(rinvsq00-felec);
239 /* BUCKINGHAM DISPERSION/REPULSION */
240 rinvsix = rinvsq00*rinvsq00*rinvsq00;
241 vvdw6 = c6_00*rinvsix;
243 vvdwexp = cexp1_00*exp(-br);
244 vvdw = (vvdwexp-cexp1_00*exp(-cexp2_00*rvdw)) - (vvdw6 - c6_00*sh_vdw_invrcut6)*(1.0/6.0);
245 fvdw = (br*vvdwexp-vvdw6)*rinvsq00;
247 /* Update potential sums from outer loop */
253 /* Calculate temporary vectorial force */
258 /* Update vectorial force */
262 f[j_coord_offset+DIM*0+XX] -= tx;
263 f[j_coord_offset+DIM*0+YY] -= ty;
264 f[j_coord_offset+DIM*0+ZZ] -= tz;
268 /**************************
269 * CALCULATE INTERACTIONS *
270 **************************/
279 /* EWALD ELECTROSTATICS */
281 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
282 ewrt = r10*ewtabscale;
286 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
287 velec = qq10*((rinv10-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
288 felec = qq10*rinv10*(rinvsq10-felec);
290 /* Update potential sums from outer loop */
295 /* Calculate temporary vectorial force */
300 /* Update vectorial force */
304 f[j_coord_offset+DIM*0+XX] -= tx;
305 f[j_coord_offset+DIM*0+YY] -= ty;
306 f[j_coord_offset+DIM*0+ZZ] -= tz;
310 /**************************
311 * CALCULATE INTERACTIONS *
312 **************************/
321 /* EWALD ELECTROSTATICS */
323 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
324 ewrt = r20*ewtabscale;
328 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
329 velec = qq20*((rinv20-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
330 felec = qq20*rinv20*(rinvsq20-felec);
332 /* Update potential sums from outer loop */
337 /* Calculate temporary vectorial force */
342 /* Update vectorial force */
346 f[j_coord_offset+DIM*0+XX] -= tx;
347 f[j_coord_offset+DIM*0+YY] -= ty;
348 f[j_coord_offset+DIM*0+ZZ] -= tz;
352 /* Inner loop uses 195 flops */
354 /* End of innermost loop */
357 f[i_coord_offset+DIM*0+XX] += fix0;
358 f[i_coord_offset+DIM*0+YY] += fiy0;
359 f[i_coord_offset+DIM*0+ZZ] += fiz0;
363 f[i_coord_offset+DIM*1+XX] += fix1;
364 f[i_coord_offset+DIM*1+YY] += fiy1;
365 f[i_coord_offset+DIM*1+ZZ] += fiz1;
369 f[i_coord_offset+DIM*2+XX] += fix2;
370 f[i_coord_offset+DIM*2+YY] += fiy2;
371 f[i_coord_offset+DIM*2+ZZ] += fiz2;
375 fshift[i_shift_offset+XX] += tx;
376 fshift[i_shift_offset+YY] += ty;
377 fshift[i_shift_offset+ZZ] += tz;
380 /* Update potential energies */
381 kernel_data->energygrp_elec[ggid] += velecsum;
382 kernel_data->energygrp_vdw[ggid] += vvdwsum;
384 /* Increment number of inner iterations */
385 inneriter += j_index_end - j_index_start;
387 /* Outer loop uses 32 flops */
390 /* Increment number of outer iterations */
393 /* Update outer/inner flops */
395 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*32 + inneriter*195);
398 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwBhamSh_GeomW3P1_F_c
399 * Electrostatics interaction: Ewald
400 * VdW interaction: Buckingham
401 * Geometry: Water3-Particle
402 * Calculate force/pot: Force
405 nb_kernel_ElecEwSh_VdwBhamSh_GeomW3P1_F_c
406 (t_nblist * gmx_restrict nlist,
407 rvec * gmx_restrict xx,
408 rvec * gmx_restrict ff,
409 t_forcerec * gmx_restrict fr,
410 t_mdatoms * gmx_restrict mdatoms,
411 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
412 t_nrnb * gmx_restrict nrnb)
414 int i_shift_offset,i_coord_offset,j_coord_offset;
415 int j_index_start,j_index_end;
416 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
417 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
418 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
419 real *shiftvec,*fshift,*x,*f;
421 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
423 real ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
425 real ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
427 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
428 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
429 real dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
430 real dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
431 real velec,felec,velecsum,facel,crf,krf,krf2;
434 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
438 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
446 jindex = nlist->jindex;
448 shiftidx = nlist->shift;
450 shiftvec = fr->shift_vec[0];
451 fshift = fr->fshift[0];
453 charge = mdatoms->chargeA;
454 nvdwtype = fr->ntype;
456 vdwtype = mdatoms->typeA;
458 sh_ewald = fr->ic->sh_ewald;
459 ewtab = fr->ic->tabq_coul_F;
460 ewtabscale = fr->ic->tabq_scale;
461 ewtabhalfspace = 0.5/ewtabscale;
463 /* Setup water-specific parameters */
464 inr = nlist->iinr[0];
465 iq0 = facel*charge[inr+0];
466 iq1 = facel*charge[inr+1];
467 iq2 = facel*charge[inr+2];
468 vdwioffset0 = 3*nvdwtype*vdwtype[inr+0];
470 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
471 rcutoff = fr->rcoulomb;
472 rcutoff2 = rcutoff*rcutoff;
474 sh_vdw_invrcut6 = fr->ic->sh_invrc6;
480 /* Start outer loop over neighborlists */
481 for(iidx=0; iidx<nri; iidx++)
483 /* Load shift vector for this list */
484 i_shift_offset = DIM*shiftidx[iidx];
485 shX = shiftvec[i_shift_offset+XX];
486 shY = shiftvec[i_shift_offset+YY];
487 shZ = shiftvec[i_shift_offset+ZZ];
489 /* Load limits for loop over neighbors */
490 j_index_start = jindex[iidx];
491 j_index_end = jindex[iidx+1];
493 /* Get outer coordinate index */
495 i_coord_offset = DIM*inr;
497 /* Load i particle coords and add shift vector */
498 ix0 = shX + x[i_coord_offset+DIM*0+XX];
499 iy0 = shY + x[i_coord_offset+DIM*0+YY];
500 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
501 ix1 = shX + x[i_coord_offset+DIM*1+XX];
502 iy1 = shY + x[i_coord_offset+DIM*1+YY];
503 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
504 ix2 = shX + x[i_coord_offset+DIM*2+XX];
505 iy2 = shY + x[i_coord_offset+DIM*2+YY];
506 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
518 /* Start inner kernel loop */
519 for(jidx=j_index_start; jidx<j_index_end; jidx++)
521 /* Get j neighbor index, and coordinate index */
523 j_coord_offset = DIM*jnr;
525 /* load j atom coordinates */
526 jx0 = x[j_coord_offset+DIM*0+XX];
527 jy0 = x[j_coord_offset+DIM*0+YY];
528 jz0 = x[j_coord_offset+DIM*0+ZZ];
530 /* Calculate displacement vector */
541 /* Calculate squared distance and things based on it */
542 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
543 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
544 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
546 rinv00 = gmx_invsqrt(rsq00);
547 rinv10 = gmx_invsqrt(rsq10);
548 rinv20 = gmx_invsqrt(rsq20);
550 rinvsq00 = rinv00*rinv00;
551 rinvsq10 = rinv10*rinv10;
552 rinvsq20 = rinv20*rinv20;
554 /* Load parameters for j particles */
556 vdwjidx0 = 3*vdwtype[jnr+0];
558 /**************************
559 * CALCULATE INTERACTIONS *
560 **************************/
568 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
569 cexp1_00 = vdwparam[vdwioffset0+vdwjidx0+1];
570 cexp2_00 = vdwparam[vdwioffset0+vdwjidx0+2];
572 /* EWALD ELECTROSTATICS */
574 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
575 ewrt = r00*ewtabscale;
578 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
579 felec = qq00*rinv00*(rinvsq00-felec);
581 /* BUCKINGHAM DISPERSION/REPULSION */
582 rinvsix = rinvsq00*rinvsq00*rinvsq00;
583 vvdw6 = c6_00*rinvsix;
585 vvdwexp = cexp1_00*exp(-br);
586 fvdw = (br*vvdwexp-vvdw6)*rinvsq00;
590 /* Calculate temporary vectorial force */
595 /* Update vectorial force */
599 f[j_coord_offset+DIM*0+XX] -= tx;
600 f[j_coord_offset+DIM*0+YY] -= ty;
601 f[j_coord_offset+DIM*0+ZZ] -= tz;
605 /**************************
606 * CALCULATE INTERACTIONS *
607 **************************/
616 /* EWALD ELECTROSTATICS */
618 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
619 ewrt = r10*ewtabscale;
622 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
623 felec = qq10*rinv10*(rinvsq10-felec);
627 /* Calculate temporary vectorial force */
632 /* Update vectorial force */
636 f[j_coord_offset+DIM*0+XX] -= tx;
637 f[j_coord_offset+DIM*0+YY] -= ty;
638 f[j_coord_offset+DIM*0+ZZ] -= tz;
642 /**************************
643 * CALCULATE INTERACTIONS *
644 **************************/
653 /* EWALD ELECTROSTATICS */
655 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
656 ewrt = r20*ewtabscale;
659 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
660 felec = qq20*rinv20*(rinvsq20-felec);
664 /* Calculate temporary vectorial force */
669 /* Update vectorial force */
673 f[j_coord_offset+DIM*0+XX] -= tx;
674 f[j_coord_offset+DIM*0+YY] -= ty;
675 f[j_coord_offset+DIM*0+ZZ] -= tz;
679 /* Inner loop uses 137 flops */
681 /* End of innermost loop */
684 f[i_coord_offset+DIM*0+XX] += fix0;
685 f[i_coord_offset+DIM*0+YY] += fiy0;
686 f[i_coord_offset+DIM*0+ZZ] += fiz0;
690 f[i_coord_offset+DIM*1+XX] += fix1;
691 f[i_coord_offset+DIM*1+YY] += fiy1;
692 f[i_coord_offset+DIM*1+ZZ] += fiz1;
696 f[i_coord_offset+DIM*2+XX] += fix2;
697 f[i_coord_offset+DIM*2+YY] += fiy2;
698 f[i_coord_offset+DIM*2+ZZ] += fiz2;
702 fshift[i_shift_offset+XX] += tx;
703 fshift[i_shift_offset+YY] += ty;
704 fshift[i_shift_offset+ZZ] += tz;
706 /* Increment number of inner iterations */
707 inneriter += j_index_end - j_index_start;
709 /* Outer loop uses 30 flops */
712 /* Increment number of outer iterations */
715 /* Update outer/inner flops */
717 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*30 + inneriter*137);