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