Merge release-5-0 into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecRF_VdwNone_GeomW3W3_c.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS c kernel generator.
37  */
38 #include "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_ElecRF_VdwNone_GeomW3W3_VF_c
51  * Electrostatics interaction: ReactionField
52  * VdW interaction:            None
53  * Geometry:                   Water3-Water3
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecRF_VdwNone_GeomW3W3_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              vdwioffset0;
73     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
74     int              vdwioffset1;
75     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
76     int              vdwioffset2;
77     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
78     int              vdwjidx0;
79     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
80     int              vdwjidx1;
81     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
82     int              vdwjidx2;
83     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
84     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
85     real             dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01,cexp1_01,cexp2_01;
86     real             dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02,cexp1_02,cexp2_02;
87     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
88     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
89     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
90     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
91     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
92     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
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     iq0              = facel*charge[inr+0];
116     iq1              = facel*charge[inr+1];
117     iq2              = facel*charge[inr+2];
118
119     jq0              = charge[inr+0];
120     jq1              = charge[inr+1];
121     jq2              = charge[inr+2];
122     qq00             = iq0*jq0;
123     qq01             = iq0*jq1;
124     qq02             = iq0*jq2;
125     qq10             = iq1*jq0;
126     qq11             = iq1*jq1;
127     qq12             = iq1*jq2;
128     qq20             = iq2*jq0;
129     qq21             = iq2*jq1;
130     qq22             = iq2*jq2;
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         ix0              = shX + x[i_coord_offset+DIM*0+XX];
154         iy0              = shY + x[i_coord_offset+DIM*0+YY];
155         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
156         ix1              = shX + x[i_coord_offset+DIM*1+XX];
157         iy1              = shY + x[i_coord_offset+DIM*1+YY];
158         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
159         ix2              = shX + x[i_coord_offset+DIM*2+XX];
160         iy2              = shY + x[i_coord_offset+DIM*2+YY];
161         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
162
163         fix0             = 0.0;
164         fiy0             = 0.0;
165         fiz0             = 0.0;
166         fix1             = 0.0;
167         fiy1             = 0.0;
168         fiz1             = 0.0;
169         fix2             = 0.0;
170         fiy2             = 0.0;
171         fiz2             = 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             jx0              = x[j_coord_offset+DIM*0+XX];
185             jy0              = x[j_coord_offset+DIM*0+YY];
186             jz0              = x[j_coord_offset+DIM*0+ZZ];
187             jx1              = x[j_coord_offset+DIM*1+XX];
188             jy1              = x[j_coord_offset+DIM*1+YY];
189             jz1              = x[j_coord_offset+DIM*1+ZZ];
190             jx2              = x[j_coord_offset+DIM*2+XX];
191             jy2              = x[j_coord_offset+DIM*2+YY];
192             jz2              = x[j_coord_offset+DIM*2+ZZ];
193
194             /* Calculate displacement vector */
195             dx00             = ix0 - jx0;
196             dy00             = iy0 - jy0;
197             dz00             = iz0 - jz0;
198             dx01             = ix0 - jx1;
199             dy01             = iy0 - jy1;
200             dz01             = iz0 - jz1;
201             dx02             = ix0 - jx2;
202             dy02             = iy0 - jy2;
203             dz02             = iz0 - jz2;
204             dx10             = ix1 - jx0;
205             dy10             = iy1 - jy0;
206             dz10             = iz1 - jz0;
207             dx11             = ix1 - jx1;
208             dy11             = iy1 - jy1;
209             dz11             = iz1 - jz1;
210             dx12             = ix1 - jx2;
211             dy12             = iy1 - jy2;
212             dz12             = iz1 - jz2;
213             dx20             = ix2 - jx0;
214             dy20             = iy2 - jy0;
215             dz20             = iz2 - jz0;
216             dx21             = ix2 - jx1;
217             dy21             = iy2 - jy1;
218             dz21             = iz2 - jz1;
219             dx22             = ix2 - jx2;
220             dy22             = iy2 - jy2;
221             dz22             = iz2 - jz2;
222
223             /* Calculate squared distance and things based on it */
224             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
225             rsq01            = dx01*dx01+dy01*dy01+dz01*dz01;
226             rsq02            = dx02*dx02+dy02*dy02+dz02*dz02;
227             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
228             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
229             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
230             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
231             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
232             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
233
234             rinv00           = gmx_invsqrt(rsq00);
235             rinv01           = gmx_invsqrt(rsq01);
236             rinv02           = gmx_invsqrt(rsq02);
237             rinv10           = gmx_invsqrt(rsq10);
238             rinv11           = gmx_invsqrt(rsq11);
239             rinv12           = gmx_invsqrt(rsq12);
240             rinv20           = gmx_invsqrt(rsq20);
241             rinv21           = gmx_invsqrt(rsq21);
242             rinv22           = gmx_invsqrt(rsq22);
243
244             rinvsq00         = rinv00*rinv00;
245             rinvsq01         = rinv01*rinv01;
246             rinvsq02         = rinv02*rinv02;
247             rinvsq10         = rinv10*rinv10;
248             rinvsq11         = rinv11*rinv11;
249             rinvsq12         = rinv12*rinv12;
250             rinvsq20         = rinv20*rinv20;
251             rinvsq21         = rinv21*rinv21;
252             rinvsq22         = rinv22*rinv22;
253
254             /**************************
255              * CALCULATE INTERACTIONS *
256              **************************/
257
258             /* REACTION-FIELD ELECTROSTATICS */
259             velec            = qq00*(rinv00+krf*rsq00-crf);
260             felec            = qq00*(rinv00*rinvsq00-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*dx00;
269             ty               = fscal*dy00;
270             tz               = fscal*dz00;
271
272             /* Update vectorial force */
273             fix0            += tx;
274             fiy0            += ty;
275             fiz0            += tz;
276             f[j_coord_offset+DIM*0+XX] -= tx;
277             f[j_coord_offset+DIM*0+YY] -= ty;
278             f[j_coord_offset+DIM*0+ZZ] -= tz;
279
280             /**************************
281              * CALCULATE INTERACTIONS *
282              **************************/
283
284             /* REACTION-FIELD ELECTROSTATICS */
285             velec            = qq01*(rinv01+krf*rsq01-crf);
286             felec            = qq01*(rinv01*rinvsq01-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*dx01;
295             ty               = fscal*dy01;
296             tz               = fscal*dz01;
297
298             /* Update vectorial force */
299             fix0            += tx;
300             fiy0            += ty;
301             fiz0            += tz;
302             f[j_coord_offset+DIM*1+XX] -= tx;
303             f[j_coord_offset+DIM*1+YY] -= ty;
304             f[j_coord_offset+DIM*1+ZZ] -= tz;
305
306             /**************************
307              * CALCULATE INTERACTIONS *
308              **************************/
309
310             /* REACTION-FIELD ELECTROSTATICS */
311             velec            = qq02*(rinv02+krf*rsq02-crf);
312             felec            = qq02*(rinv02*rinvsq02-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*dx02;
321             ty               = fscal*dy02;
322             tz               = fscal*dz02;
323
324             /* Update vectorial force */
325             fix0            += tx;
326             fiy0            += ty;
327             fiz0            += tz;
328             f[j_coord_offset+DIM*2+XX] -= tx;
329             f[j_coord_offset+DIM*2+YY] -= ty;
330             f[j_coord_offset+DIM*2+ZZ] -= tz;
331
332             /**************************
333              * CALCULATE INTERACTIONS *
334              **************************/
335
336             /* REACTION-FIELD ELECTROSTATICS */
337             velec            = qq10*(rinv10+krf*rsq10-crf);
338             felec            = qq10*(rinv10*rinvsq10-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*dx10;
347             ty               = fscal*dy10;
348             tz               = fscal*dz10;
349
350             /* Update vectorial force */
351             fix1            += tx;
352             fiy1            += ty;
353             fiz1            += tz;
354             f[j_coord_offset+DIM*0+XX] -= tx;
355             f[j_coord_offset+DIM*0+YY] -= ty;
356             f[j_coord_offset+DIM*0+ZZ] -= tz;
357
358             /**************************
359              * CALCULATE INTERACTIONS *
360              **************************/
361
362             /* REACTION-FIELD ELECTROSTATICS */
363             velec            = qq11*(rinv11+krf*rsq11-crf);
364             felec            = qq11*(rinv11*rinvsq11-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*dx11;
373             ty               = fscal*dy11;
374             tz               = fscal*dz11;
375
376             /* Update vectorial force */
377             fix1            += tx;
378             fiy1            += ty;
379             fiz1            += tz;
380             f[j_coord_offset+DIM*1+XX] -= tx;
381             f[j_coord_offset+DIM*1+YY] -= ty;
382             f[j_coord_offset+DIM*1+ZZ] -= tz;
383
384             /**************************
385              * CALCULATE INTERACTIONS *
386              **************************/
387
388             /* REACTION-FIELD ELECTROSTATICS */
389             velec            = qq12*(rinv12+krf*rsq12-crf);
390             felec            = qq12*(rinv12*rinvsq12-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*dx12;
399             ty               = fscal*dy12;
400             tz               = fscal*dz12;
401
402             /* Update vectorial force */
403             fix1            += tx;
404             fiy1            += ty;
405             fiz1            += tz;
406             f[j_coord_offset+DIM*2+XX] -= tx;
407             f[j_coord_offset+DIM*2+YY] -= ty;
408             f[j_coord_offset+DIM*2+ZZ] -= tz;
409
410             /**************************
411              * CALCULATE INTERACTIONS *
412              **************************/
413
414             /* REACTION-FIELD ELECTROSTATICS */
415             velec            = qq20*(rinv20+krf*rsq20-crf);
416             felec            = qq20*(rinv20*rinvsq20-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*dx20;
425             ty               = fscal*dy20;
426             tz               = fscal*dz20;
427
428             /* Update vectorial force */
429             fix2            += tx;
430             fiy2            += ty;
431             fiz2            += tz;
432             f[j_coord_offset+DIM*0+XX] -= tx;
433             f[j_coord_offset+DIM*0+YY] -= ty;
434             f[j_coord_offset+DIM*0+ZZ] -= tz;
435
436             /**************************
437              * CALCULATE INTERACTIONS *
438              **************************/
439
440             /* REACTION-FIELD ELECTROSTATICS */
441             velec            = qq21*(rinv21+krf*rsq21-crf);
442             felec            = qq21*(rinv21*rinvsq21-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*dx21;
451             ty               = fscal*dy21;
452             tz               = fscal*dz21;
453
454             /* Update vectorial force */
455             fix2            += tx;
456             fiy2            += ty;
457             fiz2            += tz;
458             f[j_coord_offset+DIM*1+XX] -= tx;
459             f[j_coord_offset+DIM*1+YY] -= ty;
460             f[j_coord_offset+DIM*1+ZZ] -= tz;
461
462             /**************************
463              * CALCULATE INTERACTIONS *
464              **************************/
465
466             /* REACTION-FIELD ELECTROSTATICS */
467             velec            = qq22*(rinv22+krf*rsq22-crf);
468             felec            = qq22*(rinv22*rinvsq22-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*dx22;
477             ty               = fscal*dy22;
478             tz               = fscal*dz22;
479
480             /* Update vectorial force */
481             fix2            += tx;
482             fiy2            += ty;
483             fiz2            += tz;
484             f[j_coord_offset+DIM*2+XX] -= tx;
485             f[j_coord_offset+DIM*2+YY] -= ty;
486             f[j_coord_offset+DIM*2+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*0+XX] += fix0;
494         f[i_coord_offset+DIM*0+YY] += fiy0;
495         f[i_coord_offset+DIM*0+ZZ] += fiz0;
496         tx                         += fix0;
497         ty                         += fiy0;
498         tz                         += fiz0;
499         f[i_coord_offset+DIM*1+XX] += fix1;
500         f[i_coord_offset+DIM*1+YY] += fiy1;
501         f[i_coord_offset+DIM*1+ZZ] += fiz1;
502         tx                         += fix1;
503         ty                         += fiy1;
504         tz                         += fiz1;
505         f[i_coord_offset+DIM*2+XX] += fix2;
506         f[i_coord_offset+DIM*2+YY] += fiy2;
507         f[i_coord_offset+DIM*2+ZZ] += fiz2;
508         tx                         += fix2;
509         ty                         += fiy2;
510         tz                         += fiz2;
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_W3W3_VF,outeriter*31 + inneriter*279);
531 }
532 /*
533  * Gromacs nonbonded kernel:   nb_kernel_ElecRF_VdwNone_GeomW3W3_F_c
534  * Electrostatics interaction: ReactionField
535  * VdW interaction:            None
536  * Geometry:                   Water3-Water3
537  * Calculate force/pot:        Force
538  */
539 void
540 nb_kernel_ElecRF_VdwNone_GeomW3W3_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              vdwioffset0;
556     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
557     int              vdwioffset1;
558     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
559     int              vdwioffset2;
560     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
561     int              vdwjidx0;
562     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
563     int              vdwjidx1;
564     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
565     int              vdwjidx2;
566     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
567     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
568     real             dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01,cexp1_01,cexp2_01;
569     real             dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02,cexp1_02,cexp2_02;
570     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
571     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
572     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
573     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
574     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
575     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
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     iq0              = facel*charge[inr+0];
599     iq1              = facel*charge[inr+1];
600     iq2              = facel*charge[inr+2];
601
602     jq0              = charge[inr+0];
603     jq1              = charge[inr+1];
604     jq2              = charge[inr+2];
605     qq00             = iq0*jq0;
606     qq01             = iq0*jq1;
607     qq02             = iq0*jq2;
608     qq10             = iq1*jq0;
609     qq11             = iq1*jq1;
610     qq12             = iq1*jq2;
611     qq20             = iq2*jq0;
612     qq21             = iq2*jq1;
613     qq22             = iq2*jq2;
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         ix0              = shX + x[i_coord_offset+DIM*0+XX];
637         iy0              = shY + x[i_coord_offset+DIM*0+YY];
638         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
639         ix1              = shX + x[i_coord_offset+DIM*1+XX];
640         iy1              = shY + x[i_coord_offset+DIM*1+YY];
641         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
642         ix2              = shX + x[i_coord_offset+DIM*2+XX];
643         iy2              = shY + x[i_coord_offset+DIM*2+YY];
644         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
645
646         fix0             = 0.0;
647         fiy0             = 0.0;
648         fiz0             = 0.0;
649         fix1             = 0.0;
650         fiy1             = 0.0;
651         fiz1             = 0.0;
652         fix2             = 0.0;
653         fiy2             = 0.0;
654         fiz2             = 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             jx0              = x[j_coord_offset+DIM*0+XX];
665             jy0              = x[j_coord_offset+DIM*0+YY];
666             jz0              = x[j_coord_offset+DIM*0+ZZ];
667             jx1              = x[j_coord_offset+DIM*1+XX];
668             jy1              = x[j_coord_offset+DIM*1+YY];
669             jz1              = x[j_coord_offset+DIM*1+ZZ];
670             jx2              = x[j_coord_offset+DIM*2+XX];
671             jy2              = x[j_coord_offset+DIM*2+YY];
672             jz2              = x[j_coord_offset+DIM*2+ZZ];
673
674             /* Calculate displacement vector */
675             dx00             = ix0 - jx0;
676             dy00             = iy0 - jy0;
677             dz00             = iz0 - jz0;
678             dx01             = ix0 - jx1;
679             dy01             = iy0 - jy1;
680             dz01             = iz0 - jz1;
681             dx02             = ix0 - jx2;
682             dy02             = iy0 - jy2;
683             dz02             = iz0 - jz2;
684             dx10             = ix1 - jx0;
685             dy10             = iy1 - jy0;
686             dz10             = iz1 - jz0;
687             dx11             = ix1 - jx1;
688             dy11             = iy1 - jy1;
689             dz11             = iz1 - jz1;
690             dx12             = ix1 - jx2;
691             dy12             = iy1 - jy2;
692             dz12             = iz1 - jz2;
693             dx20             = ix2 - jx0;
694             dy20             = iy2 - jy0;
695             dz20             = iz2 - jz0;
696             dx21             = ix2 - jx1;
697             dy21             = iy2 - jy1;
698             dz21             = iz2 - jz1;
699             dx22             = ix2 - jx2;
700             dy22             = iy2 - jy2;
701             dz22             = iz2 - jz2;
702
703             /* Calculate squared distance and things based on it */
704             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
705             rsq01            = dx01*dx01+dy01*dy01+dz01*dz01;
706             rsq02            = dx02*dx02+dy02*dy02+dz02*dz02;
707             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
708             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
709             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
710             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
711             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
712             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
713
714             rinv00           = gmx_invsqrt(rsq00);
715             rinv01           = gmx_invsqrt(rsq01);
716             rinv02           = gmx_invsqrt(rsq02);
717             rinv10           = gmx_invsqrt(rsq10);
718             rinv11           = gmx_invsqrt(rsq11);
719             rinv12           = gmx_invsqrt(rsq12);
720             rinv20           = gmx_invsqrt(rsq20);
721             rinv21           = gmx_invsqrt(rsq21);
722             rinv22           = gmx_invsqrt(rsq22);
723
724             rinvsq00         = rinv00*rinv00;
725             rinvsq01         = rinv01*rinv01;
726             rinvsq02         = rinv02*rinv02;
727             rinvsq10         = rinv10*rinv10;
728             rinvsq11         = rinv11*rinv11;
729             rinvsq12         = rinv12*rinv12;
730             rinvsq20         = rinv20*rinv20;
731             rinvsq21         = rinv21*rinv21;
732             rinvsq22         = rinv22*rinv22;
733
734             /**************************
735              * CALCULATE INTERACTIONS *
736              **************************/
737
738             /* REACTION-FIELD ELECTROSTATICS */
739             felec            = qq00*(rinv00*rinvsq00-krf2);
740
741             fscal            = felec;
742
743             /* Calculate temporary vectorial force */
744             tx               = fscal*dx00;
745             ty               = fscal*dy00;
746             tz               = fscal*dz00;
747
748             /* Update vectorial force */
749             fix0            += tx;
750             fiy0            += ty;
751             fiz0            += tz;
752             f[j_coord_offset+DIM*0+XX] -= tx;
753             f[j_coord_offset+DIM*0+YY] -= ty;
754             f[j_coord_offset+DIM*0+ZZ] -= tz;
755
756             /**************************
757              * CALCULATE INTERACTIONS *
758              **************************/
759
760             /* REACTION-FIELD ELECTROSTATICS */
761             felec            = qq01*(rinv01*rinvsq01-krf2);
762
763             fscal            = felec;
764
765             /* Calculate temporary vectorial force */
766             tx               = fscal*dx01;
767             ty               = fscal*dy01;
768             tz               = fscal*dz01;
769
770             /* Update vectorial force */
771             fix0            += tx;
772             fiy0            += ty;
773             fiz0            += tz;
774             f[j_coord_offset+DIM*1+XX] -= tx;
775             f[j_coord_offset+DIM*1+YY] -= ty;
776             f[j_coord_offset+DIM*1+ZZ] -= tz;
777
778             /**************************
779              * CALCULATE INTERACTIONS *
780              **************************/
781
782             /* REACTION-FIELD ELECTROSTATICS */
783             felec            = qq02*(rinv02*rinvsq02-krf2);
784
785             fscal            = felec;
786
787             /* Calculate temporary vectorial force */
788             tx               = fscal*dx02;
789             ty               = fscal*dy02;
790             tz               = fscal*dz02;
791
792             /* Update vectorial force */
793             fix0            += tx;
794             fiy0            += ty;
795             fiz0            += tz;
796             f[j_coord_offset+DIM*2+XX] -= tx;
797             f[j_coord_offset+DIM*2+YY] -= ty;
798             f[j_coord_offset+DIM*2+ZZ] -= tz;
799
800             /**************************
801              * CALCULATE INTERACTIONS *
802              **************************/
803
804             /* REACTION-FIELD ELECTROSTATICS */
805             felec            = qq10*(rinv10*rinvsq10-krf2);
806
807             fscal            = felec;
808
809             /* Calculate temporary vectorial force */
810             tx               = fscal*dx10;
811             ty               = fscal*dy10;
812             tz               = fscal*dz10;
813
814             /* Update vectorial force */
815             fix1            += tx;
816             fiy1            += ty;
817             fiz1            += tz;
818             f[j_coord_offset+DIM*0+XX] -= tx;
819             f[j_coord_offset+DIM*0+YY] -= ty;
820             f[j_coord_offset+DIM*0+ZZ] -= tz;
821
822             /**************************
823              * CALCULATE INTERACTIONS *
824              **************************/
825
826             /* REACTION-FIELD ELECTROSTATICS */
827             felec            = qq11*(rinv11*rinvsq11-krf2);
828
829             fscal            = felec;
830
831             /* Calculate temporary vectorial force */
832             tx               = fscal*dx11;
833             ty               = fscal*dy11;
834             tz               = fscal*dz11;
835
836             /* Update vectorial force */
837             fix1            += tx;
838             fiy1            += ty;
839             fiz1            += tz;
840             f[j_coord_offset+DIM*1+XX] -= tx;
841             f[j_coord_offset+DIM*1+YY] -= ty;
842             f[j_coord_offset+DIM*1+ZZ] -= tz;
843
844             /**************************
845              * CALCULATE INTERACTIONS *
846              **************************/
847
848             /* REACTION-FIELD ELECTROSTATICS */
849             felec            = qq12*(rinv12*rinvsq12-krf2);
850
851             fscal            = felec;
852
853             /* Calculate temporary vectorial force */
854             tx               = fscal*dx12;
855             ty               = fscal*dy12;
856             tz               = fscal*dz12;
857
858             /* Update vectorial force */
859             fix1            += tx;
860             fiy1            += ty;
861             fiz1            += tz;
862             f[j_coord_offset+DIM*2+XX] -= tx;
863             f[j_coord_offset+DIM*2+YY] -= ty;
864             f[j_coord_offset+DIM*2+ZZ] -= tz;
865
866             /**************************
867              * CALCULATE INTERACTIONS *
868              **************************/
869
870             /* REACTION-FIELD ELECTROSTATICS */
871             felec            = qq20*(rinv20*rinvsq20-krf2);
872
873             fscal            = felec;
874
875             /* Calculate temporary vectorial force */
876             tx               = fscal*dx20;
877             ty               = fscal*dy20;
878             tz               = fscal*dz20;
879
880             /* Update vectorial force */
881             fix2            += tx;
882             fiy2            += ty;
883             fiz2            += tz;
884             f[j_coord_offset+DIM*0+XX] -= tx;
885             f[j_coord_offset+DIM*0+YY] -= ty;
886             f[j_coord_offset+DIM*0+ZZ] -= tz;
887
888             /**************************
889              * CALCULATE INTERACTIONS *
890              **************************/
891
892             /* REACTION-FIELD ELECTROSTATICS */
893             felec            = qq21*(rinv21*rinvsq21-krf2);
894
895             fscal            = felec;
896
897             /* Calculate temporary vectorial force */
898             tx               = fscal*dx21;
899             ty               = fscal*dy21;
900             tz               = fscal*dz21;
901
902             /* Update vectorial force */
903             fix2            += tx;
904             fiy2            += ty;
905             fiz2            += tz;
906             f[j_coord_offset+DIM*1+XX] -= tx;
907             f[j_coord_offset+DIM*1+YY] -= ty;
908             f[j_coord_offset+DIM*1+ZZ] -= tz;
909
910             /**************************
911              * CALCULATE INTERACTIONS *
912              **************************/
913
914             /* REACTION-FIELD ELECTROSTATICS */
915             felec            = qq22*(rinv22*rinvsq22-krf2);
916
917             fscal            = felec;
918
919             /* Calculate temporary vectorial force */
920             tx               = fscal*dx22;
921             ty               = fscal*dy22;
922             tz               = fscal*dz22;
923
924             /* Update vectorial force */
925             fix2            += tx;
926             fiy2            += ty;
927             fiz2            += tz;
928             f[j_coord_offset+DIM*2+XX] -= tx;
929             f[j_coord_offset+DIM*2+YY] -= ty;
930             f[j_coord_offset+DIM*2+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*0+XX] += fix0;
938         f[i_coord_offset+DIM*0+YY] += fiy0;
939         f[i_coord_offset+DIM*0+ZZ] += fiz0;
940         tx                         += fix0;
941         ty                         += fiy0;
942         tz                         += fiz0;
943         f[i_coord_offset+DIM*1+XX] += fix1;
944         f[i_coord_offset+DIM*1+YY] += fiy1;
945         f[i_coord_offset+DIM*1+ZZ] += fiz1;
946         tx                         += fix1;
947         ty                         += fiy1;
948         tz                         += fiz1;
949         f[i_coord_offset+DIM*2+XX] += fix2;
950         f[i_coord_offset+DIM*2+YY] += fiy2;
951         f[i_coord_offset+DIM*2+ZZ] += fiz2;
952         tx                         += fix2;
953         ty                         += fiy2;
954         tz                         += fiz2;
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_W3W3_F,outeriter*30 + inneriter*234);
971 }