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