Merge branch release-4-6
[alexxy/gromacs.git] / src / gromacs / mdlib / wnblist.c
1 /*
2  *
3  *                This source code is part of
4  *
5  *                 G   R   O   M   A   C   S
6  *
7  *          GROningen MAchine for Chemical Simulations
8  *
9  *                        VERSION 3.2.0
10  * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12  * Copyright (c) 2001-2004, The GROMACS development team,
13  * check out http://www.gromacs.org for more information.
14
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * If you want to redistribute modifications, please consider that
21  * scientific software is very special. Version control is crucial -
22  * bugs must be traceable. We will be happy to consider code for
23  * inclusion in the official distribution, but derived work must not
24  * be called official GROMACS. Details are found in the README & COPYING
25  * files - if they are missing, get the official version at www.gromacs.org.
26  *
27  * To help us fund GROMACS development, we humbly ask that you cite
28  * the papers on the package - you can find them in the top README file.
29  *
30  * For more info, check our website at http://www.gromacs.org
31  *
32  * And Hey:
33  * GROwing Monsters And Cloning Shrimps
34  */
35 /* This file is completely threadsafe - keep it that way! */
36 #ifdef HAVE_CONFIG_H
37 #include <config.h>
38 #endif
39
40 #include <stdio.h>
41 #include <string.h>
42 #include "string2.h"
43 #include "force.h"
44 #include "smalloc.h"
45 #include "ns.h"
46 #include "nrnb.h"
47 #include "gmx_fatal.h"
48 #include "macros.h"
49 #include "gromacs/fileio/futil.h"
50 #include "names.h"
51 #include "domdec.h"
52 #include "gromacs/fileio/gmxfio.h"
53
54 #define header "Neighborlist:"
55
56 static void write_nblist(FILE *out, gmx_domdec_t *dd, t_nblist *nblist, int nDNL)
57 {
58     int                 i, nii, ii, j, zi, zj0, zj1, aj, zj, nj;
59     int                 ca1[DD_MAXZONE], np[DD_MAXZONE];
60     gmx_domdec_zones_t *dd_zones;
61
62     if (nblist->nri > 0)
63     {
64         fprintf(out, "ielec: %d, ivdw: %d, type: %d, Solvent opt: %s\n",
65                 nblist->ielec, nblist->ivdw, nblist->type,
66                 gmx_nblist_geometry_names[nblist->igeometry]);
67         fprintf(out, "nri: %d  npair: %d\n", nblist->nri, nblist->nrj);
68         if (dd)
69         {
70             dd_zones = domdec_zones(dd);
71
72             for (zi = 0; zi < dd_zones->n; zi++)
73             {
74                 ca1[zi] = dd->cgindex[dd_zones->cg_range[zi+1]];
75             }
76             i = 0;
77             for (zi = 0; zi < dd_zones->nizone; zi++)
78             {
79                 zj0 = dd_zones->izone[zi].j0;
80                 zj1 = dd_zones->izone[zi].j1;
81                 for (zj = zj0; zj < zj1; zj++)
82                 {
83                     np[zj] = 0;
84                 }
85                 while (i < nblist->nri && nblist->iinr[i] < ca1[zi])
86                 {
87                     for (j = nblist->jindex[i]; (j < nblist->jindex[i+1]); j++)
88                     {
89                         aj = nblist->jjnr[j];
90                         zj = zj0;
91                         while (aj >= ca1[zj])
92                         {
93                             zj++;
94                         }
95                         np[zj]++;
96                     }
97                     i++;
98                 }
99                 fprintf(out, "DD zone %d:", zi);
100                 for (zj = zj0; zj < zj1; zj++)
101                 {
102                     fprintf(out, " %d %d", zj, np[zj]);
103                 }
104                 fprintf(out, "\n");
105             }
106         }
107         if (nDNL >= 2)
108         {
109             for (i = 0; i < nblist->nri; i++)
110             {
111                 nii = 1;
112                 if (nDNL >= 3 && nblist->igeometry != GMX_NBLIST_GEOMETRY_PARTICLE_PARTICLE)
113                 {
114                     nii = 3;
115                 }
116                 nj = nblist->jindex[i+1] - nblist->jindex[i];
117                 fprintf(out, "i: %d shift: %d gid: %d nj: %d\n",
118                         ddglatnr(dd, nblist->iinr[i]),
119                         nblist->shift[i], nblist->gid[i], nj);
120                 for (ii = 0; ii < nii; ii++)
121                 {
122                     for (j = nblist->jindex[i]; (j < nblist->jindex[i+1]); j++)
123                     {
124                         fprintf(out, "  i: %5d  j: %5d\n",
125                                 ddglatnr(dd, nblist->iinr[i]+ii),
126                                 ddglatnr(dd, nblist->jjnr[j]));
127                     }
128                 }
129             }
130         }
131         fflush(out);
132     }
133 }
134
135 static void set_mat(FILE *fp, int **mat, int i0, int ni, int j0, int nj,
136                     gmx_bool bSymm, int shift)
137 {
138     int i, j;
139
140     for (i = i0; (i < i0+ni); i++)
141     {
142         for (j = j0; (j < j0+nj); j++)
143         {
144             if (mat[i][j] != 0)
145             {
146                 fprintf(fp, "mat[%d][%d] changing from %d to %d\n",
147                         i, j, mat[i][j], shift+1);
148             }
149             mat[i][j] = shift+1;
150             if (bSymm)
151             {
152                 mat[j][i] = 27-shift;
153             }
154         }
155     }
156 }
157
158
159
160 void dump_nblist(FILE *out, t_commrec *cr, t_forcerec *fr, int nDNL)
161 {
162 #if 0
163     static FILE *fp = NULL;
164     char         buf[STRLEN];
165     int          n, i;
166
167     if (fp == NULL)
168     {
169         if (PAR(cr))
170         {
171             sprintf(buf, "nlist_n%d.txt", cr->nodeid);
172         }
173         else
174         {
175             sprintf(buf, "nlist.txt");
176         }
177         fp = gmx_fio_fopen(buf, "w");
178     }
179     fprintf(fp, "%s\n", header);
180
181     for (n = 0; (n < fr->nnblists); n++)
182     {
183         for (i = 0; (i < eNL_NR); i++)
184         {
185             write_nblist(fp, cr->dd, &fr->nblists[n].nlist_sr[i], nDNL);
186         }
187     }
188 #endif
189     char buf[STRLEN];
190     int  n, i;
191
192     fprintf(out, "%s\n", header);
193
194     for (n = 0; (n < fr->nnblists); n++)
195     {
196         for (i = 0; (i < eNL_NR); i++)
197         {
198             write_nblist(out, cr->dd, &fr->nblists[n].nlist_sr[i], nDNL);
199         }
200     }
201
202 }