Merge remote-tracking branch 'origin/release-4-6' into HEAD
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_adress_c / nb_kernel320_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_kernel320_adress.h"
28
29
30
31 /*
32  * Gromacs nonbonded kernel nb_kernel320_adress_cg
33  * Coulomb interaction:     Tabulated
34  * VdW interaction:         Buckingham
35  * water optimization:      No
36  * Calculate forces:        yes
37  */
38 void nb_kernel320_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         iq;
80     real         qq,vcoul,vctot;
81     int           nti;
82     int           tj;
83     real         rinvsix;
84     real         Vvdw6,Vvdwtot;
85     real         r,rt,eps,eps2;
86     int           n0,nnn;
87     real         Y,F,Geps,Heps2,Fp,VV;
88     real         FF;
89     real         fijC;
90     real         Vvdwexp,br;
91     real         ix1,iy1,iz1,fix1,fiy1,fiz1;
92     real         jx1,jy1,jz1;
93     real         dx11,dy11,dz11,rsq11,rinv11;
94     real         c6,cexp1,cexp2;
95     real         weight_cg1, weight_cg2, weight_product;
96     real         hybscal;
97
98     nri              = *p_nri;         
99     ntype            = *p_ntype;       
100     nthreads         = *p_nthreads;    
101     facel            = *p_facel;       
102     krf              = *p_krf;         
103     crf              = *p_crf;         
104     tabscale         = *p_tabscale;    
105     nouter           = 0;              
106     ninner           = 0;              
107     
108     do
109     {
110         #ifdef GMX_THREAD_SHM_FDECOMP
111         tMPI_Thread_mutex_lock((tMPI_Thread_mutex_t *)mtx);
112         nn0              = *count;         
113         nn1              = nn0+(nri-nn0)/(2*nthreads)+10;
114         *count           = nn1;            
115         tMPI_Thread_mutex_unlock((tMPI_Thread_mutex_t *)mtx);
116         if(nn1>nri) nn1=nri;
117         #else
118         nn0 = 0;
119         nn1 = nri;
120         #endif
121         
122         for(n=nn0; (n<nn1); n++)
123         {
124             is3              = 3*shift[n];     
125             shX              = shiftvec[is3];  
126             shY              = shiftvec[is3+1];
127             shZ              = shiftvec[is3+2];
128             nj0              = jindex[n];      
129             nj1              = jindex[n+1];    
130             ii               = iinr[n];        
131             ii3              = 3*ii;           
132             ix1              = shX + pos[ii3+0];
133             iy1              = shY + pos[ii3+1];
134             iz1              = shZ + pos[ii3+2];
135             iq               = facel*charge[ii];
136             nti              = 3*ntype*type[ii];
137             weight_cg1       = wf[ii];         
138             vctot            = 0;              
139             Vvdwtot          = 0;              
140             fix1             = 0;              
141             fiy1             = 0;              
142             fiz1             = 0;              
143             
144             for(k=nj0; (k<nj1); k++)
145             {
146                 jnr              = jjnr[k];        
147                 weight_cg2       = wf[jnr];        
148                 weight_product   = weight_cg1*weight_cg2;
149                 if (weight_product < ALMOST_ZERO) {
150                        hybscal = 1.0;
151                 }
152                 else if (weight_product >= ALMOST_ONE)
153                 {
154                   /* force is zero, skip this molecule */
155                        continue;
156                 }
157                 else
158                 {
159                    hybscal = 1.0 - weight_product;
160                 }
161                 j3               = 3*jnr;          
162                 jx1              = pos[j3+0];      
163                 jy1              = pos[j3+1];      
164                 jz1              = pos[j3+2];      
165                 dx11             = ix1 - jx1;      
166                 dy11             = iy1 - jy1;      
167                 dz11             = iz1 - jz1;      
168                 rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
169                 rinv11           = 1.0/sqrt(rsq11);
170                 qq               = iq*charge[jnr]; 
171                 tj               = nti+3*type[jnr];
172                 c6               = vdwparam[tj];   
173                 cexp1            = vdwparam[tj+1]; 
174                 cexp2            = vdwparam[tj+2]; 
175                 rinvsq           = rinv11*rinv11;  
176                 r                = rsq11*rinv11;   
177                 rt               = r*tabscale;     
178                 n0               = rt;             
179                 eps              = rt-n0;          
180                 eps2             = eps*eps;        
181                 nnn              = 4*n0;           
182                 Y                = VFtab[nnn];     
183                 F                = VFtab[nnn+1];   
184                 Geps             = eps*VFtab[nnn+2];
185                 Heps2            = eps2*VFtab[nnn+3];
186                 Fp               = F+Geps+Heps2;   
187                 VV               = Y+eps*Fp;       
188                 FF               = Fp+Geps+2.0*Heps2;
189                 vcoul            = qq*VV;          
190                 fijC             = qq*FF;          
191                 vctot            = vctot + vcoul;  
192                 rinvsix          = rinvsq*rinvsq*rinvsq;
193                 Vvdw6            = c6*rinvsix;     
194                 br               = cexp2*rsq11*rinv11;
195                 Vvdwexp          = cexp1*exp(-br); 
196                 Vvdwtot          = Vvdwtot+Vvdwexp-Vvdw6;
197                 fscal            = (br*Vvdwexp-6.0*Vvdw6)*rinvsq-((fijC)*tabscale)*rinv11;
198                 fscal *= hybscal;
199                 tx               = fscal*dx11;     
200                 ty               = fscal*dy11;     
201                 tz               = fscal*dz11;     
202                 fix1             = fix1 + tx;      
203                 fiy1             = fiy1 + ty;      
204                 fiz1             = fiz1 + tz;      
205                 faction[j3+0]    = faction[j3+0] - tx;
206                 faction[j3+1]    = faction[j3+1] - ty;
207                 faction[j3+2]    = faction[j3+2] - tz;
208             }
209             
210             faction[ii3+0]   = faction[ii3+0] + fix1;
211             faction[ii3+1]   = faction[ii3+1] + fiy1;
212             faction[ii3+2]   = faction[ii3+2] + fiz1;
213             fshift[is3]      = fshift[is3]+fix1;
214             fshift[is3+1]    = fshift[is3+1]+fiy1;
215             fshift[is3+2]    = fshift[is3+2]+fiz1;
216             ggid             = gid[n];         
217             Vc[ggid]         = Vc[ggid] + vctot;
218             Vvdw[ggid]       = Vvdw[ggid] + Vvdwtot;
219             ninner           = ninner + nj1 - nj0;
220         }
221         
222         nouter           = nouter + nn1 - nn0;
223     }
224     while (nn1<nri);
225     
226     *outeriter       = nouter;         
227     *inneriter       = ninner;         
228 }
229
230
231
232
233
234 /*
235  * Gromacs nonbonded kernel nb_kernel320_adress_ex
236  * Coulomb interaction:     Tabulated
237  * VdW interaction:         Buckingham
238  * water optimization:      No
239  * Calculate forces:        yes
240  */
241 void nb_kernel320_adress_ex(
242                     int *           p_nri,
243                     int *           iinr,
244                     int *           jindex,
245                     int *           jjnr,
246                     int *           shift,
247                     real *         shiftvec,
248                     real *         fshift,
249                     int *           gid,
250                     real *         pos,
251                     real *         faction,
252                     real *         charge,
253                     real *         p_facel,
254                     real *         p_krf,
255                     real *         p_crf,
256                     real *         Vc,
257                     int *           type,
258                     int *           p_ntype,
259                     real *         vdwparam,
260                     real *         Vvdw,
261                     real *         p_tabscale,
262                     real *         VFtab,
263                     real *         invsqrta,
264                     real *         dvda,
265                     real *         p_gbtabscale,
266                     real *         GBtab,
267                     int *           p_nthreads,
268                     int *           count,
269                     void *          mtx,
270                     int *           outeriter,
271                     int *           inneriter,
272                     real           force_cap,
273                     real *         wf)
274 {
275     int           nri,ntype,nthreads;
276     real         facel,krf,crf,tabscale,gbtabscale;
277     int           n,ii,is3,ii3,k,nj0,nj1,jnr,j3,ggid;
278     int           nn0,nn1,nouter,ninner;
279     real         shX,shY,shZ;
280     real         fscal,tx,ty,tz;
281     real         rinvsq;
282     real         iq;
283     real         qq,vcoul,vctot;
284     int           nti;
285     int           tj;
286     real         rinvsix;
287     real         Vvdw6,Vvdwtot;
288     real         r,rt,eps,eps2;
289     int           n0,nnn;
290     real         Y,F,Geps,Heps2,Fp,VV;
291     real         FF;
292     real         fijC;
293     real         Vvdwexp,br;
294     real         ix1,iy1,iz1,fix1,fiy1,fiz1;
295     real         jx1,jy1,jz1;
296     real         dx11,dy11,dz11,rsq11,rinv11;
297     real         c6,cexp1,cexp2;
298     real         weight_cg1, weight_cg2, weight_product;
299     real         hybscal;
300
301     nri              = *p_nri;         
302     ntype            = *p_ntype;       
303     nthreads         = *p_nthreads;    
304     facel            = *p_facel;       
305     krf              = *p_krf;         
306     crf              = *p_crf;         
307     tabscale         = *p_tabscale;    
308     nouter           = 0;              
309     ninner           = 0;              
310     
311     do
312     {
313         #ifdef GMX_THREAD_SHM_FDECOMP
314         tMPI_Thread_mutex_lock((tMPI_Thread_mutex_t *)mtx);
315         nn0              = *count;         
316         nn1              = nn0+(nri-nn0)/(2*nthreads)+10;
317         *count           = nn1;            
318         tMPI_Thread_mutex_unlock((tMPI_Thread_mutex_t *)mtx);
319         if(nn1>nri) nn1=nri;
320         #else
321         nn0 = 0;
322         nn1 = nri;
323         #endif
324         
325         for(n=nn0; (n<nn1); n++)
326         {
327             is3              = 3*shift[n];     
328             shX              = shiftvec[is3];  
329             shY              = shiftvec[is3+1];
330             shZ              = shiftvec[is3+2];
331             nj0              = jindex[n];      
332             nj1              = jindex[n+1];    
333             ii               = iinr[n];        
334             ii3              = 3*ii;           
335             ix1              = shX + pos[ii3+0];
336             iy1              = shY + pos[ii3+1];
337             iz1              = shZ + pos[ii3+2];
338             iq               = facel*charge[ii];
339             nti              = 3*ntype*type[ii];
340             weight_cg1       = wf[ii];         
341             vctot            = 0;              
342             Vvdwtot          = 0;              
343             fix1             = 0;              
344             fiy1             = 0;              
345             fiz1             = 0;              
346             
347             for(k=nj0; (k<nj1); k++)
348             {
349                 jnr              = jjnr[k];        
350                 weight_cg2       = wf[jnr];        
351                 weight_product   = weight_cg1*weight_cg2;
352                 if (weight_product < ALMOST_ZERO) {
353                 /* force is zero, skip this molecule */
354                  continue;
355                 }
356                 else if (weight_product >= ALMOST_ONE)
357                 {
358                        hybscal = 1.0;
359                 }
360                 else
361                 {
362                    hybscal = weight_product;
363                 }
364                 j3               = 3*jnr;          
365                 jx1              = pos[j3+0];      
366                 jy1              = pos[j3+1];      
367                 jz1              = pos[j3+2];      
368                 dx11             = ix1 - jx1;      
369                 dy11             = iy1 - jy1;      
370                 dz11             = iz1 - jz1;      
371                 rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
372                 rinv11           = 1.0/sqrt(rsq11);
373                 qq               = iq*charge[jnr]; 
374                 tj               = nti+3*type[jnr];
375                 c6               = vdwparam[tj];   
376                 cexp1            = vdwparam[tj+1]; 
377                 cexp2            = vdwparam[tj+2]; 
378                 rinvsq           = rinv11*rinv11;  
379                 r                = rsq11*rinv11;   
380                 rt               = r*tabscale;     
381                 n0               = rt;             
382                 eps              = rt-n0;          
383                 eps2             = eps*eps;        
384                 nnn              = 4*n0;           
385                 Y                = VFtab[nnn];     
386                 F                = VFtab[nnn+1];   
387                 Geps             = eps*VFtab[nnn+2];
388                 Heps2            = eps2*VFtab[nnn+3];
389                 Fp               = F+Geps+Heps2;   
390                 VV               = Y+eps*Fp;       
391                 FF               = Fp+Geps+2.0*Heps2;
392                 vcoul            = qq*VV;          
393                 fijC             = qq*FF;          
394                 vctot            = vctot + vcoul;  
395                 rinvsix          = rinvsq*rinvsq*rinvsq;
396                 Vvdw6            = c6*rinvsix;     
397                 br               = cexp2*rsq11*rinv11;
398                 Vvdwexp          = cexp1*exp(-br); 
399                 Vvdwtot          = Vvdwtot+Vvdwexp-Vvdw6;
400                 fscal            = (br*Vvdwexp-6.0*Vvdw6)*rinvsq-((fijC)*tabscale)*rinv11;
401                 fscal *= hybscal;
402                 if(force_cap>0 && (fabs(fscal)> force_cap)){
403                 fscal=force_cap*fscal/fabs(fscal);
404                 }
405                 tx               = fscal*dx11;     
406                 ty               = fscal*dy11;     
407                 tz               = fscal*dz11;     
408                 fix1             = fix1 + tx;      
409                 fiy1             = fiy1 + ty;      
410                 fiz1             = fiz1 + tz;      
411                 faction[j3+0]    = faction[j3+0] - tx;
412                 faction[j3+1]    = faction[j3+1] - ty;
413                 faction[j3+2]    = faction[j3+2] - tz;
414             }
415             
416             faction[ii3+0]   = faction[ii3+0] + fix1;
417             faction[ii3+1]   = faction[ii3+1] + fiy1;
418             faction[ii3+2]   = faction[ii3+2] + fiz1;
419             fshift[is3]      = fshift[is3]+fix1;
420             fshift[is3+1]    = fshift[is3+1]+fiy1;
421             fshift[is3+2]    = fshift[is3+2]+fiz1;
422             ggid             = gid[n];         
423             Vc[ggid]         = Vc[ggid] + vctot;
424             Vvdw[ggid]       = Vvdw[ggid] + Vvdwtot;
425             ninner           = ninner + nj1 - nj0;
426         }
427         
428         nouter           = nouter + nn1 - nn0;
429     }
430     while (nn1<nri);
431     
432     *outeriter       = nouter;         
433     *inneriter       = ninner;         
434 }
435
436