dune-grid  2.2.1
common/gridinfo.hh
Go to the documentation of this file.
1 // $Id: gridinfo.hh 7772 2011-11-15 09:31:37Z sander $
2 
3 #ifndef DUNE_GRIDINFO_HH
4 #define DUNE_GRIDINFO_HH
5 
6 #include <iostream>
7 #include <typeinfo>
8 #include <dune/common/exceptions.hh>
9 #include <dune/common/classname.hh>
10 #include <dune/geometry/referenceelements.hh>
11 #include "grid.hh"
12 
19 namespace Dune
20 {
29  template<class G>
30  void gridinfo (const G& grid, std::string prefix="")
31  {
32  // first we extract the dimensions of the grid
33  const int dim = G::dimension;
34  const int dimworld = G::dimensionworld;
35 
36  // grid type and dimension
37  std::cout << prefix << "=> " << className(grid)
38  << " (dim=" << dim
39  << ", dimworld=" << dimworld
40  << ")" << std::endl;
41 
42  // level information
43  for (int level=0; level<=grid.maxLevel(); level++)
44  {
45  std::cout << prefix << "level " << level;
46  for (int cd=0; cd<=dim; cd++)
47  {
48  std::cout << " codim[" << cd << "]=" << grid.size(level,cd);
49  }
50  std::cout << std::endl;
51  }
52 
53  // leaf information
54  std::cout << prefix << "leaf ";
55  for (int cd=0; cd<=dim; cd++)
56  {
57  std::cout << " codim[" << cd << "]=" << grid.size(cd);
58  }
59  std::cout << std::endl;
60 
61  std::cout << prefix << "leaf"
62  << " dim=" << dim
63  << " geomTypes=(";
64  bool first=true;
65  for (int c=0; c<=dim; c++)
66  {
67  for (std::size_t i=0; i<grid.leafIndexSet().geomTypes(c).size(); i++)
68  {
69  if (!first) std::cout << ",";
70  std::cout << grid.leafIndexSet().geomTypes(c)[i]
71  << "[" << c << "]"
72  << "=" << grid.leafIndexSet().size(grid.leafIndexSet().geomTypes(c)[i]);
73  first=false;
74  }
75  }
76  std::cout << ")" << std::endl;
77 
78 
79  return;
80  }
81 
82 
85  template<class G>
86  void gridlevellist (const G& grid, int level, std::string prefix)
87  {
88  // first we extract the dimensions of the grid
89  const int dim = G::dimension;
90 
91  // type used for coordinates in the grid
92  typedef typename G::ctype ct;
93 
94  // the grid has an iterator providing the access to
95  // all elements (better codim 0 entities) on a grid level
96  // Note the use of the typename and template keywords.
97  typedef typename G::Traits::template Codim<0>::LevelIterator LevelIterator;
98 
99  // print info about this level
100  std::cout << prefix << "level=" << level
101  << " dim=" << dim
102  << " geomTypes=(";
103  bool first=true;
104  for (unsigned i=0; i<grid.levelIndexSet(level).geomTypes(0).size(); i++)
105  {
106  if (!first) std::cout << ",";
107  std::cout << grid.levelIndexSet(level).geomTypes(0)[i]
108  << "=" << grid.levelIndexSet(level).size(grid.levelIndexSet(level).geomTypes(0)[i]);
109  first=false;
110  }
111  std::cout << ")" << std::endl;
112 
113  // print info about each element on given level
114  LevelIterator eendit = grid.template lend<0>(level);
115  for (LevelIterator it = grid.template lbegin<0>(level); it!=eendit; ++it)
116  {
117  std::cout << prefix << "level=" << it->level()
118  << " " << it->type() << "[" << dim << "]"
119  << " index=" << grid.levelIndexSet(level).index(*it)
120  << " gid=" << grid.globalIdSet().template id<0>(*it)
121  << " leaf=" << it->isLeaf()
122  << " partition=" << PartitionName(it->partitionType())
123  << " center=("
124  << it->geometry().global(Dune::GenericReferenceElements<ct,dim>::general(it->type()).position(0,0))
125  << ")"
126  << " first=(" << it->geometry().corner(0) << ")"
127  << std::endl;
128 
129  std::cout << prefix << "codim " << dim << " subindex";
130  for (int i=0; i<it->template count<dim>(); i++)
131  {
132  std::cout << " " << i << ":" << grid.levelIndexSet(level).subIndex(*it,i,dim);
133  }
134  std::cout << std::endl;
135 
136  std::cout << prefix << "codim " << dim-1 << " subindex";
137  for (int i=0; i<it->template count<dim-1>(); i++)
138  {
139  std::cout << " " << i << ":" << grid.levelIndexSet(level).subIndex(*it,i,dim-1);
140  }
141  std::cout << std::endl;
142 
143  }
144 
145  return;
146  }
147 
148 
151  template<class G>
152  void gridleaflist (const G& grid, std::string prefix)
153  {
154  // first we extract the dimensions of the grid
155  const int dim = G::dimension;
156 
157  // type used for coordinates in the grid
158  typedef typename G::ctype ct;
159 
160  // the grid has an iterator providing the access to
161  // all elements (better codim 0 entities) on a grid level
162  // Note the use of the typename and template keywords.
163  typedef typename G::Traits::template Codim<0>::LeafIterator LeafIterator;
164  typedef typename G::Traits::template Codim<dim>::LeafIterator VLeafIterator;
165 
166  // print info about the leaf grid
167  std::cout << prefix << "leaf"
168  << " dim=" << dim
169  << " geomTypes=(";
170  bool first=true;
171  for (int c=0; c<=dim; c++)
172  {
173  for (unsigned i=0; i<grid.leafIndexSet().geomTypes(c).size(); i++)
174  {
175  if (!first) std::cout << ",";
176  std::cout << grid.leafIndexSet().geomTypes(c)[i]
177  << "[" << c << "]"
178  << "=" << grid.leafIndexSet().size(grid.leafIndexSet().geomTypes(c)[i]);
179  first=false;
180  }
181  }
182  std::cout << ")" << std::endl;
183 
184  // print info about nodes in leaf grid
185  VLeafIterator veendit = grid.template leafend<dim>();
186  for (VLeafIterator it = grid.template leafbegin<dim>(); it!=veendit; ++it)
187  {
188  std::cout << prefix << "level=" << it->level()
189  << " " << it->type() << "[" << dim << "]"
190  << " index=" << grid.leafIndexSet().index(*it)
191  << " gid=" << grid.globalIdSet().template id<dim>(*it)
192  << " partition=" << PartitionName(it->partitionType())
193  << " pos=(" << it->geometry().corner(0) << ")"
194  << std::endl;
195  }
196 
197  // print info about each element in leaf grid
198  LeafIterator eendit = grid.template leafend<0>();
199  for (LeafIterator it = grid.template leafbegin<0>(); it!=eendit; ++it)
200  {
201  std::cout << prefix << "level=" << it->level()
202  << " " << it->type() << "[" << dim << "]"
203  << " index=" << grid.leafIndexSet().index(*it)
204  << " gid=" << grid.globalIdSet().template id<0>(*it)
205  << " leaf=" << it->isLeaf()
206  << " partition=" << PartitionName(it->partitionType())
207  << " center=("
208  << it->geometry().global(Dune::GenericReferenceElements<ct,dim>::general(it->type()).position(0,0))
209  << ")"
210  << " first=(" << it->geometry().corner(0) << ")"
211  << std::endl;
212 
213  std::cout << prefix << "codim " << dim << " subindex";
214  for (int i=0; i<it->template count<dim>(); i++)
215  {
216  std::cout << " " << i << ":" << grid.leafIndexSet().subIndex(*it,i,dim);
217  }
218  std::cout << std::endl;
219 
220  std::cout << prefix << "codim " << dim-1 << " subindex";
221  for (int i=0; i<it->template count<dim-1>(); i++)
222  {
223  std::cout << " " << i << ":" << grid.leafIndexSet().subIndex(*it,i,dim-1);
224  }
225  std::cout << std::endl;
226 
227  }
228 
229  return;
230  }
231 
232 
235 }
236 #endif