Fix component for libcudart
[alexxy/gromacs.git] / src / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecEwSw_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_ElecEwSw_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_ElecEwSw_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     real             rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
83
84     x                = xx[0];
85     f                = ff[0];
86
87     nri              = nlist->nri;
88     iinr             = nlist->iinr;
89     jindex           = nlist->jindex;
90     jjnr             = nlist->jjnr;
91     shiftidx         = nlist->shift;
92     gid              = nlist->gid;
93     shiftvec         = fr->shift_vec[0];
94     fshift           = fr->fshift[0];
95     facel            = fr->epsfac;
96     charge           = mdatoms->chargeA;
97
98     sh_ewald         = fr->ic->sh_ewald;
99     ewtab            = fr->ic->tabq_coul_FDV0;
100     ewtabscale       = fr->ic->tabq_scale;
101     ewtabhalfspace   = 0.5/ewtabscale;
102
103     /* Setup water-specific parameters */
104     inr              = nlist->iinr[0];
105     iq0              = facel*charge[inr+0];
106     iq1              = facel*charge[inr+1];
107     iq2              = facel*charge[inr+2];
108
109     jq0              = charge[inr+0];
110     jq1              = charge[inr+1];
111     jq2              = charge[inr+2];
112     qq00             = iq0*jq0;
113     qq01             = iq0*jq1;
114     qq02             = iq0*jq2;
115     qq10             = iq1*jq0;
116     qq11             = iq1*jq1;
117     qq12             = iq1*jq2;
118     qq20             = iq2*jq0;
119     qq21             = iq2*jq1;
120     qq22             = iq2*jq2;
121
122     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
123     rcutoff          = fr->rcoulomb;
124     rcutoff2         = rcutoff*rcutoff;
125
126     rswitch          = fr->rcoulomb_switch;
127     /* Setup switch parameters */
128     d                = rcutoff-rswitch;
129     swV3             = -10.0/(d*d*d);
130     swV4             =  15.0/(d*d*d*d);
131     swV5             =  -6.0/(d*d*d*d*d);
132     swF2             = -30.0/(d*d*d);
133     swF3             =  60.0/(d*d*d*d);
134     swF4             = -30.0/(d*d*d*d*d);
135
136     outeriter        = 0;
137     inneriter        = 0;
138
139     /* Start outer loop over neighborlists */
140     for(iidx=0; iidx<nri; iidx++)
141     {
142         /* Load shift vector for this list */
143         i_shift_offset   = DIM*shiftidx[iidx];
144         shX              = shiftvec[i_shift_offset+XX];
145         shY              = shiftvec[i_shift_offset+YY];
146         shZ              = shiftvec[i_shift_offset+ZZ];
147
148         /* Load limits for loop over neighbors */
149         j_index_start    = jindex[iidx];
150         j_index_end      = jindex[iidx+1];
151
152         /* Get outer coordinate index */
153         inr              = iinr[iidx];
154         i_coord_offset   = DIM*inr;
155
156         /* Load i particle coords and add shift vector */
157         ix0              = shX + x[i_coord_offset+DIM*0+XX];
158         iy0              = shY + x[i_coord_offset+DIM*0+YY];
159         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
160         ix1              = shX + x[i_coord_offset+DIM*1+XX];
161         iy1              = shY + x[i_coord_offset+DIM*1+YY];
162         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
163         ix2              = shX + x[i_coord_offset+DIM*2+XX];
164         iy2              = shY + x[i_coord_offset+DIM*2+YY];
165         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
166
167         fix0             = 0.0;
168         fiy0             = 0.0;
169         fiz0             = 0.0;
170         fix1             = 0.0;
171         fiy1             = 0.0;
172         fiz1             = 0.0;
173         fix2             = 0.0;
174         fiy2             = 0.0;
175         fiz2             = 0.0;
176
177         /* Reset potential sums */
178         velecsum         = 0.0;
179
180         /* Start inner kernel loop */
181         for(jidx=j_index_start; jidx<j_index_end; jidx++)
182         {
183             /* Get j neighbor index, and coordinate index */
184             jnr              = jjnr[jidx];
185             j_coord_offset   = DIM*jnr;
186
187             /* load j atom coordinates */
188             jx0              = x[j_coord_offset+DIM*0+XX];
189             jy0              = x[j_coord_offset+DIM*0+YY];
190             jz0              = x[j_coord_offset+DIM*0+ZZ];
191             jx1              = x[j_coord_offset+DIM*1+XX];
192             jy1              = x[j_coord_offset+DIM*1+YY];
193             jz1              = x[j_coord_offset+DIM*1+ZZ];
194             jx2              = x[j_coord_offset+DIM*2+XX];
195             jy2              = x[j_coord_offset+DIM*2+YY];
196             jz2              = x[j_coord_offset+DIM*2+ZZ];
197
198             /* Calculate displacement vector */
199             dx00             = ix0 - jx0;
200             dy00             = iy0 - jy0;
201             dz00             = iz0 - jz0;
202             dx01             = ix0 - jx1;
203             dy01             = iy0 - jy1;
204             dz01             = iz0 - jz1;
205             dx02             = ix0 - jx2;
206             dy02             = iy0 - jy2;
207             dz02             = iz0 - jz2;
208             dx10             = ix1 - jx0;
209             dy10             = iy1 - jy0;
210             dz10             = iz1 - jz0;
211             dx11             = ix1 - jx1;
212             dy11             = iy1 - jy1;
213             dz11             = iz1 - jz1;
214             dx12             = ix1 - jx2;
215             dy12             = iy1 - jy2;
216             dz12             = iz1 - jz2;
217             dx20             = ix2 - jx0;
218             dy20             = iy2 - jy0;
219             dz20             = iz2 - jz0;
220             dx21             = ix2 - jx1;
221             dy21             = iy2 - jy1;
222             dz21             = iz2 - jz1;
223             dx22             = ix2 - jx2;
224             dy22             = iy2 - jy2;
225             dz22             = iz2 - jz2;
226
227             /* Calculate squared distance and things based on it */
228             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
229             rsq01            = dx01*dx01+dy01*dy01+dz01*dz01;
230             rsq02            = dx02*dx02+dy02*dy02+dz02*dz02;
231             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
232             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
233             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
234             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
235             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
236             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
237
238             rinv00           = gmx_invsqrt(rsq00);
239             rinv01           = gmx_invsqrt(rsq01);
240             rinv02           = gmx_invsqrt(rsq02);
241             rinv10           = gmx_invsqrt(rsq10);
242             rinv11           = gmx_invsqrt(rsq11);
243             rinv12           = gmx_invsqrt(rsq12);
244             rinv20           = gmx_invsqrt(rsq20);
245             rinv21           = gmx_invsqrt(rsq21);
246             rinv22           = gmx_invsqrt(rsq22);
247
248             rinvsq00         = rinv00*rinv00;
249             rinvsq01         = rinv01*rinv01;
250             rinvsq02         = rinv02*rinv02;
251             rinvsq10         = rinv10*rinv10;
252             rinvsq11         = rinv11*rinv11;
253             rinvsq12         = rinv12*rinv12;
254             rinvsq20         = rinv20*rinv20;
255             rinvsq21         = rinv21*rinv21;
256             rinvsq22         = rinv22*rinv22;
257
258             /**************************
259              * CALCULATE INTERACTIONS *
260              **************************/
261
262             if (rsq00<rcutoff2)
263             {
264
265             r00              = rsq00*rinv00;
266
267             /* EWALD ELECTROSTATICS */
268
269             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
270             ewrt             = r00*ewtabscale;
271             ewitab           = ewrt;
272             eweps            = ewrt-ewitab;
273             ewitab           = 4*ewitab;
274             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
275             velec            = qq00*(rinv00-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
276             felec            = qq00*rinv00*(rinvsq00-felec);
277
278             d                = r00-rswitch;
279             d                = (d>0.0) ? d : 0.0;
280             d2               = d*d;
281             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
282
283             dsw              = d2*(swF2+d*(swF3+d*swF4));
284
285             /* Evaluate switch function */
286             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
287             felec            = felec*sw - rinv00*velec*dsw;
288             velec           *= sw;
289
290             /* Update potential sums from outer loop */
291             velecsum        += velec;
292
293             fscal            = felec;
294
295             /* Calculate temporary vectorial force */
296             tx               = fscal*dx00;
297             ty               = fscal*dy00;
298             tz               = fscal*dz00;
299
300             /* Update vectorial force */
301             fix0            += tx;
302             fiy0            += ty;
303             fiz0            += tz;
304             f[j_coord_offset+DIM*0+XX] -= tx;
305             f[j_coord_offset+DIM*0+YY] -= ty;
306             f[j_coord_offset+DIM*0+ZZ] -= tz;
307
308             }
309
310             /**************************
311              * CALCULATE INTERACTIONS *
312              **************************/
313
314             if (rsq01<rcutoff2)
315             {
316
317             r01              = rsq01*rinv01;
318
319             /* EWALD ELECTROSTATICS */
320
321             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
322             ewrt             = r01*ewtabscale;
323             ewitab           = ewrt;
324             eweps            = ewrt-ewitab;
325             ewitab           = 4*ewitab;
326             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
327             velec            = qq01*(rinv01-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
328             felec            = qq01*rinv01*(rinvsq01-felec);
329
330             d                = r01-rswitch;
331             d                = (d>0.0) ? d : 0.0;
332             d2               = d*d;
333             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
334
335             dsw              = d2*(swF2+d*(swF3+d*swF4));
336
337             /* Evaluate switch function */
338             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
339             felec            = felec*sw - rinv01*velec*dsw;
340             velec           *= sw;
341
342             /* Update potential sums from outer loop */
343             velecsum        += velec;
344
345             fscal            = felec;
346
347             /* Calculate temporary vectorial force */
348             tx               = fscal*dx01;
349             ty               = fscal*dy01;
350             tz               = fscal*dz01;
351
352             /* Update vectorial force */
353             fix0            += tx;
354             fiy0            += ty;
355             fiz0            += tz;
356             f[j_coord_offset+DIM*1+XX] -= tx;
357             f[j_coord_offset+DIM*1+YY] -= ty;
358             f[j_coord_offset+DIM*1+ZZ] -= tz;
359
360             }
361
362             /**************************
363              * CALCULATE INTERACTIONS *
364              **************************/
365
366             if (rsq02<rcutoff2)
367             {
368
369             r02              = rsq02*rinv02;
370
371             /* EWALD ELECTROSTATICS */
372
373             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
374             ewrt             = r02*ewtabscale;
375             ewitab           = ewrt;
376             eweps            = ewrt-ewitab;
377             ewitab           = 4*ewitab;
378             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
379             velec            = qq02*(rinv02-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
380             felec            = qq02*rinv02*(rinvsq02-felec);
381
382             d                = r02-rswitch;
383             d                = (d>0.0) ? d : 0.0;
384             d2               = d*d;
385             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
386
387             dsw              = d2*(swF2+d*(swF3+d*swF4));
388
389             /* Evaluate switch function */
390             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
391             felec            = felec*sw - rinv02*velec*dsw;
392             velec           *= sw;
393
394             /* Update potential sums from outer loop */
395             velecsum        += velec;
396
397             fscal            = felec;
398
399             /* Calculate temporary vectorial force */
400             tx               = fscal*dx02;
401             ty               = fscal*dy02;
402             tz               = fscal*dz02;
403
404             /* Update vectorial force */
405             fix0            += tx;
406             fiy0            += ty;
407             fiz0            += tz;
408             f[j_coord_offset+DIM*2+XX] -= tx;
409             f[j_coord_offset+DIM*2+YY] -= ty;
410             f[j_coord_offset+DIM*2+ZZ] -= tz;
411
412             }
413
414             /**************************
415              * CALCULATE INTERACTIONS *
416              **************************/
417
418             if (rsq10<rcutoff2)
419             {
420
421             r10              = rsq10*rinv10;
422
423             /* EWALD ELECTROSTATICS */
424
425             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
426             ewrt             = r10*ewtabscale;
427             ewitab           = ewrt;
428             eweps            = ewrt-ewitab;
429             ewitab           = 4*ewitab;
430             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
431             velec            = qq10*(rinv10-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
432             felec            = qq10*rinv10*(rinvsq10-felec);
433
434             d                = r10-rswitch;
435             d                = (d>0.0) ? d : 0.0;
436             d2               = d*d;
437             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
438
439             dsw              = d2*(swF2+d*(swF3+d*swF4));
440
441             /* Evaluate switch function */
442             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
443             felec            = felec*sw - rinv10*velec*dsw;
444             velec           *= sw;
445
446             /* Update potential sums from outer loop */
447             velecsum        += velec;
448
449             fscal            = felec;
450
451             /* Calculate temporary vectorial force */
452             tx               = fscal*dx10;
453             ty               = fscal*dy10;
454             tz               = fscal*dz10;
455
456             /* Update vectorial force */
457             fix1            += tx;
458             fiy1            += ty;
459             fiz1            += tz;
460             f[j_coord_offset+DIM*0+XX] -= tx;
461             f[j_coord_offset+DIM*0+YY] -= ty;
462             f[j_coord_offset+DIM*0+ZZ] -= tz;
463
464             }
465
466             /**************************
467              * CALCULATE INTERACTIONS *
468              **************************/
469
470             if (rsq11<rcutoff2)
471             {
472
473             r11              = rsq11*rinv11;
474
475             /* EWALD ELECTROSTATICS */
476
477             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
478             ewrt             = r11*ewtabscale;
479             ewitab           = ewrt;
480             eweps            = ewrt-ewitab;
481             ewitab           = 4*ewitab;
482             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
483             velec            = qq11*(rinv11-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
484             felec            = qq11*rinv11*(rinvsq11-felec);
485
486             d                = r11-rswitch;
487             d                = (d>0.0) ? d : 0.0;
488             d2               = d*d;
489             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
490
491             dsw              = d2*(swF2+d*(swF3+d*swF4));
492
493             /* Evaluate switch function */
494             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
495             felec            = felec*sw - rinv11*velec*dsw;
496             velec           *= sw;
497
498             /* Update potential sums from outer loop */
499             velecsum        += velec;
500
501             fscal            = felec;
502
503             /* Calculate temporary vectorial force */
504             tx               = fscal*dx11;
505             ty               = fscal*dy11;
506             tz               = fscal*dz11;
507
508             /* Update vectorial force */
509             fix1            += tx;
510             fiy1            += ty;
511             fiz1            += tz;
512             f[j_coord_offset+DIM*1+XX] -= tx;
513             f[j_coord_offset+DIM*1+YY] -= ty;
514             f[j_coord_offset+DIM*1+ZZ] -= tz;
515
516             }
517
518             /**************************
519              * CALCULATE INTERACTIONS *
520              **************************/
521
522             if (rsq12<rcutoff2)
523             {
524
525             r12              = rsq12*rinv12;
526
527             /* EWALD ELECTROSTATICS */
528
529             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
530             ewrt             = r12*ewtabscale;
531             ewitab           = ewrt;
532             eweps            = ewrt-ewitab;
533             ewitab           = 4*ewitab;
534             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
535             velec            = qq12*(rinv12-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
536             felec            = qq12*rinv12*(rinvsq12-felec);
537
538             d                = r12-rswitch;
539             d                = (d>0.0) ? d : 0.0;
540             d2               = d*d;
541             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
542
543             dsw              = d2*(swF2+d*(swF3+d*swF4));
544
545             /* Evaluate switch function */
546             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
547             felec            = felec*sw - rinv12*velec*dsw;
548             velec           *= sw;
549
550             /* Update potential sums from outer loop */
551             velecsum        += velec;
552
553             fscal            = felec;
554
555             /* Calculate temporary vectorial force */
556             tx               = fscal*dx12;
557             ty               = fscal*dy12;
558             tz               = fscal*dz12;
559
560             /* Update vectorial force */
561             fix1            += tx;
562             fiy1            += ty;
563             fiz1            += tz;
564             f[j_coord_offset+DIM*2+XX] -= tx;
565             f[j_coord_offset+DIM*2+YY] -= ty;
566             f[j_coord_offset+DIM*2+ZZ] -= tz;
567
568             }
569
570             /**************************
571              * CALCULATE INTERACTIONS *
572              **************************/
573
574             if (rsq20<rcutoff2)
575             {
576
577             r20              = rsq20*rinv20;
578
579             /* EWALD ELECTROSTATICS */
580
581             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
582             ewrt             = r20*ewtabscale;
583             ewitab           = ewrt;
584             eweps            = ewrt-ewitab;
585             ewitab           = 4*ewitab;
586             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
587             velec            = qq20*(rinv20-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
588             felec            = qq20*rinv20*(rinvsq20-felec);
589
590             d                = r20-rswitch;
591             d                = (d>0.0) ? d : 0.0;
592             d2               = d*d;
593             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
594
595             dsw              = d2*(swF2+d*(swF3+d*swF4));
596
597             /* Evaluate switch function */
598             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
599             felec            = felec*sw - rinv20*velec*dsw;
600             velec           *= sw;
601
602             /* Update potential sums from outer loop */
603             velecsum        += velec;
604
605             fscal            = felec;
606
607             /* Calculate temporary vectorial force */
608             tx               = fscal*dx20;
609             ty               = fscal*dy20;
610             tz               = fscal*dz20;
611
612             /* Update vectorial force */
613             fix2            += tx;
614             fiy2            += ty;
615             fiz2            += tz;
616             f[j_coord_offset+DIM*0+XX] -= tx;
617             f[j_coord_offset+DIM*0+YY] -= ty;
618             f[j_coord_offset+DIM*0+ZZ] -= tz;
619
620             }
621
622             /**************************
623              * CALCULATE INTERACTIONS *
624              **************************/
625
626             if (rsq21<rcutoff2)
627             {
628
629             r21              = rsq21*rinv21;
630
631             /* EWALD ELECTROSTATICS */
632
633             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
634             ewrt             = r21*ewtabscale;
635             ewitab           = ewrt;
636             eweps            = ewrt-ewitab;
637             ewitab           = 4*ewitab;
638             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
639             velec            = qq21*(rinv21-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
640             felec            = qq21*rinv21*(rinvsq21-felec);
641
642             d                = r21-rswitch;
643             d                = (d>0.0) ? d : 0.0;
644             d2               = d*d;
645             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
646
647             dsw              = d2*(swF2+d*(swF3+d*swF4));
648
649             /* Evaluate switch function */
650             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
651             felec            = felec*sw - rinv21*velec*dsw;
652             velec           *= sw;
653
654             /* Update potential sums from outer loop */
655             velecsum        += velec;
656
657             fscal            = felec;
658
659             /* Calculate temporary vectorial force */
660             tx               = fscal*dx21;
661             ty               = fscal*dy21;
662             tz               = fscal*dz21;
663
664             /* Update vectorial force */
665             fix2            += tx;
666             fiy2            += ty;
667             fiz2            += tz;
668             f[j_coord_offset+DIM*1+XX] -= tx;
669             f[j_coord_offset+DIM*1+YY] -= ty;
670             f[j_coord_offset+DIM*1+ZZ] -= tz;
671
672             }
673
674             /**************************
675              * CALCULATE INTERACTIONS *
676              **************************/
677
678             if (rsq22<rcutoff2)
679             {
680
681             r22              = rsq22*rinv22;
682
683             /* EWALD ELECTROSTATICS */
684
685             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
686             ewrt             = r22*ewtabscale;
687             ewitab           = ewrt;
688             eweps            = ewrt-ewitab;
689             ewitab           = 4*ewitab;
690             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
691             velec            = qq22*(rinv22-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
692             felec            = qq22*rinv22*(rinvsq22-felec);
693
694             d                = r22-rswitch;
695             d                = (d>0.0) ? d : 0.0;
696             d2               = d*d;
697             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
698
699             dsw              = d2*(swF2+d*(swF3+d*swF4));
700
701             /* Evaluate switch function */
702             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
703             felec            = felec*sw - rinv22*velec*dsw;
704             velec           *= sw;
705
706             /* Update potential sums from outer loop */
707             velecsum        += velec;
708
709             fscal            = felec;
710
711             /* Calculate temporary vectorial force */
712             tx               = fscal*dx22;
713             ty               = fscal*dy22;
714             tz               = fscal*dz22;
715
716             /* Update vectorial force */
717             fix2            += tx;
718             fiy2            += ty;
719             fiz2            += tz;
720             f[j_coord_offset+DIM*2+XX] -= tx;
721             f[j_coord_offset+DIM*2+YY] -= ty;
722             f[j_coord_offset+DIM*2+ZZ] -= tz;
723
724             }
725
726             /* Inner loop uses 522 flops */
727         }
728         /* End of innermost loop */
729
730         tx = ty = tz = 0;
731         f[i_coord_offset+DIM*0+XX] += fix0;
732         f[i_coord_offset+DIM*0+YY] += fiy0;
733         f[i_coord_offset+DIM*0+ZZ] += fiz0;
734         tx                         += fix0;
735         ty                         += fiy0;
736         tz                         += fiz0;
737         f[i_coord_offset+DIM*1+XX] += fix1;
738         f[i_coord_offset+DIM*1+YY] += fiy1;
739         f[i_coord_offset+DIM*1+ZZ] += fiz1;
740         tx                         += fix1;
741         ty                         += fiy1;
742         tz                         += fiz1;
743         f[i_coord_offset+DIM*2+XX] += fix2;
744         f[i_coord_offset+DIM*2+YY] += fiy2;
745         f[i_coord_offset+DIM*2+ZZ] += fiz2;
746         tx                         += fix2;
747         ty                         += fiy2;
748         tz                         += fiz2;
749         fshift[i_shift_offset+XX]  += tx;
750         fshift[i_shift_offset+YY]  += ty;
751         fshift[i_shift_offset+ZZ]  += tz;
752
753         ggid                        = gid[iidx];
754         /* Update potential energies */
755         kernel_data->energygrp_elec[ggid] += velecsum;
756
757         /* Increment number of inner iterations */
758         inneriter                  += j_index_end - j_index_start;
759
760         /* Outer loop uses 31 flops */
761     }
762
763     /* Increment number of outer iterations */
764     outeriter        += nri;
765
766     /* Update outer/inner flops */
767
768     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3W3_VF,outeriter*31 + inneriter*522);
769 }
770 /*
771  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSw_VdwNone_GeomW3W3_F_c
772  * Electrostatics interaction: Ewald
773  * VdW interaction:            None
774  * Geometry:                   Water3-Water3
775  * Calculate force/pot:        Force
776  */
777 void
778 nb_kernel_ElecEwSw_VdwNone_GeomW3W3_F_c
779                     (t_nblist * gmx_restrict                nlist,
780                      rvec * gmx_restrict                    xx,
781                      rvec * gmx_restrict                    ff,
782                      t_forcerec * gmx_restrict              fr,
783                      t_mdatoms * gmx_restrict               mdatoms,
784                      nb_kernel_data_t * gmx_restrict        kernel_data,
785                      t_nrnb * gmx_restrict                  nrnb)
786 {
787     int              i_shift_offset,i_coord_offset,j_coord_offset;
788     int              j_index_start,j_index_end;
789     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
790     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
791     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
792     real             *shiftvec,*fshift,*x,*f;
793     int              vdwioffset0;
794     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
795     int              vdwioffset1;
796     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
797     int              vdwioffset2;
798     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
799     int              vdwjidx0;
800     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
801     int              vdwjidx1;
802     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
803     int              vdwjidx2;
804     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
805     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
806     real             dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01,cexp1_01,cexp2_01;
807     real             dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02,cexp1_02,cexp2_02;
808     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
809     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
810     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
811     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
812     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
813     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
814     real             velec,felec,velecsum,facel,crf,krf,krf2;
815     real             *charge;
816     int              ewitab;
817     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
818     real             *ewtab;
819     real             rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
820
821     x                = xx[0];
822     f                = ff[0];
823
824     nri              = nlist->nri;
825     iinr             = nlist->iinr;
826     jindex           = nlist->jindex;
827     jjnr             = nlist->jjnr;
828     shiftidx         = nlist->shift;
829     gid              = nlist->gid;
830     shiftvec         = fr->shift_vec[0];
831     fshift           = fr->fshift[0];
832     facel            = fr->epsfac;
833     charge           = mdatoms->chargeA;
834
835     sh_ewald         = fr->ic->sh_ewald;
836     ewtab            = fr->ic->tabq_coul_FDV0;
837     ewtabscale       = fr->ic->tabq_scale;
838     ewtabhalfspace   = 0.5/ewtabscale;
839
840     /* Setup water-specific parameters */
841     inr              = nlist->iinr[0];
842     iq0              = facel*charge[inr+0];
843     iq1              = facel*charge[inr+1];
844     iq2              = facel*charge[inr+2];
845
846     jq0              = charge[inr+0];
847     jq1              = charge[inr+1];
848     jq2              = charge[inr+2];
849     qq00             = iq0*jq0;
850     qq01             = iq0*jq1;
851     qq02             = iq0*jq2;
852     qq10             = iq1*jq0;
853     qq11             = iq1*jq1;
854     qq12             = iq1*jq2;
855     qq20             = iq2*jq0;
856     qq21             = iq2*jq1;
857     qq22             = iq2*jq2;
858
859     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
860     rcutoff          = fr->rcoulomb;
861     rcutoff2         = rcutoff*rcutoff;
862
863     rswitch          = fr->rcoulomb_switch;
864     /* Setup switch parameters */
865     d                = rcutoff-rswitch;
866     swV3             = -10.0/(d*d*d);
867     swV4             =  15.0/(d*d*d*d);
868     swV5             =  -6.0/(d*d*d*d*d);
869     swF2             = -30.0/(d*d*d);
870     swF3             =  60.0/(d*d*d*d);
871     swF4             = -30.0/(d*d*d*d*d);
872
873     outeriter        = 0;
874     inneriter        = 0;
875
876     /* Start outer loop over neighborlists */
877     for(iidx=0; iidx<nri; iidx++)
878     {
879         /* Load shift vector for this list */
880         i_shift_offset   = DIM*shiftidx[iidx];
881         shX              = shiftvec[i_shift_offset+XX];
882         shY              = shiftvec[i_shift_offset+YY];
883         shZ              = shiftvec[i_shift_offset+ZZ];
884
885         /* Load limits for loop over neighbors */
886         j_index_start    = jindex[iidx];
887         j_index_end      = jindex[iidx+1];
888
889         /* Get outer coordinate index */
890         inr              = iinr[iidx];
891         i_coord_offset   = DIM*inr;
892
893         /* Load i particle coords and add shift vector */
894         ix0              = shX + x[i_coord_offset+DIM*0+XX];
895         iy0              = shY + x[i_coord_offset+DIM*0+YY];
896         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
897         ix1              = shX + x[i_coord_offset+DIM*1+XX];
898         iy1              = shY + x[i_coord_offset+DIM*1+YY];
899         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
900         ix2              = shX + x[i_coord_offset+DIM*2+XX];
901         iy2              = shY + x[i_coord_offset+DIM*2+YY];
902         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
903
904         fix0             = 0.0;
905         fiy0             = 0.0;
906         fiz0             = 0.0;
907         fix1             = 0.0;
908         fiy1             = 0.0;
909         fiz1             = 0.0;
910         fix2             = 0.0;
911         fiy2             = 0.0;
912         fiz2             = 0.0;
913
914         /* Start inner kernel loop */
915         for(jidx=j_index_start; jidx<j_index_end; jidx++)
916         {
917             /* Get j neighbor index, and coordinate index */
918             jnr              = jjnr[jidx];
919             j_coord_offset   = DIM*jnr;
920
921             /* load j atom coordinates */
922             jx0              = x[j_coord_offset+DIM*0+XX];
923             jy0              = x[j_coord_offset+DIM*0+YY];
924             jz0              = x[j_coord_offset+DIM*0+ZZ];
925             jx1              = x[j_coord_offset+DIM*1+XX];
926             jy1              = x[j_coord_offset+DIM*1+YY];
927             jz1              = x[j_coord_offset+DIM*1+ZZ];
928             jx2              = x[j_coord_offset+DIM*2+XX];
929             jy2              = x[j_coord_offset+DIM*2+YY];
930             jz2              = x[j_coord_offset+DIM*2+ZZ];
931
932             /* Calculate displacement vector */
933             dx00             = ix0 - jx0;
934             dy00             = iy0 - jy0;
935             dz00             = iz0 - jz0;
936             dx01             = ix0 - jx1;
937             dy01             = iy0 - jy1;
938             dz01             = iz0 - jz1;
939             dx02             = ix0 - jx2;
940             dy02             = iy0 - jy2;
941             dz02             = iz0 - jz2;
942             dx10             = ix1 - jx0;
943             dy10             = iy1 - jy0;
944             dz10             = iz1 - jz0;
945             dx11             = ix1 - jx1;
946             dy11             = iy1 - jy1;
947             dz11             = iz1 - jz1;
948             dx12             = ix1 - jx2;
949             dy12             = iy1 - jy2;
950             dz12             = iz1 - jz2;
951             dx20             = ix2 - jx0;
952             dy20             = iy2 - jy0;
953             dz20             = iz2 - jz0;
954             dx21             = ix2 - jx1;
955             dy21             = iy2 - jy1;
956             dz21             = iz2 - jz1;
957             dx22             = ix2 - jx2;
958             dy22             = iy2 - jy2;
959             dz22             = iz2 - jz2;
960
961             /* Calculate squared distance and things based on it */
962             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
963             rsq01            = dx01*dx01+dy01*dy01+dz01*dz01;
964             rsq02            = dx02*dx02+dy02*dy02+dz02*dz02;
965             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
966             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
967             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
968             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
969             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
970             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
971
972             rinv00           = gmx_invsqrt(rsq00);
973             rinv01           = gmx_invsqrt(rsq01);
974             rinv02           = gmx_invsqrt(rsq02);
975             rinv10           = gmx_invsqrt(rsq10);
976             rinv11           = gmx_invsqrt(rsq11);
977             rinv12           = gmx_invsqrt(rsq12);
978             rinv20           = gmx_invsqrt(rsq20);
979             rinv21           = gmx_invsqrt(rsq21);
980             rinv22           = gmx_invsqrt(rsq22);
981
982             rinvsq00         = rinv00*rinv00;
983             rinvsq01         = rinv01*rinv01;
984             rinvsq02         = rinv02*rinv02;
985             rinvsq10         = rinv10*rinv10;
986             rinvsq11         = rinv11*rinv11;
987             rinvsq12         = rinv12*rinv12;
988             rinvsq20         = rinv20*rinv20;
989             rinvsq21         = rinv21*rinv21;
990             rinvsq22         = rinv22*rinv22;
991
992             /**************************
993              * CALCULATE INTERACTIONS *
994              **************************/
995
996             if (rsq00<rcutoff2)
997             {
998
999             r00              = rsq00*rinv00;
1000
1001             /* EWALD ELECTROSTATICS */
1002
1003             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1004             ewrt             = r00*ewtabscale;
1005             ewitab           = ewrt;
1006             eweps            = ewrt-ewitab;
1007             ewitab           = 4*ewitab;
1008             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1009             velec            = qq00*(rinv00-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1010             felec            = qq00*rinv00*(rinvsq00-felec);
1011
1012             d                = r00-rswitch;
1013             d                = (d>0.0) ? d : 0.0;
1014             d2               = d*d;
1015             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1016
1017             dsw              = d2*(swF2+d*(swF3+d*swF4));
1018
1019             /* Evaluate switch function */
1020             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1021             felec            = felec*sw - rinv00*velec*dsw;
1022
1023             fscal            = felec;
1024
1025             /* Calculate temporary vectorial force */
1026             tx               = fscal*dx00;
1027             ty               = fscal*dy00;
1028             tz               = fscal*dz00;
1029
1030             /* Update vectorial force */
1031             fix0            += tx;
1032             fiy0            += ty;
1033             fiz0            += tz;
1034             f[j_coord_offset+DIM*0+XX] -= tx;
1035             f[j_coord_offset+DIM*0+YY] -= ty;
1036             f[j_coord_offset+DIM*0+ZZ] -= tz;
1037
1038             }
1039
1040             /**************************
1041              * CALCULATE INTERACTIONS *
1042              **************************/
1043
1044             if (rsq01<rcutoff2)
1045             {
1046
1047             r01              = rsq01*rinv01;
1048
1049             /* EWALD ELECTROSTATICS */
1050
1051             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1052             ewrt             = r01*ewtabscale;
1053             ewitab           = ewrt;
1054             eweps            = ewrt-ewitab;
1055             ewitab           = 4*ewitab;
1056             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1057             velec            = qq01*(rinv01-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1058             felec            = qq01*rinv01*(rinvsq01-felec);
1059
1060             d                = r01-rswitch;
1061             d                = (d>0.0) ? d : 0.0;
1062             d2               = d*d;
1063             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1064
1065             dsw              = d2*(swF2+d*(swF3+d*swF4));
1066
1067             /* Evaluate switch function */
1068             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1069             felec            = felec*sw - rinv01*velec*dsw;
1070
1071             fscal            = felec;
1072
1073             /* Calculate temporary vectorial force */
1074             tx               = fscal*dx01;
1075             ty               = fscal*dy01;
1076             tz               = fscal*dz01;
1077
1078             /* Update vectorial force */
1079             fix0            += tx;
1080             fiy0            += ty;
1081             fiz0            += tz;
1082             f[j_coord_offset+DIM*1+XX] -= tx;
1083             f[j_coord_offset+DIM*1+YY] -= ty;
1084             f[j_coord_offset+DIM*1+ZZ] -= tz;
1085
1086             }
1087
1088             /**************************
1089              * CALCULATE INTERACTIONS *
1090              **************************/
1091
1092             if (rsq02<rcutoff2)
1093             {
1094
1095             r02              = rsq02*rinv02;
1096
1097             /* EWALD ELECTROSTATICS */
1098
1099             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1100             ewrt             = r02*ewtabscale;
1101             ewitab           = ewrt;
1102             eweps            = ewrt-ewitab;
1103             ewitab           = 4*ewitab;
1104             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1105             velec            = qq02*(rinv02-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1106             felec            = qq02*rinv02*(rinvsq02-felec);
1107
1108             d                = r02-rswitch;
1109             d                = (d>0.0) ? d : 0.0;
1110             d2               = d*d;
1111             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1112
1113             dsw              = d2*(swF2+d*(swF3+d*swF4));
1114
1115             /* Evaluate switch function */
1116             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1117             felec            = felec*sw - rinv02*velec*dsw;
1118
1119             fscal            = felec;
1120
1121             /* Calculate temporary vectorial force */
1122             tx               = fscal*dx02;
1123             ty               = fscal*dy02;
1124             tz               = fscal*dz02;
1125
1126             /* Update vectorial force */
1127             fix0            += tx;
1128             fiy0            += ty;
1129             fiz0            += tz;
1130             f[j_coord_offset+DIM*2+XX] -= tx;
1131             f[j_coord_offset+DIM*2+YY] -= ty;
1132             f[j_coord_offset+DIM*2+ZZ] -= tz;
1133
1134             }
1135
1136             /**************************
1137              * CALCULATE INTERACTIONS *
1138              **************************/
1139
1140             if (rsq10<rcutoff2)
1141             {
1142
1143             r10              = rsq10*rinv10;
1144
1145             /* EWALD ELECTROSTATICS */
1146
1147             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1148             ewrt             = r10*ewtabscale;
1149             ewitab           = ewrt;
1150             eweps            = ewrt-ewitab;
1151             ewitab           = 4*ewitab;
1152             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1153             velec            = qq10*(rinv10-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1154             felec            = qq10*rinv10*(rinvsq10-felec);
1155
1156             d                = r10-rswitch;
1157             d                = (d>0.0) ? d : 0.0;
1158             d2               = d*d;
1159             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1160
1161             dsw              = d2*(swF2+d*(swF3+d*swF4));
1162
1163             /* Evaluate switch function */
1164             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1165             felec            = felec*sw - rinv10*velec*dsw;
1166
1167             fscal            = felec;
1168
1169             /* Calculate temporary vectorial force */
1170             tx               = fscal*dx10;
1171             ty               = fscal*dy10;
1172             tz               = fscal*dz10;
1173
1174             /* Update vectorial force */
1175             fix1            += tx;
1176             fiy1            += ty;
1177             fiz1            += tz;
1178             f[j_coord_offset+DIM*0+XX] -= tx;
1179             f[j_coord_offset+DIM*0+YY] -= ty;
1180             f[j_coord_offset+DIM*0+ZZ] -= tz;
1181
1182             }
1183
1184             /**************************
1185              * CALCULATE INTERACTIONS *
1186              **************************/
1187
1188             if (rsq11<rcutoff2)
1189             {
1190
1191             r11              = rsq11*rinv11;
1192
1193             /* EWALD ELECTROSTATICS */
1194
1195             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1196             ewrt             = r11*ewtabscale;
1197             ewitab           = ewrt;
1198             eweps            = ewrt-ewitab;
1199             ewitab           = 4*ewitab;
1200             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1201             velec            = qq11*(rinv11-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1202             felec            = qq11*rinv11*(rinvsq11-felec);
1203
1204             d                = r11-rswitch;
1205             d                = (d>0.0) ? d : 0.0;
1206             d2               = d*d;
1207             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1208
1209             dsw              = d2*(swF2+d*(swF3+d*swF4));
1210
1211             /* Evaluate switch function */
1212             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1213             felec            = felec*sw - rinv11*velec*dsw;
1214
1215             fscal            = felec;
1216
1217             /* Calculate temporary vectorial force */
1218             tx               = fscal*dx11;
1219             ty               = fscal*dy11;
1220             tz               = fscal*dz11;
1221
1222             /* Update vectorial force */
1223             fix1            += tx;
1224             fiy1            += ty;
1225             fiz1            += tz;
1226             f[j_coord_offset+DIM*1+XX] -= tx;
1227             f[j_coord_offset+DIM*1+YY] -= ty;
1228             f[j_coord_offset+DIM*1+ZZ] -= tz;
1229
1230             }
1231
1232             /**************************
1233              * CALCULATE INTERACTIONS *
1234              **************************/
1235
1236             if (rsq12<rcutoff2)
1237             {
1238
1239             r12              = rsq12*rinv12;
1240
1241             /* EWALD ELECTROSTATICS */
1242
1243             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1244             ewrt             = r12*ewtabscale;
1245             ewitab           = ewrt;
1246             eweps            = ewrt-ewitab;
1247             ewitab           = 4*ewitab;
1248             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1249             velec            = qq12*(rinv12-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1250             felec            = qq12*rinv12*(rinvsq12-felec);
1251
1252             d                = r12-rswitch;
1253             d                = (d>0.0) ? d : 0.0;
1254             d2               = d*d;
1255             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1256
1257             dsw              = d2*(swF2+d*(swF3+d*swF4));
1258
1259             /* Evaluate switch function */
1260             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1261             felec            = felec*sw - rinv12*velec*dsw;
1262
1263             fscal            = felec;
1264
1265             /* Calculate temporary vectorial force */
1266             tx               = fscal*dx12;
1267             ty               = fscal*dy12;
1268             tz               = fscal*dz12;
1269
1270             /* Update vectorial force */
1271             fix1            += tx;
1272             fiy1            += ty;
1273             fiz1            += tz;
1274             f[j_coord_offset+DIM*2+XX] -= tx;
1275             f[j_coord_offset+DIM*2+YY] -= ty;
1276             f[j_coord_offset+DIM*2+ZZ] -= tz;
1277
1278             }
1279
1280             /**************************
1281              * CALCULATE INTERACTIONS *
1282              **************************/
1283
1284             if (rsq20<rcutoff2)
1285             {
1286
1287             r20              = rsq20*rinv20;
1288
1289             /* EWALD ELECTROSTATICS */
1290
1291             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1292             ewrt             = r20*ewtabscale;
1293             ewitab           = ewrt;
1294             eweps            = ewrt-ewitab;
1295             ewitab           = 4*ewitab;
1296             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1297             velec            = qq20*(rinv20-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1298             felec            = qq20*rinv20*(rinvsq20-felec);
1299
1300             d                = r20-rswitch;
1301             d                = (d>0.0) ? d : 0.0;
1302             d2               = d*d;
1303             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1304
1305             dsw              = d2*(swF2+d*(swF3+d*swF4));
1306
1307             /* Evaluate switch function */
1308             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1309             felec            = felec*sw - rinv20*velec*dsw;
1310
1311             fscal            = felec;
1312
1313             /* Calculate temporary vectorial force */
1314             tx               = fscal*dx20;
1315             ty               = fscal*dy20;
1316             tz               = fscal*dz20;
1317
1318             /* Update vectorial force */
1319             fix2            += tx;
1320             fiy2            += ty;
1321             fiz2            += tz;
1322             f[j_coord_offset+DIM*0+XX] -= tx;
1323             f[j_coord_offset+DIM*0+YY] -= ty;
1324             f[j_coord_offset+DIM*0+ZZ] -= tz;
1325
1326             }
1327
1328             /**************************
1329              * CALCULATE INTERACTIONS *
1330              **************************/
1331
1332             if (rsq21<rcutoff2)
1333             {
1334
1335             r21              = rsq21*rinv21;
1336
1337             /* EWALD ELECTROSTATICS */
1338
1339             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1340             ewrt             = r21*ewtabscale;
1341             ewitab           = ewrt;
1342             eweps            = ewrt-ewitab;
1343             ewitab           = 4*ewitab;
1344             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1345             velec            = qq21*(rinv21-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1346             felec            = qq21*rinv21*(rinvsq21-felec);
1347
1348             d                = r21-rswitch;
1349             d                = (d>0.0) ? d : 0.0;
1350             d2               = d*d;
1351             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1352
1353             dsw              = d2*(swF2+d*(swF3+d*swF4));
1354
1355             /* Evaluate switch function */
1356             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1357             felec            = felec*sw - rinv21*velec*dsw;
1358
1359             fscal            = felec;
1360
1361             /* Calculate temporary vectorial force */
1362             tx               = fscal*dx21;
1363             ty               = fscal*dy21;
1364             tz               = fscal*dz21;
1365
1366             /* Update vectorial force */
1367             fix2            += tx;
1368             fiy2            += ty;
1369             fiz2            += tz;
1370             f[j_coord_offset+DIM*1+XX] -= tx;
1371             f[j_coord_offset+DIM*1+YY] -= ty;
1372             f[j_coord_offset+DIM*1+ZZ] -= tz;
1373
1374             }
1375
1376             /**************************
1377              * CALCULATE INTERACTIONS *
1378              **************************/
1379
1380             if (rsq22<rcutoff2)
1381             {
1382
1383             r22              = rsq22*rinv22;
1384
1385             /* EWALD ELECTROSTATICS */
1386
1387             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1388             ewrt             = r22*ewtabscale;
1389             ewitab           = ewrt;
1390             eweps            = ewrt-ewitab;
1391             ewitab           = 4*ewitab;
1392             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1393             velec            = qq22*(rinv22-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1394             felec            = qq22*rinv22*(rinvsq22-felec);
1395
1396             d                = r22-rswitch;
1397             d                = (d>0.0) ? d : 0.0;
1398             d2               = d*d;
1399             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1400
1401             dsw              = d2*(swF2+d*(swF3+d*swF4));
1402
1403             /* Evaluate switch function */
1404             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1405             felec            = felec*sw - rinv22*velec*dsw;
1406
1407             fscal            = felec;
1408
1409             /* Calculate temporary vectorial force */
1410             tx               = fscal*dx22;
1411             ty               = fscal*dy22;
1412             tz               = fscal*dz22;
1413
1414             /* Update vectorial force */
1415             fix2            += tx;
1416             fiy2            += ty;
1417             fiz2            += tz;
1418             f[j_coord_offset+DIM*2+XX] -= tx;
1419             f[j_coord_offset+DIM*2+YY] -= ty;
1420             f[j_coord_offset+DIM*2+ZZ] -= tz;
1421
1422             }
1423
1424             /* Inner loop uses 504 flops */
1425         }
1426         /* End of innermost loop */
1427
1428         tx = ty = tz = 0;
1429         f[i_coord_offset+DIM*0+XX] += fix0;
1430         f[i_coord_offset+DIM*0+YY] += fiy0;
1431         f[i_coord_offset+DIM*0+ZZ] += fiz0;
1432         tx                         += fix0;
1433         ty                         += fiy0;
1434         tz                         += fiz0;
1435         f[i_coord_offset+DIM*1+XX] += fix1;
1436         f[i_coord_offset+DIM*1+YY] += fiy1;
1437         f[i_coord_offset+DIM*1+ZZ] += fiz1;
1438         tx                         += fix1;
1439         ty                         += fiy1;
1440         tz                         += fiz1;
1441         f[i_coord_offset+DIM*2+XX] += fix2;
1442         f[i_coord_offset+DIM*2+YY] += fiy2;
1443         f[i_coord_offset+DIM*2+ZZ] += fiz2;
1444         tx                         += fix2;
1445         ty                         += fiy2;
1446         tz                         += fiz2;
1447         fshift[i_shift_offset+XX]  += tx;
1448         fshift[i_shift_offset+YY]  += ty;
1449         fshift[i_shift_offset+ZZ]  += tz;
1450
1451         /* Increment number of inner iterations */
1452         inneriter                  += j_index_end - j_index_start;
1453
1454         /* Outer loop uses 30 flops */
1455     }
1456
1457     /* Increment number of outer iterations */
1458     outeriter        += nri;
1459
1460     /* Update outer/inner flops */
1461
1462     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3W3_F,outeriter*30 + inneriter*504);
1463 }