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