bc5f12b8950ef8c28508e0e81f64a6a83b51b5be
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecRFCut_VdwLJSw_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 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "nrnb.h"
48
49 /*
50  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwLJSw_GeomW3W3_VF_c
51  * Electrostatics interaction: ReactionField
52  * VdW interaction:            LennardJones
53  * Geometry:                   Water3-Water3
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecRFCut_VdwLJSw_GeomW3W3_VF_c
58                     (t_nblist                    * gmx_restrict       nlist,
59                      rvec                        * gmx_restrict          xx,
60                      rvec                        * gmx_restrict          ff,
61                      t_forcerec                  * gmx_restrict          fr,
62                      t_mdatoms                   * gmx_restrict     mdatoms,
63                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64                      t_nrnb                      * gmx_restrict        nrnb)
65 {
66     int              i_shift_offset,i_coord_offset,j_coord_offset;
67     int              j_index_start,j_index_end;
68     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
69     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
70     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
71     real             *shiftvec,*fshift,*x,*f;
72     int              vdwioffset0;
73     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
74     int              vdwioffset1;
75     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
76     int              vdwioffset2;
77     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
78     int              vdwjidx0;
79     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
80     int              vdwjidx1;
81     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
82     int              vdwjidx2;
83     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
84     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
85     real             dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01,cexp1_01,cexp2_01;
86     real             dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02,cexp1_02,cexp2_02;
87     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
88     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
89     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
90     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
91     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
92     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
93     real             velec,felec,velecsum,facel,crf,krf,krf2;
94     real             *charge;
95     int              nvdwtype;
96     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
97     int              *vdwtype;
98     real             *vdwparam;
99     real             rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
100
101     x                = xx[0];
102     f                = ff[0];
103
104     nri              = nlist->nri;
105     iinr             = nlist->iinr;
106     jindex           = nlist->jindex;
107     jjnr             = nlist->jjnr;
108     shiftidx         = nlist->shift;
109     gid              = nlist->gid;
110     shiftvec         = fr->shift_vec[0];
111     fshift           = fr->fshift[0];
112     facel            = fr->epsfac;
113     charge           = mdatoms->chargeA;
114     krf              = fr->ic->k_rf;
115     krf2             = krf*2.0;
116     crf              = fr->ic->c_rf;
117     nvdwtype         = fr->ntype;
118     vdwparam         = fr->nbfp;
119     vdwtype          = mdatoms->typeA;
120
121     /* Setup water-specific parameters */
122     inr              = nlist->iinr[0];
123     iq0              = facel*charge[inr+0];
124     iq1              = facel*charge[inr+1];
125     iq2              = facel*charge[inr+2];
126     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
127
128     jq0              = charge[inr+0];
129     jq1              = charge[inr+1];
130     jq2              = charge[inr+2];
131     vdwjidx0         = 2*vdwtype[inr+0];
132     qq00             = iq0*jq0;
133     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
134     c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
135     qq01             = iq0*jq1;
136     qq02             = iq0*jq2;
137     qq10             = iq1*jq0;
138     qq11             = iq1*jq1;
139     qq12             = iq1*jq2;
140     qq20             = iq2*jq0;
141     qq21             = iq2*jq1;
142     qq22             = iq2*jq2;
143
144     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
145     rcutoff          = fr->rcoulomb;
146     rcutoff2         = rcutoff*rcutoff;
147
148     rswitch          = fr->rvdw_switch;
149     /* Setup switch parameters */
150     d                = rcutoff-rswitch;
151     swV3             = -10.0/(d*d*d);
152     swV4             =  15.0/(d*d*d*d);
153     swV5             =  -6.0/(d*d*d*d*d);
154     swF2             = -30.0/(d*d*d);
155     swF3             =  60.0/(d*d*d*d);
156     swF4             = -30.0/(d*d*d*d*d);
157
158     outeriter        = 0;
159     inneriter        = 0;
160
161     /* Start outer loop over neighborlists */
162     for(iidx=0; iidx<nri; iidx++)
163     {
164         /* Load shift vector for this list */
165         i_shift_offset   = DIM*shiftidx[iidx];
166         shX              = shiftvec[i_shift_offset+XX];
167         shY              = shiftvec[i_shift_offset+YY];
168         shZ              = shiftvec[i_shift_offset+ZZ];
169
170         /* Load limits for loop over neighbors */
171         j_index_start    = jindex[iidx];
172         j_index_end      = jindex[iidx+1];
173
174         /* Get outer coordinate index */
175         inr              = iinr[iidx];
176         i_coord_offset   = DIM*inr;
177
178         /* Load i particle coords and add shift vector */
179         ix0              = shX + x[i_coord_offset+DIM*0+XX];
180         iy0              = shY + x[i_coord_offset+DIM*0+YY];
181         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
182         ix1              = shX + x[i_coord_offset+DIM*1+XX];
183         iy1              = shY + x[i_coord_offset+DIM*1+YY];
184         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
185         ix2              = shX + x[i_coord_offset+DIM*2+XX];
186         iy2              = shY + x[i_coord_offset+DIM*2+YY];
187         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
188
189         fix0             = 0.0;
190         fiy0             = 0.0;
191         fiz0             = 0.0;
192         fix1             = 0.0;
193         fiy1             = 0.0;
194         fiz1             = 0.0;
195         fix2             = 0.0;
196         fiy2             = 0.0;
197         fiz2             = 0.0;
198
199         /* Reset potential sums */
200         velecsum         = 0.0;
201         vvdwsum          = 0.0;
202
203         /* Start inner kernel loop */
204         for(jidx=j_index_start; jidx<j_index_end; jidx++)
205         {
206             /* Get j neighbor index, and coordinate index */
207             jnr              = jjnr[jidx];
208             j_coord_offset   = DIM*jnr;
209
210             /* load j atom coordinates */
211             jx0              = x[j_coord_offset+DIM*0+XX];
212             jy0              = x[j_coord_offset+DIM*0+YY];
213             jz0              = x[j_coord_offset+DIM*0+ZZ];
214             jx1              = x[j_coord_offset+DIM*1+XX];
215             jy1              = x[j_coord_offset+DIM*1+YY];
216             jz1              = x[j_coord_offset+DIM*1+ZZ];
217             jx2              = x[j_coord_offset+DIM*2+XX];
218             jy2              = x[j_coord_offset+DIM*2+YY];
219             jz2              = x[j_coord_offset+DIM*2+ZZ];
220
221             /* Calculate displacement vector */
222             dx00             = ix0 - jx0;
223             dy00             = iy0 - jy0;
224             dz00             = iz0 - jz0;
225             dx01             = ix0 - jx1;
226             dy01             = iy0 - jy1;
227             dz01             = iz0 - jz1;
228             dx02             = ix0 - jx2;
229             dy02             = iy0 - jy2;
230             dz02             = iz0 - jz2;
231             dx10             = ix1 - jx0;
232             dy10             = iy1 - jy0;
233             dz10             = iz1 - jz0;
234             dx11             = ix1 - jx1;
235             dy11             = iy1 - jy1;
236             dz11             = iz1 - jz1;
237             dx12             = ix1 - jx2;
238             dy12             = iy1 - jy2;
239             dz12             = iz1 - jz2;
240             dx20             = ix2 - jx0;
241             dy20             = iy2 - jy0;
242             dz20             = iz2 - jz0;
243             dx21             = ix2 - jx1;
244             dy21             = iy2 - jy1;
245             dz21             = iz2 - jz1;
246             dx22             = ix2 - jx2;
247             dy22             = iy2 - jy2;
248             dz22             = iz2 - jz2;
249
250             /* Calculate squared distance and things based on it */
251             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
252             rsq01            = dx01*dx01+dy01*dy01+dz01*dz01;
253             rsq02            = dx02*dx02+dy02*dy02+dz02*dz02;
254             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
255             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
256             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
257             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
258             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
259             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
260
261             rinv00           = gmx_invsqrt(rsq00);
262             rinv01           = gmx_invsqrt(rsq01);
263             rinv02           = gmx_invsqrt(rsq02);
264             rinv10           = gmx_invsqrt(rsq10);
265             rinv11           = gmx_invsqrt(rsq11);
266             rinv12           = gmx_invsqrt(rsq12);
267             rinv20           = gmx_invsqrt(rsq20);
268             rinv21           = gmx_invsqrt(rsq21);
269             rinv22           = gmx_invsqrt(rsq22);
270
271             rinvsq00         = rinv00*rinv00;
272             rinvsq01         = rinv01*rinv01;
273             rinvsq02         = rinv02*rinv02;
274             rinvsq10         = rinv10*rinv10;
275             rinvsq11         = rinv11*rinv11;
276             rinvsq12         = rinv12*rinv12;
277             rinvsq20         = rinv20*rinv20;
278             rinvsq21         = rinv21*rinv21;
279             rinvsq22         = rinv22*rinv22;
280
281             /**************************
282              * CALCULATE INTERACTIONS *
283              **************************/
284
285             if (rsq00<rcutoff2)
286             {
287
288             r00              = rsq00*rinv00;
289
290             /* REACTION-FIELD ELECTROSTATICS */
291             velec            = qq00*(rinv00+krf*rsq00-crf);
292             felec            = qq00*(rinv00*rinvsq00-krf2);
293
294             /* LENNARD-JONES DISPERSION/REPULSION */
295
296             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
297             vvdw6            = c6_00*rinvsix;
298             vvdw12           = c12_00*rinvsix*rinvsix;
299             vvdw             = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
300             fvdw             = (vvdw12-vvdw6)*rinvsq00;
301
302             d                = r00-rswitch;
303             d                = (d>0.0) ? d : 0.0;
304             d2               = d*d;
305             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
306
307             dsw              = d2*(swF2+d*(swF3+d*swF4));
308
309             /* Evaluate switch function */
310             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
311             fvdw             = fvdw*sw - rinv00*vvdw*dsw;
312             vvdw            *= sw;
313
314             /* Update potential sums from outer loop */
315             velecsum        += velec;
316             vvdwsum         += vvdw;
317
318             fscal            = felec+fvdw;
319
320             /* Calculate temporary vectorial force */
321             tx               = fscal*dx00;
322             ty               = fscal*dy00;
323             tz               = fscal*dz00;
324
325             /* Update vectorial force */
326             fix0            += tx;
327             fiy0            += ty;
328             fiz0            += tz;
329             f[j_coord_offset+DIM*0+XX] -= tx;
330             f[j_coord_offset+DIM*0+YY] -= ty;
331             f[j_coord_offset+DIM*0+ZZ] -= tz;
332
333             }
334
335             /**************************
336              * CALCULATE INTERACTIONS *
337              **************************/
338
339             if (rsq01<rcutoff2)
340             {
341
342             /* REACTION-FIELD ELECTROSTATICS */
343             velec            = qq01*(rinv01+krf*rsq01-crf);
344             felec            = qq01*(rinv01*rinvsq01-krf2);
345
346             /* Update potential sums from outer loop */
347             velecsum        += velec;
348
349             fscal            = felec;
350
351             /* Calculate temporary vectorial force */
352             tx               = fscal*dx01;
353             ty               = fscal*dy01;
354             tz               = fscal*dz01;
355
356             /* Update vectorial force */
357             fix0            += tx;
358             fiy0            += ty;
359             fiz0            += tz;
360             f[j_coord_offset+DIM*1+XX] -= tx;
361             f[j_coord_offset+DIM*1+YY] -= ty;
362             f[j_coord_offset+DIM*1+ZZ] -= tz;
363
364             }
365
366             /**************************
367              * CALCULATE INTERACTIONS *
368              **************************/
369
370             if (rsq02<rcutoff2)
371             {
372
373             /* REACTION-FIELD ELECTROSTATICS */
374             velec            = qq02*(rinv02+krf*rsq02-crf);
375             felec            = qq02*(rinv02*rinvsq02-krf2);
376
377             /* Update potential sums from outer loop */
378             velecsum        += velec;
379
380             fscal            = felec;
381
382             /* Calculate temporary vectorial force */
383             tx               = fscal*dx02;
384             ty               = fscal*dy02;
385             tz               = fscal*dz02;
386
387             /* Update vectorial force */
388             fix0            += tx;
389             fiy0            += ty;
390             fiz0            += tz;
391             f[j_coord_offset+DIM*2+XX] -= tx;
392             f[j_coord_offset+DIM*2+YY] -= ty;
393             f[j_coord_offset+DIM*2+ZZ] -= tz;
394
395             }
396
397             /**************************
398              * CALCULATE INTERACTIONS *
399              **************************/
400
401             if (rsq10<rcutoff2)
402             {
403
404             /* REACTION-FIELD ELECTROSTATICS */
405             velec            = qq10*(rinv10+krf*rsq10-crf);
406             felec            = qq10*(rinv10*rinvsq10-krf2);
407
408             /* Update potential sums from outer loop */
409             velecsum        += velec;
410
411             fscal            = felec;
412
413             /* Calculate temporary vectorial force */
414             tx               = fscal*dx10;
415             ty               = fscal*dy10;
416             tz               = fscal*dz10;
417
418             /* Update vectorial force */
419             fix1            += tx;
420             fiy1            += ty;
421             fiz1            += tz;
422             f[j_coord_offset+DIM*0+XX] -= tx;
423             f[j_coord_offset+DIM*0+YY] -= ty;
424             f[j_coord_offset+DIM*0+ZZ] -= tz;
425
426             }
427
428             /**************************
429              * CALCULATE INTERACTIONS *
430              **************************/
431
432             if (rsq11<rcutoff2)
433             {
434
435             /* REACTION-FIELD ELECTROSTATICS */
436             velec            = qq11*(rinv11+krf*rsq11-crf);
437             felec            = qq11*(rinv11*rinvsq11-krf2);
438
439             /* Update potential sums from outer loop */
440             velecsum        += velec;
441
442             fscal            = felec;
443
444             /* Calculate temporary vectorial force */
445             tx               = fscal*dx11;
446             ty               = fscal*dy11;
447             tz               = fscal*dz11;
448
449             /* Update vectorial force */
450             fix1            += tx;
451             fiy1            += ty;
452             fiz1            += tz;
453             f[j_coord_offset+DIM*1+XX] -= tx;
454             f[j_coord_offset+DIM*1+YY] -= ty;
455             f[j_coord_offset+DIM*1+ZZ] -= tz;
456
457             }
458
459             /**************************
460              * CALCULATE INTERACTIONS *
461              **************************/
462
463             if (rsq12<rcutoff2)
464             {
465
466             /* REACTION-FIELD ELECTROSTATICS */
467             velec            = qq12*(rinv12+krf*rsq12-crf);
468             felec            = qq12*(rinv12*rinvsq12-krf2);
469
470             /* Update potential sums from outer loop */
471             velecsum        += velec;
472
473             fscal            = felec;
474
475             /* Calculate temporary vectorial force */
476             tx               = fscal*dx12;
477             ty               = fscal*dy12;
478             tz               = fscal*dz12;
479
480             /* Update vectorial force */
481             fix1            += tx;
482             fiy1            += ty;
483             fiz1            += tz;
484             f[j_coord_offset+DIM*2+XX] -= tx;
485             f[j_coord_offset+DIM*2+YY] -= ty;
486             f[j_coord_offset+DIM*2+ZZ] -= tz;
487
488             }
489
490             /**************************
491              * CALCULATE INTERACTIONS *
492              **************************/
493
494             if (rsq20<rcutoff2)
495             {
496
497             /* REACTION-FIELD ELECTROSTATICS */
498             velec            = qq20*(rinv20+krf*rsq20-crf);
499             felec            = qq20*(rinv20*rinvsq20-krf2);
500
501             /* Update potential sums from outer loop */
502             velecsum        += velec;
503
504             fscal            = felec;
505
506             /* Calculate temporary vectorial force */
507             tx               = fscal*dx20;
508             ty               = fscal*dy20;
509             tz               = fscal*dz20;
510
511             /* Update vectorial force */
512             fix2            += tx;
513             fiy2            += ty;
514             fiz2            += tz;
515             f[j_coord_offset+DIM*0+XX] -= tx;
516             f[j_coord_offset+DIM*0+YY] -= ty;
517             f[j_coord_offset+DIM*0+ZZ] -= tz;
518
519             }
520
521             /**************************
522              * CALCULATE INTERACTIONS *
523              **************************/
524
525             if (rsq21<rcutoff2)
526             {
527
528             /* REACTION-FIELD ELECTROSTATICS */
529             velec            = qq21*(rinv21+krf*rsq21-crf);
530             felec            = qq21*(rinv21*rinvsq21-krf2);
531
532             /* Update potential sums from outer loop */
533             velecsum        += velec;
534
535             fscal            = felec;
536
537             /* Calculate temporary vectorial force */
538             tx               = fscal*dx21;
539             ty               = fscal*dy21;
540             tz               = fscal*dz21;
541
542             /* Update vectorial force */
543             fix2            += tx;
544             fiy2            += ty;
545             fiz2            += tz;
546             f[j_coord_offset+DIM*1+XX] -= tx;
547             f[j_coord_offset+DIM*1+YY] -= ty;
548             f[j_coord_offset+DIM*1+ZZ] -= tz;
549
550             }
551
552             /**************************
553              * CALCULATE INTERACTIONS *
554              **************************/
555
556             if (rsq22<rcutoff2)
557             {
558
559             /* REACTION-FIELD ELECTROSTATICS */
560             velec            = qq22*(rinv22+krf*rsq22-crf);
561             felec            = qq22*(rinv22*rinvsq22-krf2);
562
563             /* Update potential sums from outer loop */
564             velecsum        += velec;
565
566             fscal            = felec;
567
568             /* Calculate temporary vectorial force */
569             tx               = fscal*dx22;
570             ty               = fscal*dy22;
571             tz               = fscal*dz22;
572
573             /* Update vectorial force */
574             fix2            += tx;
575             fiy2            += ty;
576             fiz2            += tz;
577             f[j_coord_offset+DIM*2+XX] -= tx;
578             f[j_coord_offset+DIM*2+YY] -= ty;
579             f[j_coord_offset+DIM*2+ZZ] -= tz;
580
581             }
582
583             /* Inner loop uses 310 flops */
584         }
585         /* End of innermost loop */
586
587         tx = ty = tz = 0;
588         f[i_coord_offset+DIM*0+XX] += fix0;
589         f[i_coord_offset+DIM*0+YY] += fiy0;
590         f[i_coord_offset+DIM*0+ZZ] += fiz0;
591         tx                         += fix0;
592         ty                         += fiy0;
593         tz                         += fiz0;
594         f[i_coord_offset+DIM*1+XX] += fix1;
595         f[i_coord_offset+DIM*1+YY] += fiy1;
596         f[i_coord_offset+DIM*1+ZZ] += fiz1;
597         tx                         += fix1;
598         ty                         += fiy1;
599         tz                         += fiz1;
600         f[i_coord_offset+DIM*2+XX] += fix2;
601         f[i_coord_offset+DIM*2+YY] += fiy2;
602         f[i_coord_offset+DIM*2+ZZ] += fiz2;
603         tx                         += fix2;
604         ty                         += fiy2;
605         tz                         += fiz2;
606         fshift[i_shift_offset+XX]  += tx;
607         fshift[i_shift_offset+YY]  += ty;
608         fshift[i_shift_offset+ZZ]  += tz;
609
610         ggid                        = gid[iidx];
611         /* Update potential energies */
612         kernel_data->energygrp_elec[ggid] += velecsum;
613         kernel_data->energygrp_vdw[ggid] += vvdwsum;
614
615         /* Increment number of inner iterations */
616         inneriter                  += j_index_end - j_index_start;
617
618         /* Outer loop uses 32 flops */
619     }
620
621     /* Increment number of outer iterations */
622     outeriter        += nri;
623
624     /* Update outer/inner flops */
625
626     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_VF,outeriter*32 + inneriter*310);
627 }
628 /*
629  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwLJSw_GeomW3W3_F_c
630  * Electrostatics interaction: ReactionField
631  * VdW interaction:            LennardJones
632  * Geometry:                   Water3-Water3
633  * Calculate force/pot:        Force
634  */
635 void
636 nb_kernel_ElecRFCut_VdwLJSw_GeomW3W3_F_c
637                     (t_nblist                    * gmx_restrict       nlist,
638                      rvec                        * gmx_restrict          xx,
639                      rvec                        * gmx_restrict          ff,
640                      t_forcerec                  * gmx_restrict          fr,
641                      t_mdatoms                   * gmx_restrict     mdatoms,
642                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
643                      t_nrnb                      * gmx_restrict        nrnb)
644 {
645     int              i_shift_offset,i_coord_offset,j_coord_offset;
646     int              j_index_start,j_index_end;
647     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
648     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
649     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
650     real             *shiftvec,*fshift,*x,*f;
651     int              vdwioffset0;
652     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
653     int              vdwioffset1;
654     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
655     int              vdwioffset2;
656     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
657     int              vdwjidx0;
658     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
659     int              vdwjidx1;
660     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
661     int              vdwjidx2;
662     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
663     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
664     real             dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01,cexp1_01,cexp2_01;
665     real             dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02,cexp1_02,cexp2_02;
666     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
667     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
668     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
669     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
670     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
671     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
672     real             velec,felec,velecsum,facel,crf,krf,krf2;
673     real             *charge;
674     int              nvdwtype;
675     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
676     int              *vdwtype;
677     real             *vdwparam;
678     real             rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
679
680     x                = xx[0];
681     f                = ff[0];
682
683     nri              = nlist->nri;
684     iinr             = nlist->iinr;
685     jindex           = nlist->jindex;
686     jjnr             = nlist->jjnr;
687     shiftidx         = nlist->shift;
688     gid              = nlist->gid;
689     shiftvec         = fr->shift_vec[0];
690     fshift           = fr->fshift[0];
691     facel            = fr->epsfac;
692     charge           = mdatoms->chargeA;
693     krf              = fr->ic->k_rf;
694     krf2             = krf*2.0;
695     crf              = fr->ic->c_rf;
696     nvdwtype         = fr->ntype;
697     vdwparam         = fr->nbfp;
698     vdwtype          = mdatoms->typeA;
699
700     /* Setup water-specific parameters */
701     inr              = nlist->iinr[0];
702     iq0              = facel*charge[inr+0];
703     iq1              = facel*charge[inr+1];
704     iq2              = facel*charge[inr+2];
705     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
706
707     jq0              = charge[inr+0];
708     jq1              = charge[inr+1];
709     jq2              = charge[inr+2];
710     vdwjidx0         = 2*vdwtype[inr+0];
711     qq00             = iq0*jq0;
712     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
713     c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
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             /* LENNARD-JONES DISPERSION/REPULSION */
869
870             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
871             vvdw6            = c6_00*rinvsix;
872             vvdw12           = c12_00*rinvsix*rinvsix;
873             vvdw             = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
874             fvdw             = (vvdw12-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 263 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*263);
1159 }