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