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_GeomW3P1_VF_c
35 * Electrostatics interaction: Ewald
36 * VdW interaction: LennardJones
37 * Geometry: Water3-Particle
38 * Calculate force/pot: PotentialAndForce
41 nb_kernel_ElecEwSh_VdwLJSh_GeomW3P1_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 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
64 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
65 real dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
66 real dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
67 real velec,felec,velecsum,facel,crf,krf,krf2;
70 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
74 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
82 jindex = nlist->jindex;
84 shiftidx = nlist->shift;
86 shiftvec = fr->shift_vec[0];
87 fshift = fr->fshift[0];
89 charge = mdatoms->chargeA;
92 vdwtype = mdatoms->typeA;
94 sh_ewald = fr->ic->sh_ewald;
95 ewtab = fr->ic->tabq_coul_FDV0;
96 ewtabscale = fr->ic->tabq_scale;
97 ewtabhalfspace = 0.5/ewtabscale;
99 /* Setup water-specific parameters */
100 inr = nlist->iinr[0];
101 iq0 = facel*charge[inr+0];
102 iq1 = facel*charge[inr+1];
103 iq2 = facel*charge[inr+2];
104 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
106 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
107 rcutoff = fr->rcoulomb;
108 rcutoff2 = rcutoff*rcutoff;
110 sh_vdw_invrcut6 = fr->ic->sh_invrc6;
116 /* Start outer loop over neighborlists */
117 for(iidx=0; iidx<nri; iidx++)
119 /* Load shift vector for this list */
120 i_shift_offset = DIM*shiftidx[iidx];
121 shX = shiftvec[i_shift_offset+XX];
122 shY = shiftvec[i_shift_offset+YY];
123 shZ = shiftvec[i_shift_offset+ZZ];
125 /* Load limits for loop over neighbors */
126 j_index_start = jindex[iidx];
127 j_index_end = jindex[iidx+1];
129 /* Get outer coordinate index */
131 i_coord_offset = DIM*inr;
133 /* Load i particle coords and add shift vector */
134 ix0 = shX + x[i_coord_offset+DIM*0+XX];
135 iy0 = shY + x[i_coord_offset+DIM*0+YY];
136 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
137 ix1 = shX + x[i_coord_offset+DIM*1+XX];
138 iy1 = shY + x[i_coord_offset+DIM*1+YY];
139 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
140 ix2 = shX + x[i_coord_offset+DIM*2+XX];
141 iy2 = shY + x[i_coord_offset+DIM*2+YY];
142 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
154 /* Reset potential sums */
158 /* Start inner kernel loop */
159 for(jidx=j_index_start; jidx<j_index_end; jidx++)
161 /* Get j neighbor index, and coordinate index */
163 j_coord_offset = DIM*jnr;
165 /* load j atom coordinates */
166 jx0 = x[j_coord_offset+DIM*0+XX];
167 jy0 = x[j_coord_offset+DIM*0+YY];
168 jz0 = x[j_coord_offset+DIM*0+ZZ];
170 /* Calculate displacement vector */
181 /* Calculate squared distance and things based on it */
182 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
183 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
184 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
186 rinv00 = gmx_invsqrt(rsq00);
187 rinv10 = gmx_invsqrt(rsq10);
188 rinv20 = gmx_invsqrt(rsq20);
190 rinvsq00 = rinv00*rinv00;
191 rinvsq10 = rinv10*rinv10;
192 rinvsq20 = rinv20*rinv20;
194 /* Load parameters for j particles */
196 vdwjidx0 = 2*vdwtype[jnr+0];
198 /**************************
199 * CALCULATE INTERACTIONS *
200 **************************/
208 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
209 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
211 /* EWALD ELECTROSTATICS */
213 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
214 ewrt = r00*ewtabscale;
218 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
219 velec = qq00*((rinv00-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
220 felec = qq00*rinv00*(rinvsq00-felec);
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 */
236 /* Calculate temporary vectorial force */
241 /* Update vectorial force */
245 f[j_coord_offset+DIM*0+XX] -= tx;
246 f[j_coord_offset+DIM*0+YY] -= ty;
247 f[j_coord_offset+DIM*0+ZZ] -= tz;
251 /**************************
252 * CALCULATE INTERACTIONS *
253 **************************/
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-sh_ewald)-(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;
293 /**************************
294 * CALCULATE INTERACTIONS *
295 **************************/
304 /* EWALD ELECTROSTATICS */
306 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
307 ewrt = r20*ewtabscale;
311 felec = ewtab[ewitab]+eweps*ewtab[ewitab+1];
312 velec = qq20*((rinv20-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
313 felec = qq20*rinv20*(rinvsq20-felec);
315 /* Update potential sums from outer loop */
320 /* Calculate temporary vectorial force */
325 /* Update vectorial force */
329 f[j_coord_offset+DIM*0+XX] -= tx;
330 f[j_coord_offset+DIM*0+YY] -= ty;
331 f[j_coord_offset+DIM*0+ZZ] -= tz;
335 /* Inner loop uses 143 flops */
337 /* End of innermost loop */
340 f[i_coord_offset+DIM*0+XX] += fix0;
341 f[i_coord_offset+DIM*0+YY] += fiy0;
342 f[i_coord_offset+DIM*0+ZZ] += fiz0;
346 f[i_coord_offset+DIM*1+XX] += fix1;
347 f[i_coord_offset+DIM*1+YY] += fiy1;
348 f[i_coord_offset+DIM*1+ZZ] += fiz1;
352 f[i_coord_offset+DIM*2+XX] += fix2;
353 f[i_coord_offset+DIM*2+YY] += fiy2;
354 f[i_coord_offset+DIM*2+ZZ] += fiz2;
358 fshift[i_shift_offset+XX] += tx;
359 fshift[i_shift_offset+YY] += ty;
360 fshift[i_shift_offset+ZZ] += tz;
363 /* Update potential energies */
364 kernel_data->energygrp_elec[ggid] += velecsum;
365 kernel_data->energygrp_vdw[ggid] += vvdwsum;
367 /* Increment number of inner iterations */
368 inneriter += j_index_end - j_index_start;
370 /* Outer loop uses 32 flops */
373 /* Increment number of outer iterations */
376 /* Update outer/inner flops */
378 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*32 + inneriter*143);
381 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomW3P1_F_c
382 * Electrostatics interaction: Ewald
383 * VdW interaction: LennardJones
384 * Geometry: Water3-Particle
385 * Calculate force/pot: Force
388 nb_kernel_ElecEwSh_VdwLJSh_GeomW3P1_F_c
389 (t_nblist * gmx_restrict nlist,
390 rvec * gmx_restrict xx,
391 rvec * gmx_restrict ff,
392 t_forcerec * gmx_restrict fr,
393 t_mdatoms * gmx_restrict mdatoms,
394 nb_kernel_data_t * gmx_restrict kernel_data,
395 t_nrnb * gmx_restrict nrnb)
397 int i_shift_offset,i_coord_offset,j_coord_offset;
398 int j_index_start,j_index_end;
399 int nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
400 real shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
401 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
402 real *shiftvec,*fshift,*x,*f;
404 real ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
406 real ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
408 real ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
410 real jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
411 real dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
412 real dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
413 real dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
414 real velec,felec,velecsum,facel,crf,krf,krf2;
417 real rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
421 real ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
429 jindex = nlist->jindex;
431 shiftidx = nlist->shift;
433 shiftvec = fr->shift_vec[0];
434 fshift = fr->fshift[0];
436 charge = mdatoms->chargeA;
437 nvdwtype = fr->ntype;
439 vdwtype = mdatoms->typeA;
441 sh_ewald = fr->ic->sh_ewald;
442 ewtab = fr->ic->tabq_coul_F;
443 ewtabscale = fr->ic->tabq_scale;
444 ewtabhalfspace = 0.5/ewtabscale;
446 /* Setup water-specific parameters */
447 inr = nlist->iinr[0];
448 iq0 = facel*charge[inr+0];
449 iq1 = facel*charge[inr+1];
450 iq2 = facel*charge[inr+2];
451 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
453 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
454 rcutoff = fr->rcoulomb;
455 rcutoff2 = rcutoff*rcutoff;
457 sh_vdw_invrcut6 = fr->ic->sh_invrc6;
463 /* Start outer loop over neighborlists */
464 for(iidx=0; iidx<nri; iidx++)
466 /* Load shift vector for this list */
467 i_shift_offset = DIM*shiftidx[iidx];
468 shX = shiftvec[i_shift_offset+XX];
469 shY = shiftvec[i_shift_offset+YY];
470 shZ = shiftvec[i_shift_offset+ZZ];
472 /* Load limits for loop over neighbors */
473 j_index_start = jindex[iidx];
474 j_index_end = jindex[iidx+1];
476 /* Get outer coordinate index */
478 i_coord_offset = DIM*inr;
480 /* Load i particle coords and add shift vector */
481 ix0 = shX + x[i_coord_offset+DIM*0+XX];
482 iy0 = shY + x[i_coord_offset+DIM*0+YY];
483 iz0 = shZ + x[i_coord_offset+DIM*0+ZZ];
484 ix1 = shX + x[i_coord_offset+DIM*1+XX];
485 iy1 = shY + x[i_coord_offset+DIM*1+YY];
486 iz1 = shZ + x[i_coord_offset+DIM*1+ZZ];
487 ix2 = shX + x[i_coord_offset+DIM*2+XX];
488 iy2 = shY + x[i_coord_offset+DIM*2+YY];
489 iz2 = shZ + x[i_coord_offset+DIM*2+ZZ];
501 /* Start inner kernel loop */
502 for(jidx=j_index_start; jidx<j_index_end; jidx++)
504 /* Get j neighbor index, and coordinate index */
506 j_coord_offset = DIM*jnr;
508 /* load j atom coordinates */
509 jx0 = x[j_coord_offset+DIM*0+XX];
510 jy0 = x[j_coord_offset+DIM*0+YY];
511 jz0 = x[j_coord_offset+DIM*0+ZZ];
513 /* Calculate displacement vector */
524 /* Calculate squared distance and things based on it */
525 rsq00 = dx00*dx00+dy00*dy00+dz00*dz00;
526 rsq10 = dx10*dx10+dy10*dy10+dz10*dz10;
527 rsq20 = dx20*dx20+dy20*dy20+dz20*dz20;
529 rinv00 = gmx_invsqrt(rsq00);
530 rinv10 = gmx_invsqrt(rsq10);
531 rinv20 = gmx_invsqrt(rsq20);
533 rinvsq00 = rinv00*rinv00;
534 rinvsq10 = rinv10*rinv10;
535 rinvsq20 = rinv20*rinv20;
537 /* Load parameters for j particles */
539 vdwjidx0 = 2*vdwtype[jnr+0];
541 /**************************
542 * CALCULATE INTERACTIONS *
543 **************************/
551 c6_00 = vdwparam[vdwioffset0+vdwjidx0];
552 c12_00 = vdwparam[vdwioffset0+vdwjidx0+1];
554 /* EWALD ELECTROSTATICS */
556 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
557 ewrt = r00*ewtabscale;
560 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
561 felec = qq00*rinv00*(rinvsq00-felec);
563 /* LENNARD-JONES DISPERSION/REPULSION */
565 rinvsix = rinvsq00*rinvsq00*rinvsq00;
566 fvdw = (c12_00*rinvsix-c6_00)*rinvsix*rinvsq00;
570 /* Calculate temporary vectorial force */
575 /* Update vectorial force */
579 f[j_coord_offset+DIM*0+XX] -= tx;
580 f[j_coord_offset+DIM*0+YY] -= ty;
581 f[j_coord_offset+DIM*0+ZZ] -= tz;
585 /**************************
586 * CALCULATE INTERACTIONS *
587 **************************/
596 /* EWALD ELECTROSTATICS */
598 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
599 ewrt = r10*ewtabscale;
602 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
603 felec = qq10*rinv10*(rinvsq10-felec);
607 /* Calculate temporary vectorial force */
612 /* Update vectorial force */
616 f[j_coord_offset+DIM*0+XX] -= tx;
617 f[j_coord_offset+DIM*0+YY] -= ty;
618 f[j_coord_offset+DIM*0+ZZ] -= tz;
622 /**************************
623 * CALCULATE INTERACTIONS *
624 **************************/
633 /* EWALD ELECTROSTATICS */
635 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
636 ewrt = r20*ewtabscale;
639 felec = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
640 felec = qq20*rinv20*(rinvsq20-felec);
644 /* Calculate temporary vectorial force */
649 /* Update vectorial force */
653 f[j_coord_offset+DIM*0+XX] -= tx;
654 f[j_coord_offset+DIM*0+YY] -= ty;
655 f[j_coord_offset+DIM*0+ZZ] -= tz;
659 /* Inner loop uses 109 flops */
661 /* End of innermost loop */
664 f[i_coord_offset+DIM*0+XX] += fix0;
665 f[i_coord_offset+DIM*0+YY] += fiy0;
666 f[i_coord_offset+DIM*0+ZZ] += fiz0;
670 f[i_coord_offset+DIM*1+XX] += fix1;
671 f[i_coord_offset+DIM*1+YY] += fiy1;
672 f[i_coord_offset+DIM*1+ZZ] += fiz1;
676 f[i_coord_offset+DIM*2+XX] += fix2;
677 f[i_coord_offset+DIM*2+YY] += fiy2;
678 f[i_coord_offset+DIM*2+ZZ] += fiz2;
682 fshift[i_shift_offset+XX] += tx;
683 fshift[i_shift_offset+YY] += ty;
684 fshift[i_shift_offset+ZZ] += tz;
686 /* Increment number of inner iterations */
687 inneriter += j_index_end - j_index_start;
689 /* Outer loop uses 30 flops */
692 /* Increment number of outer iterations */
695 /* Update outer/inner flops */
697 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*30 + inneriter*109);