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