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