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