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