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