d921bcad815362eb16c031f5d97bf707f6bbc42a
[alexxy/gromacs.git] / src / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecCoul_VdwCSTab_GeomW4W4_c.c
1 /*
2  * Note: this file was generated by the Gromacs c kernel generator.
3  *
4  *                This source code is part of
5  *
6  *                 G   R   O   M   A   C   S
7  *
8  * Copyright (c) 2001-2012, The GROMACS Development Team
9  *
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
13  *
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
17  * later version.
18  *
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.
21  */
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <math.h>
27
28 #include "../nb_kernel.h"
29 #include "types/simple.h"
30 #include "vec.h"
31 #include "nrnb.h"
32
33 /*
34  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwCSTab_GeomW4W4_VF_c
35  * Electrostatics interaction: Coulomb
36  * VdW interaction:            CubicSplineTable
37  * Geometry:                   Water4-Water4
38  * Calculate force/pot:        PotentialAndForce
39  */
40 void
41 nb_kernel_ElecCoul_VdwCSTab_GeomW4W4_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)
49 {
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;
56     int              vdwioffset0;
57     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
58     int              vdwioffset1;
59     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
60     int              vdwioffset2;
61     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
62     int              vdwioffset3;
63     real             ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
64     int              vdwjidx0;
65     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
66     int              vdwjidx1;
67     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
68     int              vdwjidx2;
69     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
70     int              vdwjidx3;
71     real             jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
72     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
73     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
74     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
75     real             dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13,cexp1_13,cexp2_13;
76     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
77     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
78     real             dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23,cexp1_23,cexp2_23;
79     real             dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31,cexp1_31,cexp2_31;
80     real             dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32,cexp1_32,cexp2_32;
81     real             dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33,cexp1_33,cexp2_33;
82     real             velec,felec,velecsum,facel,crf,krf,krf2;
83     real             *charge;
84     int              nvdwtype;
85     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
86     int              *vdwtype;
87     real             *vdwparam;
88     int              vfitab;
89     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
90     real             *vftab;
91
92     x                = xx[0];
93     f                = ff[0];
94
95     nri              = nlist->nri;
96     iinr             = nlist->iinr;
97     jindex           = nlist->jindex;
98     jjnr             = nlist->jjnr;
99     shiftidx         = nlist->shift;
100     gid              = nlist->gid;
101     shiftvec         = fr->shift_vec[0];
102     fshift           = fr->fshift[0];
103     facel            = fr->epsfac;
104     charge           = mdatoms->chargeA;
105     nvdwtype         = fr->ntype;
106     vdwparam         = fr->nbfp;
107     vdwtype          = mdatoms->typeA;
108
109     vftab            = kernel_data->table_vdw->data;
110     vftabscale       = kernel_data->table_vdw->scale;
111
112     /* Setup water-specific parameters */
113     inr              = nlist->iinr[0];
114     iq1              = facel*charge[inr+1];
115     iq2              = facel*charge[inr+2];
116     iq3              = facel*charge[inr+3];
117     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
118
119     jq1              = charge[inr+1];
120     jq2              = charge[inr+2];
121     jq3              = charge[inr+3];
122     vdwjidx0         = 2*vdwtype[inr+0];
123     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
124     c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
125     qq11             = iq1*jq1;
126     qq12             = iq1*jq2;
127     qq13             = iq1*jq3;
128     qq21             = iq2*jq1;
129     qq22             = iq2*jq2;
130     qq23             = iq2*jq3;
131     qq31             = iq3*jq1;
132     qq32             = iq3*jq2;
133     qq33             = iq3*jq3;
134
135     outeriter        = 0;
136     inneriter        = 0;
137
138     /* Start outer loop over neighborlists */
139     for(iidx=0; iidx<nri; iidx++)
140     {
141         /* Load shift vector for this list */
142         i_shift_offset   = DIM*shiftidx[iidx];
143         shX              = shiftvec[i_shift_offset+XX];
144         shY              = shiftvec[i_shift_offset+YY];
145         shZ              = shiftvec[i_shift_offset+ZZ];
146
147         /* Load limits for loop over neighbors */
148         j_index_start    = jindex[iidx];
149         j_index_end      = jindex[iidx+1];
150
151         /* Get outer coordinate index */
152         inr              = iinr[iidx];
153         i_coord_offset   = DIM*inr;
154
155         /* Load i particle coords and add shift vector */
156         ix0              = shX + x[i_coord_offset+DIM*0+XX];
157         iy0              = shY + x[i_coord_offset+DIM*0+YY];
158         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
159         ix1              = shX + x[i_coord_offset+DIM*1+XX];
160         iy1              = shY + x[i_coord_offset+DIM*1+YY];
161         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
162         ix2              = shX + x[i_coord_offset+DIM*2+XX];
163         iy2              = shY + x[i_coord_offset+DIM*2+YY];
164         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
165         ix3              = shX + x[i_coord_offset+DIM*3+XX];
166         iy3              = shY + x[i_coord_offset+DIM*3+YY];
167         iz3              = shZ + x[i_coord_offset+DIM*3+ZZ];
168
169         fix0             = 0.0;
170         fiy0             = 0.0;
171         fiz0             = 0.0;
172         fix1             = 0.0;
173         fiy1             = 0.0;
174         fiz1             = 0.0;
175         fix2             = 0.0;
176         fiy2             = 0.0;
177         fiz2             = 0.0;
178         fix3             = 0.0;
179         fiy3             = 0.0;
180         fiz3             = 0.0;
181
182         /* Reset potential sums */
183         velecsum         = 0.0;
184         vvdwsum          = 0.0;
185
186         /* Start inner kernel loop */
187         for(jidx=j_index_start; jidx<j_index_end; jidx++)
188         {
189             /* Get j neighbor index, and coordinate index */
190             jnr              = jjnr[jidx];
191             j_coord_offset   = DIM*jnr;
192
193             /* load j atom coordinates */
194             jx0              = x[j_coord_offset+DIM*0+XX];
195             jy0              = x[j_coord_offset+DIM*0+YY];
196             jz0              = x[j_coord_offset+DIM*0+ZZ];
197             jx1              = x[j_coord_offset+DIM*1+XX];
198             jy1              = x[j_coord_offset+DIM*1+YY];
199             jz1              = x[j_coord_offset+DIM*1+ZZ];
200             jx2              = x[j_coord_offset+DIM*2+XX];
201             jy2              = x[j_coord_offset+DIM*2+YY];
202             jz2              = x[j_coord_offset+DIM*2+ZZ];
203             jx3              = x[j_coord_offset+DIM*3+XX];
204             jy3              = x[j_coord_offset+DIM*3+YY];
205             jz3              = x[j_coord_offset+DIM*3+ZZ];
206
207             /* Calculate displacement vector */
208             dx00             = ix0 - jx0;
209             dy00             = iy0 - jy0;
210             dz00             = iz0 - jz0;
211             dx11             = ix1 - jx1;
212             dy11             = iy1 - jy1;
213             dz11             = iz1 - jz1;
214             dx12             = ix1 - jx2;
215             dy12             = iy1 - jy2;
216             dz12             = iz1 - jz2;
217             dx13             = ix1 - jx3;
218             dy13             = iy1 - jy3;
219             dz13             = iz1 - jz3;
220             dx21             = ix2 - jx1;
221             dy21             = iy2 - jy1;
222             dz21             = iz2 - jz1;
223             dx22             = ix2 - jx2;
224             dy22             = iy2 - jy2;
225             dz22             = iz2 - jz2;
226             dx23             = ix2 - jx3;
227             dy23             = iy2 - jy3;
228             dz23             = iz2 - jz3;
229             dx31             = ix3 - jx1;
230             dy31             = iy3 - jy1;
231             dz31             = iz3 - jz1;
232             dx32             = ix3 - jx2;
233             dy32             = iy3 - jy2;
234             dz32             = iz3 - jz2;
235             dx33             = ix3 - jx3;
236             dy33             = iy3 - jy3;
237             dz33             = iz3 - jz3;
238
239             /* Calculate squared distance and things based on it */
240             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
241             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
242             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
243             rsq13            = dx13*dx13+dy13*dy13+dz13*dz13;
244             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
245             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
246             rsq23            = dx23*dx23+dy23*dy23+dz23*dz23;
247             rsq31            = dx31*dx31+dy31*dy31+dz31*dz31;
248             rsq32            = dx32*dx32+dy32*dy32+dz32*dz32;
249             rsq33            = dx33*dx33+dy33*dy33+dz33*dz33;
250
251             rinv00           = gmx_invsqrt(rsq00);
252             rinv11           = gmx_invsqrt(rsq11);
253             rinv12           = gmx_invsqrt(rsq12);
254             rinv13           = gmx_invsqrt(rsq13);
255             rinv21           = gmx_invsqrt(rsq21);
256             rinv22           = gmx_invsqrt(rsq22);
257             rinv23           = gmx_invsqrt(rsq23);
258             rinv31           = gmx_invsqrt(rsq31);
259             rinv32           = gmx_invsqrt(rsq32);
260             rinv33           = gmx_invsqrt(rsq33);
261
262             rinvsq11         = rinv11*rinv11;
263             rinvsq12         = rinv12*rinv12;
264             rinvsq13         = rinv13*rinv13;
265             rinvsq21         = rinv21*rinv21;
266             rinvsq22         = rinv22*rinv22;
267             rinvsq23         = rinv23*rinv23;
268             rinvsq31         = rinv31*rinv31;
269             rinvsq32         = rinv32*rinv32;
270             rinvsq33         = rinv33*rinv33;
271
272             /**************************
273              * CALCULATE INTERACTIONS *
274              **************************/
275
276             r00              = rsq00*rinv00;
277
278             /* Calculate table index by multiplying r with table scale and truncate to integer */
279             rt               = r00*vftabscale;
280             vfitab           = rt;
281             vfeps            = rt-vfitab;
282             vfitab           = 2*4*vfitab;
283
284             /* CUBIC SPLINE TABLE DISPERSION */
285             vfitab          += 0;
286             Y                = vftab[vfitab];
287             F                = vftab[vfitab+1];
288             Geps             = vfeps*vftab[vfitab+2];
289             Heps2            = vfeps*vfeps*vftab[vfitab+3];
290             Fp               = F+Geps+Heps2;
291             VV               = Y+vfeps*Fp;
292             vvdw6            = c6_00*VV;
293             FF               = Fp+Geps+2.0*Heps2;
294             fvdw6            = c6_00*FF;
295
296             /* CUBIC SPLINE TABLE REPULSION */
297             Y                = vftab[vfitab+4];
298             F                = vftab[vfitab+5];
299             Geps             = vfeps*vftab[vfitab+6];
300             Heps2            = vfeps*vfeps*vftab[vfitab+7];
301             Fp               = F+Geps+Heps2;
302             VV               = Y+vfeps*Fp;
303             vvdw12           = c12_00*VV;
304             FF               = Fp+Geps+2.0*Heps2;
305             fvdw12           = c12_00*FF;
306             vvdw             = vvdw12+vvdw6;
307             fvdw             = -(fvdw6+fvdw12)*vftabscale*rinv00;
308
309             /* Update potential sums from outer loop */
310             vvdwsum         += vvdw;
311
312             fscal            = fvdw;
313
314             /* Calculate temporary vectorial force */
315             tx               = fscal*dx00;
316             ty               = fscal*dy00;
317             tz               = fscal*dz00;
318
319             /* Update vectorial force */
320             fix0            += tx;
321             fiy0            += ty;
322             fiz0            += tz;
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;
326
327             /**************************
328              * CALCULATE INTERACTIONS *
329              **************************/
330
331             /* COULOMB ELECTROSTATICS */
332             velec            = qq11*rinv11;
333             felec            = velec*rinvsq11;
334
335             /* Update potential sums from outer loop */
336             velecsum        += velec;
337
338             fscal            = felec;
339
340             /* Calculate temporary vectorial force */
341             tx               = fscal*dx11;
342             ty               = fscal*dy11;
343             tz               = fscal*dz11;
344
345             /* Update vectorial force */
346             fix1            += tx;
347             fiy1            += ty;
348             fiz1            += tz;
349             f[j_coord_offset+DIM*1+XX] -= tx;
350             f[j_coord_offset+DIM*1+YY] -= ty;
351             f[j_coord_offset+DIM*1+ZZ] -= tz;
352
353             /**************************
354              * CALCULATE INTERACTIONS *
355              **************************/
356
357             /* COULOMB ELECTROSTATICS */
358             velec            = qq12*rinv12;
359             felec            = velec*rinvsq12;
360
361             /* Update potential sums from outer loop */
362             velecsum        += velec;
363
364             fscal            = felec;
365
366             /* Calculate temporary vectorial force */
367             tx               = fscal*dx12;
368             ty               = fscal*dy12;
369             tz               = fscal*dz12;
370
371             /* Update vectorial force */
372             fix1            += tx;
373             fiy1            += ty;
374             fiz1            += tz;
375             f[j_coord_offset+DIM*2+XX] -= tx;
376             f[j_coord_offset+DIM*2+YY] -= ty;
377             f[j_coord_offset+DIM*2+ZZ] -= tz;
378
379             /**************************
380              * CALCULATE INTERACTIONS *
381              **************************/
382
383             /* COULOMB ELECTROSTATICS */
384             velec            = qq13*rinv13;
385             felec            = velec*rinvsq13;
386
387             /* Update potential sums from outer loop */
388             velecsum        += velec;
389
390             fscal            = felec;
391
392             /* Calculate temporary vectorial force */
393             tx               = fscal*dx13;
394             ty               = fscal*dy13;
395             tz               = fscal*dz13;
396
397             /* Update vectorial force */
398             fix1            += tx;
399             fiy1            += ty;
400             fiz1            += tz;
401             f[j_coord_offset+DIM*3+XX] -= tx;
402             f[j_coord_offset+DIM*3+YY] -= ty;
403             f[j_coord_offset+DIM*3+ZZ] -= tz;
404
405             /**************************
406              * CALCULATE INTERACTIONS *
407              **************************/
408
409             /* COULOMB ELECTROSTATICS */
410             velec            = qq21*rinv21;
411             felec            = velec*rinvsq21;
412
413             /* Update potential sums from outer loop */
414             velecsum        += velec;
415
416             fscal            = felec;
417
418             /* Calculate temporary vectorial force */
419             tx               = fscal*dx21;
420             ty               = fscal*dy21;
421             tz               = fscal*dz21;
422
423             /* Update vectorial force */
424             fix2            += tx;
425             fiy2            += ty;
426             fiz2            += tz;
427             f[j_coord_offset+DIM*1+XX] -= tx;
428             f[j_coord_offset+DIM*1+YY] -= ty;
429             f[j_coord_offset+DIM*1+ZZ] -= tz;
430
431             /**************************
432              * CALCULATE INTERACTIONS *
433              **************************/
434
435             /* COULOMB ELECTROSTATICS */
436             velec            = qq22*rinv22;
437             felec            = velec*rinvsq22;
438
439             /* Update potential sums from outer loop */
440             velecsum        += velec;
441
442             fscal            = felec;
443
444             /* Calculate temporary vectorial force */
445             tx               = fscal*dx22;
446             ty               = fscal*dy22;
447             tz               = fscal*dz22;
448
449             /* Update vectorial force */
450             fix2            += tx;
451             fiy2            += ty;
452             fiz2            += tz;
453             f[j_coord_offset+DIM*2+XX] -= tx;
454             f[j_coord_offset+DIM*2+YY] -= ty;
455             f[j_coord_offset+DIM*2+ZZ] -= tz;
456
457             /**************************
458              * CALCULATE INTERACTIONS *
459              **************************/
460
461             /* COULOMB ELECTROSTATICS */
462             velec            = qq23*rinv23;
463             felec            = velec*rinvsq23;
464
465             /* Update potential sums from outer loop */
466             velecsum        += velec;
467
468             fscal            = felec;
469
470             /* Calculate temporary vectorial force */
471             tx               = fscal*dx23;
472             ty               = fscal*dy23;
473             tz               = fscal*dz23;
474
475             /* Update vectorial force */
476             fix2            += tx;
477             fiy2            += ty;
478             fiz2            += tz;
479             f[j_coord_offset+DIM*3+XX] -= tx;
480             f[j_coord_offset+DIM*3+YY] -= ty;
481             f[j_coord_offset+DIM*3+ZZ] -= tz;
482
483             /**************************
484              * CALCULATE INTERACTIONS *
485              **************************/
486
487             /* COULOMB ELECTROSTATICS */
488             velec            = qq31*rinv31;
489             felec            = velec*rinvsq31;
490
491             /* Update potential sums from outer loop */
492             velecsum        += velec;
493
494             fscal            = felec;
495
496             /* Calculate temporary vectorial force */
497             tx               = fscal*dx31;
498             ty               = fscal*dy31;
499             tz               = fscal*dz31;
500
501             /* Update vectorial force */
502             fix3            += tx;
503             fiy3            += ty;
504             fiz3            += tz;
505             f[j_coord_offset+DIM*1+XX] -= tx;
506             f[j_coord_offset+DIM*1+YY] -= ty;
507             f[j_coord_offset+DIM*1+ZZ] -= tz;
508
509             /**************************
510              * CALCULATE INTERACTIONS *
511              **************************/
512
513             /* COULOMB ELECTROSTATICS */
514             velec            = qq32*rinv32;
515             felec            = velec*rinvsq32;
516
517             /* Update potential sums from outer loop */
518             velecsum        += velec;
519
520             fscal            = felec;
521
522             /* Calculate temporary vectorial force */
523             tx               = fscal*dx32;
524             ty               = fscal*dy32;
525             tz               = fscal*dz32;
526
527             /* Update vectorial force */
528             fix3            += tx;
529             fiy3            += ty;
530             fiz3            += tz;
531             f[j_coord_offset+DIM*2+XX] -= tx;
532             f[j_coord_offset+DIM*2+YY] -= ty;
533             f[j_coord_offset+DIM*2+ZZ] -= tz;
534
535             /**************************
536              * CALCULATE INTERACTIONS *
537              **************************/
538
539             /* COULOMB ELECTROSTATICS */
540             velec            = qq33*rinv33;
541             felec            = velec*rinvsq33;
542
543             /* Update potential sums from outer loop */
544             velecsum        += velec;
545
546             fscal            = felec;
547
548             /* Calculate temporary vectorial force */
549             tx               = fscal*dx33;
550             ty               = fscal*dy33;
551             tz               = fscal*dz33;
552
553             /* Update vectorial force */
554             fix3            += tx;
555             fiy3            += ty;
556             fiz3            += tz;
557             f[j_coord_offset+DIM*3+XX] -= tx;
558             f[j_coord_offset+DIM*3+YY] -= ty;
559             f[j_coord_offset+DIM*3+ZZ] -= tz;
560
561             /* Inner loop uses 298 flops */
562         }
563         /* End of innermost loop */
564
565         tx = ty = tz = 0;
566         f[i_coord_offset+DIM*0+XX] += fix0;
567         f[i_coord_offset+DIM*0+YY] += fiy0;
568         f[i_coord_offset+DIM*0+ZZ] += fiz0;
569         tx                         += fix0;
570         ty                         += fiy0;
571         tz                         += fiz0;
572         f[i_coord_offset+DIM*1+XX] += fix1;
573         f[i_coord_offset+DIM*1+YY] += fiy1;
574         f[i_coord_offset+DIM*1+ZZ] += fiz1;
575         tx                         += fix1;
576         ty                         += fiy1;
577         tz                         += fiz1;
578         f[i_coord_offset+DIM*2+XX] += fix2;
579         f[i_coord_offset+DIM*2+YY] += fiy2;
580         f[i_coord_offset+DIM*2+ZZ] += fiz2;
581         tx                         += fix2;
582         ty                         += fiy2;
583         tz                         += fiz2;
584         f[i_coord_offset+DIM*3+XX] += fix3;
585         f[i_coord_offset+DIM*3+YY] += fiy3;
586         f[i_coord_offset+DIM*3+ZZ] += fiz3;
587         tx                         += fix3;
588         ty                         += fiy3;
589         tz                         += fiz3;
590         fshift[i_shift_offset+XX]  += tx;
591         fshift[i_shift_offset+YY]  += ty;
592         fshift[i_shift_offset+ZZ]  += tz;
593
594         ggid                        = gid[iidx];
595         /* Update potential energies */
596         kernel_data->energygrp_elec[ggid] += velecsum;
597         kernel_data->energygrp_vdw[ggid] += vvdwsum;
598
599         /* Increment number of inner iterations */
600         inneriter                  += j_index_end - j_index_start;
601
602         /* Outer loop uses 41 flops */
603     }
604
605     /* Increment number of outer iterations */
606     outeriter        += nri;
607
608     /* Update outer/inner flops */
609
610     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_VF,outeriter*41 + inneriter*298);
611 }
612 /*
613  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwCSTab_GeomW4W4_F_c
614  * Electrostatics interaction: Coulomb
615  * VdW interaction:            CubicSplineTable
616  * Geometry:                   Water4-Water4
617  * Calculate force/pot:        Force
618  */
619 void
620 nb_kernel_ElecCoul_VdwCSTab_GeomW4W4_F_c
621                     (t_nblist * gmx_restrict                nlist,
622                      rvec * gmx_restrict                    xx,
623                      rvec * gmx_restrict                    ff,
624                      t_forcerec * gmx_restrict              fr,
625                      t_mdatoms * gmx_restrict               mdatoms,
626                      nb_kernel_data_t * gmx_restrict        kernel_data,
627                      t_nrnb * gmx_restrict                  nrnb)
628 {
629     int              i_shift_offset,i_coord_offset,j_coord_offset;
630     int              j_index_start,j_index_end;
631     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
632     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
633     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
634     real             *shiftvec,*fshift,*x,*f;
635     int              vdwioffset0;
636     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
637     int              vdwioffset1;
638     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
639     int              vdwioffset2;
640     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
641     int              vdwioffset3;
642     real             ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
643     int              vdwjidx0;
644     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
645     int              vdwjidx1;
646     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
647     int              vdwjidx2;
648     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
649     int              vdwjidx3;
650     real             jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
651     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
652     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
653     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
654     real             dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13,cexp1_13,cexp2_13;
655     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
656     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
657     real             dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23,cexp1_23,cexp2_23;
658     real             dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31,cexp1_31,cexp2_31;
659     real             dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32,cexp1_32,cexp2_32;
660     real             dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33,cexp1_33,cexp2_33;
661     real             velec,felec,velecsum,facel,crf,krf,krf2;
662     real             *charge;
663     int              nvdwtype;
664     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
665     int              *vdwtype;
666     real             *vdwparam;
667     int              vfitab;
668     real             rt,vfeps,vftabscale,Y,F,Geps,Heps2,Fp,VV,FF;
669     real             *vftab;
670
671     x                = xx[0];
672     f                = ff[0];
673
674     nri              = nlist->nri;
675     iinr             = nlist->iinr;
676     jindex           = nlist->jindex;
677     jjnr             = nlist->jjnr;
678     shiftidx         = nlist->shift;
679     gid              = nlist->gid;
680     shiftvec         = fr->shift_vec[0];
681     fshift           = fr->fshift[0];
682     facel            = fr->epsfac;
683     charge           = mdatoms->chargeA;
684     nvdwtype         = fr->ntype;
685     vdwparam         = fr->nbfp;
686     vdwtype          = mdatoms->typeA;
687
688     vftab            = kernel_data->table_vdw->data;
689     vftabscale       = kernel_data->table_vdw->scale;
690
691     /* Setup water-specific parameters */
692     inr              = nlist->iinr[0];
693     iq1              = facel*charge[inr+1];
694     iq2              = facel*charge[inr+2];
695     iq3              = facel*charge[inr+3];
696     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
697
698     jq1              = charge[inr+1];
699     jq2              = charge[inr+2];
700     jq3              = charge[inr+3];
701     vdwjidx0         = 2*vdwtype[inr+0];
702     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
703     c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
704     qq11             = iq1*jq1;
705     qq12             = iq1*jq2;
706     qq13             = iq1*jq3;
707     qq21             = iq2*jq1;
708     qq22             = iq2*jq2;
709     qq23             = iq2*jq3;
710     qq31             = iq3*jq1;
711     qq32             = iq3*jq2;
712     qq33             = iq3*jq3;
713
714     outeriter        = 0;
715     inneriter        = 0;
716
717     /* Start outer loop over neighborlists */
718     for(iidx=0; iidx<nri; iidx++)
719     {
720         /* Load shift vector for this list */
721         i_shift_offset   = DIM*shiftidx[iidx];
722         shX              = shiftvec[i_shift_offset+XX];
723         shY              = shiftvec[i_shift_offset+YY];
724         shZ              = shiftvec[i_shift_offset+ZZ];
725
726         /* Load limits for loop over neighbors */
727         j_index_start    = jindex[iidx];
728         j_index_end      = jindex[iidx+1];
729
730         /* Get outer coordinate index */
731         inr              = iinr[iidx];
732         i_coord_offset   = DIM*inr;
733
734         /* Load i particle coords and add shift vector */
735         ix0              = shX + x[i_coord_offset+DIM*0+XX];
736         iy0              = shY + x[i_coord_offset+DIM*0+YY];
737         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
738         ix1              = shX + x[i_coord_offset+DIM*1+XX];
739         iy1              = shY + x[i_coord_offset+DIM*1+YY];
740         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
741         ix2              = shX + x[i_coord_offset+DIM*2+XX];
742         iy2              = shY + x[i_coord_offset+DIM*2+YY];
743         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
744         ix3              = shX + x[i_coord_offset+DIM*3+XX];
745         iy3              = shY + x[i_coord_offset+DIM*3+YY];
746         iz3              = shZ + x[i_coord_offset+DIM*3+ZZ];
747
748         fix0             = 0.0;
749         fiy0             = 0.0;
750         fiz0             = 0.0;
751         fix1             = 0.0;
752         fiy1             = 0.0;
753         fiz1             = 0.0;
754         fix2             = 0.0;
755         fiy2             = 0.0;
756         fiz2             = 0.0;
757         fix3             = 0.0;
758         fiy3             = 0.0;
759         fiz3             = 0.0;
760
761         /* Start inner kernel loop */
762         for(jidx=j_index_start; jidx<j_index_end; jidx++)
763         {
764             /* Get j neighbor index, and coordinate index */
765             jnr              = jjnr[jidx];
766             j_coord_offset   = DIM*jnr;
767
768             /* load j atom coordinates */
769             jx0              = x[j_coord_offset+DIM*0+XX];
770             jy0              = x[j_coord_offset+DIM*0+YY];
771             jz0              = x[j_coord_offset+DIM*0+ZZ];
772             jx1              = x[j_coord_offset+DIM*1+XX];
773             jy1              = x[j_coord_offset+DIM*1+YY];
774             jz1              = x[j_coord_offset+DIM*1+ZZ];
775             jx2              = x[j_coord_offset+DIM*2+XX];
776             jy2              = x[j_coord_offset+DIM*2+YY];
777             jz2              = x[j_coord_offset+DIM*2+ZZ];
778             jx3              = x[j_coord_offset+DIM*3+XX];
779             jy3              = x[j_coord_offset+DIM*3+YY];
780             jz3              = x[j_coord_offset+DIM*3+ZZ];
781
782             /* Calculate displacement vector */
783             dx00             = ix0 - jx0;
784             dy00             = iy0 - jy0;
785             dz00             = iz0 - jz0;
786             dx11             = ix1 - jx1;
787             dy11             = iy1 - jy1;
788             dz11             = iz1 - jz1;
789             dx12             = ix1 - jx2;
790             dy12             = iy1 - jy2;
791             dz12             = iz1 - jz2;
792             dx13             = ix1 - jx3;
793             dy13             = iy1 - jy3;
794             dz13             = iz1 - jz3;
795             dx21             = ix2 - jx1;
796             dy21             = iy2 - jy1;
797             dz21             = iz2 - jz1;
798             dx22             = ix2 - jx2;
799             dy22             = iy2 - jy2;
800             dz22             = iz2 - jz2;
801             dx23             = ix2 - jx3;
802             dy23             = iy2 - jy3;
803             dz23             = iz2 - jz3;
804             dx31             = ix3 - jx1;
805             dy31             = iy3 - jy1;
806             dz31             = iz3 - jz1;
807             dx32             = ix3 - jx2;
808             dy32             = iy3 - jy2;
809             dz32             = iz3 - jz2;
810             dx33             = ix3 - jx3;
811             dy33             = iy3 - jy3;
812             dz33             = iz3 - jz3;
813
814             /* Calculate squared distance and things based on it */
815             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
816             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
817             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
818             rsq13            = dx13*dx13+dy13*dy13+dz13*dz13;
819             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
820             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
821             rsq23            = dx23*dx23+dy23*dy23+dz23*dz23;
822             rsq31            = dx31*dx31+dy31*dy31+dz31*dz31;
823             rsq32            = dx32*dx32+dy32*dy32+dz32*dz32;
824             rsq33            = dx33*dx33+dy33*dy33+dz33*dz33;
825
826             rinv00           = gmx_invsqrt(rsq00);
827             rinv11           = gmx_invsqrt(rsq11);
828             rinv12           = gmx_invsqrt(rsq12);
829             rinv13           = gmx_invsqrt(rsq13);
830             rinv21           = gmx_invsqrt(rsq21);
831             rinv22           = gmx_invsqrt(rsq22);
832             rinv23           = gmx_invsqrt(rsq23);
833             rinv31           = gmx_invsqrt(rsq31);
834             rinv32           = gmx_invsqrt(rsq32);
835             rinv33           = gmx_invsqrt(rsq33);
836
837             rinvsq11         = rinv11*rinv11;
838             rinvsq12         = rinv12*rinv12;
839             rinvsq13         = rinv13*rinv13;
840             rinvsq21         = rinv21*rinv21;
841             rinvsq22         = rinv22*rinv22;
842             rinvsq23         = rinv23*rinv23;
843             rinvsq31         = rinv31*rinv31;
844             rinvsq32         = rinv32*rinv32;
845             rinvsq33         = rinv33*rinv33;
846
847             /**************************
848              * CALCULATE INTERACTIONS *
849              **************************/
850
851             r00              = rsq00*rinv00;
852
853             /* Calculate table index by multiplying r with table scale and truncate to integer */
854             rt               = r00*vftabscale;
855             vfitab           = rt;
856             vfeps            = rt-vfitab;
857             vfitab           = 2*4*vfitab;
858
859             /* CUBIC SPLINE TABLE DISPERSION */
860             vfitab          += 0;
861             F                = vftab[vfitab+1];
862             Geps             = vfeps*vftab[vfitab+2];
863             Heps2            = vfeps*vfeps*vftab[vfitab+3];
864             Fp               = F+Geps+Heps2;
865             FF               = Fp+Geps+2.0*Heps2;
866             fvdw6            = c6_00*FF;
867
868             /* CUBIC SPLINE TABLE REPULSION */
869             F                = vftab[vfitab+5];
870             Geps             = vfeps*vftab[vfitab+6];
871             Heps2            = vfeps*vfeps*vftab[vfitab+7];
872             Fp               = F+Geps+Heps2;
873             FF               = Fp+Geps+2.0*Heps2;
874             fvdw12           = c12_00*FF;
875             fvdw             = -(fvdw6+fvdw12)*vftabscale*rinv00;
876
877             fscal            = fvdw;
878
879             /* Calculate temporary vectorial force */
880             tx               = fscal*dx00;
881             ty               = fscal*dy00;
882             tz               = fscal*dz00;
883
884             /* Update vectorial force */
885             fix0            += tx;
886             fiy0            += ty;
887             fiz0            += tz;
888             f[j_coord_offset+DIM*0+XX] -= tx;
889             f[j_coord_offset+DIM*0+YY] -= ty;
890             f[j_coord_offset+DIM*0+ZZ] -= tz;
891
892             /**************************
893              * CALCULATE INTERACTIONS *
894              **************************/
895
896             /* COULOMB ELECTROSTATICS */
897             velec            = qq11*rinv11;
898             felec            = velec*rinvsq11;
899
900             fscal            = felec;
901
902             /* Calculate temporary vectorial force */
903             tx               = fscal*dx11;
904             ty               = fscal*dy11;
905             tz               = fscal*dz11;
906
907             /* Update vectorial force */
908             fix1            += tx;
909             fiy1            += ty;
910             fiz1            += tz;
911             f[j_coord_offset+DIM*1+XX] -= tx;
912             f[j_coord_offset+DIM*1+YY] -= ty;
913             f[j_coord_offset+DIM*1+ZZ] -= tz;
914
915             /**************************
916              * CALCULATE INTERACTIONS *
917              **************************/
918
919             /* COULOMB ELECTROSTATICS */
920             velec            = qq12*rinv12;
921             felec            = velec*rinvsq12;
922
923             fscal            = felec;
924
925             /* Calculate temporary vectorial force */
926             tx               = fscal*dx12;
927             ty               = fscal*dy12;
928             tz               = fscal*dz12;
929
930             /* Update vectorial force */
931             fix1            += tx;
932             fiy1            += ty;
933             fiz1            += tz;
934             f[j_coord_offset+DIM*2+XX] -= tx;
935             f[j_coord_offset+DIM*2+YY] -= ty;
936             f[j_coord_offset+DIM*2+ZZ] -= tz;
937
938             /**************************
939              * CALCULATE INTERACTIONS *
940              **************************/
941
942             /* COULOMB ELECTROSTATICS */
943             velec            = qq13*rinv13;
944             felec            = velec*rinvsq13;
945
946             fscal            = felec;
947
948             /* Calculate temporary vectorial force */
949             tx               = fscal*dx13;
950             ty               = fscal*dy13;
951             tz               = fscal*dz13;
952
953             /* Update vectorial force */
954             fix1            += tx;
955             fiy1            += ty;
956             fiz1            += tz;
957             f[j_coord_offset+DIM*3+XX] -= tx;
958             f[j_coord_offset+DIM*3+YY] -= ty;
959             f[j_coord_offset+DIM*3+ZZ] -= tz;
960
961             /**************************
962              * CALCULATE INTERACTIONS *
963              **************************/
964
965             /* COULOMB ELECTROSTATICS */
966             velec            = qq21*rinv21;
967             felec            = velec*rinvsq21;
968
969             fscal            = felec;
970
971             /* Calculate temporary vectorial force */
972             tx               = fscal*dx21;
973             ty               = fscal*dy21;
974             tz               = fscal*dz21;
975
976             /* Update vectorial force */
977             fix2            += tx;
978             fiy2            += ty;
979             fiz2            += tz;
980             f[j_coord_offset+DIM*1+XX] -= tx;
981             f[j_coord_offset+DIM*1+YY] -= ty;
982             f[j_coord_offset+DIM*1+ZZ] -= tz;
983
984             /**************************
985              * CALCULATE INTERACTIONS *
986              **************************/
987
988             /* COULOMB ELECTROSTATICS */
989             velec            = qq22*rinv22;
990             felec            = velec*rinvsq22;
991
992             fscal            = felec;
993
994             /* Calculate temporary vectorial force */
995             tx               = fscal*dx22;
996             ty               = fscal*dy22;
997             tz               = fscal*dz22;
998
999             /* Update vectorial force */
1000             fix2            += tx;
1001             fiy2            += ty;
1002             fiz2            += tz;
1003             f[j_coord_offset+DIM*2+XX] -= tx;
1004             f[j_coord_offset+DIM*2+YY] -= ty;
1005             f[j_coord_offset+DIM*2+ZZ] -= tz;
1006
1007             /**************************
1008              * CALCULATE INTERACTIONS *
1009              **************************/
1010
1011             /* COULOMB ELECTROSTATICS */
1012             velec            = qq23*rinv23;
1013             felec            = velec*rinvsq23;
1014
1015             fscal            = felec;
1016
1017             /* Calculate temporary vectorial force */
1018             tx               = fscal*dx23;
1019             ty               = fscal*dy23;
1020             tz               = fscal*dz23;
1021
1022             /* Update vectorial force */
1023             fix2            += tx;
1024             fiy2            += ty;
1025             fiz2            += tz;
1026             f[j_coord_offset+DIM*3+XX] -= tx;
1027             f[j_coord_offset+DIM*3+YY] -= ty;
1028             f[j_coord_offset+DIM*3+ZZ] -= tz;
1029
1030             /**************************
1031              * CALCULATE INTERACTIONS *
1032              **************************/
1033
1034             /* COULOMB ELECTROSTATICS */
1035             velec            = qq31*rinv31;
1036             felec            = velec*rinvsq31;
1037
1038             fscal            = felec;
1039
1040             /* Calculate temporary vectorial force */
1041             tx               = fscal*dx31;
1042             ty               = fscal*dy31;
1043             tz               = fscal*dz31;
1044
1045             /* Update vectorial force */
1046             fix3            += tx;
1047             fiy3            += ty;
1048             fiz3            += tz;
1049             f[j_coord_offset+DIM*1+XX] -= tx;
1050             f[j_coord_offset+DIM*1+YY] -= ty;
1051             f[j_coord_offset+DIM*1+ZZ] -= tz;
1052
1053             /**************************
1054              * CALCULATE INTERACTIONS *
1055              **************************/
1056
1057             /* COULOMB ELECTROSTATICS */
1058             velec            = qq32*rinv32;
1059             felec            = velec*rinvsq32;
1060
1061             fscal            = felec;
1062
1063             /* Calculate temporary vectorial force */
1064             tx               = fscal*dx32;
1065             ty               = fscal*dy32;
1066             tz               = fscal*dz32;
1067
1068             /* Update vectorial force */
1069             fix3            += tx;
1070             fiy3            += ty;
1071             fiz3            += tz;
1072             f[j_coord_offset+DIM*2+XX] -= tx;
1073             f[j_coord_offset+DIM*2+YY] -= ty;
1074             f[j_coord_offset+DIM*2+ZZ] -= tz;
1075
1076             /**************************
1077              * CALCULATE INTERACTIONS *
1078              **************************/
1079
1080             /* COULOMB ELECTROSTATICS */
1081             velec            = qq33*rinv33;
1082             felec            = velec*rinvsq33;
1083
1084             fscal            = felec;
1085
1086             /* Calculate temporary vectorial force */
1087             tx               = fscal*dx33;
1088             ty               = fscal*dy33;
1089             tz               = fscal*dz33;
1090
1091             /* Update vectorial force */
1092             fix3            += tx;
1093             fiy3            += ty;
1094             fiz3            += tz;
1095             f[j_coord_offset+DIM*3+XX] -= tx;
1096             f[j_coord_offset+DIM*3+YY] -= ty;
1097             f[j_coord_offset+DIM*3+ZZ] -= tz;
1098
1099             /* Inner loop uses 281 flops */
1100         }
1101         /* End of innermost loop */
1102
1103         tx = ty = tz = 0;
1104         f[i_coord_offset+DIM*0+XX] += fix0;
1105         f[i_coord_offset+DIM*0+YY] += fiy0;
1106         f[i_coord_offset+DIM*0+ZZ] += fiz0;
1107         tx                         += fix0;
1108         ty                         += fiy0;
1109         tz                         += fiz0;
1110         f[i_coord_offset+DIM*1+XX] += fix1;
1111         f[i_coord_offset+DIM*1+YY] += fiy1;
1112         f[i_coord_offset+DIM*1+ZZ] += fiz1;
1113         tx                         += fix1;
1114         ty                         += fiy1;
1115         tz                         += fiz1;
1116         f[i_coord_offset+DIM*2+XX] += fix2;
1117         f[i_coord_offset+DIM*2+YY] += fiy2;
1118         f[i_coord_offset+DIM*2+ZZ] += fiz2;
1119         tx                         += fix2;
1120         ty                         += fiy2;
1121         tz                         += fiz2;
1122         f[i_coord_offset+DIM*3+XX] += fix3;
1123         f[i_coord_offset+DIM*3+YY] += fiy3;
1124         f[i_coord_offset+DIM*3+ZZ] += fiz3;
1125         tx                         += fix3;
1126         ty                         += fiy3;
1127         tz                         += fiz3;
1128         fshift[i_shift_offset+XX]  += tx;
1129         fshift[i_shift_offset+YY]  += ty;
1130         fshift[i_shift_offset+ZZ]  += tz;
1131
1132         /* Increment number of inner iterations */
1133         inneriter                  += j_index_end - j_index_start;
1134
1135         /* Outer loop uses 39 flops */
1136     }
1137
1138     /* Increment number of outer iterations */
1139     outeriter        += nri;
1140
1141     /* Update outer/inner flops */
1142
1143     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_F,outeriter*39 + inneriter*281);
1144 }