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