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