DUNE PDELab (2.8)

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_GRID_COMMON_GRIDINFO_HH
5#define DUNE_GRID_COMMON_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
83 template<class G>
84 void gridlevellist (const G& grid, int level, std::string prefix)
85 {
86 // first we extract the dimensions of the grid
87 const int dim = G::dimension;
88
89 // type used for coordinates in the grid
90 typedef typename G::ctype ct;
91
92 // print info about this level
93 std::cout << prefix << "level=" << level
94 << " dim=" << dim
95 << " types=(";
96 bool first=true;
97 for (unsigned i=0; i<grid.levelIndexSet(level).types(0).size(); i++)
98 {
99 if (!first) std::cout << ",";
100 std::cout << grid.levelIndexSet(level).types(0)[i]
101 << "=" << grid.levelIndexSet(level).size(grid.levelIndexSet(level).types(0)[i]);
102 first=false;
103 }
104 std::cout << ")" << std::endl;
105
106 // print info about each element on given level
107 for (const auto& element : elements(levelGridView(grid, level)))
108 {
109 const auto& geometry = element.geometry();
110 std::cout << prefix << "level=" << element.level()
111 << " " << element.type() << "[" << dim << "]"
112 << " index=" << grid.levelIndexSet(level).index(element)
113 << " gid=" << grid.globalIdSet().template id<0>(element)
114 << " leaf=" << element.isLeaf()
115 << " partition=" << PartitionName(element.partitionType())
116 << " center=("
117 << geometry.global(Dune::ReferenceElements<ct,dim>::general(element.type()).position(0,0))
118 << ")"
119 << " first=(" << geometry.corner(0) << ")"
120 << std::endl;
121
122 std::cout << prefix << "codim " << dim << " subindex";
123 for (unsigned int i=0; i < element.subEntities(dim); i++)
124 {
125 std::cout << " " << i << ":" << grid.levelIndexSet(level).subIndex(element,i,dim);
126 }
127 std::cout << std::endl;
128
129 std::cout << prefix << "codim " << dim-1 << " subindex";
130 for (unsigned int i=0; i < element.subEntities(dim-1); i++)
131 {
132 std::cout << " " << i << ":" << grid.levelIndexSet(level).subIndex(element,i,dim-1);
133 }
134 std::cout << std::endl;
135
136 }
137 }
138
139
142 template<class G>
143 void gridleaflist (const G& grid, std::string prefix)
144 {
145 // first we extract the dimensions of the grid
146 const int dim = G::dimension;
147
148 // type used for coordinates in the grid
149 typedef typename G::ctype ct;
150
151 // print info about the leaf grid
152 std::cout << prefix << "leaf"
153 << " dim=" << dim
154 << " types=(";
155 bool first=true;
156 for (int c=0; c<=dim; c++)
157 {
158 for (unsigned i=0; i<grid.leafIndexSet().types(c).size(); i++)
159 {
160 if (!first) std::cout << ",";
161 std::cout << grid.leafIndexSet().types(c)[i]
162 << "[" << c << "]"
163 << "=" << grid.leafIndexSet().size(grid.leafIndexSet().types(c)[i]);
164 first=false;
165 }
166 }
167 std::cout << ")" << std::endl;
168
169 // print info about nodes in leaf grid
170 for (const auto& vertex : vertices(leafGridView(grid)))
171 {
172 std::cout << prefix << "level=" << vertex.level()
173 << " " << vertex.type() << "[" << dim << "]"
174 << " index=" << grid.leafIndexSet().index(vertex)
175 << " gid=" << grid.globalIdSet().template id<dim>(vertex)
176 << " partition=" << PartitionName(vertex.partitionType())
177 << " pos=(" << vertex.geometry().corner(0) << ")"
178 << std::endl;
179 }
180
181 // print info about each element in leaf grid
182 for (const auto& element : elements(leafGridView(grid)))
183 {
184 const auto& geometry = element.geometry();
185 std::cout << prefix << "level=" << element.level()
186 << " " << element.type() << "[" << dim << "]"
187 << " index=" << grid.leafIndexSet().index(element)
188 << " gid=" << grid.globalIdSet().template id<0>(element)
189 << " leaf=" << element.isLeaf()
190 << " partition=" << PartitionName(element.partitionType())
191 << " center=("
192 << geometry.global(Dune::ReferenceElements<ct,dim>::general(element.type()).position(0,0))
193 << ")"
194 << " first=(" << geometry.corner(0) << ")"
195 << std::endl;
196
197 std::cout << prefix << "codim " << dim << " subindex";
198 for (unsigned int i=0; i < element.subEntities(dim); i++)
199 {
200 std::cout << " " << i << ":" << grid.leafIndexSet().subIndex(element,i,dim);
201 }
202 std::cout << std::endl;
203
204 std::cout << prefix << "codim " << dim-1 << " subindex";
205 for (unsigned int i=0; i < element.subEntities(dim-1); i++)
206 {
207 std::cout << " " << i << ":" << grid.leafIndexSet().subIndex(element,i,dim-1);
208 }
209 std::cout << std::endl;
210
211 }
212 }
213
214
217}
218#endif
A free function to provide the demangled class name of a given object or type as a string.
A few common exception classes.
Grid< dim, dimworld, ct, GridFamily >::LeafGridView leafGridView(const Grid< dim, dimworld, ct, GridFamily > &grid)
leaf grid view for the given grid
Definition: grid.hh:808
Grid< dim, dimworld, ct, GridFamily >::LevelGridView levelGridView(const Grid< dim, dimworld, ct, GridFamily > &grid, int level)
level grid view for the given grid and level.
Definition: grid.hh:791
std::string PartitionName(PartitionType type)
Provide names for the partition types.
Definition: gridenums.hh:44
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:504
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:84
void gridleaflist(const G &grid, std::string prefix)
A function to print info about a leaf grid and its entities.
Definition: gridinfo.hh:143
Dune namespace.
Definition: alignedallocator.hh:11
std::string className()
Provide the demangled class name of a type T as a string.
Definition: classname.hh:45
Class providing access to the singletons of the reference elements.
Definition: referenceelements.hh:168
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)