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