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