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