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