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