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