Remove all unnecessary HAVE_CONFIG_H
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecEwSh_VdwNone_GeomW4P1_c.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS c kernel generator.
37  */
38 #include "config.h"
39
40 #include <math.h>
41
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "nrnb.h"
46
47 /*
48  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSh_VdwNone_GeomW4P1_VF_c
49  * Electrostatics interaction: Ewald
50  * VdW interaction:            None
51  * Geometry:                   Water4-Particle
52  * Calculate force/pot:        PotentialAndForce
53  */
54 void
55 nb_kernel_ElecEwSh_VdwNone_GeomW4P1_VF_c
56                     (t_nblist                    * gmx_restrict       nlist,
57                      rvec                        * gmx_restrict          xx,
58                      rvec                        * gmx_restrict          ff,
59                      t_forcerec                  * gmx_restrict          fr,
60                      t_mdatoms                   * gmx_restrict     mdatoms,
61                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
62                      t_nrnb                      * gmx_restrict        nrnb)
63 {
64     int              i_shift_offset,i_coord_offset,j_coord_offset;
65     int              j_index_start,j_index_end;
66     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
67     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
68     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
69     real             *shiftvec,*fshift,*x,*f;
70     int              vdwioffset1;
71     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
72     int              vdwioffset2;
73     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
74     int              vdwioffset3;
75     real             ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
76     int              vdwjidx0;
77     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
78     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
79     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
80     real             dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
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->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     iq1              = facel*charge[inr+1];
109     iq2              = facel*charge[inr+2];
110     iq3              = facel*charge[inr+3];
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->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         ix1              = shX + x[i_coord_offset+DIM*1+XX];
138         iy1              = shY + x[i_coord_offset+DIM*1+YY];
139         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
140         ix2              = shX + x[i_coord_offset+DIM*2+XX];
141         iy2              = shY + x[i_coord_offset+DIM*2+YY];
142         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
143         ix3              = shX + x[i_coord_offset+DIM*3+XX];
144         iy3              = shY + x[i_coord_offset+DIM*3+YY];
145         iz3              = shZ + x[i_coord_offset+DIM*3+ZZ];
146
147         fix1             = 0.0;
148         fiy1             = 0.0;
149         fiz1             = 0.0;
150         fix2             = 0.0;
151         fiy2             = 0.0;
152         fiz2             = 0.0;
153         fix3             = 0.0;
154         fiy3             = 0.0;
155         fiz3             = 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             dx10             = ix1 - jx0;
174             dy10             = iy1 - jy0;
175             dz10             = iz1 - jz0;
176             dx20             = ix2 - jx0;
177             dy20             = iy2 - jy0;
178             dz20             = iz2 - jz0;
179             dx30             = ix3 - jx0;
180             dy30             = iy3 - jy0;
181             dz30             = iz3 - jz0;
182
183             /* Calculate squared distance and things based on it */
184             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
185             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
186             rsq30            = dx30*dx30+dy30*dy30+dz30*dz30;
187
188             rinv10           = gmx_invsqrt(rsq10);
189             rinv20           = gmx_invsqrt(rsq20);
190             rinv30           = gmx_invsqrt(rsq30);
191
192             rinvsq10         = rinv10*rinv10;
193             rinvsq20         = rinv20*rinv20;
194             rinvsq30         = rinv30*rinv30;
195
196             /* Load parameters for j particles */
197             jq0              = charge[jnr+0];
198
199             /**************************
200              * CALCULATE INTERACTIONS *
201              **************************/
202
203             if (rsq10<rcutoff2)
204             {
205
206             r10              = rsq10*rinv10;
207
208             qq10             = iq1*jq0;
209
210             /* EWALD ELECTROSTATICS */
211
212             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
213             ewrt             = r10*ewtabscale;
214             ewitab           = ewrt;
215             eweps            = ewrt-ewitab;
216             ewitab           = 4*ewitab;
217             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
218             velec            = qq10*((rinv10-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
219             felec            = qq10*rinv10*(rinvsq10-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*dx10;
228             ty               = fscal*dy10;
229             tz               = fscal*dz10;
230
231             /* Update vectorial force */
232             fix1            += tx;
233             fiy1            += ty;
234             fiz1            += 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 (rsq20<rcutoff2)
246             {
247
248             r20              = rsq20*rinv20;
249
250             qq20             = iq2*jq0;
251
252             /* EWALD ELECTROSTATICS */
253
254             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
255             ewrt             = r20*ewtabscale;
256             ewitab           = ewrt;
257             eweps            = ewrt-ewitab;
258             ewitab           = 4*ewitab;
259             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
260             velec            = qq20*((rinv20-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
261             felec            = qq20*rinv20*(rinvsq20-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*dx20;
270             ty               = fscal*dy20;
271             tz               = fscal*dz20;
272
273             /* Update vectorial force */
274             fix2            += tx;
275             fiy2            += ty;
276             fiz2            += 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 (rsq30<rcutoff2)
288             {
289
290             r30              = rsq30*rinv30;
291
292             qq30             = iq3*jq0;
293
294             /* EWALD ELECTROSTATICS */
295
296             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
297             ewrt             = r30*ewtabscale;
298             ewitab           = ewrt;
299             eweps            = ewrt-ewitab;
300             ewitab           = 4*ewitab;
301             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
302             velec            = qq30*((rinv30-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
303             felec            = qq30*rinv30*(rinvsq30-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*dx30;
312             ty               = fscal*dy30;
313             tz               = fscal*dz30;
314
315             /* Update vectorial force */
316             fix3            += tx;
317             fiy3            += ty;
318             fiz3            += 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*1+XX] += fix1;
331         f[i_coord_offset+DIM*1+YY] += fiy1;
332         f[i_coord_offset+DIM*1+ZZ] += fiz1;
333         tx                         += fix1;
334         ty                         += fiy1;
335         tz                         += fiz1;
336         f[i_coord_offset+DIM*2+XX] += fix2;
337         f[i_coord_offset+DIM*2+YY] += fiy2;
338         f[i_coord_offset+DIM*2+ZZ] += fiz2;
339         tx                         += fix2;
340         ty                         += fiy2;
341         tz                         += fiz2;
342         f[i_coord_offset+DIM*3+XX] += fix3;
343         f[i_coord_offset+DIM*3+YY] += fiy3;
344         f[i_coord_offset+DIM*3+ZZ] += fiz3;
345         tx                         += fix3;
346         ty                         += fiy3;
347         tz                         += fiz3;
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_W4_VF,outeriter*31 + inneriter*126);
368 }
369 /*
370  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSh_VdwNone_GeomW4P1_F_c
371  * Electrostatics interaction: Ewald
372  * VdW interaction:            None
373  * Geometry:                   Water4-Particle
374  * Calculate force/pot:        Force
375  */
376 void
377 nb_kernel_ElecEwSh_VdwNone_GeomW4P1_F_c
378                     (t_nblist                    * gmx_restrict       nlist,
379                      rvec                        * gmx_restrict          xx,
380                      rvec                        * gmx_restrict          ff,
381                      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              vdwioffset1;
393     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
394     int              vdwioffset2;
395     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
396     int              vdwioffset3;
397     real             ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
398     int              vdwjidx0;
399     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
400     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
401     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
402     real             dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
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->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     iq1              = facel*charge[inr+1];
431     iq2              = facel*charge[inr+2];
432     iq3              = facel*charge[inr+3];
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->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         ix1              = shX + x[i_coord_offset+DIM*1+XX];
460         iy1              = shY + x[i_coord_offset+DIM*1+YY];
461         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
462         ix2              = shX + x[i_coord_offset+DIM*2+XX];
463         iy2              = shY + x[i_coord_offset+DIM*2+YY];
464         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
465         ix3              = shX + x[i_coord_offset+DIM*3+XX];
466         iy3              = shY + x[i_coord_offset+DIM*3+YY];
467         iz3              = shZ + x[i_coord_offset+DIM*3+ZZ];
468
469         fix1             = 0.0;
470         fiy1             = 0.0;
471         fiz1             = 0.0;
472         fix2             = 0.0;
473         fiy2             = 0.0;
474         fiz2             = 0.0;
475         fix3             = 0.0;
476         fiy3             = 0.0;
477         fiz3             = 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             dx10             = ix1 - jx0;
493             dy10             = iy1 - jy0;
494             dz10             = iz1 - jz0;
495             dx20             = ix2 - jx0;
496             dy20             = iy2 - jy0;
497             dz20             = iz2 - jz0;
498             dx30             = ix3 - jx0;
499             dy30             = iy3 - jy0;
500             dz30             = iz3 - jz0;
501
502             /* Calculate squared distance and things based on it */
503             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
504             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
505             rsq30            = dx30*dx30+dy30*dy30+dz30*dz30;
506
507             rinv10           = gmx_invsqrt(rsq10);
508             rinv20           = gmx_invsqrt(rsq20);
509             rinv30           = gmx_invsqrt(rsq30);
510
511             rinvsq10         = rinv10*rinv10;
512             rinvsq20         = rinv20*rinv20;
513             rinvsq30         = rinv30*rinv30;
514
515             /* Load parameters for j particles */
516             jq0              = charge[jnr+0];
517
518             /**************************
519              * CALCULATE INTERACTIONS *
520              **************************/
521
522             if (rsq10<rcutoff2)
523             {
524
525             r10              = rsq10*rinv10;
526
527             qq10             = iq1*jq0;
528
529             /* EWALD ELECTROSTATICS */
530
531             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
532             ewrt             = r10*ewtabscale;
533             ewitab           = ewrt;
534             eweps            = ewrt-ewitab;
535             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
536             felec            = qq10*rinv10*(rinvsq10-felec);
537
538             fscal            = felec;
539
540             /* Calculate temporary vectorial force */
541             tx               = fscal*dx10;
542             ty               = fscal*dy10;
543             tz               = fscal*dz10;
544
545             /* Update vectorial force */
546             fix1            += tx;
547             fiy1            += ty;
548             fiz1            += 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 (rsq20<rcutoff2)
560             {
561
562             r20              = rsq20*rinv20;
563
564             qq20             = iq2*jq0;
565
566             /* EWALD ELECTROSTATICS */
567
568             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
569             ewrt             = r20*ewtabscale;
570             ewitab           = ewrt;
571             eweps            = ewrt-ewitab;
572             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
573             felec            = qq20*rinv20*(rinvsq20-felec);
574
575             fscal            = felec;
576
577             /* Calculate temporary vectorial force */
578             tx               = fscal*dx20;
579             ty               = fscal*dy20;
580             tz               = fscal*dz20;
581
582             /* Update vectorial force */
583             fix2            += tx;
584             fiy2            += ty;
585             fiz2            += 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 (rsq30<rcutoff2)
597             {
598
599             r30              = rsq30*rinv30;
600
601             qq30             = iq3*jq0;
602
603             /* EWALD ELECTROSTATICS */
604
605             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
606             ewrt             = r30*ewtabscale;
607             ewitab           = ewrt;
608             eweps            = ewrt-ewitab;
609             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
610             felec            = qq30*rinv30*(rinvsq30-felec);
611
612             fscal            = felec;
613
614             /* Calculate temporary vectorial force */
615             tx               = fscal*dx30;
616             ty               = fscal*dy30;
617             tz               = fscal*dz30;
618
619             /* Update vectorial force */
620             fix3            += tx;
621             fiy3            += ty;
622             fiz3            += 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*1+XX] += fix1;
635         f[i_coord_offset+DIM*1+YY] += fiy1;
636         f[i_coord_offset+DIM*1+ZZ] += fiz1;
637         tx                         += fix1;
638         ty                         += fiy1;
639         tz                         += fiz1;
640         f[i_coord_offset+DIM*2+XX] += fix2;
641         f[i_coord_offset+DIM*2+YY] += fiy2;
642         f[i_coord_offset+DIM*2+ZZ] += fiz2;
643         tx                         += fix2;
644         ty                         += fiy2;
645         tz                         += fiz2;
646         f[i_coord_offset+DIM*3+XX] += fix3;
647         f[i_coord_offset+DIM*3+YY] += fiy3;
648         f[i_coord_offset+DIM*3+ZZ] += fiz3;
649         tx                         += fix3;
650         ty                         += fiy3;
651         tz                         += fiz3;
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_W4_F,outeriter*30 + inneriter*102);
668 }