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