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