2 * Note: this file was generated by the Gromacs c kernel generator.
4 * This source code is part of
8 * Copyright (c) 2001-2012, The GROMACS Development Team
10 * Gromacs is a library for molecular simulation and trajectory analysis,
11 * written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
12 * a full list of developers and information, check out http://www.gromacs.org
14 * This program is free software; you can redistribute it and/or modify it under
15 * the terms of the GNU Lesser General Public License as published by the Free
16 * Software Foundation; either version 2 of the License, or (at your option) any
19 * To help fund GROMACS development, we humbly ask that you cite
20 * the papers people have written on it - you can find them on the website.
28 #include "../nb_kernel.h"
29 #include "types/simple.h"
34 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_VF_c
35 * Electrostatics interaction: Ewald
36 * VdW interaction: LennardJones
37 * Geometry: Water4-Particle
38 * Calculate force/pot: PotentialAndForce
41 nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_VF_c
42 (t_nblist * gmx_restrict nlist,
43 rvec * gmx_restrict xx,
44 rvec * gmx_restrict ff,
45 t_forcerec * gmx_restrict fr,
46 t_mdatoms * gmx_restrict mdatoms,
47 nb_kernel_data_t * gmx_restrict kernel_data,
48 t_nrnb * gmx_restrict nrnb)
50 int i_shift_offset,i_coord_offset,j_coord_offset;
51 int j_index_start,j_index_end;
52 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
53 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
54 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
55 real *shiftvec,*fshift,*x,*f;
57 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
59 real ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
61 real ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
63 real ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
65 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
66 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
67 real dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
68 real dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
69 real dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
70 real velec,felec,velecsum,facel,crf,krf,krf2;
73 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
77 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
85 jindex = nlist->jindex;
87 shiftidx = nlist->shift;
89 shiftvec = fr->shift_vec[0];
90 fshift = fr->fshift[0];
92 charge = mdatoms->chargeA;
95 vdwtype = mdatoms->typeA;
97 sh_ewald = fr->ic->sh_ewald;
98 ewtab = fr->ic->tabq_coul_FDV0;
99 ewtabscale = fr->ic->tabq_scale;
100 ewtabhalfspace = 0.5/ewtabscale;
102 /* Setup water-specific parameters */
103 inr = nlist->iinr[0];
104 iq1 = facel*charge[inr+1];
105 iq2 = facel*charge[inr+2];
106 iq3 = facel*charge[inr+3];
107 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
109 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
110 rcutoff = fr->rcoulomb;
111 rcutoff2 = rcutoff*rcutoff;
113 sh_vdw_invrcut6 = fr->ic->sh_invrc6;
119 /* Start outer loop over neighborlists */
120 for(iidx=0; iidx<nri; iidx++)
122 /* Load shift vector for this list */
123 i_shift_offset = DIM*shiftidx[iidx];
124 shX = shiftvec[i_shift_offset+XX];
125 shY = shiftvec[i_shift_offset+YY];
126 shZ = shiftvec[i_shift_offset+ZZ];
128 /* Load limits for loop over neighbors */
129 j_index_start = jindex[iidx];
130 j_index_end = jindex[iidx+1];
132 /* Get outer coordinate index */
134 i_coord_offset = DIM*inr;
136 /* Load i particle coords and add shift vector */
137 ix0 = shX + x[i_coord_offset+DIM*0+XX];
138 iy0 = shY + x[i_coord_offset+DIM*0+YY];
139 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
140 ix1 = shX + x[i_coord_offset+DIM*1+XX];
141 iy1 = shY + x[i_coord_offset+DIM*1+YY];
142 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
143 ix2 = shX + x[i_coord_offset+DIM*2+XX];
144 iy2 = shY + x[i_coord_offset+DIM*2+YY];
145 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
146 ix3 = shX + x[i_coord_offset+DIM*3+XX];
147 iy3 = shY + x[i_coord_offset+DIM*3+YY];
148 iz3 = shZ + x[i_coord_offset+DIM*3+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 */
193 /* Calculate squared distance and things based on it */
194 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
195 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
196 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
197 rsq30 = dx30*dx30+dy30*dy30+dz30*dz30;
199 rinv10 = gmx_invsqrt(rsq10);
200 rinv20 = gmx_invsqrt(rsq20);
201 rinv30 = gmx_invsqrt(rsq30);
203 rinvsq00 = 1.0/rsq00;
204 rinvsq10 = rinv10*rinv10;
205 rinvsq20 = rinv20*rinv20;
206 rinvsq30 = rinv30*rinv30;
208 /* Load parameters for j particles */
210 vdwjidx0 = 2*vdwtype[jnr+0];
212 /**************************
213 * CALCULATE INTERACTIONS *
214 **************************/
219 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
220 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
222 /* LENNARD-JONES DISPERSION/REPULSION */
224 rinvsix = rinvsq00*rinvsq00*rinvsq00;
225 vvdw6 = c6_00*rinvsix;
226 vvdw12 = c12_00*rinvsix*rinvsix;
227 vvdw = (vvdw12 - c12_00*sh_vdw_invrcut6*sh_vdw_invrcut6)*(1.0/12.0) - (vvdw6 - c6_00*sh_vdw_invrcut6)*(1.0/6.0);
228 fvdw = (vvdw12-vvdw6)*rinvsq00;
230 /* Update potential sums from outer loop */
235 /* Calculate temporary vectorial force */
240 /* Update vectorial force */
244 f[j_coord_offset+DIM*0+XX] -= tx;
245 f[j_coord_offset+DIM*0+YY] -= ty;
246 f[j_coord_offset+DIM*0+ZZ] -= tz;
250 /**************************
251 * CALCULATE INTERACTIONS *
252 **************************/
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-sh_ewald)-(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;
292 /**************************
293 * CALCULATE INTERACTIONS *
294 **************************/
303 /* EWALD ELECTROSTATICS */
305 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
306 ewrt = r20*ewtabscale;
310 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
311 velec = qq20*((rinv20-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
312 felec = qq20*rinv20*(rinvsq20-felec);
314 /* Update potential sums from outer loop */
319 /* Calculate temporary vectorial force */
324 /* Update vectorial force */
328 f[j_coord_offset+DIM*0+XX] -= tx;
329 f[j_coord_offset+DIM*0+YY] -= ty;
330 f[j_coord_offset+DIM*0+ZZ] -= tz;
334 /**************************
335 * CALCULATE INTERACTIONS *
336 **************************/
345 /* EWALD ELECTROSTATICS */
347 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
348 ewrt = r30*ewtabscale;
352 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
353 velec = qq30*((rinv30-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
354 felec = qq30*rinv30*(rinvsq30-felec);
356 /* Update potential sums from outer loop */
361 /* Calculate temporary vectorial force */
366 /* Update vectorial force */
370 f[j_coord_offset+DIM*0+XX] -= tx;
371 f[j_coord_offset+DIM*0+YY] -= ty;
372 f[j_coord_offset+DIM*0+ZZ] -= tz;
376 /* Inner loop uses 163 flops */
378 /* End of innermost loop */
381 f[i_coord_offset+DIM*0+XX] += fix0;
382 f[i_coord_offset+DIM*0+YY] += fiy0;
383 f[i_coord_offset+DIM*0+ZZ] += fiz0;
387 f[i_coord_offset+DIM*1+XX] += fix1;
388 f[i_coord_offset+DIM*1+YY] += fiy1;
389 f[i_coord_offset+DIM*1+ZZ] += fiz1;
393 f[i_coord_offset+DIM*2+XX] += fix2;
394 f[i_coord_offset+DIM*2+YY] += fiy2;
395 f[i_coord_offset+DIM*2+ZZ] += fiz2;
399 f[i_coord_offset+DIM*3+XX] += fix3;
400 f[i_coord_offset+DIM*3+YY] += fiy3;
401 f[i_coord_offset+DIM*3+ZZ] += fiz3;
405 fshift[i_shift_offset+XX] += tx;
406 fshift[i_shift_offset+YY] += ty;
407 fshift[i_shift_offset+ZZ] += tz;
410 /* Update potential energies */
411 kernel_data->energygrp_elec[ggid] += velecsum;
412 kernel_data->energygrp_vdw[ggid] += vvdwsum;
414 /* Increment number of inner iterations */
415 inneriter += j_index_end - j_index_start;
417 /* Outer loop uses 41 flops */
420 /* Increment number of outer iterations */
423 /* Update outer/inner flops */
425 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*41 + inneriter*163);
428 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_F_c
429 * Electrostatics interaction: Ewald
430 * VdW interaction: LennardJones
431 * Geometry: Water4-Particle
432 * Calculate force/pot: Force
435 nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_F_c
436 (t_nblist * gmx_restrict nlist,
437 rvec * gmx_restrict xx,
438 rvec * gmx_restrict ff,
439 t_forcerec * gmx_restrict fr,
440 t_mdatoms * gmx_restrict mdatoms,
441 nb_kernel_data_t * gmx_restrict kernel_data,
442 t_nrnb * gmx_restrict nrnb)
444 int i_shift_offset,i_coord_offset,j_coord_offset;
445 int j_index_start,j_index_end;
446 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
447 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
448 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
449 real *shiftvec,*fshift,*x,*f;
451 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
453 real ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
455 real ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
457 real ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
459 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
460 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
461 real dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
462 real dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
463 real dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
464 real velec,felec,velecsum,facel,crf,krf,krf2;
467 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
471 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
479 jindex = nlist->jindex;
481 shiftidx = nlist->shift;
483 shiftvec = fr->shift_vec[0];
484 fshift = fr->fshift[0];
486 charge = mdatoms->chargeA;
487 nvdwtype = fr->ntype;
489 vdwtype = mdatoms->typeA;
491 sh_ewald = fr->ic->sh_ewald;
492 ewtab = fr->ic->tabq_coul_F;
493 ewtabscale = fr->ic->tabq_scale;
494 ewtabhalfspace = 0.5/ewtabscale;
496 /* Setup water-specific parameters */
497 inr = nlist->iinr[0];
498 iq1 = facel*charge[inr+1];
499 iq2 = facel*charge[inr+2];
500 iq3 = facel*charge[inr+3];
501 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
503 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
504 rcutoff = fr->rcoulomb;
505 rcutoff2 = rcutoff*rcutoff;
507 sh_vdw_invrcut6 = fr->ic->sh_invrc6;
513 /* Start outer loop over neighborlists */
514 for(iidx=0; iidx<nri; iidx++)
516 /* Load shift vector for this list */
517 i_shift_offset = DIM*shiftidx[iidx];
518 shX = shiftvec[i_shift_offset+XX];
519 shY = shiftvec[i_shift_offset+YY];
520 shZ = shiftvec[i_shift_offset+ZZ];
522 /* Load limits for loop over neighbors */
523 j_index_start = jindex[iidx];
524 j_index_end = jindex[iidx+1];
526 /* Get outer coordinate index */
528 i_coord_offset = DIM*inr;
530 /* Load i particle coords and add shift vector */
531 ix0 = shX + x[i_coord_offset+DIM*0+XX];
532 iy0 = shY + x[i_coord_offset+DIM*0+YY];
533 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
534 ix1 = shX + x[i_coord_offset+DIM*1+XX];
535 iy1 = shY + x[i_coord_offset+DIM*1+YY];
536 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
537 ix2 = shX + x[i_coord_offset+DIM*2+XX];
538 iy2 = shY + x[i_coord_offset+DIM*2+YY];
539 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
540 ix3 = shX + x[i_coord_offset+DIM*3+XX];
541 iy3 = shY + x[i_coord_offset+DIM*3+YY];
542 iz3 = shZ + x[i_coord_offset+DIM*3+ZZ];
557 /* Start inner kernel loop */
558 for(jidx=j_index_start; jidx<j_index_end; jidx++)
560 /* Get j neighbor index, and coordinate index */
562 j_coord_offset = DIM*jnr;
564 /* load j atom coordinates */
565 jx0 = x[j_coord_offset+DIM*0+XX];
566 jy0 = x[j_coord_offset+DIM*0+YY];
567 jz0 = x[j_coord_offset+DIM*0+ZZ];
569 /* Calculate displacement vector */
583 /* Calculate squared distance and things based on it */
584 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
585 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
586 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
587 rsq30 = dx30*dx30+dy30*dy30+dz30*dz30;
589 rinv10 = gmx_invsqrt(rsq10);
590 rinv20 = gmx_invsqrt(rsq20);
591 rinv30 = gmx_invsqrt(rsq30);
593 rinvsq00 = 1.0/rsq00;
594 rinvsq10 = rinv10*rinv10;
595 rinvsq20 = rinv20*rinv20;
596 rinvsq30 = rinv30*rinv30;
598 /* Load parameters for j particles */
600 vdwjidx0 = 2*vdwtype[jnr+0];
602 /**************************
603 * CALCULATE INTERACTIONS *
604 **************************/
609 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
610 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
612 /* LENNARD-JONES DISPERSION/REPULSION */
614 rinvsix = rinvsq00*rinvsq00*rinvsq00;
615 fvdw = (c12_00*rinvsix-c6_00)*rinvsix*rinvsq00;
619 /* Calculate temporary vectorial force */
624 /* Update vectorial force */
628 f[j_coord_offset+DIM*0+XX] -= tx;
629 f[j_coord_offset+DIM*0+YY] -= ty;
630 f[j_coord_offset+DIM*0+ZZ] -= tz;
634 /**************************
635 * CALCULATE INTERACTIONS *
636 **************************/
645 /* EWALD ELECTROSTATICS */
647 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
648 ewrt = r10*ewtabscale;
651 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
652 felec = qq10*rinv10*(rinvsq10-felec);
656 /* Calculate temporary vectorial force */
661 /* Update vectorial force */
665 f[j_coord_offset+DIM*0+XX] -= tx;
666 f[j_coord_offset+DIM*0+YY] -= ty;
667 f[j_coord_offset+DIM*0+ZZ] -= tz;
671 /**************************
672 * CALCULATE INTERACTIONS *
673 **************************/
682 /* EWALD ELECTROSTATICS */
684 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
685 ewrt = r20*ewtabscale;
688 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
689 felec = qq20*rinv20*(rinvsq20-felec);
693 /* Calculate temporary vectorial force */
698 /* Update vectorial force */
702 f[j_coord_offset+DIM*0+XX] -= tx;
703 f[j_coord_offset+DIM*0+YY] -= ty;
704 f[j_coord_offset+DIM*0+ZZ] -= tz;
708 /**************************
709 * CALCULATE INTERACTIONS *
710 **************************/
719 /* EWALD ELECTROSTATICS */
721 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
722 ewrt = r30*ewtabscale;
725 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
726 felec = qq30*rinv30*(rinvsq30-felec);
730 /* Calculate temporary vectorial force */
735 /* Update vectorial force */
739 f[j_coord_offset+DIM*0+XX] -= tx;
740 f[j_coord_offset+DIM*0+YY] -= ty;
741 f[j_coord_offset+DIM*0+ZZ] -= tz;
745 /* Inner loop uses 129 flops */
747 /* End of innermost loop */
750 f[i_coord_offset+DIM*0+XX] += fix0;
751 f[i_coord_offset+DIM*0+YY] += fiy0;
752 f[i_coord_offset+DIM*0+ZZ] += fiz0;
756 f[i_coord_offset+DIM*1+XX] += fix1;
757 f[i_coord_offset+DIM*1+YY] += fiy1;
758 f[i_coord_offset+DIM*1+ZZ] += fiz1;
762 f[i_coord_offset+DIM*2+XX] += fix2;
763 f[i_coord_offset+DIM*2+YY] += fiy2;
764 f[i_coord_offset+DIM*2+ZZ] += fiz2;
768 f[i_coord_offset+DIM*3+XX] += fix3;
769 f[i_coord_offset+DIM*3+YY] += fiy3;
770 f[i_coord_offset+DIM*3+ZZ] += fiz3;
774 fshift[i_shift_offset+XX] += tx;
775 fshift[i_shift_offset+YY] += ty;
776 fshift[i_shift_offset+ZZ] += tz;
778 /* Increment number of inner iterations */
779 inneriter += j_index_end - j_index_start;
781 /* Outer loop uses 39 flops */
784 /* Increment number of outer iterations */
787 /* Update outer/inner flops */
789 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*39 + inneriter*129);