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