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