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