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