Dune Core Modules (unstable)

gridinfo.hh
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 // vi: set et ts=4 sw=2 sts=2:
5 
6 #ifndef DUNE_GRID_COMMON_GRIDINFO_HH
7 #define DUNE_GRID_COMMON_GRIDINFO_HH
8 
9 #include <iostream>
10 #include <typeinfo>
12 #include <dune/common/classname.hh>
13 #include <dune/geometry/referenceelements.hh>
14 #include "grid.hh"
15 
22 namespace Dune
23 {
32  template<class G>
33  void gridinfo (const G& grid, std::string prefix="")
34  {
35  // first we extract the dimensions of the grid
36  const int dim = G::dimension;
37  const int dimworld = G::dimensionworld;
38 
39  // grid type and dimension
40  std::cout << prefix << "=> " << className(grid)
41  << " (dim=" << dim
42  << ", dimworld=" << dimworld
43  << ")" << std::endl;
44 
45  // level information
46  for (int level=0; level<=grid.maxLevel(); level++)
47  {
48  std::cout << prefix << "level " << level;
49  for (int cd=0; cd<=dim; cd++)
50  {
51  std::cout << " codim[" << cd << "]=" << grid.size(level,cd);
52  }
53  std::cout << std::endl;
54  }
55 
56  // leaf information
57  std::cout << prefix << "leaf ";
58  for (int cd=0; cd<=dim; cd++)
59  {
60  std::cout << " codim[" << cd << "]=" << grid.size(cd);
61  }
62  std::cout << std::endl;
63 
64  std::cout << prefix << "leaf"
65  << " dim=" << dim
66  << " types=(";
67  bool first=true;
68  for (int c=0; c<=dim; c++)
69  {
70  for (std::size_t i=0; i<grid.leafIndexSet().types(c).size(); i++)
71  {
72  if (!first) std::cout << ",";
73  std::cout << grid.leafIndexSet().types(c)[i]
74  << "[" << c << "]"
75  << "=" << grid.leafIndexSet().size(grid.leafIndexSet().types(c)[i]);
76  first=false;
77  }
78  }
79  std::cout << ")" << std::endl;
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  // print info about this level
95  std::cout << prefix << "level=" << level
96  << " dim=" << dim
97  << " types=(";
98  bool first=true;
99  for (unsigned i=0; i<grid.levelIndexSet(level).types(0).size(); i++)
100  {
101  if (!first) std::cout << ",";
102  std::cout << grid.levelIndexSet(level).types(0)[i]
103  << "=" << grid.levelIndexSet(level).size(grid.levelIndexSet(level).types(0)[i]);
104  first=false;
105  }
106  std::cout << ")" << std::endl;
107 
108  // print info about each element on given level
109  for (const auto& element : elements(levelGridView(grid, level)))
110  {
111  const auto& geometry = element.geometry();
112  std::cout << prefix << "level=" << element.level()
113  << " " << element.type() << "[" << dim << "]"
114  << " index=" << grid.levelIndexSet(level).index(element)
115  << " gid=" << grid.globalIdSet().template id<0>(element)
116  << " leaf=" << element.isLeaf()
117  << " partition=" << PartitionName(element.partitionType())
118  << " center=("
119  << geometry.global(Dune::ReferenceElements<ct,dim>::general(element.type()).position(0,0))
120  << ")"
121  << " first=(" << geometry.corner(0) << ")"
122  << std::endl;
123 
124  std::cout << prefix << "codim " << dim << " subindex";
125  for (unsigned int i=0; i < element.subEntities(dim); i++)
126  {
127  std::cout << " " << i << ":" << grid.levelIndexSet(level).subIndex(element,i,dim);
128  }
129  std::cout << std::endl;
130 
131  std::cout << prefix << "codim " << dim-1 << " subindex";
132  for (unsigned int i=0; i < element.subEntities(dim-1); i++)
133  {
134  std::cout << " " << i << ":" << grid.levelIndexSet(level).subIndex(element,i,dim-1);
135  }
136  std::cout << std::endl;
137 
138  }
139  }
140 
141 
144  template<class G>
145  void gridleaflist (const G& grid, std::string prefix)
146  {
147  // first we extract the dimensions of the grid
148  const int dim = G::dimension;
149 
150  // type used for coordinates in the grid
151  typedef typename G::ctype ct;
152 
153  // print info about the leaf grid
154  std::cout << prefix << "leaf"
155  << " dim=" << dim
156  << " types=(";
157  bool first=true;
158  for (int c=0; c<=dim; c++)
159  {
160  for (unsigned i=0; i<grid.leafIndexSet().types(c).size(); i++)
161  {
162  if (!first) std::cout << ",";
163  std::cout << grid.leafIndexSet().types(c)[i]
164  << "[" << c << "]"
165  << "=" << grid.leafIndexSet().size(grid.leafIndexSet().types(c)[i]);
166  first=false;
167  }
168  }
169  std::cout << ")" << std::endl;
170 
171  // print info about nodes in leaf grid
172  for (const auto& vertex : vertices(leafGridView(grid)))
173  {
174  std::cout << prefix << "level=" << vertex.level()
175  << " " << vertex.type() << "[" << dim << "]"
176  << " index=" << grid.leafIndexSet().index(vertex)
177  << " gid=" << grid.globalIdSet().template id<dim>(vertex)
178  << " partition=" << PartitionName(vertex.partitionType())
179  << " pos=(" << vertex.geometry().corner(0) << ")"
180  << std::endl;
181  }
182 
183  // print info about each element in leaf grid
184  for (const auto& element : elements(leafGridView(grid)))
185  {
186  const auto& geometry = element.geometry();
187  std::cout << prefix << "level=" << element.level()
188  << " " << element.type() << "[" << dim << "]"
189  << " index=" << grid.leafIndexSet().index(element)
190  << " gid=" << grid.globalIdSet().template id<0>(element)
191  << " leaf=" << element.isLeaf()
192  << " partition=" << PartitionName(element.partitionType())
193  << " center=("
194  << geometry.global(Dune::ReferenceElements<ct,dim>::general(element.type()).position(0,0))
195  << ")"
196  << " first=(" << geometry.corner(0) << ")"
197  << std::endl;
198 
199  std::cout << prefix << "codim " << dim << " subindex";
200  for (unsigned int i=0; i < element.subEntities(dim); i++)
201  {
202  std::cout << " " << i << ":" << grid.leafIndexSet().subIndex(element,i,dim);
203  }
204  std::cout << std::endl;
205 
206  std::cout << prefix << "codim " << dim-1 << " subindex";
207  for (unsigned int i=0; i < element.subEntities(dim-1); i++)
208  {
209  std::cout << " " << i << ":" << grid.leafIndexSet().subIndex(element,i,dim-1);
210  }
211  std::cout << std::endl;
212 
213  }
214  }
215 
216 
219 }
220 #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:805
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:788
std::string PartitionName(PartitionType type)
Provide names for the partition types.
Definition: gridenums.hh:46
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:492
void gridinfo(const G &grid, std::string prefix="")
A function to print some information about the grid as a whole.
Definition: gridinfo.hh:33
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:86
void gridleaflist(const G &grid, std::string prefix)
A function to print info about a leaf grid and its entities.
Definition: gridinfo.hh:145
Dune namespace.
Definition: alignedallocator.hh:13
std::string className()
Provide the demangled class name of a type T as a string.
Definition: classname.hh:47
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
Class providing access to the singletons of the reference elements.
Definition: referenceelements.hh:128
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 6, 22:30, 2024)