Dune Core Modules (2.4.2)

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
4#ifndef DUNE_GRIDINFO_HH
5#define DUNE_GRIDINFO_HH
6
7#include <iostream>
8#include <typeinfo>
11#include <dune/geometry/referenceelements.hh>
12#include "grid.hh"
13
20namespace Dune
21{
30 template<class G>
31 void gridinfo (const G& grid, std::string prefix="")
32 {
33 // first we extract the dimensions of the grid
34 const int dim = G::dimension;
35 const int dimworld = G::dimensionworld;
36
37 // grid type and dimension
38 std::cout << prefix << "=> " << className(grid)
39 << " (dim=" << dim
40 << ", dimworld=" << dimworld
41 << ")" << std::endl;
42
43 // level information
44 for (int level=0; level<=grid.maxLevel(); level++)
45 {
46 std::cout << prefix << "level " << level;
47 for (int cd=0; cd<=dim; cd++)
48 {
49 std::cout << " codim[" << cd << "]=" << grid.size(level,cd);
50 }
51 std::cout << std::endl;
52 }
53
54 // leaf information
55 std::cout << prefix << "leaf ";
56 for (int cd=0; cd<=dim; cd++)
57 {
58 std::cout << " codim[" << cd << "]=" << grid.size(cd);
59 }
60 std::cout << std::endl;
61
62 std::cout << prefix << "leaf"
63 << " dim=" << dim
64 << " types=(";
65 bool first=true;
66 for (int c=0; c<=dim; c++)
67 {
68 for (std::size_t i=0; i<grid.leafIndexSet().types(c).size(); i++)
69 {
70 if (!first) std::cout << ",";
71 std::cout << grid.leafIndexSet().types(c)[i]
72 << "[" << c << "]"
73 << "=" << grid.leafIndexSet().size(grid.leafIndexSet().types(c)[i]);
74 first=false;
75 }
76 }
77 std::cout << ")" << std::endl;
78
79
80 return;
81 }
82
83
86 template<class G>
87 void gridlevellist (const G& grid, int level, std::string prefix)
88 {
89 // first we extract the dimensions of the grid
90 const int dim = G::dimension;
91
92 // type used for coordinates in the grid
93 typedef typename G::ctype ct;
94
95 // the grid has an iterator providing the access to
96 // all elements (better codim 0 entities) on a grid level
97 // Note the use of the typename and template keywords.
98 typedef typename G::Traits::template Codim<0>::LevelIterator LevelIterator;
99
100 // print info about this level
101 std::cout << prefix << "level=" << level
102 << " dim=" << dim
103 << " types=(";
104 bool first=true;
105 for (unsigned i=0; i<grid.levelIndexSet(level).types(0).size(); i++)
106 {
107 if (!first) std::cout << ",";
108 std::cout << grid.levelIndexSet(level).types(0)[i]
109 << "=" << grid.levelIndexSet(level).size(grid.levelIndexSet(level).types(0)[i]);
110 first=false;
111 }
112 std::cout << ")" << std::endl;
113
114 // print info about each element on given level
115 LevelIterator eendit = grid.levelGridView(level).template end<0>();
116 for (LevelIterator it = grid.levelGridView(level).template begin<0>();
117 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 << " types=(";
172 bool first=true;
173 for (int c=0; c<=dim; c++)
174 {
175 for (unsigned i=0; i<grid.leafIndexSet().types(c).size(); i++)
176 {
177 if (!first) std::cout << ",";
178 std::cout << grid.leafIndexSet().types(c)[i]
179 << "[" << c << "]"
180 << "=" << grid.leafIndexSet().size(grid.leafIndexSet().types(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
A free function to provide the demangled class name of a given object or type as a string.
A few common exception classes.
std::string PartitionName(PartitionType type)
Provide names for the partition types.
Definition: gridenums.hh:44
void gridinfo(const G &grid, std::string prefix="")
A function to print some information about the grid as a whole.
Definition: gridinfo.hh:31
void gridlevellist(const G &grid, int level, std::string prefix)
A function to print info about a grid level and its entities.
Definition: gridinfo.hh:87
void gridleaflist(const G &grid, std::string prefix)
A function to print info about a leaf grid and its entities.
Definition: gridinfo.hh:154
Dune namespace.
Definition: alignment.hh:10
std::string className(T &t)
Provide the demangled class name of a given object as a string.
Definition: classname.hh:23
Static tag representing a codimension.
Definition: dimension.hh:22
Class providing access to the singletons of the reference elements.
Definition: referenceelements.hh:479
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)