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