3e9e4ecde55b8cfd89ebf27b501e6721d1e6ba23
[alexxy/gromacs.git] / src / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecEw_VdwNone_GeomW3W3_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_GeomW3W3_VF_c
35  * Electrostatics interaction: Ewald
36  * VdW interaction:            None
37  * Geometry:                   Water3-Water3
38  * Calculate force/pot:        PotentialAndForce
39  */
40 void
41 nb_kernel_ElecEw_VdwNone_GeomW3W3_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              vdwioffset0;
57     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
58     int              vdwioffset1;
59     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
60     int              vdwioffset2;
61     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
62     int              vdwjidx0;
63     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
64     int              vdwjidx1;
65     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
66     int              vdwjidx2;
67     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
68     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
69     real             dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01,cexp1_01,cexp2_01;
70     real             dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02,cexp1_02,cexp2_02;
71     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
72     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
73     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
74     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
75     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
76     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
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     iq0              = facel*charge[inr+0];
105     iq1              = facel*charge[inr+1];
106     iq2              = facel*charge[inr+2];
107
108     jq0              = charge[inr+0];
109     jq1              = charge[inr+1];
110     jq2              = charge[inr+2];
111     qq00             = iq0*jq0;
112     qq01             = iq0*jq1;
113     qq02             = iq0*jq2;
114     qq10             = iq1*jq0;
115     qq11             = iq1*jq1;
116     qq12             = iq1*jq2;
117     qq20             = iq2*jq0;
118     qq21             = iq2*jq1;
119     qq22             = iq2*jq2;
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         ix0              = shX + x[i_coord_offset+DIM*0+XX];
143         iy0              = shY + x[i_coord_offset+DIM*0+YY];
144         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
145         ix1              = shX + x[i_coord_offset+DIM*1+XX];
146         iy1              = shY + x[i_coord_offset+DIM*1+YY];
147         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
148         ix2              = shX + x[i_coord_offset+DIM*2+XX];
149         iy2              = shY + x[i_coord_offset+DIM*2+YY];
150         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
151
152         fix0             = 0.0;
153         fiy0             = 0.0;
154         fiz0             = 0.0;
155         fix1             = 0.0;
156         fiy1             = 0.0;
157         fiz1             = 0.0;
158         fix2             = 0.0;
159         fiy2             = 0.0;
160         fiz2             = 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             jx0              = x[j_coord_offset+DIM*0+XX];
174             jy0              = x[j_coord_offset+DIM*0+YY];
175             jz0              = x[j_coord_offset+DIM*0+ZZ];
176             jx1              = x[j_coord_offset+DIM*1+XX];
177             jy1              = x[j_coord_offset+DIM*1+YY];
178             jz1              = x[j_coord_offset+DIM*1+ZZ];
179             jx2              = x[j_coord_offset+DIM*2+XX];
180             jy2              = x[j_coord_offset+DIM*2+YY];
181             jz2              = x[j_coord_offset+DIM*2+ZZ];
182
183             /* Calculate displacement vector */
184             dx00             = ix0 - jx0;
185             dy00             = iy0 - jy0;
186             dz00             = iz0 - jz0;
187             dx01             = ix0 - jx1;
188             dy01             = iy0 - jy1;
189             dz01             = iz0 - jz1;
190             dx02             = ix0 - jx2;
191             dy02             = iy0 - jy2;
192             dz02             = iz0 - jz2;
193             dx10             = ix1 - jx0;
194             dy10             = iy1 - jy0;
195             dz10             = iz1 - jz0;
196             dx11             = ix1 - jx1;
197             dy11             = iy1 - jy1;
198             dz11             = iz1 - jz1;
199             dx12             = ix1 - jx2;
200             dy12             = iy1 - jy2;
201             dz12             = iz1 - jz2;
202             dx20             = ix2 - jx0;
203             dy20             = iy2 - jy0;
204             dz20             = iz2 - jz0;
205             dx21             = ix2 - jx1;
206             dy21             = iy2 - jy1;
207             dz21             = iz2 - jz1;
208             dx22             = ix2 - jx2;
209             dy22             = iy2 - jy2;
210             dz22             = iz2 - jz2;
211
212             /* Calculate squared distance and things based on it */
213             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
214             rsq01            = dx01*dx01+dy01*dy01+dz01*dz01;
215             rsq02            = dx02*dx02+dy02*dy02+dz02*dz02;
216             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
217             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
218             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
219             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
220             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
221             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
222
223             rinv00           = gmx_invsqrt(rsq00);
224             rinv01           = gmx_invsqrt(rsq01);
225             rinv02           = gmx_invsqrt(rsq02);
226             rinv10           = gmx_invsqrt(rsq10);
227             rinv11           = gmx_invsqrt(rsq11);
228             rinv12           = gmx_invsqrt(rsq12);
229             rinv20           = gmx_invsqrt(rsq20);
230             rinv21           = gmx_invsqrt(rsq21);
231             rinv22           = gmx_invsqrt(rsq22);
232
233             rinvsq00         = rinv00*rinv00;
234             rinvsq01         = rinv01*rinv01;
235             rinvsq02         = rinv02*rinv02;
236             rinvsq10         = rinv10*rinv10;
237             rinvsq11         = rinv11*rinv11;
238             rinvsq12         = rinv12*rinv12;
239             rinvsq20         = rinv20*rinv20;
240             rinvsq21         = rinv21*rinv21;
241             rinvsq22         = rinv22*rinv22;
242
243             /**************************
244              * CALCULATE INTERACTIONS *
245              **************************/
246
247             r00              = rsq00*rinv00;
248
249             /* EWALD ELECTROSTATICS */
250
251             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
252             ewrt             = r00*ewtabscale;
253             ewitab           = ewrt;
254             eweps            = ewrt-ewitab;
255             ewitab           = 4*ewitab;
256             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
257             velec            = qq00*(rinv00-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
258             felec            = qq00*rinv00*(rinvsq00-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*dx00;
267             ty               = fscal*dy00;
268             tz               = fscal*dz00;
269
270             /* Update vectorial force */
271             fix0            += tx;
272             fiy0            += ty;
273             fiz0            += tz;
274             f[j_coord_offset+DIM*0+XX] -= tx;
275             f[j_coord_offset+DIM*0+YY] -= ty;
276             f[j_coord_offset+DIM*0+ZZ] -= tz;
277
278             /**************************
279              * CALCULATE INTERACTIONS *
280              **************************/
281
282             r01              = rsq01*rinv01;
283
284             /* EWALD ELECTROSTATICS */
285
286             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
287             ewrt             = r01*ewtabscale;
288             ewitab           = ewrt;
289             eweps            = ewrt-ewitab;
290             ewitab           = 4*ewitab;
291             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
292             velec            = qq01*(rinv01-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
293             felec            = qq01*rinv01*(rinvsq01-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*dx01;
302             ty               = fscal*dy01;
303             tz               = fscal*dz01;
304
305             /* Update vectorial force */
306             fix0            += tx;
307             fiy0            += ty;
308             fiz0            += tz;
309             f[j_coord_offset+DIM*1+XX] -= tx;
310             f[j_coord_offset+DIM*1+YY] -= ty;
311             f[j_coord_offset+DIM*1+ZZ] -= tz;
312
313             /**************************
314              * CALCULATE INTERACTIONS *
315              **************************/
316
317             r02              = rsq02*rinv02;
318
319             /* EWALD ELECTROSTATICS */
320
321             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
322             ewrt             = r02*ewtabscale;
323             ewitab           = ewrt;
324             eweps            = ewrt-ewitab;
325             ewitab           = 4*ewitab;
326             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
327             velec            = qq02*(rinv02-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
328             felec            = qq02*rinv02*(rinvsq02-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*dx02;
337             ty               = fscal*dy02;
338             tz               = fscal*dz02;
339
340             /* Update vectorial force */
341             fix0            += tx;
342             fiy0            += ty;
343             fiz0            += tz;
344             f[j_coord_offset+DIM*2+XX] -= tx;
345             f[j_coord_offset+DIM*2+YY] -= ty;
346             f[j_coord_offset+DIM*2+ZZ] -= tz;
347
348             /**************************
349              * CALCULATE INTERACTIONS *
350              **************************/
351
352             r10              = rsq10*rinv10;
353
354             /* EWALD ELECTROSTATICS */
355
356             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
357             ewrt             = r10*ewtabscale;
358             ewitab           = ewrt;
359             eweps            = ewrt-ewitab;
360             ewitab           = 4*ewitab;
361             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
362             velec            = qq10*(rinv10-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
363             felec            = qq10*rinv10*(rinvsq10-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*dx10;
372             ty               = fscal*dy10;
373             tz               = fscal*dz10;
374
375             /* Update vectorial force */
376             fix1            += tx;
377             fiy1            += ty;
378             fiz1            += tz;
379             f[j_coord_offset+DIM*0+XX] -= tx;
380             f[j_coord_offset+DIM*0+YY] -= ty;
381             f[j_coord_offset+DIM*0+ZZ] -= tz;
382
383             /**************************
384              * CALCULATE INTERACTIONS *
385              **************************/
386
387             r11              = rsq11*rinv11;
388
389             /* EWALD ELECTROSTATICS */
390
391             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
392             ewrt             = r11*ewtabscale;
393             ewitab           = ewrt;
394             eweps            = ewrt-ewitab;
395             ewitab           = 4*ewitab;
396             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
397             velec            = qq11*(rinv11-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
398             felec            = qq11*rinv11*(rinvsq11-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*dx11;
407             ty               = fscal*dy11;
408             tz               = fscal*dz11;
409
410             /* Update vectorial force */
411             fix1            += tx;
412             fiy1            += ty;
413             fiz1            += tz;
414             f[j_coord_offset+DIM*1+XX] -= tx;
415             f[j_coord_offset+DIM*1+YY] -= ty;
416             f[j_coord_offset+DIM*1+ZZ] -= tz;
417
418             /**************************
419              * CALCULATE INTERACTIONS *
420              **************************/
421
422             r12              = rsq12*rinv12;
423
424             /* EWALD ELECTROSTATICS */
425
426             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
427             ewrt             = r12*ewtabscale;
428             ewitab           = ewrt;
429             eweps            = ewrt-ewitab;
430             ewitab           = 4*ewitab;
431             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
432             velec            = qq12*(rinv12-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
433             felec            = qq12*rinv12*(rinvsq12-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*dx12;
442             ty               = fscal*dy12;
443             tz               = fscal*dz12;
444
445             /* Update vectorial force */
446             fix1            += tx;
447             fiy1            += ty;
448             fiz1            += tz;
449             f[j_coord_offset+DIM*2+XX] -= tx;
450             f[j_coord_offset+DIM*2+YY] -= ty;
451             f[j_coord_offset+DIM*2+ZZ] -= tz;
452
453             /**************************
454              * CALCULATE INTERACTIONS *
455              **************************/
456
457             r20              = rsq20*rinv20;
458
459             /* EWALD ELECTROSTATICS */
460
461             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
462             ewrt             = r20*ewtabscale;
463             ewitab           = ewrt;
464             eweps            = ewrt-ewitab;
465             ewitab           = 4*ewitab;
466             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
467             velec            = qq20*(rinv20-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
468             felec            = qq20*rinv20*(rinvsq20-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*dx20;
477             ty               = fscal*dy20;
478             tz               = fscal*dz20;
479
480             /* Update vectorial force */
481             fix2            += tx;
482             fiy2            += ty;
483             fiz2            += tz;
484             f[j_coord_offset+DIM*0+XX] -= tx;
485             f[j_coord_offset+DIM*0+YY] -= ty;
486             f[j_coord_offset+DIM*0+ZZ] -= tz;
487
488             /**************************
489              * CALCULATE INTERACTIONS *
490              **************************/
491
492             r21              = rsq21*rinv21;
493
494             /* EWALD ELECTROSTATICS */
495
496             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
497             ewrt             = r21*ewtabscale;
498             ewitab           = ewrt;
499             eweps            = ewrt-ewitab;
500             ewitab           = 4*ewitab;
501             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
502             velec            = qq21*(rinv21-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
503             felec            = qq21*rinv21*(rinvsq21-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*dx21;
512             ty               = fscal*dy21;
513             tz               = fscal*dz21;
514
515             /* Update vectorial force */
516             fix2            += tx;
517             fiy2            += ty;
518             fiz2            += tz;
519             f[j_coord_offset+DIM*1+XX] -= tx;
520             f[j_coord_offset+DIM*1+YY] -= ty;
521             f[j_coord_offset+DIM*1+ZZ] -= tz;
522
523             /**************************
524              * CALCULATE INTERACTIONS *
525              **************************/
526
527             r22              = rsq22*rinv22;
528
529             /* EWALD ELECTROSTATICS */
530
531             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
532             ewrt             = r22*ewtabscale;
533             ewitab           = ewrt;
534             eweps            = ewrt-ewitab;
535             ewitab           = 4*ewitab;
536             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
537             velec            = qq22*(rinv22-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
538             felec            = qq22*rinv22*(rinvsq22-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*dx22;
547             ty               = fscal*dy22;
548             tz               = fscal*dz22;
549
550             /* Update vectorial force */
551             fix2            += tx;
552             fiy2            += ty;
553             fiz2            += tz;
554             f[j_coord_offset+DIM*2+XX] -= tx;
555             f[j_coord_offset+DIM*2+YY] -= ty;
556             f[j_coord_offset+DIM*2+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*0+XX] += fix0;
564         f[i_coord_offset+DIM*0+YY] += fiy0;
565         f[i_coord_offset+DIM*0+ZZ] += fiz0;
566         tx                         += fix0;
567         ty                         += fiy0;
568         tz                         += fiz0;
569         f[i_coord_offset+DIM*1+XX] += fix1;
570         f[i_coord_offset+DIM*1+YY] += fiy1;
571         f[i_coord_offset+DIM*1+ZZ] += fiz1;
572         tx                         += fix1;
573         ty                         += fiy1;
574         tz                         += fiz1;
575         f[i_coord_offset+DIM*2+XX] += fix2;
576         f[i_coord_offset+DIM*2+YY] += fiy2;
577         f[i_coord_offset+DIM*2+ZZ] += fiz2;
578         tx                         += fix2;
579         ty                         += fiy2;
580         tz                         += fiz2;
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_W3W3_VF,outeriter*31 + inneriter*360);
601 }
602 /*
603  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwNone_GeomW3W3_F_c
604  * Electrostatics interaction: Ewald
605  * VdW interaction:            None
606  * Geometry:                   Water3-Water3
607  * Calculate force/pot:        Force
608  */
609 void
610 nb_kernel_ElecEw_VdwNone_GeomW3W3_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              vdwioffset0;
626     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
627     int              vdwioffset1;
628     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
629     int              vdwioffset2;
630     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
631     int              vdwjidx0;
632     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
633     int              vdwjidx1;
634     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
635     int              vdwjidx2;
636     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
637     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
638     real             dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01,cexp1_01,cexp2_01;
639     real             dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02,cexp1_02,cexp2_02;
640     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
641     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
642     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
643     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
644     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
645     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
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     iq0              = facel*charge[inr+0];
674     iq1              = facel*charge[inr+1];
675     iq2              = facel*charge[inr+2];
676
677     jq0              = charge[inr+0];
678     jq1              = charge[inr+1];
679     jq2              = charge[inr+2];
680     qq00             = iq0*jq0;
681     qq01             = iq0*jq1;
682     qq02             = iq0*jq2;
683     qq10             = iq1*jq0;
684     qq11             = iq1*jq1;
685     qq12             = iq1*jq2;
686     qq20             = iq2*jq0;
687     qq21             = iq2*jq1;
688     qq22             = iq2*jq2;
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         ix0              = shX + x[i_coord_offset+DIM*0+XX];
712         iy0              = shY + x[i_coord_offset+DIM*0+YY];
713         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
714         ix1              = shX + x[i_coord_offset+DIM*1+XX];
715         iy1              = shY + x[i_coord_offset+DIM*1+YY];
716         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
717         ix2              = shX + x[i_coord_offset+DIM*2+XX];
718         iy2              = shY + x[i_coord_offset+DIM*2+YY];
719         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
720
721         fix0             = 0.0;
722         fiy0             = 0.0;
723         fiz0             = 0.0;
724         fix1             = 0.0;
725         fiy1             = 0.0;
726         fiz1             = 0.0;
727         fix2             = 0.0;
728         fiy2             = 0.0;
729         fiz2             = 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             jx0              = x[j_coord_offset+DIM*0+XX];
740             jy0              = x[j_coord_offset+DIM*0+YY];
741             jz0              = x[j_coord_offset+DIM*0+ZZ];
742             jx1              = x[j_coord_offset+DIM*1+XX];
743             jy1              = x[j_coord_offset+DIM*1+YY];
744             jz1              = x[j_coord_offset+DIM*1+ZZ];
745             jx2              = x[j_coord_offset+DIM*2+XX];
746             jy2              = x[j_coord_offset+DIM*2+YY];
747             jz2              = x[j_coord_offset+DIM*2+ZZ];
748
749             /* Calculate displacement vector */
750             dx00             = ix0 - jx0;
751             dy00             = iy0 - jy0;
752             dz00             = iz0 - jz0;
753             dx01             = ix0 - jx1;
754             dy01             = iy0 - jy1;
755             dz01             = iz0 - jz1;
756             dx02             = ix0 - jx2;
757             dy02             = iy0 - jy2;
758             dz02             = iz0 - jz2;
759             dx10             = ix1 - jx0;
760             dy10             = iy1 - jy0;
761             dz10             = iz1 - jz0;
762             dx11             = ix1 - jx1;
763             dy11             = iy1 - jy1;
764             dz11             = iz1 - jz1;
765             dx12             = ix1 - jx2;
766             dy12             = iy1 - jy2;
767             dz12             = iz1 - jz2;
768             dx20             = ix2 - jx0;
769             dy20             = iy2 - jy0;
770             dz20             = iz2 - jz0;
771             dx21             = ix2 - jx1;
772             dy21             = iy2 - jy1;
773             dz21             = iz2 - jz1;
774             dx22             = ix2 - jx2;
775             dy22             = iy2 - jy2;
776             dz22             = iz2 - jz2;
777
778             /* Calculate squared distance and things based on it */
779             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
780             rsq01            = dx01*dx01+dy01*dy01+dz01*dz01;
781             rsq02            = dx02*dx02+dy02*dy02+dz02*dz02;
782             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
783             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
784             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
785             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
786             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
787             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
788
789             rinv00           = gmx_invsqrt(rsq00);
790             rinv01           = gmx_invsqrt(rsq01);
791             rinv02           = gmx_invsqrt(rsq02);
792             rinv10           = gmx_invsqrt(rsq10);
793             rinv11           = gmx_invsqrt(rsq11);
794             rinv12           = gmx_invsqrt(rsq12);
795             rinv20           = gmx_invsqrt(rsq20);
796             rinv21           = gmx_invsqrt(rsq21);
797             rinv22           = gmx_invsqrt(rsq22);
798
799             rinvsq00         = rinv00*rinv00;
800             rinvsq01         = rinv01*rinv01;
801             rinvsq02         = rinv02*rinv02;
802             rinvsq10         = rinv10*rinv10;
803             rinvsq11         = rinv11*rinv11;
804             rinvsq12         = rinv12*rinv12;
805             rinvsq20         = rinv20*rinv20;
806             rinvsq21         = rinv21*rinv21;
807             rinvsq22         = rinv22*rinv22;
808
809             /**************************
810              * CALCULATE INTERACTIONS *
811              **************************/
812
813             r00              = rsq00*rinv00;
814
815             /* EWALD ELECTROSTATICS */
816
817             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
818             ewrt             = r00*ewtabscale;
819             ewitab           = ewrt;
820             eweps            = ewrt-ewitab;
821             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
822             felec            = qq00*rinv00*(rinvsq00-felec);
823
824             fscal            = felec;
825
826             /* Calculate temporary vectorial force */
827             tx               = fscal*dx00;
828             ty               = fscal*dy00;
829             tz               = fscal*dz00;
830
831             /* Update vectorial force */
832             fix0            += tx;
833             fiy0            += ty;
834             fiz0            += tz;
835             f[j_coord_offset+DIM*0+XX] -= tx;
836             f[j_coord_offset+DIM*0+YY] -= ty;
837             f[j_coord_offset+DIM*0+ZZ] -= tz;
838
839             /**************************
840              * CALCULATE INTERACTIONS *
841              **************************/
842
843             r01              = rsq01*rinv01;
844
845             /* EWALD ELECTROSTATICS */
846
847             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
848             ewrt             = r01*ewtabscale;
849             ewitab           = ewrt;
850             eweps            = ewrt-ewitab;
851             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
852             felec            = qq01*rinv01*(rinvsq01-felec);
853
854             fscal            = felec;
855
856             /* Calculate temporary vectorial force */
857             tx               = fscal*dx01;
858             ty               = fscal*dy01;
859             tz               = fscal*dz01;
860
861             /* Update vectorial force */
862             fix0            += tx;
863             fiy0            += ty;
864             fiz0            += tz;
865             f[j_coord_offset+DIM*1+XX] -= tx;
866             f[j_coord_offset+DIM*1+YY] -= ty;
867             f[j_coord_offset+DIM*1+ZZ] -= tz;
868
869             /**************************
870              * CALCULATE INTERACTIONS *
871              **************************/
872
873             r02              = rsq02*rinv02;
874
875             /* EWALD ELECTROSTATICS */
876
877             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
878             ewrt             = r02*ewtabscale;
879             ewitab           = ewrt;
880             eweps            = ewrt-ewitab;
881             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
882             felec            = qq02*rinv02*(rinvsq02-felec);
883
884             fscal            = felec;
885
886             /* Calculate temporary vectorial force */
887             tx               = fscal*dx02;
888             ty               = fscal*dy02;
889             tz               = fscal*dz02;
890
891             /* Update vectorial force */
892             fix0            += tx;
893             fiy0            += ty;
894             fiz0            += tz;
895             f[j_coord_offset+DIM*2+XX] -= tx;
896             f[j_coord_offset+DIM*2+YY] -= ty;
897             f[j_coord_offset+DIM*2+ZZ] -= tz;
898
899             /**************************
900              * CALCULATE INTERACTIONS *
901              **************************/
902
903             r10              = rsq10*rinv10;
904
905             /* EWALD ELECTROSTATICS */
906
907             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
908             ewrt             = r10*ewtabscale;
909             ewitab           = ewrt;
910             eweps            = ewrt-ewitab;
911             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
912             felec            = qq10*rinv10*(rinvsq10-felec);
913
914             fscal            = felec;
915
916             /* Calculate temporary vectorial force */
917             tx               = fscal*dx10;
918             ty               = fscal*dy10;
919             tz               = fscal*dz10;
920
921             /* Update vectorial force */
922             fix1            += tx;
923             fiy1            += ty;
924             fiz1            += tz;
925             f[j_coord_offset+DIM*0+XX] -= tx;
926             f[j_coord_offset+DIM*0+YY] -= ty;
927             f[j_coord_offset+DIM*0+ZZ] -= tz;
928
929             /**************************
930              * CALCULATE INTERACTIONS *
931              **************************/
932
933             r11              = rsq11*rinv11;
934
935             /* EWALD ELECTROSTATICS */
936
937             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
938             ewrt             = r11*ewtabscale;
939             ewitab           = ewrt;
940             eweps            = ewrt-ewitab;
941             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
942             felec            = qq11*rinv11*(rinvsq11-felec);
943
944             fscal            = felec;
945
946             /* Calculate temporary vectorial force */
947             tx               = fscal*dx11;
948             ty               = fscal*dy11;
949             tz               = fscal*dz11;
950
951             /* Update vectorial force */
952             fix1            += tx;
953             fiy1            += ty;
954             fiz1            += tz;
955             f[j_coord_offset+DIM*1+XX] -= tx;
956             f[j_coord_offset+DIM*1+YY] -= ty;
957             f[j_coord_offset+DIM*1+ZZ] -= tz;
958
959             /**************************
960              * CALCULATE INTERACTIONS *
961              **************************/
962
963             r12              = rsq12*rinv12;
964
965             /* EWALD ELECTROSTATICS */
966
967             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
968             ewrt             = r12*ewtabscale;
969             ewitab           = ewrt;
970             eweps            = ewrt-ewitab;
971             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
972             felec            = qq12*rinv12*(rinvsq12-felec);
973
974             fscal            = felec;
975
976             /* Calculate temporary vectorial force */
977             tx               = fscal*dx12;
978             ty               = fscal*dy12;
979             tz               = fscal*dz12;
980
981             /* Update vectorial force */
982             fix1            += tx;
983             fiy1            += ty;
984             fiz1            += tz;
985             f[j_coord_offset+DIM*2+XX] -= tx;
986             f[j_coord_offset+DIM*2+YY] -= ty;
987             f[j_coord_offset+DIM*2+ZZ] -= tz;
988
989             /**************************
990              * CALCULATE INTERACTIONS *
991              **************************/
992
993             r20              = rsq20*rinv20;
994
995             /* EWALD ELECTROSTATICS */
996
997             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
998             ewrt             = r20*ewtabscale;
999             ewitab           = ewrt;
1000             eweps            = ewrt-ewitab;
1001             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1002             felec            = qq20*rinv20*(rinvsq20-felec);
1003
1004             fscal            = felec;
1005
1006             /* Calculate temporary vectorial force */
1007             tx               = fscal*dx20;
1008             ty               = fscal*dy20;
1009             tz               = fscal*dz20;
1010
1011             /* Update vectorial force */
1012             fix2            += tx;
1013             fiy2            += ty;
1014             fiz2            += tz;
1015             f[j_coord_offset+DIM*0+XX] -= tx;
1016             f[j_coord_offset+DIM*0+YY] -= ty;
1017             f[j_coord_offset+DIM*0+ZZ] -= tz;
1018
1019             /**************************
1020              * CALCULATE INTERACTIONS *
1021              **************************/
1022
1023             r21              = rsq21*rinv21;
1024
1025             /* EWALD ELECTROSTATICS */
1026
1027             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1028             ewrt             = r21*ewtabscale;
1029             ewitab           = ewrt;
1030             eweps            = ewrt-ewitab;
1031             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1032             felec            = qq21*rinv21*(rinvsq21-felec);
1033
1034             fscal            = felec;
1035
1036             /* Calculate temporary vectorial force */
1037             tx               = fscal*dx21;
1038             ty               = fscal*dy21;
1039             tz               = fscal*dz21;
1040
1041             /* Update vectorial force */
1042             fix2            += tx;
1043             fiy2            += ty;
1044             fiz2            += tz;
1045             f[j_coord_offset+DIM*1+XX] -= tx;
1046             f[j_coord_offset+DIM*1+YY] -= ty;
1047             f[j_coord_offset+DIM*1+ZZ] -= tz;
1048
1049             /**************************
1050              * CALCULATE INTERACTIONS *
1051              **************************/
1052
1053             r22              = rsq22*rinv22;
1054
1055             /* EWALD ELECTROSTATICS */
1056
1057             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1058             ewrt             = r22*ewtabscale;
1059             ewitab           = ewrt;
1060             eweps            = ewrt-ewitab;
1061             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1062             felec            = qq22*rinv22*(rinvsq22-felec);
1063
1064             fscal            = felec;
1065
1066             /* Calculate temporary vectorial force */
1067             tx               = fscal*dx22;
1068             ty               = fscal*dy22;
1069             tz               = fscal*dz22;
1070
1071             /* Update vectorial force */
1072             fix2            += tx;
1073             fiy2            += ty;
1074             fiz2            += tz;
1075             f[j_coord_offset+DIM*2+XX] -= tx;
1076             f[j_coord_offset+DIM*2+YY] -= ty;
1077             f[j_coord_offset+DIM*2+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*0+XX] += fix0;
1085         f[i_coord_offset+DIM*0+YY] += fiy0;
1086         f[i_coord_offset+DIM*0+ZZ] += fiz0;
1087         tx                         += fix0;
1088         ty                         += fiy0;
1089         tz                         += fiz0;
1090         f[i_coord_offset+DIM*1+XX] += fix1;
1091         f[i_coord_offset+DIM*1+YY] += fiy1;
1092         f[i_coord_offset+DIM*1+ZZ] += fiz1;
1093         tx                         += fix1;
1094         ty                         += fiy1;
1095         tz                         += fiz1;
1096         f[i_coord_offset+DIM*2+XX] += fix2;
1097         f[i_coord_offset+DIM*2+YY] += fiy2;
1098         f[i_coord_offset+DIM*2+ZZ] += fiz2;
1099         tx                         += fix2;
1100         ty                         += fiy2;
1101         tz                         += fiz2;
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_W3W3_F,outeriter*30 + inneriter*297);
1118 }