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