717e0fa5733cb46061c21e8a572d92ed90ea4ade
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecEw_VdwLJ_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_ElecEw_VdwLJ_GeomW4P1_VF_c
49  * Electrostatics interaction: Ewald
50  * VdW interaction:            LennardJones
51  * Geometry:                   Water4-Particle
52  * Calculate force/pot:        PotentialAndForce
53  */
54 void
55 nb_kernel_ElecEw_VdwLJ_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              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              vdwioffset3;
77     real             ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
78     int              vdwjidx0;
79     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
80     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
81     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
82     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
83     real             dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
84     real             velec,felec,velecsum,facel,crf,krf,krf2;
85     real             *charge;
86     int              nvdwtype;
87     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
88     int              *vdwtype;
89     real             *vdwparam;
90     int              ewitab;
91     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
92     real             *ewtab;
93
94     x                = xx[0];
95     f                = ff[0];
96
97     nri              = nlist->nri;
98     iinr             = nlist->iinr;
99     jindex           = nlist->jindex;
100     jjnr             = nlist->jjnr;
101     shiftidx         = nlist->shift;
102     gid              = nlist->gid;
103     shiftvec         = fr->shift_vec[0];
104     fshift           = fr->fshift[0];
105     facel            = fr->epsfac;
106     charge           = mdatoms->chargeA;
107     nvdwtype         = fr->ntype;
108     vdwparam         = fr->nbfp;
109     vdwtype          = mdatoms->typeA;
110
111     sh_ewald         = fr->ic->sh_ewald;
112     ewtab            = fr->ic->tabq_coul_FDV0;
113     ewtabscale       = fr->ic->tabq_scale;
114     ewtabhalfspace   = 0.5/ewtabscale;
115
116     /* Setup water-specific parameters */
117     inr              = nlist->iinr[0];
118     iq1              = facel*charge[inr+1];
119     iq2              = facel*charge[inr+2];
120     iq3              = facel*charge[inr+3];
121     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
122
123     outeriter        = 0;
124     inneriter        = 0;
125
126     /* Start outer loop over neighborlists */
127     for(iidx=0; iidx<nri; iidx++)
128     {
129         /* Load shift vector for this list */
130         i_shift_offset   = DIM*shiftidx[iidx];
131         shX              = shiftvec[i_shift_offset+XX];
132         shY              = shiftvec[i_shift_offset+YY];
133         shZ              = shiftvec[i_shift_offset+ZZ];
134
135         /* Load limits for loop over neighbors */
136         j_index_start    = jindex[iidx];
137         j_index_end      = jindex[iidx+1];
138
139         /* Get outer coordinate index */
140         inr              = iinr[iidx];
141         i_coord_offset   = DIM*inr;
142
143         /* Load i particle coords and add shift vector */
144         ix0              = shX + x[i_coord_offset+DIM*0+XX];
145         iy0              = shY + x[i_coord_offset+DIM*0+YY];
146         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
147         ix1              = shX + x[i_coord_offset+DIM*1+XX];
148         iy1              = shY + x[i_coord_offset+DIM*1+YY];
149         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
150         ix2              = shX + x[i_coord_offset+DIM*2+XX];
151         iy2              = shY + x[i_coord_offset+DIM*2+YY];
152         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
153         ix3              = shX + x[i_coord_offset+DIM*3+XX];
154         iy3              = shY + x[i_coord_offset+DIM*3+YY];
155         iz3              = shZ + x[i_coord_offset+DIM*3+ZZ];
156
157         fix0             = 0.0;
158         fiy0             = 0.0;
159         fiz0             = 0.0;
160         fix1             = 0.0;
161         fiy1             = 0.0;
162         fiz1             = 0.0;
163         fix2             = 0.0;
164         fiy2             = 0.0;
165         fiz2             = 0.0;
166         fix3             = 0.0;
167         fiy3             = 0.0;
168         fiz3             = 0.0;
169
170         /* Reset potential sums */
171         velecsum         = 0.0;
172         vvdwsum          = 0.0;
173
174         /* Start inner kernel loop */
175         for(jidx=j_index_start; jidx<j_index_end; jidx++)
176         {
177             /* Get j neighbor index, and coordinate index */
178             jnr              = jjnr[jidx];
179             j_coord_offset   = DIM*jnr;
180
181             /* load j atom coordinates */
182             jx0              = x[j_coord_offset+DIM*0+XX];
183             jy0              = x[j_coord_offset+DIM*0+YY];
184             jz0              = x[j_coord_offset+DIM*0+ZZ];
185
186             /* Calculate displacement vector */
187             dx00             = ix0 - jx0;
188             dy00             = iy0 - jy0;
189             dz00             = iz0 - jz0;
190             dx10             = ix1 - jx0;
191             dy10             = iy1 - jy0;
192             dz10             = iz1 - jz0;
193             dx20             = ix2 - jx0;
194             dy20             = iy2 - jy0;
195             dz20             = iz2 - jz0;
196             dx30             = ix3 - jx0;
197             dy30             = iy3 - jy0;
198             dz30             = iz3 - jz0;
199
200             /* Calculate squared distance and things based on it */
201             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
202             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
203             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
204             rsq30            = dx30*dx30+dy30*dy30+dz30*dz30;
205
206             rinv10           = gmx_invsqrt(rsq10);
207             rinv20           = gmx_invsqrt(rsq20);
208             rinv30           = gmx_invsqrt(rsq30);
209
210             rinvsq00         = 1.0/rsq00;
211             rinvsq10         = rinv10*rinv10;
212             rinvsq20         = rinv20*rinv20;
213             rinvsq30         = rinv30*rinv30;
214
215             /* Load parameters for j particles */
216             jq0              = charge[jnr+0];
217             vdwjidx0         = 2*vdwtype[jnr+0];
218
219             /**************************
220              * CALCULATE INTERACTIONS *
221              **************************/
222
223             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
224             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
225
226             /* LENNARD-JONES DISPERSION/REPULSION */
227
228             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
229             vvdw6            = c6_00*rinvsix;
230             vvdw12           = c12_00*rinvsix*rinvsix;
231             vvdw             = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
232             fvdw             = (vvdw12-vvdw6)*rinvsq00;
233
234             /* Update potential sums from outer loop */
235             vvdwsum         += vvdw;
236
237             fscal            = fvdw;
238
239             /* Calculate temporary vectorial force */
240             tx               = fscal*dx00;
241             ty               = fscal*dy00;
242             tz               = fscal*dz00;
243
244             /* Update vectorial force */
245             fix0            += tx;
246             fiy0            += ty;
247             fiz0            += tz;
248             f[j_coord_offset+DIM*0+XX] -= tx;
249             f[j_coord_offset+DIM*0+YY] -= ty;
250             f[j_coord_offset+DIM*0+ZZ] -= tz;
251
252             /**************************
253              * CALCULATE INTERACTIONS *
254              **************************/
255
256             r10              = rsq10*rinv10;
257
258             qq10             = iq1*jq0;
259
260             /* EWALD ELECTROSTATICS */
261
262             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
263             ewrt             = r10*ewtabscale;
264             ewitab           = ewrt;
265             eweps            = ewrt-ewitab;
266             ewitab           = 4*ewitab;
267             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
268             velec            = qq10*(rinv10-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
269             felec            = qq10*rinv10*(rinvsq10-felec);
270
271             /* Update potential sums from outer loop */
272             velecsum        += velec;
273
274             fscal            = felec;
275
276             /* Calculate temporary vectorial force */
277             tx               = fscal*dx10;
278             ty               = fscal*dy10;
279             tz               = fscal*dz10;
280
281             /* Update vectorial force */
282             fix1            += tx;
283             fiy1            += ty;
284             fiz1            += tz;
285             f[j_coord_offset+DIM*0+XX] -= tx;
286             f[j_coord_offset+DIM*0+YY] -= ty;
287             f[j_coord_offset+DIM*0+ZZ] -= tz;
288
289             /**************************
290              * CALCULATE INTERACTIONS *
291              **************************/
292
293             r20              = rsq20*rinv20;
294
295             qq20             = iq2*jq0;
296
297             /* EWALD ELECTROSTATICS */
298
299             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
300             ewrt             = r20*ewtabscale;
301             ewitab           = ewrt;
302             eweps            = ewrt-ewitab;
303             ewitab           = 4*ewitab;
304             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
305             velec            = qq20*(rinv20-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
306             felec            = qq20*rinv20*(rinvsq20-felec);
307
308             /* Update potential sums from outer loop */
309             velecsum        += velec;
310
311             fscal            = felec;
312
313             /* Calculate temporary vectorial force */
314             tx               = fscal*dx20;
315             ty               = fscal*dy20;
316             tz               = fscal*dz20;
317
318             /* Update vectorial force */
319             fix2            += tx;
320             fiy2            += ty;
321             fiz2            += tz;
322             f[j_coord_offset+DIM*0+XX] -= tx;
323             f[j_coord_offset+DIM*0+YY] -= ty;
324             f[j_coord_offset+DIM*0+ZZ] -= tz;
325
326             /**************************
327              * CALCULATE INTERACTIONS *
328              **************************/
329
330             r30              = rsq30*rinv30;
331
332             qq30             = iq3*jq0;
333
334             /* EWALD ELECTROSTATICS */
335
336             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
337             ewrt             = r30*ewtabscale;
338             ewitab           = ewrt;
339             eweps            = ewrt-ewitab;
340             ewitab           = 4*ewitab;
341             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
342             velec            = qq30*(rinv30-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
343             felec            = qq30*rinv30*(rinvsq30-felec);
344
345             /* Update potential sums from outer loop */
346             velecsum        += velec;
347
348             fscal            = felec;
349
350             /* Calculate temporary vectorial force */
351             tx               = fscal*dx30;
352             ty               = fscal*dy30;
353             tz               = fscal*dz30;
354
355             /* Update vectorial force */
356             fix3            += tx;
357             fiy3            += ty;
358             fiz3            += tz;
359             f[j_coord_offset+DIM*0+XX] -= tx;
360             f[j_coord_offset+DIM*0+YY] -= ty;
361             f[j_coord_offset+DIM*0+ZZ] -= tz;
362
363             /* Inner loop uses 155 flops */
364         }
365         /* End of innermost loop */
366
367         tx = ty = tz = 0;
368         f[i_coord_offset+DIM*0+XX] += fix0;
369         f[i_coord_offset+DIM*0+YY] += fiy0;
370         f[i_coord_offset+DIM*0+ZZ] += fiz0;
371         tx                         += fix0;
372         ty                         += fiy0;
373         tz                         += fiz0;
374         f[i_coord_offset+DIM*1+XX] += fix1;
375         f[i_coord_offset+DIM*1+YY] += fiy1;
376         f[i_coord_offset+DIM*1+ZZ] += fiz1;
377         tx                         += fix1;
378         ty                         += fiy1;
379         tz                         += fiz1;
380         f[i_coord_offset+DIM*2+XX] += fix2;
381         f[i_coord_offset+DIM*2+YY] += fiy2;
382         f[i_coord_offset+DIM*2+ZZ] += fiz2;
383         tx                         += fix2;
384         ty                         += fiy2;
385         tz                         += fiz2;
386         f[i_coord_offset+DIM*3+XX] += fix3;
387         f[i_coord_offset+DIM*3+YY] += fiy3;
388         f[i_coord_offset+DIM*3+ZZ] += fiz3;
389         tx                         += fix3;
390         ty                         += fiy3;
391         tz                         += fiz3;
392         fshift[i_shift_offset+XX]  += tx;
393         fshift[i_shift_offset+YY]  += ty;
394         fshift[i_shift_offset+ZZ]  += tz;
395
396         ggid                        = gid[iidx];
397         /* Update potential energies */
398         kernel_data->energygrp_elec[ggid] += velecsum;
399         kernel_data->energygrp_vdw[ggid] += vvdwsum;
400
401         /* Increment number of inner iterations */
402         inneriter                  += j_index_end - j_index_start;
403
404         /* Outer loop uses 41 flops */
405     }
406
407     /* Increment number of outer iterations */
408     outeriter        += nri;
409
410     /* Update outer/inner flops */
411
412     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*41 + inneriter*155);
413 }
414 /*
415  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwLJ_GeomW4P1_F_c
416  * Electrostatics interaction: Ewald
417  * VdW interaction:            LennardJones
418  * Geometry:                   Water4-Particle
419  * Calculate force/pot:        Force
420  */
421 void
422 nb_kernel_ElecEw_VdwLJ_GeomW4P1_F_c
423                     (t_nblist                    * gmx_restrict       nlist,
424                      rvec                        * gmx_restrict          xx,
425                      rvec                        * gmx_restrict          ff,
426                      t_forcerec                  * gmx_restrict          fr,
427                      t_mdatoms                   * gmx_restrict     mdatoms,
428                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
429                      t_nrnb                      * gmx_restrict        nrnb)
430 {
431     int              i_shift_offset,i_coord_offset,j_coord_offset;
432     int              j_index_start,j_index_end;
433     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
434     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
435     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
436     real             *shiftvec,*fshift,*x,*f;
437     int              vdwioffset0;
438     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
439     int              vdwioffset1;
440     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
441     int              vdwioffset2;
442     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
443     int              vdwioffset3;
444     real             ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
445     int              vdwjidx0;
446     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
447     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
448     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
449     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
450     real             dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
451     real             velec,felec,velecsum,facel,crf,krf,krf2;
452     real             *charge;
453     int              nvdwtype;
454     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
455     int              *vdwtype;
456     real             *vdwparam;
457     int              ewitab;
458     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
459     real             *ewtab;
460
461     x                = xx[0];
462     f                = ff[0];
463
464     nri              = nlist->nri;
465     iinr             = nlist->iinr;
466     jindex           = nlist->jindex;
467     jjnr             = nlist->jjnr;
468     shiftidx         = nlist->shift;
469     gid              = nlist->gid;
470     shiftvec         = fr->shift_vec[0];
471     fshift           = fr->fshift[0];
472     facel            = fr->epsfac;
473     charge           = mdatoms->chargeA;
474     nvdwtype         = fr->ntype;
475     vdwparam         = fr->nbfp;
476     vdwtype          = mdatoms->typeA;
477
478     sh_ewald         = fr->ic->sh_ewald;
479     ewtab            = fr->ic->tabq_coul_F;
480     ewtabscale       = fr->ic->tabq_scale;
481     ewtabhalfspace   = 0.5/ewtabscale;
482
483     /* Setup water-specific parameters */
484     inr              = nlist->iinr[0];
485     iq1              = facel*charge[inr+1];
486     iq2              = facel*charge[inr+2];
487     iq3              = facel*charge[inr+3];
488     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
489
490     outeriter        = 0;
491     inneriter        = 0;
492
493     /* Start outer loop over neighborlists */
494     for(iidx=0; iidx<nri; iidx++)
495     {
496         /* Load shift vector for this list */
497         i_shift_offset   = DIM*shiftidx[iidx];
498         shX              = shiftvec[i_shift_offset+XX];
499         shY              = shiftvec[i_shift_offset+YY];
500         shZ              = shiftvec[i_shift_offset+ZZ];
501
502         /* Load limits for loop over neighbors */
503         j_index_start    = jindex[iidx];
504         j_index_end      = jindex[iidx+1];
505
506         /* Get outer coordinate index */
507         inr              = iinr[iidx];
508         i_coord_offset   = DIM*inr;
509
510         /* Load i particle coords and add shift vector */
511         ix0              = shX + x[i_coord_offset+DIM*0+XX];
512         iy0              = shY + x[i_coord_offset+DIM*0+YY];
513         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
514         ix1              = shX + x[i_coord_offset+DIM*1+XX];
515         iy1              = shY + x[i_coord_offset+DIM*1+YY];
516         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
517         ix2              = shX + x[i_coord_offset+DIM*2+XX];
518         iy2              = shY + x[i_coord_offset+DIM*2+YY];
519         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
520         ix3              = shX + x[i_coord_offset+DIM*3+XX];
521         iy3              = shY + x[i_coord_offset+DIM*3+YY];
522         iz3              = shZ + x[i_coord_offset+DIM*3+ZZ];
523
524         fix0             = 0.0;
525         fiy0             = 0.0;
526         fiz0             = 0.0;
527         fix1             = 0.0;
528         fiy1             = 0.0;
529         fiz1             = 0.0;
530         fix2             = 0.0;
531         fiy2             = 0.0;
532         fiz2             = 0.0;
533         fix3             = 0.0;
534         fiy3             = 0.0;
535         fiz3             = 0.0;
536
537         /* Start inner kernel loop */
538         for(jidx=j_index_start; jidx<j_index_end; jidx++)
539         {
540             /* Get j neighbor index, and coordinate index */
541             jnr              = jjnr[jidx];
542             j_coord_offset   = DIM*jnr;
543
544             /* load j atom coordinates */
545             jx0              = x[j_coord_offset+DIM*0+XX];
546             jy0              = x[j_coord_offset+DIM*0+YY];
547             jz0              = x[j_coord_offset+DIM*0+ZZ];
548
549             /* Calculate displacement vector */
550             dx00             = ix0 - jx0;
551             dy00             = iy0 - jy0;
552             dz00             = iz0 - jz0;
553             dx10             = ix1 - jx0;
554             dy10             = iy1 - jy0;
555             dz10             = iz1 - jz0;
556             dx20             = ix2 - jx0;
557             dy20             = iy2 - jy0;
558             dz20             = iz2 - jz0;
559             dx30             = ix3 - jx0;
560             dy30             = iy3 - jy0;
561             dz30             = iz3 - jz0;
562
563             /* Calculate squared distance and things based on it */
564             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
565             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
566             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
567             rsq30            = dx30*dx30+dy30*dy30+dz30*dz30;
568
569             rinv10           = gmx_invsqrt(rsq10);
570             rinv20           = gmx_invsqrt(rsq20);
571             rinv30           = gmx_invsqrt(rsq30);
572
573             rinvsq00         = 1.0/rsq00;
574             rinvsq10         = rinv10*rinv10;
575             rinvsq20         = rinv20*rinv20;
576             rinvsq30         = rinv30*rinv30;
577
578             /* Load parameters for j particles */
579             jq0              = charge[jnr+0];
580             vdwjidx0         = 2*vdwtype[jnr+0];
581
582             /**************************
583              * CALCULATE INTERACTIONS *
584              **************************/
585
586             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
587             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
588
589             /* LENNARD-JONES DISPERSION/REPULSION */
590
591             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
592             fvdw             = (c12_00*rinvsix-c6_00)*rinvsix*rinvsq00;
593
594             fscal            = fvdw;
595
596             /* Calculate temporary vectorial force */
597             tx               = fscal*dx00;
598             ty               = fscal*dy00;
599             tz               = fscal*dz00;
600
601             /* Update vectorial force */
602             fix0            += tx;
603             fiy0            += ty;
604             fiz0            += tz;
605             f[j_coord_offset+DIM*0+XX] -= tx;
606             f[j_coord_offset+DIM*0+YY] -= ty;
607             f[j_coord_offset+DIM*0+ZZ] -= tz;
608
609             /**************************
610              * CALCULATE INTERACTIONS *
611              **************************/
612
613             r10              = rsq10*rinv10;
614
615             qq10             = iq1*jq0;
616
617             /* EWALD ELECTROSTATICS */
618
619             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
620             ewrt             = r10*ewtabscale;
621             ewitab           = ewrt;
622             eweps            = ewrt-ewitab;
623             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
624             felec            = qq10*rinv10*(rinvsq10-felec);
625
626             fscal            = felec;
627
628             /* Calculate temporary vectorial force */
629             tx               = fscal*dx10;
630             ty               = fscal*dy10;
631             tz               = fscal*dz10;
632
633             /* Update vectorial force */
634             fix1            += tx;
635             fiy1            += ty;
636             fiz1            += tz;
637             f[j_coord_offset+DIM*0+XX] -= tx;
638             f[j_coord_offset+DIM*0+YY] -= ty;
639             f[j_coord_offset+DIM*0+ZZ] -= tz;
640
641             /**************************
642              * CALCULATE INTERACTIONS *
643              **************************/
644
645             r20              = rsq20*rinv20;
646
647             qq20             = iq2*jq0;
648
649             /* EWALD ELECTROSTATICS */
650
651             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
652             ewrt             = r20*ewtabscale;
653             ewitab           = ewrt;
654             eweps            = ewrt-ewitab;
655             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
656             felec            = qq20*rinv20*(rinvsq20-felec);
657
658             fscal            = felec;
659
660             /* Calculate temporary vectorial force */
661             tx               = fscal*dx20;
662             ty               = fscal*dy20;
663             tz               = fscal*dz20;
664
665             /* Update vectorial force */
666             fix2            += tx;
667             fiy2            += ty;
668             fiz2            += tz;
669             f[j_coord_offset+DIM*0+XX] -= tx;
670             f[j_coord_offset+DIM*0+YY] -= ty;
671             f[j_coord_offset+DIM*0+ZZ] -= tz;
672
673             /**************************
674              * CALCULATE INTERACTIONS *
675              **************************/
676
677             r30              = rsq30*rinv30;
678
679             qq30             = iq3*jq0;
680
681             /* EWALD ELECTROSTATICS */
682
683             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
684             ewrt             = r30*ewtabscale;
685             ewitab           = ewrt;
686             eweps            = ewrt-ewitab;
687             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
688             felec            = qq30*rinv30*(rinvsq30-felec);
689
690             fscal            = felec;
691
692             /* Calculate temporary vectorial force */
693             tx               = fscal*dx30;
694             ty               = fscal*dy30;
695             tz               = fscal*dz30;
696
697             /* Update vectorial force */
698             fix3            += tx;
699             fiy3            += ty;
700             fiz3            += tz;
701             f[j_coord_offset+DIM*0+XX] -= tx;
702             f[j_coord_offset+DIM*0+YY] -= ty;
703             f[j_coord_offset+DIM*0+ZZ] -= tz;
704
705             /* Inner loop uses 129 flops */
706         }
707         /* End of innermost loop */
708
709         tx = ty = tz = 0;
710         f[i_coord_offset+DIM*0+XX] += fix0;
711         f[i_coord_offset+DIM*0+YY] += fiy0;
712         f[i_coord_offset+DIM*0+ZZ] += fiz0;
713         tx                         += fix0;
714         ty                         += fiy0;
715         tz                         += fiz0;
716         f[i_coord_offset+DIM*1+XX] += fix1;
717         f[i_coord_offset+DIM*1+YY] += fiy1;
718         f[i_coord_offset+DIM*1+ZZ] += fiz1;
719         tx                         += fix1;
720         ty                         += fiy1;
721         tz                         += fiz1;
722         f[i_coord_offset+DIM*2+XX] += fix2;
723         f[i_coord_offset+DIM*2+YY] += fiy2;
724         f[i_coord_offset+DIM*2+ZZ] += fiz2;
725         tx                         += fix2;
726         ty                         += fiy2;
727         tz                         += fiz2;
728         f[i_coord_offset+DIM*3+XX] += fix3;
729         f[i_coord_offset+DIM*3+YY] += fiy3;
730         f[i_coord_offset+DIM*3+ZZ] += fiz3;
731         tx                         += fix3;
732         ty                         += fiy3;
733         tz                         += fiz3;
734         fshift[i_shift_offset+XX]  += tx;
735         fshift[i_shift_offset+YY]  += ty;
736         fshift[i_shift_offset+ZZ]  += tz;
737
738         /* Increment number of inner iterations */
739         inneriter                  += j_index_end - j_index_start;
740
741         /* Outer loop uses 39 flops */
742     }
743
744     /* Increment number of outer iterations */
745     outeriter        += nri;
746
747     /* Update outer/inner flops */
748
749     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*39 + inneriter*129);
750 }