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