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