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