Added option to gmx nmeig to print ZPE.
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecEwSh_VdwNone_GeomW3P1_c.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014.2015,2017, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS c kernel generator.
37  */
38 #include "gmxpre.h"
39
40 #include "config.h"
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
46
47 /*
48  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSh_VdwNone_GeomW3P1_VF_c
49  * Electrostatics interaction: Ewald
50  * VdW interaction:            None
51  * Geometry:                   Water3-Particle
52  * Calculate force/pot:        PotentialAndForce
53  */
54 void
55 nb_kernel_ElecEwSh_VdwNone_GeomW3P1_VF_c
56                     (t_nblist                    * gmx_restrict       nlist,
57                      rvec                        * gmx_restrict          xx,
58                      rvec                        * gmx_restrict          ff,
59                      struct t_forcerec           * gmx_restrict          fr,
60                      t_mdatoms                   * gmx_restrict     mdatoms,
61                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
62                      t_nrnb                      * gmx_restrict        nrnb)
63 {
64     int              i_shift_offset,i_coord_offset,j_coord_offset;
65     int              j_index_start,j_index_end;
66     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
67     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
68     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
69     real             *shiftvec,*fshift,*x,*f;
70     int              vdwioffset0;
71     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
72     int              vdwioffset1;
73     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
74     int              vdwioffset2;
75     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
76     int              vdwjidx0;
77     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
78     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
79     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
80     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
81     real             velec,felec,velecsum,facel,crf,krf,krf2;
82     real             *charge;
83     int              ewitab;
84     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
85     real             *ewtab;
86
87     x                = xx[0];
88     f                = ff[0];
89
90     nri              = nlist->nri;
91     iinr             = nlist->iinr;
92     jindex           = nlist->jindex;
93     jjnr             = nlist->jjnr;
94     shiftidx         = nlist->shift;
95     gid              = nlist->gid;
96     shiftvec         = fr->shift_vec[0];
97     fshift           = fr->fshift[0];
98     facel            = fr->ic->epsfac;
99     charge           = mdatoms->chargeA;
100
101     sh_ewald         = fr->ic->sh_ewald;
102     ewtab            = fr->ic->tabq_coul_FDV0;
103     ewtabscale       = fr->ic->tabq_scale;
104     ewtabhalfspace   = 0.5/ewtabscale;
105
106     /* Setup water-specific parameters */
107     inr              = nlist->iinr[0];
108     iq0              = facel*charge[inr+0];
109     iq1              = facel*charge[inr+1];
110     iq2              = facel*charge[inr+2];
111
112     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
113     rcutoff          = fr->ic->rcoulomb;
114     rcutoff2         = rcutoff*rcutoff;
115
116     outeriter        = 0;
117     inneriter        = 0;
118
119     /* Start outer loop over neighborlists */
120     for(iidx=0; iidx<nri; iidx++)
121     {
122         /* Load shift vector for this list */
123         i_shift_offset   = DIM*shiftidx[iidx];
124         shX              = shiftvec[i_shift_offset+XX];
125         shY              = shiftvec[i_shift_offset+YY];
126         shZ              = shiftvec[i_shift_offset+ZZ];
127
128         /* Load limits for loop over neighbors */
129         j_index_start    = jindex[iidx];
130         j_index_end      = jindex[iidx+1];
131
132         /* Get outer coordinate index */
133         inr              = iinr[iidx];
134         i_coord_offset   = DIM*inr;
135
136         /* Load i particle coords and add shift vector */
137         ix0              = shX + x[i_coord_offset+DIM*0+XX];
138         iy0              = shY + x[i_coord_offset+DIM*0+YY];
139         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
140         ix1              = shX + x[i_coord_offset+DIM*1+XX];
141         iy1              = shY + x[i_coord_offset+DIM*1+YY];
142         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
143         ix2              = shX + x[i_coord_offset+DIM*2+XX];
144         iy2              = shY + x[i_coord_offset+DIM*2+YY];
145         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
146
147         fix0             = 0.0;
148         fiy0             = 0.0;
149         fiz0             = 0.0;
150         fix1             = 0.0;
151         fiy1             = 0.0;
152         fiz1             = 0.0;
153         fix2             = 0.0;
154         fiy2             = 0.0;
155         fiz2             = 0.0;
156
157         /* Reset potential sums */
158         velecsum         = 0.0;
159
160         /* Start inner kernel loop */
161         for(jidx=j_index_start; jidx<j_index_end; jidx++)
162         {
163             /* Get j neighbor index, and coordinate index */
164             jnr              = jjnr[jidx];
165             j_coord_offset   = DIM*jnr;
166
167             /* load j atom coordinates */
168             jx0              = x[j_coord_offset+DIM*0+XX];
169             jy0              = x[j_coord_offset+DIM*0+YY];
170             jz0              = x[j_coord_offset+DIM*0+ZZ];
171
172             /* Calculate displacement vector */
173             dx00             = ix0 - jx0;
174             dy00             = iy0 - jy0;
175             dz00             = iz0 - jz0;
176             dx10             = ix1 - jx0;
177             dy10             = iy1 - jy0;
178             dz10             = iz1 - jz0;
179             dx20             = ix2 - jx0;
180             dy20             = iy2 - jy0;
181             dz20             = iz2 - jz0;
182
183             /* Calculate squared distance and things based on it */
184             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
185             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
186             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
187
188             rinv00           = 1.0/sqrt(rsq00);
189             rinv10           = 1.0/sqrt(rsq10);
190             rinv20           = 1.0/sqrt(rsq20);
191
192             rinvsq00         = rinv00*rinv00;
193             rinvsq10         = rinv10*rinv10;
194             rinvsq20         = rinv20*rinv20;
195
196             /* Load parameters for j particles */
197             jq0              = charge[jnr+0];
198
199             /**************************
200              * CALCULATE INTERACTIONS *
201              **************************/
202
203             if (rsq00<rcutoff2)
204             {
205
206             r00              = rsq00*rinv00;
207
208             qq00             = iq0*jq0;
209
210             /* EWALD ELECTROSTATICS */
211
212             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
213             ewrt             = r00*ewtabscale;
214             ewitab           = ewrt;
215             eweps            = ewrt-ewitab;
216             ewitab           = 4*ewitab;
217             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
218             velec            = qq00*((rinv00-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
219             felec            = qq00*rinv00*(rinvsq00-felec);
220
221             /* Update potential sums from outer loop */
222             velecsum        += velec;
223
224             fscal            = felec;
225
226             /* Calculate temporary vectorial force */
227             tx               = fscal*dx00;
228             ty               = fscal*dy00;
229             tz               = fscal*dz00;
230
231             /* Update vectorial force */
232             fix0            += tx;
233             fiy0            += ty;
234             fiz0            += tz;
235             f[j_coord_offset+DIM*0+XX] -= tx;
236             f[j_coord_offset+DIM*0+YY] -= ty;
237             f[j_coord_offset+DIM*0+ZZ] -= tz;
238
239             }
240
241             /**************************
242              * CALCULATE INTERACTIONS *
243              **************************/
244
245             if (rsq10<rcutoff2)
246             {
247
248             r10              = rsq10*rinv10;
249
250             qq10             = iq1*jq0;
251
252             /* EWALD ELECTROSTATICS */
253
254             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
255             ewrt             = r10*ewtabscale;
256             ewitab           = ewrt;
257             eweps            = ewrt-ewitab;
258             ewitab           = 4*ewitab;
259             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
260             velec            = qq10*((rinv10-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
261             felec            = qq10*rinv10*(rinvsq10-felec);
262
263             /* Update potential sums from outer loop */
264             velecsum        += velec;
265
266             fscal            = felec;
267
268             /* Calculate temporary vectorial force */
269             tx               = fscal*dx10;
270             ty               = fscal*dy10;
271             tz               = fscal*dz10;
272
273             /* Update vectorial force */
274             fix1            += tx;
275             fiy1            += ty;
276             fiz1            += tz;
277             f[j_coord_offset+DIM*0+XX] -= tx;
278             f[j_coord_offset+DIM*0+YY] -= ty;
279             f[j_coord_offset+DIM*0+ZZ] -= tz;
280
281             }
282
283             /**************************
284              * CALCULATE INTERACTIONS *
285              **************************/
286
287             if (rsq20<rcutoff2)
288             {
289
290             r20              = rsq20*rinv20;
291
292             qq20             = iq2*jq0;
293
294             /* EWALD ELECTROSTATICS */
295
296             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
297             ewrt             = r20*ewtabscale;
298             ewitab           = ewrt;
299             eweps            = ewrt-ewitab;
300             ewitab           = 4*ewitab;
301             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
302             velec            = qq20*((rinv20-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
303             felec            = qq20*rinv20*(rinvsq20-felec);
304
305             /* Update potential sums from outer loop */
306             velecsum        += velec;
307
308             fscal            = felec;
309
310             /* Calculate temporary vectorial force */
311             tx               = fscal*dx20;
312             ty               = fscal*dy20;
313             tz               = fscal*dz20;
314
315             /* Update vectorial force */
316             fix2            += tx;
317             fiy2            += ty;
318             fiz2            += tz;
319             f[j_coord_offset+DIM*0+XX] -= tx;
320             f[j_coord_offset+DIM*0+YY] -= ty;
321             f[j_coord_offset+DIM*0+ZZ] -= tz;
322
323             }
324
325             /* Inner loop uses 126 flops */
326         }
327         /* End of innermost loop */
328
329         tx = ty = tz = 0;
330         f[i_coord_offset+DIM*0+XX] += fix0;
331         f[i_coord_offset+DIM*0+YY] += fiy0;
332         f[i_coord_offset+DIM*0+ZZ] += fiz0;
333         tx                         += fix0;
334         ty                         += fiy0;
335         tz                         += fiz0;
336         f[i_coord_offset+DIM*1+XX] += fix1;
337         f[i_coord_offset+DIM*1+YY] += fiy1;
338         f[i_coord_offset+DIM*1+ZZ] += fiz1;
339         tx                         += fix1;
340         ty                         += fiy1;
341         tz                         += fiz1;
342         f[i_coord_offset+DIM*2+XX] += fix2;
343         f[i_coord_offset+DIM*2+YY] += fiy2;
344         f[i_coord_offset+DIM*2+ZZ] += fiz2;
345         tx                         += fix2;
346         ty                         += fiy2;
347         tz                         += fiz2;
348         fshift[i_shift_offset+XX]  += tx;
349         fshift[i_shift_offset+YY]  += ty;
350         fshift[i_shift_offset+ZZ]  += tz;
351
352         ggid                        = gid[iidx];
353         /* Update potential energies */
354         kernel_data->energygrp_elec[ggid] += velecsum;
355
356         /* Increment number of inner iterations */
357         inneriter                  += j_index_end - j_index_start;
358
359         /* Outer loop uses 31 flops */
360     }
361
362     /* Increment number of outer iterations */
363     outeriter        += nri;
364
365     /* Update outer/inner flops */
366
367     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_VF,outeriter*31 + inneriter*126);
368 }
369 /*
370  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSh_VdwNone_GeomW3P1_F_c
371  * Electrostatics interaction: Ewald
372  * VdW interaction:            None
373  * Geometry:                   Water3-Particle
374  * Calculate force/pot:        Force
375  */
376 void
377 nb_kernel_ElecEwSh_VdwNone_GeomW3P1_F_c
378                     (t_nblist                    * gmx_restrict       nlist,
379                      rvec                        * gmx_restrict          xx,
380                      rvec                        * gmx_restrict          ff,
381                      struct t_forcerec           * gmx_restrict          fr,
382                      t_mdatoms                   * gmx_restrict     mdatoms,
383                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
384                      t_nrnb                      * gmx_restrict        nrnb)
385 {
386     int              i_shift_offset,i_coord_offset,j_coord_offset;
387     int              j_index_start,j_index_end;
388     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
389     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
390     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
391     real             *shiftvec,*fshift,*x,*f;
392     int              vdwioffset0;
393     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
394     int              vdwioffset1;
395     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
396     int              vdwioffset2;
397     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
398     int              vdwjidx0;
399     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
400     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
401     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
402     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
403     real             velec,felec,velecsum,facel,crf,krf,krf2;
404     real             *charge;
405     int              ewitab;
406     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
407     real             *ewtab;
408
409     x                = xx[0];
410     f                = ff[0];
411
412     nri              = nlist->nri;
413     iinr             = nlist->iinr;
414     jindex           = nlist->jindex;
415     jjnr             = nlist->jjnr;
416     shiftidx         = nlist->shift;
417     gid              = nlist->gid;
418     shiftvec         = fr->shift_vec[0];
419     fshift           = fr->fshift[0];
420     facel            = fr->ic->epsfac;
421     charge           = mdatoms->chargeA;
422
423     sh_ewald         = fr->ic->sh_ewald;
424     ewtab            = fr->ic->tabq_coul_F;
425     ewtabscale       = fr->ic->tabq_scale;
426     ewtabhalfspace   = 0.5/ewtabscale;
427
428     /* Setup water-specific parameters */
429     inr              = nlist->iinr[0];
430     iq0              = facel*charge[inr+0];
431     iq1              = facel*charge[inr+1];
432     iq2              = facel*charge[inr+2];
433
434     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
435     rcutoff          = fr->ic->rcoulomb;
436     rcutoff2         = rcutoff*rcutoff;
437
438     outeriter        = 0;
439     inneriter        = 0;
440
441     /* Start outer loop over neighborlists */
442     for(iidx=0; iidx<nri; iidx++)
443     {
444         /* Load shift vector for this list */
445         i_shift_offset   = DIM*shiftidx[iidx];
446         shX              = shiftvec[i_shift_offset+XX];
447         shY              = shiftvec[i_shift_offset+YY];
448         shZ              = shiftvec[i_shift_offset+ZZ];
449
450         /* Load limits for loop over neighbors */
451         j_index_start    = jindex[iidx];
452         j_index_end      = jindex[iidx+1];
453
454         /* Get outer coordinate index */
455         inr              = iinr[iidx];
456         i_coord_offset   = DIM*inr;
457
458         /* Load i particle coords and add shift vector */
459         ix0              = shX + x[i_coord_offset+DIM*0+XX];
460         iy0              = shY + x[i_coord_offset+DIM*0+YY];
461         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
462         ix1              = shX + x[i_coord_offset+DIM*1+XX];
463         iy1              = shY + x[i_coord_offset+DIM*1+YY];
464         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
465         ix2              = shX + x[i_coord_offset+DIM*2+XX];
466         iy2              = shY + x[i_coord_offset+DIM*2+YY];
467         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
468
469         fix0             = 0.0;
470         fiy0             = 0.0;
471         fiz0             = 0.0;
472         fix1             = 0.0;
473         fiy1             = 0.0;
474         fiz1             = 0.0;
475         fix2             = 0.0;
476         fiy2             = 0.0;
477         fiz2             = 0.0;
478
479         /* Start inner kernel loop */
480         for(jidx=j_index_start; jidx<j_index_end; jidx++)
481         {
482             /* Get j neighbor index, and coordinate index */
483             jnr              = jjnr[jidx];
484             j_coord_offset   = DIM*jnr;
485
486             /* load j atom coordinates */
487             jx0              = x[j_coord_offset+DIM*0+XX];
488             jy0              = x[j_coord_offset+DIM*0+YY];
489             jz0              = x[j_coord_offset+DIM*0+ZZ];
490
491             /* Calculate displacement vector */
492             dx00             = ix0 - jx0;
493             dy00             = iy0 - jy0;
494             dz00             = iz0 - jz0;
495             dx10             = ix1 - jx0;
496             dy10             = iy1 - jy0;
497             dz10             = iz1 - jz0;
498             dx20             = ix2 - jx0;
499             dy20             = iy2 - jy0;
500             dz20             = iz2 - jz0;
501
502             /* Calculate squared distance and things based on it */
503             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
504             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
505             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
506
507             rinv00           = 1.0/sqrt(rsq00);
508             rinv10           = 1.0/sqrt(rsq10);
509             rinv20           = 1.0/sqrt(rsq20);
510
511             rinvsq00         = rinv00*rinv00;
512             rinvsq10         = rinv10*rinv10;
513             rinvsq20         = rinv20*rinv20;
514
515             /* Load parameters for j particles */
516             jq0              = charge[jnr+0];
517
518             /**************************
519              * CALCULATE INTERACTIONS *
520              **************************/
521
522             if (rsq00<rcutoff2)
523             {
524
525             r00              = rsq00*rinv00;
526
527             qq00             = iq0*jq0;
528
529             /* EWALD ELECTROSTATICS */
530
531             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
532             ewrt             = r00*ewtabscale;
533             ewitab           = ewrt;
534             eweps            = ewrt-ewitab;
535             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
536             felec            = qq00*rinv00*(rinvsq00-felec);
537
538             fscal            = felec;
539
540             /* Calculate temporary vectorial force */
541             tx               = fscal*dx00;
542             ty               = fscal*dy00;
543             tz               = fscal*dz00;
544
545             /* Update vectorial force */
546             fix0            += tx;
547             fiy0            += ty;
548             fiz0            += tz;
549             f[j_coord_offset+DIM*0+XX] -= tx;
550             f[j_coord_offset+DIM*0+YY] -= ty;
551             f[j_coord_offset+DIM*0+ZZ] -= tz;
552
553             }
554
555             /**************************
556              * CALCULATE INTERACTIONS *
557              **************************/
558
559             if (rsq10<rcutoff2)
560             {
561
562             r10              = rsq10*rinv10;
563
564             qq10             = iq1*jq0;
565
566             /* EWALD ELECTROSTATICS */
567
568             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
569             ewrt             = r10*ewtabscale;
570             ewitab           = ewrt;
571             eweps            = ewrt-ewitab;
572             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
573             felec            = qq10*rinv10*(rinvsq10-felec);
574
575             fscal            = felec;
576
577             /* Calculate temporary vectorial force */
578             tx               = fscal*dx10;
579             ty               = fscal*dy10;
580             tz               = fscal*dz10;
581
582             /* Update vectorial force */
583             fix1            += tx;
584             fiy1            += ty;
585             fiz1            += tz;
586             f[j_coord_offset+DIM*0+XX] -= tx;
587             f[j_coord_offset+DIM*0+YY] -= ty;
588             f[j_coord_offset+DIM*0+ZZ] -= tz;
589
590             }
591
592             /**************************
593              * CALCULATE INTERACTIONS *
594              **************************/
595
596             if (rsq20<rcutoff2)
597             {
598
599             r20              = rsq20*rinv20;
600
601             qq20             = iq2*jq0;
602
603             /* EWALD ELECTROSTATICS */
604
605             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
606             ewrt             = r20*ewtabscale;
607             ewitab           = ewrt;
608             eweps            = ewrt-ewitab;
609             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
610             felec            = qq20*rinv20*(rinvsq20-felec);
611
612             fscal            = felec;
613
614             /* Calculate temporary vectorial force */
615             tx               = fscal*dx20;
616             ty               = fscal*dy20;
617             tz               = fscal*dz20;
618
619             /* Update vectorial force */
620             fix2            += tx;
621             fiy2            += ty;
622             fiz2            += tz;
623             f[j_coord_offset+DIM*0+XX] -= tx;
624             f[j_coord_offset+DIM*0+YY] -= ty;
625             f[j_coord_offset+DIM*0+ZZ] -= tz;
626
627             }
628
629             /* Inner loop uses 102 flops */
630         }
631         /* End of innermost loop */
632
633         tx = ty = tz = 0;
634         f[i_coord_offset+DIM*0+XX] += fix0;
635         f[i_coord_offset+DIM*0+YY] += fiy0;
636         f[i_coord_offset+DIM*0+ZZ] += fiz0;
637         tx                         += fix0;
638         ty                         += fiy0;
639         tz                         += fiz0;
640         f[i_coord_offset+DIM*1+XX] += fix1;
641         f[i_coord_offset+DIM*1+YY] += fiy1;
642         f[i_coord_offset+DIM*1+ZZ] += fiz1;
643         tx                         += fix1;
644         ty                         += fiy1;
645         tz                         += fiz1;
646         f[i_coord_offset+DIM*2+XX] += fix2;
647         f[i_coord_offset+DIM*2+YY] += fiy2;
648         f[i_coord_offset+DIM*2+ZZ] += fiz2;
649         tx                         += fix2;
650         ty                         += fiy2;
651         tz                         += fiz2;
652         fshift[i_shift_offset+XX]  += tx;
653         fshift[i_shift_offset+YY]  += ty;
654         fshift[i_shift_offset+ZZ]  += tz;
655
656         /* Increment number of inner iterations */
657         inneriter                  += j_index_end - j_index_start;
658
659         /* Outer loop uses 30 flops */
660     }
661
662     /* Increment number of outer iterations */
663     outeriter        += nri;
664
665     /* Update outer/inner flops */
666
667     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_F,outeriter*30 + inneriter*102);
668 }