Merge remote-tracking branch 'origin/release-4-6' into HEAD
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_adress_c / nb_kernel121_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_kernel121_adress.h"
28
29
30
31 /*
32  * Gromacs nonbonded kernel nb_kernel121_adress_cg
33  * Coulomb interaction:     Normal Coulomb
34  * VdW interaction:         Buckingham
35  * water optimization:      SPC/TIP3P - other atoms
36  * Calculate forces:        yes
37  */
38 void nb_kernel121_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         rinvsix;
84     real         Vvdw6,Vvdwtot;
85     real         Vvdwexp,br;
86     real         ix1,iy1,iz1,fix1,fiy1,fiz1;
87     real         ix2,iy2,iz2,fix2,fiy2,fiz2;
88     real         ix3,iy3,iz3,fix3,fiy3,fiz3;
89     real         jx1,jy1,jz1,fjx1,fjy1,fjz1;
90     real         dx11,dy11,dz11,rsq11,rinv11;
91     real         dx21,dy21,dz21,rsq21,rinv21;
92     real         dx31,dy31,dz31,rsq31,rinv31;
93     real         qO,qH;
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     ii               = iinr[0];        
106     qO               = facel*charge[ii];
107     qH               = facel*charge[ii+1];
108     nti              = 3*ntype*type[ii];
109
110     nouter           = 0;              
111     ninner           = 0;              
112     
113     do
114     {
115         #ifdef GMX_THREAD_SHM_FDECOMP
116         tMPI_Thread_mutex_lock((tMPI_Thread_mutex_t *)mtx);
117         nn0              = *count;         
118         nn1              = nn0+(nri-nn0)/(2*nthreads)+10;
119         *count           = nn1;            
120         tMPI_Thread_mutex_unlock((tMPI_Thread_mutex_t *)mtx);
121         if(nn1>nri) nn1=nri;
122         #else
123         nn0 = 0;
124         nn1 = nri;
125         #endif
126         
127         for(n=nn0; (n<nn1); n++)
128         {
129             is3              = 3*shift[n];     
130             shX              = shiftvec[is3];  
131             shY              = shiftvec[is3+1];
132             shZ              = shiftvec[is3+2];
133             nj0              = jindex[n];      
134             nj1              = jindex[n+1];    
135             ii               = iinr[n];        
136             ii3              = 3*ii;           
137             ix1              = shX + pos[ii3+0];
138             iy1              = shY + pos[ii3+1];
139             iz1              = shZ + pos[ii3+2];
140             ix2              = shX + pos[ii3+3];
141             iy2              = shY + pos[ii3+4];
142             iz2              = shZ + pos[ii3+5];
143             ix3              = shX + pos[ii3+6];
144             iy3              = shY + pos[ii3+7];
145             iz3              = shZ + pos[ii3+8];
146             weight_cg1       = wf[ii];         
147             vctot            = 0;              
148             Vvdwtot          = 0;              
149             fix1             = 0;              
150             fiy1             = 0;              
151             fiz1             = 0;              
152             fix2             = 0;              
153             fiy2             = 0;              
154             fiz2             = 0;              
155             fix3             = 0;              
156             fiy3             = 0;              
157             fiz3             = 0;              
158             
159             for(k=nj0; (k<nj1); k++)
160             {
161                 jnr              = jjnr[k];        
162                 weight_cg2       = wf[jnr];        
163                 weight_product   = weight_cg1*weight_cg2;
164                 if (weight_product < ALMOST_ZERO) {
165                        hybscal = 1.0;
166                 }
167                 else if (weight_product >= ALMOST_ONE)
168                 {
169                   /* force is zero, skip this molecule */
170                        continue;
171                 }
172                 else
173                 {
174                    hybscal = 1.0 - weight_product;
175                 }
176                 j3               = 3*jnr;          
177                 jx1              = pos[j3+0];      
178                 jy1              = pos[j3+1];      
179                 jz1              = pos[j3+2];      
180                 dx11             = ix1 - jx1;      
181                 dy11             = iy1 - jy1;      
182                 dz11             = iz1 - jz1;      
183                 rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
184                 dx21             = ix2 - jx1;      
185                 dy21             = iy2 - jy1;      
186                 dz21             = iz2 - jz1;      
187                 rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
188                 dx31             = ix3 - jx1;      
189                 dy31             = iy3 - jy1;      
190                 dz31             = iz3 - jz1;      
191                 rsq31            = dx31*dx31+dy31*dy31+dz31*dz31;
192                 rinv11           = 1.0/sqrt(rsq11);
193                 rinv21           = 1.0/sqrt(rsq21);
194                 rinv31           = 1.0/sqrt(rsq31);
195                 jq               = charge[jnr+0];  
196                 qq               = qO*jq;          
197                 tj               = nti+3*type[jnr];
198                 c6               = vdwparam[tj];   
199                 cexp1            = vdwparam[tj+1]; 
200                 cexp2            = vdwparam[tj+2]; 
201                 rinvsq           = rinv11*rinv11;  
202                 vcoul            = qq*rinv11;      
203                 vctot            = vctot+vcoul;    
204                 rinvsix          = rinvsq*rinvsq*rinvsq;
205                 Vvdw6            = c6*rinvsix;     
206                 br               = cexp2*rsq11*rinv11;
207                 Vvdwexp          = cexp1*exp(-br); 
208                 Vvdwtot          = Vvdwtot+Vvdwexp-Vvdw6;
209                 fscal            = (vcoul+br*Vvdwexp-6.0*Vvdw6)*rinvsq;
210                 fscal *= hybscal;
211                 tx               = fscal*dx11;     
212                 ty               = fscal*dy11;     
213                 tz               = fscal*dz11;     
214                 fix1             = fix1 + tx;      
215                 fiy1             = fiy1 + ty;      
216                 fiz1             = fiz1 + tz;      
217                 fjx1             = faction[j3+0] - tx;
218                 fjy1             = faction[j3+1] - ty;
219                 fjz1             = faction[j3+2] - tz;
220                 qq               = qH*jq;          
221                 rinvsq           = rinv21*rinv21;  
222                 vcoul            = qq*rinv21;      
223                 vctot            = vctot+vcoul;    
224                 fscal            = (vcoul)*rinvsq; 
225                 fscal *= hybscal;
226                 tx               = fscal*dx21;     
227                 ty               = fscal*dy21;     
228                 tz               = fscal*dz21;     
229                 fix2             = fix2 + tx;      
230                 fiy2             = fiy2 + ty;      
231                 fiz2             = fiz2 + tz;      
232                 fjx1             = fjx1 - tx;      
233                 fjy1             = fjy1 - ty;      
234                 fjz1             = fjz1 - tz;      
235                 rinvsq           = rinv31*rinv31;  
236                 vcoul            = qq*rinv31;      
237                 vctot            = vctot+vcoul;    
238                 fscal            = (vcoul)*rinvsq; 
239                 fscal *= hybscal;
240                 tx               = fscal*dx31;     
241                 ty               = fscal*dy31;     
242                 tz               = fscal*dz31;     
243                 fix3             = fix3 + tx;      
244                 fiy3             = fiy3 + ty;      
245                 fiz3             = fiz3 + tz;      
246                 faction[j3+0]    = fjx1 - tx;      
247                 faction[j3+1]    = fjy1 - ty;      
248                 faction[j3+2]    = fjz1 - tz;      
249             }
250             
251             faction[ii3+0]   = faction[ii3+0] + fix1;
252             faction[ii3+1]   = faction[ii3+1] + fiy1;
253             faction[ii3+2]   = faction[ii3+2] + fiz1;
254             faction[ii3+3]   = faction[ii3+3] + fix2;
255             faction[ii3+4]   = faction[ii3+4] + fiy2;
256             faction[ii3+5]   = faction[ii3+5] + fiz2;
257             faction[ii3+6]   = faction[ii3+6] + fix3;
258             faction[ii3+7]   = faction[ii3+7] + fiy3;
259             faction[ii3+8]   = faction[ii3+8] + fiz3;
260             fshift[is3]      = fshift[is3]+fix1+fix2+fix3;
261             fshift[is3+1]    = fshift[is3+1]+fiy1+fiy2+fiy3;
262             fshift[is3+2]    = fshift[is3+2]+fiz1+fiz2+fiz3;
263             ggid             = gid[n];         
264             Vc[ggid]         = Vc[ggid] + vctot;
265             Vvdw[ggid]       = Vvdw[ggid] + Vvdwtot;
266             ninner           = ninner + nj1 - nj0;
267         }
268         
269         nouter           = nouter + nn1 - nn0;
270     }
271     while (nn1<nri);
272     
273     *outeriter       = nouter;         
274     *inneriter       = ninner;         
275 }
276
277
278
279
280
281 /*
282  * Gromacs nonbonded kernel nb_kernel121_adress_ex
283  * Coulomb interaction:     Normal Coulomb
284  * VdW interaction:         Buckingham
285  * water optimization:      SPC/TIP3P - other atoms
286  * Calculate forces:        yes
287  */
288 void nb_kernel121_adress_ex(
289                     int *           p_nri,
290                     int *           iinr,
291                     int *           jindex,
292                     int *           jjnr,
293                     int *           shift,
294                     real *         shiftvec,
295                     real *         fshift,
296                     int *           gid,
297                     real *         pos,
298                     real *         faction,
299                     real *         charge,
300                     real *         p_facel,
301                     real *         p_krf,
302                     real *         p_crf,
303                     real *         Vc,
304                     int *           type,
305                     int *           p_ntype,
306                     real *         vdwparam,
307                     real *         Vvdw,
308                     real *         p_tabscale,
309                     real *         VFtab,
310                     real *         invsqrta,
311                     real *         dvda,
312                     real *         p_gbtabscale,
313                     real *         GBtab,
314                     int *           p_nthreads,
315                     int *           count,
316                     void *          mtx,
317                     int *           outeriter,
318                     int *           inneriter,
319                     real           force_cap,
320                     real *         wf)
321 {
322     int           nri,ntype,nthreads;
323     real         facel,krf,crf,tabscale,gbtabscale;
324     int           n,ii,is3,ii3,k,nj0,nj1,jnr,j3,ggid;
325     int           nn0,nn1,nouter,ninner;
326     real         shX,shY,shZ;
327     real         fscal,tx,ty,tz;
328     real         rinvsq;
329     real         jq;
330     real         qq,vcoul,vctot;
331     int           nti;
332     int           tj;
333     real         rinvsix;
334     real         Vvdw6,Vvdwtot;
335     real         Vvdwexp,br;
336     real         ix1,iy1,iz1,fix1,fiy1,fiz1;
337     real         ix2,iy2,iz2,fix2,fiy2,fiz2;
338     real         ix3,iy3,iz3,fix3,fiy3,fiz3;
339     real         jx1,jy1,jz1,fjx1,fjy1,fjz1;
340     real         dx11,dy11,dz11,rsq11,rinv11;
341     real         dx21,dy21,dz21,rsq21,rinv21;
342     real         dx31,dy31,dz31,rsq31,rinv31;
343     real         qO,qH;
344     real         c6,cexp1,cexp2;
345     real         weight_cg1, weight_cg2, weight_product;
346     real         hybscal;
347
348     nri              = *p_nri;         
349     ntype            = *p_ntype;       
350     nthreads         = *p_nthreads;    
351     facel            = *p_facel;       
352     krf              = *p_krf;         
353     crf              = *p_crf;         
354     tabscale         = *p_tabscale;    
355     ii               = iinr[0];        
356     qO               = facel*charge[ii];
357     qH               = facel*charge[ii+1];
358     nti              = 3*ntype*type[ii];
359
360     nouter           = 0;              
361     ninner           = 0;              
362     
363     do
364     {
365         #ifdef GMX_THREAD_SHM_FDECOMP
366         tMPI_Thread_mutex_lock((tMPI_Thread_mutex_t *)mtx);
367         nn0              = *count;         
368         nn1              = nn0+(nri-nn0)/(2*nthreads)+10;
369         *count           = nn1;            
370         tMPI_Thread_mutex_unlock((tMPI_Thread_mutex_t *)mtx);
371         if(nn1>nri) nn1=nri;
372         #else
373         nn0 = 0;
374         nn1 = nri;
375         #endif
376         
377         for(n=nn0; (n<nn1); n++)
378         {
379             is3              = 3*shift[n];     
380             shX              = shiftvec[is3];  
381             shY              = shiftvec[is3+1];
382             shZ              = shiftvec[is3+2];
383             nj0              = jindex[n];      
384             nj1              = jindex[n+1];    
385             ii               = iinr[n];        
386             ii3              = 3*ii;           
387             ix1              = shX + pos[ii3+0];
388             iy1              = shY + pos[ii3+1];
389             iz1              = shZ + pos[ii3+2];
390             ix2              = shX + pos[ii3+3];
391             iy2              = shY + pos[ii3+4];
392             iz2              = shZ + pos[ii3+5];
393             ix3              = shX + pos[ii3+6];
394             iy3              = shY + pos[ii3+7];
395             iz3              = shZ + pos[ii3+8];
396             weight_cg1       = wf[ii];         
397             vctot            = 0;              
398             Vvdwtot          = 0;              
399             fix1             = 0;              
400             fiy1             = 0;              
401             fiz1             = 0;              
402             fix2             = 0;              
403             fiy2             = 0;              
404             fiz2             = 0;              
405             fix3             = 0;              
406             fiy3             = 0;              
407             fiz3             = 0;              
408             
409             for(k=nj0; (k<nj1); k++)
410             {
411                 jnr              = jjnr[k];        
412                 weight_cg2       = wf[jnr];        
413                 weight_product   = weight_cg1*weight_cg2;
414                 if (weight_product < ALMOST_ZERO) {
415                 /* force is zero, skip this molecule */
416                  continue;
417                 }
418                 else if (weight_product >= ALMOST_ONE)
419                 {
420                        hybscal = 1.0;
421                 }
422                 else
423                 {
424                    hybscal = weight_product;
425                 }
426                 j3               = 3*jnr;          
427                 jx1              = pos[j3+0];      
428                 jy1              = pos[j3+1];      
429                 jz1              = pos[j3+2];      
430                 dx11             = ix1 - jx1;      
431                 dy11             = iy1 - jy1;      
432                 dz11             = iz1 - jz1;      
433                 rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
434                 dx21             = ix2 - jx1;      
435                 dy21             = iy2 - jy1;      
436                 dz21             = iz2 - jz1;      
437                 rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
438                 dx31             = ix3 - jx1;      
439                 dy31             = iy3 - jy1;      
440                 dz31             = iz3 - jz1;      
441                 rsq31            = dx31*dx31+dy31*dy31+dz31*dz31;
442                 rinv11           = 1.0/sqrt(rsq11);
443                 rinv21           = 1.0/sqrt(rsq21);
444                 rinv31           = 1.0/sqrt(rsq31);
445                 jq               = charge[jnr+0];  
446                 qq               = qO*jq;          
447                 tj               = nti+3*type[jnr];
448                 c6               = vdwparam[tj];   
449                 cexp1            = vdwparam[tj+1]; 
450                 cexp2            = vdwparam[tj+2]; 
451                 rinvsq           = rinv11*rinv11;  
452                 vcoul            = qq*rinv11;      
453                 vctot            = vctot+vcoul;    
454                 rinvsix          = rinvsq*rinvsq*rinvsq;
455                 Vvdw6            = c6*rinvsix;     
456                 br               = cexp2*rsq11*rinv11;
457                 Vvdwexp          = cexp1*exp(-br); 
458                 Vvdwtot          = Vvdwtot+Vvdwexp-Vvdw6;
459                 fscal            = (vcoul+br*Vvdwexp-6.0*Vvdw6)*rinvsq;
460                 fscal *= hybscal;
461                 if(force_cap>0 && (fabs(fscal)> force_cap)){
462                 fscal=force_cap*fscal/fabs(fscal);
463                 }
464                 tx               = fscal*dx11;     
465                 ty               = fscal*dy11;     
466                 tz               = fscal*dz11;     
467                 fix1             = fix1 + tx;      
468                 fiy1             = fiy1 + ty;      
469                 fiz1             = fiz1 + tz;      
470                 fjx1             = faction[j3+0] - tx;
471                 fjy1             = faction[j3+1] - ty;
472                 fjz1             = faction[j3+2] - tz;
473                 qq               = qH*jq;          
474                 rinvsq           = rinv21*rinv21;  
475                 vcoul            = qq*rinv21;      
476                 vctot            = vctot+vcoul;    
477                 fscal            = (vcoul)*rinvsq; 
478                 fscal *= hybscal;
479                 if(force_cap>0 && (fabs(fscal)> force_cap)){
480                 fscal=force_cap*fscal/fabs(fscal);
481                 }
482                 tx               = fscal*dx21;     
483                 ty               = fscal*dy21;     
484                 tz               = fscal*dz21;     
485                 fix2             = fix2 + tx;      
486                 fiy2             = fiy2 + ty;      
487                 fiz2             = fiz2 + tz;      
488                 fjx1             = fjx1 - tx;      
489                 fjy1             = fjy1 - ty;      
490                 fjz1             = fjz1 - tz;      
491                 rinvsq           = rinv31*rinv31;  
492                 vcoul            = qq*rinv31;      
493                 vctot            = vctot+vcoul;    
494                 fscal            = (vcoul)*rinvsq; 
495                 fscal *= hybscal;
496                 if(force_cap>0 && (fabs(fscal)> force_cap)){
497                 fscal=force_cap*fscal/fabs(fscal);
498                 }
499                 tx               = fscal*dx31;     
500                 ty               = fscal*dy31;     
501                 tz               = fscal*dz31;     
502                 fix3             = fix3 + tx;      
503                 fiy3             = fiy3 + ty;      
504                 fiz3             = fiz3 + tz;      
505                 faction[j3+0]    = fjx1 - tx;      
506                 faction[j3+1]    = fjy1 - ty;      
507                 faction[j3+2]    = fjz1 - tz;      
508             }
509             
510             faction[ii3+0]   = faction[ii3+0] + fix1;
511             faction[ii3+1]   = faction[ii3+1] + fiy1;
512             faction[ii3+2]   = faction[ii3+2] + fiz1;
513             faction[ii3+3]   = faction[ii3+3] + fix2;
514             faction[ii3+4]   = faction[ii3+4] + fiy2;
515             faction[ii3+5]   = faction[ii3+5] + fiz2;
516             faction[ii3+6]   = faction[ii3+6] + fix3;
517             faction[ii3+7]   = faction[ii3+7] + fiy3;
518             faction[ii3+8]   = faction[ii3+8] + fiz3;
519             fshift[is3]      = fshift[is3]+fix1+fix2+fix3;
520             fshift[is3+1]    = fshift[is3+1]+fiy1+fiy2+fiy3;
521             fshift[is3+2]    = fshift[is3+2]+fiz1+fiz2+fiz3;
522             ggid             = gid[n];         
523             Vc[ggid]         = Vc[ggid] + vctot;
524             Vvdw[ggid]       = Vvdw[ggid] + Vvdwtot;
525             ninner           = ninner + nj1 - nj0;
526         }
527         
528         nouter           = nouter + nn1 - nn0;
529     }
530     while (nn1<nri);
531     
532     *outeriter       = nouter;         
533     *inneriter       = ninner;         
534 }
535
536