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