Merge remote-tracking branch 'origin/release-4-6' into HEAD
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_adress_c / nb_kernel231_c_adress.c
1 /*
2  * Copyright (c) Erik Lindahl, David van der Spoel 2003
3  * 
4  * This file is generated automatically at compile time
5  * by the program mknb in the Gromacs distribution.
6  *
7  * Options used when generation this file:
8  * Language:         c
9  * Precision:        single
10  * Threads:          yes
11  * Software invsqrt: no
12  * PowerPC invsqrt:  no
13  * Prefetch forces:  no
14  * Adress kernel:  yes
15  * Comments:         no
16  */
17 #ifdef HAVE_CONFIG_H
18 #include<config.h>
19 #endif
20 #ifdef GMX_THREAD_SHM_FDECOMP
21 #include<thread_mpi.h>
22 #endif
23 #define ALMOST_ZERO 1e-30
24 #define ALMOST_ONE 1-(1e-30)
25 #include<math.h>
26
27 #include "nb_kernel231_adress.h"
28
29
30
31 /*
32  * Gromacs nonbonded kernel nb_kernel231_adress_cg
33  * Coulomb interaction:     Reaction field
34  * VdW interaction:         Tabulated
35  * water optimization:      SPC/TIP3P - other atoms
36  * Calculate forces:        yes
37  */
38 void nb_kernel231_adress_cg(
39                     int *           p_nri,
40                     int *           iinr,
41                     int *           jindex,
42                     int *           jjnr,
43                     int *           shift,
44                     real *         shiftvec,
45                     real *         fshift,
46                     int *           gid,
47                     real *         pos,
48                     real *         faction,
49                     real *         charge,
50                     real *         p_facel,
51                     real *         p_krf,
52                     real *         p_crf,
53                     real *         Vc,
54                     int *           type,
55                     int *           p_ntype,
56                     real *         vdwparam,
57                     real *         Vvdw,
58                     real *         p_tabscale,
59                     real *         VFtab,
60                     real *         invsqrta,
61                     real *         dvda,
62                     real *         p_gbtabscale,
63                     real *         GBtab,
64                     int *           p_nthreads,
65                     int *           count,
66                     void *          mtx,
67                     int *           outeriter,
68                     int *           inneriter,
69                     real           force_cap,
70                     real *         wf)
71 {
72     int           nri,ntype,nthreads;
73     real         facel,krf,crf,tabscale,gbtabscale;
74     int           n,ii,is3,ii3,k,nj0,nj1,jnr,j3,ggid;
75     int           nn0,nn1,nouter,ninner;
76     real         shX,shY,shZ;
77     real         fscal,tx,ty,tz;
78     real         rinvsq;
79     real         jq;
80     real         qq,vcoul,vctot;
81     int           nti;
82     int           tj;
83     real         Vvdw6,Vvdwtot;
84     real         Vvdw12;
85     real         r,rt,eps,eps2;
86     int           n0,nnn;
87     real         Y,F,Geps,Heps2,Fp,VV;
88     real         FF;
89     real         fijD,fijR;
90     real         krsq;
91     real         ix1,iy1,iz1,fix1,fiy1,fiz1;
92     real         ix2,iy2,iz2,fix2,fiy2,fiz2;
93     real         ix3,iy3,iz3,fix3,fiy3,fiz3;
94     real         jx1,jy1,jz1,fjx1,fjy1,fjz1;
95     real         dx11,dy11,dz11,rsq11,rinv11;
96     real         dx21,dy21,dz21,rsq21,rinv21;
97     real         dx31,dy31,dz31,rsq31,rinv31;
98     real         qO,qH;
99     real         c6,c12;
100     real         weight_cg1, weight_cg2, weight_product;
101     real         hybscal;
102
103     nri              = *p_nri;         
104     ntype            = *p_ntype;       
105     nthreads         = *p_nthreads;    
106     facel            = *p_facel;       
107     krf              = *p_krf;         
108     crf              = *p_crf;         
109     tabscale         = *p_tabscale;    
110     ii               = iinr[0];        
111     qO               = facel*charge[ii];
112     qH               = facel*charge[ii+1];
113     nti              = 2*ntype*type[ii];
114
115     nouter           = 0;              
116     ninner           = 0;              
117     
118     do
119     {
120         #ifdef GMX_THREAD_SHM_FDECOMP
121         tMPI_Thread_mutex_lock((tMPI_Thread_mutex_t *)mtx);
122         nn0              = *count;         
123         nn1              = nn0+(nri-nn0)/(2*nthreads)+10;
124         *count           = nn1;            
125         tMPI_Thread_mutex_unlock((tMPI_Thread_mutex_t *)mtx);
126         if(nn1>nri) nn1=nri;
127         #else
128         nn0 = 0;
129         nn1 = nri;
130         #endif
131         
132         for(n=nn0; (n<nn1); n++)
133         {
134             is3              = 3*shift[n];     
135             shX              = shiftvec[is3];  
136             shY              = shiftvec[is3+1];
137             shZ              = shiftvec[is3+2];
138             nj0              = jindex[n];      
139             nj1              = jindex[n+1];    
140             ii               = iinr[n];        
141             ii3              = 3*ii;           
142             ix1              = shX + pos[ii3+0];
143             iy1              = shY + pos[ii3+1];
144             iz1              = shZ + pos[ii3+2];
145             ix2              = shX + pos[ii3+3];
146             iy2              = shY + pos[ii3+4];
147             iz2              = shZ + pos[ii3+5];
148             ix3              = shX + pos[ii3+6];
149             iy3              = shY + pos[ii3+7];
150             iz3              = shZ + pos[ii3+8];
151             weight_cg1       = wf[ii];         
152             vctot            = 0;              
153             Vvdwtot          = 0;              
154             fix1             = 0;              
155             fiy1             = 0;              
156             fiz1             = 0;              
157             fix2             = 0;              
158             fiy2             = 0;              
159             fiz2             = 0;              
160             fix3             = 0;              
161             fiy3             = 0;              
162             fiz3             = 0;              
163             
164             for(k=nj0; (k<nj1); k++)
165             {
166                 jnr              = jjnr[k];        
167                 weight_cg2       = wf[jnr];        
168                 weight_product   = weight_cg1*weight_cg2;
169                 if (weight_product < ALMOST_ZERO) {
170                        hybscal = 1.0;
171                 }
172                 else if (weight_product >= ALMOST_ONE)
173                 {
174                   /* force is zero, skip this molecule */
175                        continue;
176                 }
177                 else
178                 {
179                    hybscal = 1.0 - weight_product;
180                 }
181                 j3               = 3*jnr;          
182                 jx1              = pos[j3+0];      
183                 jy1              = pos[j3+1];      
184                 jz1              = pos[j3+2];      
185                 dx11             = ix1 - jx1;      
186                 dy11             = iy1 - jy1;      
187                 dz11             = iz1 - jz1;      
188                 rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
189                 dx21             = ix2 - jx1;      
190                 dy21             = iy2 - jy1;      
191                 dz21             = iz2 - jz1;      
192                 rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
193                 dx31             = ix3 - jx1;      
194                 dy31             = iy3 - jy1;      
195                 dz31             = iz3 - jz1;      
196                 rsq31            = dx31*dx31+dy31*dy31+dz31*dz31;
197                 rinv11           = 1.0/sqrt(rsq11);
198                 rinv21           = 1.0/sqrt(rsq21);
199                 rinv31           = 1.0/sqrt(rsq31);
200                 jq               = charge[jnr+0];  
201                 qq               = qO*jq;          
202                 tj               = nti+2*type[jnr];
203                 c6               = vdwparam[tj];   
204                 c12              = vdwparam[tj+1]; 
205                 rinvsq           = rinv11*rinv11;  
206                 krsq             = krf*rsq11;      
207                 vcoul            = qq*(rinv11+krsq-crf);
208                 vctot            = vctot+vcoul;    
209                 r                = rsq11*rinv11;   
210                 rt               = r*tabscale;     
211                 n0               = rt;             
212                 eps              = rt-n0;          
213                 eps2             = eps*eps;        
214                 nnn              = 8*n0;           
215                 Y                = VFtab[nnn];     
216                 F                = VFtab[nnn+1];   
217                 Geps             = eps*VFtab[nnn+2];
218                 Heps2            = eps2*VFtab[nnn+3];
219                 Fp               = F+Geps+Heps2;   
220                 VV               = Y+eps*Fp;       
221                 FF               = Fp+Geps+2.0*Heps2;
222                 Vvdw6            = c6*VV;          
223                 fijD             = c6*FF;          
224                 nnn              = nnn+4;          
225                 Y                = VFtab[nnn];     
226                 F                = VFtab[nnn+1];   
227                 Geps             = eps*VFtab[nnn+2];
228                 Heps2            = eps2*VFtab[nnn+3];
229                 Fp               = F+Geps+Heps2;   
230                 VV               = Y+eps*Fp;       
231                 FF               = Fp+Geps+2.0*Heps2;
232                 Vvdw12           = c12*VV;         
233                 fijR             = c12*FF;         
234                 Vvdwtot          = Vvdwtot+ Vvdw6 + Vvdw12;
235                 fscal            = (qq*(rinv11-2.0*krsq))*rinvsq-((fijD+fijR)*tabscale)*rinv11;
236                 fscal *= hybscal;
237                 tx               = fscal*dx11;     
238                 ty               = fscal*dy11;     
239                 tz               = fscal*dz11;     
240                 fix1             = fix1 + tx;      
241                 fiy1             = fiy1 + ty;      
242                 fiz1             = fiz1 + tz;      
243                 fjx1             = faction[j3+0] - tx;
244                 fjy1             = faction[j3+1] - ty;
245                 fjz1             = faction[j3+2] - tz;
246                 qq               = qH*jq;          
247                 rinvsq           = rinv21*rinv21;  
248                 krsq             = krf*rsq21;      
249                 vcoul            = qq*(rinv21+krsq-crf);
250                 vctot            = vctot+vcoul;    
251                 fscal            = (qq*(rinv21-2.0*krsq))*rinvsq;
252                 fscal *= hybscal;
253                 tx               = fscal*dx21;     
254                 ty               = fscal*dy21;     
255                 tz               = fscal*dz21;     
256                 fix2             = fix2 + tx;      
257                 fiy2             = fiy2 + ty;      
258                 fiz2             = fiz2 + tz;      
259                 fjx1             = fjx1 - tx;      
260                 fjy1             = fjy1 - ty;      
261                 fjz1             = fjz1 - tz;      
262                 rinvsq           = rinv31*rinv31;  
263                 krsq             = krf*rsq31;      
264                 vcoul            = qq*(rinv31+krsq-crf);
265                 vctot            = vctot+vcoul;    
266                 fscal            = (qq*(rinv31-2.0*krsq))*rinvsq;
267                 fscal *= hybscal;
268                 tx               = fscal*dx31;     
269                 ty               = fscal*dy31;     
270                 tz               = fscal*dz31;     
271                 fix3             = fix3 + tx;      
272                 fiy3             = fiy3 + ty;      
273                 fiz3             = fiz3 + tz;      
274                 faction[j3+0]    = fjx1 - tx;      
275                 faction[j3+1]    = fjy1 - ty;      
276                 faction[j3+2]    = fjz1 - tz;      
277             }
278             
279             faction[ii3+0]   = faction[ii3+0] + fix1;
280             faction[ii3+1]   = faction[ii3+1] + fiy1;
281             faction[ii3+2]   = faction[ii3+2] + fiz1;
282             faction[ii3+3]   = faction[ii3+3] + fix2;
283             faction[ii3+4]   = faction[ii3+4] + fiy2;
284             faction[ii3+5]   = faction[ii3+5] + fiz2;
285             faction[ii3+6]   = faction[ii3+6] + fix3;
286             faction[ii3+7]   = faction[ii3+7] + fiy3;
287             faction[ii3+8]   = faction[ii3+8] + fiz3;
288             fshift[is3]      = fshift[is3]+fix1+fix2+fix3;
289             fshift[is3+1]    = fshift[is3+1]+fiy1+fiy2+fiy3;
290             fshift[is3+2]    = fshift[is3+2]+fiz1+fiz2+fiz3;
291             ggid             = gid[n];         
292             Vc[ggid]         = Vc[ggid] + vctot;
293             Vvdw[ggid]       = Vvdw[ggid] + Vvdwtot;
294             ninner           = ninner + nj1 - nj0;
295         }
296         
297         nouter           = nouter + nn1 - nn0;
298     }
299     while (nn1<nri);
300     
301     *outeriter       = nouter;         
302     *inneriter       = ninner;         
303 }
304
305
306
307
308
309 /*
310  * Gromacs nonbonded kernel nb_kernel231_adress_ex
311  * Coulomb interaction:     Reaction field
312  * VdW interaction:         Tabulated
313  * water optimization:      SPC/TIP3P - other atoms
314  * Calculate forces:        yes
315  */
316 void nb_kernel231_adress_ex(
317                     int *           p_nri,
318                     int *           iinr,
319                     int *           jindex,
320                     int *           jjnr,
321                     int *           shift,
322                     real *         shiftvec,
323                     real *         fshift,
324                     int *           gid,
325                     real *         pos,
326                     real *         faction,
327                     real *         charge,
328                     real *         p_facel,
329                     real *         p_krf,
330                     real *         p_crf,
331                     real *         Vc,
332                     int *           type,
333                     int *           p_ntype,
334                     real *         vdwparam,
335                     real *         Vvdw,
336                     real *         p_tabscale,
337                     real *         VFtab,
338                     real *         invsqrta,
339                     real *         dvda,
340                     real *         p_gbtabscale,
341                     real *         GBtab,
342                     int *           p_nthreads,
343                     int *           count,
344                     void *          mtx,
345                     int *           outeriter,
346                     int *           inneriter,
347                     real           force_cap,
348                     real *         wf)
349 {
350     int           nri,ntype,nthreads;
351     real         facel,krf,crf,tabscale,gbtabscale;
352     int           n,ii,is3,ii3,k,nj0,nj1,jnr,j3,ggid;
353     int           nn0,nn1,nouter,ninner;
354     real         shX,shY,shZ;
355     real         fscal,tx,ty,tz;
356     real         rinvsq;
357     real         jq;
358     real         qq,vcoul,vctot;
359     int           nti;
360     int           tj;
361     real         Vvdw6,Vvdwtot;
362     real         Vvdw12;
363     real         r,rt,eps,eps2;
364     int           n0,nnn;
365     real         Y,F,Geps,Heps2,Fp,VV;
366     real         FF;
367     real         fijD,fijR;
368     real         krsq;
369     real         ix1,iy1,iz1,fix1,fiy1,fiz1;
370     real         ix2,iy2,iz2,fix2,fiy2,fiz2;
371     real         ix3,iy3,iz3,fix3,fiy3,fiz3;
372     real         jx1,jy1,jz1,fjx1,fjy1,fjz1;
373     real         dx11,dy11,dz11,rsq11,rinv11;
374     real         dx21,dy21,dz21,rsq21,rinv21;
375     real         dx31,dy31,dz31,rsq31,rinv31;
376     real         qO,qH;
377     real         c6,c12;
378     real         weight_cg1, weight_cg2, weight_product;
379     real         hybscal;
380
381     nri              = *p_nri;         
382     ntype            = *p_ntype;       
383     nthreads         = *p_nthreads;    
384     facel            = *p_facel;       
385     krf              = *p_krf;         
386     crf              = *p_crf;         
387     tabscale         = *p_tabscale;    
388     ii               = iinr[0];        
389     qO               = facel*charge[ii];
390     qH               = facel*charge[ii+1];
391     nti              = 2*ntype*type[ii];
392
393     nouter           = 0;              
394     ninner           = 0;              
395     
396     do
397     {
398         #ifdef GMX_THREAD_SHM_FDECOMP
399         tMPI_Thread_mutex_lock((tMPI_Thread_mutex_t *)mtx);
400         nn0              = *count;         
401         nn1              = nn0+(nri-nn0)/(2*nthreads)+10;
402         *count           = nn1;            
403         tMPI_Thread_mutex_unlock((tMPI_Thread_mutex_t *)mtx);
404         if(nn1>nri) nn1=nri;
405         #else
406         nn0 = 0;
407         nn1 = nri;
408         #endif
409         
410         for(n=nn0; (n<nn1); n++)
411         {
412             is3              = 3*shift[n];     
413             shX              = shiftvec[is3];  
414             shY              = shiftvec[is3+1];
415             shZ              = shiftvec[is3+2];
416             nj0              = jindex[n];      
417             nj1              = jindex[n+1];    
418             ii               = iinr[n];        
419             ii3              = 3*ii;           
420             ix1              = shX + pos[ii3+0];
421             iy1              = shY + pos[ii3+1];
422             iz1              = shZ + pos[ii3+2];
423             ix2              = shX + pos[ii3+3];
424             iy2              = shY + pos[ii3+4];
425             iz2              = shZ + pos[ii3+5];
426             ix3              = shX + pos[ii3+6];
427             iy3              = shY + pos[ii3+7];
428             iz3              = shZ + pos[ii3+8];
429             weight_cg1       = wf[ii];         
430             vctot            = 0;              
431             Vvdwtot          = 0;              
432             fix1             = 0;              
433             fiy1             = 0;              
434             fiz1             = 0;              
435             fix2             = 0;              
436             fiy2             = 0;              
437             fiz2             = 0;              
438             fix3             = 0;              
439             fiy3             = 0;              
440             fiz3             = 0;              
441             
442             for(k=nj0; (k<nj1); k++)
443             {
444                 jnr              = jjnr[k];        
445                 weight_cg2       = wf[jnr];        
446                 weight_product   = weight_cg1*weight_cg2;
447                 if (weight_product < ALMOST_ZERO) {
448                 /* force is zero, skip this molecule */
449                  continue;
450                 }
451                 else if (weight_product >= ALMOST_ONE)
452                 {
453                        hybscal = 1.0;
454                 }
455                 else
456                 {
457                    hybscal = weight_product;
458                 }
459                 j3               = 3*jnr;          
460                 jx1              = pos[j3+0];      
461                 jy1              = pos[j3+1];      
462                 jz1              = pos[j3+2];      
463                 dx11             = ix1 - jx1;      
464                 dy11             = iy1 - jy1;      
465                 dz11             = iz1 - jz1;      
466                 rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
467                 dx21             = ix2 - jx1;      
468                 dy21             = iy2 - jy1;      
469                 dz21             = iz2 - jz1;      
470                 rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
471                 dx31             = ix3 - jx1;      
472                 dy31             = iy3 - jy1;      
473                 dz31             = iz3 - jz1;      
474                 rsq31            = dx31*dx31+dy31*dy31+dz31*dz31;
475                 rinv11           = 1.0/sqrt(rsq11);
476                 rinv21           = 1.0/sqrt(rsq21);
477                 rinv31           = 1.0/sqrt(rsq31);
478                 jq               = charge[jnr+0];  
479                 qq               = qO*jq;          
480                 tj               = nti+2*type[jnr];
481                 c6               = vdwparam[tj];   
482                 c12              = vdwparam[tj+1]; 
483                 rinvsq           = rinv11*rinv11;  
484                 krsq             = krf*rsq11;      
485                 vcoul            = qq*(rinv11+krsq-crf);
486                 vctot            = vctot+vcoul;    
487                 r                = rsq11*rinv11;   
488                 rt               = r*tabscale;     
489                 n0               = rt;             
490                 eps              = rt-n0;          
491                 eps2             = eps*eps;        
492                 nnn              = 8*n0;           
493                 Y                = VFtab[nnn];     
494                 F                = VFtab[nnn+1];   
495                 Geps             = eps*VFtab[nnn+2];
496                 Heps2            = eps2*VFtab[nnn+3];
497                 Fp               = F+Geps+Heps2;   
498                 VV               = Y+eps*Fp;       
499                 FF               = Fp+Geps+2.0*Heps2;
500                 Vvdw6            = c6*VV;          
501                 fijD             = c6*FF;          
502                 nnn              = nnn+4;          
503                 Y                = VFtab[nnn];     
504                 F                = VFtab[nnn+1];   
505                 Geps             = eps*VFtab[nnn+2];
506                 Heps2            = eps2*VFtab[nnn+3];
507                 Fp               = F+Geps+Heps2;   
508                 VV               = Y+eps*Fp;       
509                 FF               = Fp+Geps+2.0*Heps2;
510                 Vvdw12           = c12*VV;         
511                 fijR             = c12*FF;         
512                 Vvdwtot          = Vvdwtot+ Vvdw6 + Vvdw12;
513                 fscal            = (qq*(rinv11-2.0*krsq))*rinvsq-((fijD+fijR)*tabscale)*rinv11;
514                 fscal *= hybscal;
515                 if(force_cap>0 && (fabs(fscal)> force_cap)){
516                 fscal=force_cap*fscal/fabs(fscal);
517                 }
518                 tx               = fscal*dx11;     
519                 ty               = fscal*dy11;     
520                 tz               = fscal*dz11;     
521                 fix1             = fix1 + tx;      
522                 fiy1             = fiy1 + ty;      
523                 fiz1             = fiz1 + tz;      
524                 fjx1             = faction[j3+0] - tx;
525                 fjy1             = faction[j3+1] - ty;
526                 fjz1             = faction[j3+2] - tz;
527                 qq               = qH*jq;          
528                 rinvsq           = rinv21*rinv21;  
529                 krsq             = krf*rsq21;      
530                 vcoul            = qq*(rinv21+krsq-crf);
531                 vctot            = vctot+vcoul;    
532                 fscal            = (qq*(rinv21-2.0*krsq))*rinvsq;
533                 fscal *= hybscal;
534                 if(force_cap>0 && (fabs(fscal)> force_cap)){
535                 fscal=force_cap*fscal/fabs(fscal);
536                 }
537                 tx               = fscal*dx21;     
538                 ty               = fscal*dy21;     
539                 tz               = fscal*dz21;     
540                 fix2             = fix2 + tx;      
541                 fiy2             = fiy2 + ty;      
542                 fiz2             = fiz2 + tz;      
543                 fjx1             = fjx1 - tx;      
544                 fjy1             = fjy1 - ty;      
545                 fjz1             = fjz1 - tz;      
546                 rinvsq           = rinv31*rinv31;  
547                 krsq             = krf*rsq31;      
548                 vcoul            = qq*(rinv31+krsq-crf);
549                 vctot            = vctot+vcoul;    
550                 fscal            = (qq*(rinv31-2.0*krsq))*rinvsq;
551                 fscal *= hybscal;
552                 if(force_cap>0 && (fabs(fscal)> force_cap)){
553                 fscal=force_cap*fscal/fabs(fscal);
554                 }
555                 tx               = fscal*dx31;     
556                 ty               = fscal*dy31;     
557                 tz               = fscal*dz31;     
558                 fix3             = fix3 + tx;      
559                 fiy3             = fiy3 + ty;      
560                 fiz3             = fiz3 + tz;      
561                 faction[j3+0]    = fjx1 - tx;      
562                 faction[j3+1]    = fjy1 - ty;      
563                 faction[j3+2]    = fjz1 - tz;      
564             }
565             
566             faction[ii3+0]   = faction[ii3+0] + fix1;
567             faction[ii3+1]   = faction[ii3+1] + fiy1;
568             faction[ii3+2]   = faction[ii3+2] + fiz1;
569             faction[ii3+3]   = faction[ii3+3] + fix2;
570             faction[ii3+4]   = faction[ii3+4] + fiy2;
571             faction[ii3+5]   = faction[ii3+5] + fiz2;
572             faction[ii3+6]   = faction[ii3+6] + fix3;
573             faction[ii3+7]   = faction[ii3+7] + fiy3;
574             faction[ii3+8]   = faction[ii3+8] + fiz3;
575             fshift[is3]      = fshift[is3]+fix1+fix2+fix3;
576             fshift[is3+1]    = fshift[is3+1]+fiy1+fiy2+fiy3;
577             fshift[is3+2]    = fshift[is3+2]+fiz1+fiz2+fiz3;
578             ggid             = gid[n];         
579             Vc[ggid]         = Vc[ggid] + vctot;
580             Vvdw[ggid]       = Vvdw[ggid] + Vvdwtot;
581             ninner           = ninner + nj1 - nj0;
582         }
583         
584         nouter           = nouter + nn1 - nn0;
585     }
586     while (nn1<nri);
587     
588     *outeriter       = nouter;         
589     *inneriter       = ninner;         
590 }
591
592