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