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