Fluid structure interaction suite
grid_info.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2022 by Luca Heltai
4 //
5 // This file is part of the FSI-suite platform, based on the deal.II library.
6 //
7 // The FSI-suite platform is free software; you can use it, redistribute it,
8 // and/or modify it under the terms of the GNU Lesser General Public License as
9 // published by the Free Software Foundation; either version 3.0 of the License,
10 // or (at your option) any later version. The full text of the license can be
11 // found in the file LICENSE at the top level of the FSI-suite platform
12 // distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef parsed_tools_grid_info_h
17 #define parsed_tools_grid_info_h
18 
19 #include <deal.II/base/patterns.h>
20 
22 #include <deal.II/grid/tria.h>
23 
24 namespace dealii
25 {
26  namespace Patterns
27  {
28  namespace Tools
29  {
35  template <>
36  struct Convert<dealii::types::manifold_id>
37  {
38  using T = dealii::types::manifold_id;
44  static std::unique_ptr<dealii::Patterns::PatternBase>
46  {
47  return Patterns::Integer(-1).clone();
48  }
49 
57  static std::string
58  to_string(const T &t,
59  const dealii::Patterns::PatternBase &pattern =
60  *Convert<T>::to_pattern())
61  {
62  return Convert<int>::to_string(static_cast<int>(t), pattern);
63  }
64 
72  static T
73  to_value(const std::string &s,
74  const dealii::Patterns::PatternBase &pattern =
75  *Convert<T>::to_pattern())
76  {
77  return T(Convert<int>::to_value(s, pattern));
78  }
79  };
80 
86  template <>
87  struct Convert<dealii::ReferenceCell>
88  {
89  using T = dealii::ReferenceCell;
95  static std::unique_ptr<dealii::Patterns::PatternBase>
97  {
98  return Convert<int>::to_pattern();
99  }
100 
108  static std::string
109  to_string(const T &t,
110  const dealii::Patterns::PatternBase &pattern =
111  *Convert<T>::to_pattern())
112  {
113  return Convert<int>::to_string(t, pattern);
114  }
115 
116 
124  static T
125  to_value(const std::string &s,
126  const dealii::Patterns::PatternBase &pattern =
127  *Convert<T>::to_pattern())
128  {
129  return dealii::internal::make_reference_cell_from_int(
130  Convert<int>::to_value(s, pattern));
131  }
132  };
133  } // namespace Tools
134  } // namespace Patterns
135 } // namespace dealii
136 
137 namespace ParsedTools
138 {
148  struct GridInfo
149  {
156  GridInfo(const unsigned int info_level = 0)
158  {}
159 
168  template <int dim, int spacedim>
169  GridInfo(const dealii::Triangulation<dim, spacedim> &tria,
170  const unsigned int info_level = 0)
172  {
173  build_info(tria);
174  }
175 
181  template <int dim, int spacedim>
182  void
183  build_info(const dealii::Triangulation<dim, spacedim> &tria)
184  {
185  n_active_cells = tria.n_active_cells();
186  n_vertices = tria.n_vertices();
187  n_used_vertices = tria.n_used_vertices();
188  n_levels = tria.n_levels();
189  if (info_level > 0)
190  {
192  n_cells_at_level.resize(n_levels);
193  for (unsigned int i = 0; i < n_levels; ++i)
194  {
195  n_active_cells_at_level[i] = tria.n_active_cells(i);
196  n_cells_at_level[i] = tria.n_cells(i);
197  }
198  }
199  if (info_level > 1)
200  {
201  boundary_ids = tria.get_boundary_ids();
202  manifold_ids = tria.get_manifold_ids();
203  reference_cell_types = tria.get_reference_cells();
204 
205  std::set<dealii::types::material_id> m_ids;
206  for (const auto &cell : tria.active_cell_iterators())
207  m_ids.insert(cell->material_id());
208  material_ids.insert(material_ids.end(), m_ids.begin(), m_ids.end());
209  }
210 
211  if (info_level > 2)
212  {
213  for (const auto &id : boundary_ids)
214  faces_per_boundary_id[id] = 0;
215 
216  for (const auto &id : material_ids)
217  cells_per_material_id[id] = 0;
218 
219  for (const auto &id : manifold_ids)
220  {
221  faces_per_manifold_id[id] = 0;
222  cells_per_manifold_id[id] = 0;
223  }
224 
225  for (const auto &id : reference_cell_types)
227 
228  for (const auto &cell : tria.active_cell_iterators())
229  {
230  ++cells_per_material_id[cell->material_id()];
231  ++cells_per_manifold_id[cell->manifold_id()];
232  ++cells_per_reference_cell_type[cell->reference_cell()];
233  }
234 
235  for (const auto &f : tria.active_face_iterators())
236  {
237  if (f->at_boundary())
238  ++faces_per_boundary_id[f->boundary_id()];
239  ++faces_per_manifold_id[f->manifold_id()];
240  }
241  }
242  }
243 
249  template <typename StreamType>
250  void
251  print_info(StreamType &out)
252  {
253  out << "Active cells : " << n_active_cells << std::endl
254  << "Vertices : " << n_vertices << std::endl
255  << "Used vertices : " << n_used_vertices << std::endl
256  << "Levels : " << n_levels << std::endl;
257  if (info_level > 0 && n_levels > 1)
258  {
259  out << "Active cells/level : "
260  << dealii::Patterns::Tools::to_string(n_active_cells_at_level)
261  << std::endl
262  << "Cells/level : "
263  << dealii::Patterns::Tools::to_string(n_cells_at_level)
264  << std::endl;
265  }
266  if (info_level > 1)
267  {
268  out << "Boundary ids : "
269  << dealii::Patterns::Tools::to_string(boundary_ids) << std::endl
270  << "Manifold ids : "
271  << dealii::Patterns::Tools::to_string(manifold_ids) << std::endl
272  << "Material ids : "
273  << dealii::Patterns::Tools::to_string(material_ids) << std::endl
274  << "Reference cell types : "
275  << dealii::Patterns::Tools::to_string(reference_cell_types)
276  << std::endl;
277  }
278  if (info_level > 2)
279  {
280  out << "Boundary id:n_faces : "
281  << dealii::Patterns::Tools::to_string(faces_per_boundary_id)
282  << std::endl
283  << "Material id:n_cells : "
284  << dealii::Patterns::Tools::to_string(cells_per_material_id)
285  << std::endl
286  << "Manifold id:n_faces : "
287  << dealii::Patterns::Tools::to_string(faces_per_manifold_id)
288  << std::endl
289  << "Manifold id:n_cells : "
290  << dealii::Patterns::Tools::to_string(cells_per_manifold_id)
291  << std::endl
292  << "Reference cell type:n_cells : "
293  << dealii::Patterns::Tools::to_string(
295  << std::endl;
296  }
297  }
298 
300  unsigned int info_level = 0;
301 
303  unsigned int n_active_cells = 0;
304 
306  unsigned int n_vertices = 0;
307 
309  unsigned int n_used_vertices = 0;
310 
312  unsigned int n_levels = 0;
313 
315  std::vector<unsigned int> n_active_cells_at_level;
316 
318  std::vector<unsigned int> n_cells_at_level;
319 
321  std::vector<dealii::types::boundary_id> boundary_ids;
322 
324  std::vector<dealii::types::material_id> material_ids;
325 
327  std::vector<dealii::types::manifold_id> manifold_ids;
328 
330  std::vector<dealii::ReferenceCell> reference_cell_types;
331 
333  std::map<dealii::types::boundary_id, unsigned int> faces_per_boundary_id;
334 
336  std::map<dealii::types::material_id, unsigned int> cells_per_material_id;
337 
339  std::map<dealii::types::manifold_id, unsigned int> faces_per_manifold_id;
340 
342  std::map<dealii::types::manifold_id, unsigned int> cells_per_manifold_id;
343 
345  std::map<dealii::ReferenceCell, unsigned int> cells_per_reference_cell_type;
346  };
347 } // namespace ParsedTools
348 #endif
virtual std::unique_ptr< PatternBase > clone() const override
We collect in this namespace some wrappers around commonly used deal.II classes, derived from the Par...
unsigned int manifold_id
Gather information about a Triangulation.
Definition: grid_info.h:149
GridInfo(const Triangulation< dim, spacedim > &tria, const unsigned int info_level=0)
Construct a new Grid Info object, and gather all information about the Triangulation tria.
Definition: grid_info.h:169
unsigned int n_active_cells
Number of active cells.
Definition: grid_info.h:303
void print_info(StreamType &out)
Print all gathered information about the Triangulation.
Definition: grid_info.h:251
std::vector< types::manifold_id > manifold_ids
Manifold ids.
Definition: grid_info.h:327
GridInfo(const unsigned int info_level=0)
Construct a new (empty) Grid Info object.
Definition: grid_info.h:156
std::vector< unsigned int > n_active_cells_at_level
Number of active cells at each level.
Definition: grid_info.h:315
void build_info(const Triangulation< dim, spacedim > &tria)
Actually build the information about the Triangulation.
Definition: grid_info.h:183
std::map< types::boundary_id, unsigned int > faces_per_boundary_id
Number of faces per boundary id.
Definition: grid_info.h:333
unsigned int n_levels
Number of levels.
Definition: grid_info.h:312
std::map< types::material_id, unsigned int > cells_per_material_id
Number of cells per boundary id.
Definition: grid_info.h:336
std::map< ReferenceCell, unsigned int > cells_per_reference_cell_type
Number of cells per reference cell type.
Definition: grid_info.h:345
std::vector< types::boundary_id > boundary_ids
Boundary ids.
Definition: grid_info.h:321
std::vector< ReferenceCell > reference_cell_types
Reference cell types.
Definition: grid_info.h:330
std::map< types::manifold_id, unsigned int > cells_per_manifold_id
Number of cells per manifold id.
Definition: grid_info.h:342
std::vector< unsigned int > n_cells_at_level
Number of cells at each level.
Definition: grid_info.h:318
unsigned int info_level
Level of information to gather.
Definition: grid_info.h:300
std::vector< types::material_id > material_ids
Material ids.
Definition: grid_info.h:324
unsigned int n_vertices
Number of vertices.
Definition: grid_info.h:306
std::map< types::manifold_id, unsigned int > faces_per_manifold_id
Number of faces per manifold id.
Definition: grid_info.h:339
unsigned int n_used_vertices
Number of used vertices.
Definition: grid_info.h:309
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Default pattern for converting a ReferenceCell to a string.
Definition: grid_info.h:96
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Convert a ReferenceCell to a string.
Definition: grid_info.h:109
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Convert a string to a ReferenceCell.
Definition: grid_info.h:125
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Convert a string to a manifold_id.
Definition: grid_info.h:73
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Convert a manifold_id to a string.
Definition: grid_info.h:58
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Default pattern for converting a manifold_id to a string.
Definition: grid_info.h:45