LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
Loading...
Searching...
No Matches
print_info.cc
1
9#include "print_info.h"
10
11#include <typeinfo>
12
13#include "lf/geometry/geometry.h"
14
15namespace lf::mesh::utils {
16
17// NOLINTNEXTLINE(readability-function-cognitive-complexity)
18void PrintInfo(std::ostream &o, const lf::mesh::Mesh &mesh, int ctrl) {
19 using dim_t = lf::base::dim_t;
21
22 const dim_t dim_mesh = mesh.DimMesh();
23 const dim_t dim_world = mesh.DimWorld();
24 o << "Mesh of dimension " << static_cast<int>(dim_mesh)
25 << ", ambient dimension " << static_cast<int>(dim_world) << '\n';
26
27 if (ctrl > 10) {
28 // Loop over codimensions
29
30 for (int co_dim = base::narrow<int>(dim_mesh); co_dim >= 0; co_dim--) {
31 const size_type no_ent = mesh.NumEntities(co_dim);
32 o << "Co-dimension " << co_dim << ": " << no_ent << " entities" << '\n';
33
34 // Loop over entities
35 for (const Entity *e : mesh.Entities(co_dim)) {
36 const size_type e_idx = mesh.Index(*e);
37 const dim_t e_codim = e->Codim();
38 const geometry::Geometry *e_geo_ptr = e->Geometry();
39 const lf::base::RefEl e_refel = e->RefEl();
40
41 LF_VERIFY_MSG(e_geo_ptr,
42 co_dim << "-entity " << e_idx << ": missing geometry");
43 LF_VERIFY_MSG(e_geo_ptr->DimLocal() == dim_mesh - co_dim,
44 co_dim << "-entity " << e_idx << ": wrong dimension");
45 LF_VERIFY_MSG(e_geo_ptr->RefEl() == e_refel,
46 co_dim << "-entity " << e_idx << ": refEl mismatch");
47 LF_VERIFY_MSG(e_codim == co_dim, co_dim << "-entity " << e_idx
48 << " co-dimension mismatch");
49 const Eigen::MatrixXd &ref_el_corners(e_refel.NodeCoords());
50 o << "entity " << e_idx << " (" << e_refel << "): ";
51
52 // Loop over local co-dimensions
53 if (ctrl > 90) {
54 for (int l = 1; l <= base::narrow<int>(dim_mesh) - co_dim; l++) {
55 o << "rel codim-" << l << " subent: [";
56 // Fetch subentities of co-dimension l
57 auto sub_ent_range = e->SubEntities(l);
58 for (const Entity *sub_ent : sub_ent_range) {
59 o << mesh.Index(*sub_ent) << ' ';
60 }
61 o << "]";
62 }
63 }
64 if (ctrl > 50) {
65 o << '\n' << e_geo_ptr->Global(ref_el_corners);
66 }
67 o << '\n';
68 } // end loop over entities
69 } // end loop over co-dimensions
70 } // end printinfo_ctrl > 10
71} // end function PrintInfo
72
73// Print function for Entity object
74void PrintInfo(std::ostream &stream, const lf::mesh::Entity &e,
75 int output_ctrl) {
76 // Topological type of entity
77 const lf::base::RefEl e_ref_el = e.RefEl();
78 const base::dim_t dim_ref_el = e_ref_el.Dimension();
79 // Geometry of entity and coordinates
80 const geometry::Geometry *e_geo_ptr = e.Geometry();
81 LF_ASSERT_MSG(e_geo_ptr != nullptr, "Missing geometry information!");
82
83 stream << "Entity " << e_ref_el << "/" << typeid(*e_geo_ptr).name() << '\n';
84
85 if (output_ctrl > 10) {
86 stream << "Dimension: " << dim_ref_el << '\n';
87
88 const Eigen::MatrixXd &ref_el_corners(e_ref_el.NodeCoords());
89
90 // Loop over codimensions
91 for (base::dim_t co_dim = dim_ref_el; co_dim > 0; co_dim--) {
92 const base::size_type num_sub_ent = e_ref_el.NumSubEntities(co_dim);
93 stream << '\n'
94 << "Codimension " << co_dim << ": " << num_sub_ent
95 << " sub-entities" << '\n';
96
97 if (output_ctrl > 50) {
98 int sub_ent_num = 0;
99 // Loop over subentities
100 for (const Entity *sub_ent : e.SubEntities(co_dim)) {
101 const lf::base::RefEl sub_ent_refel = sub_ent->RefEl();
102 stream << "* Subentity " << sub_ent_num << " (" << sub_ent_refel
103 << ")" << '\n';
104
105 if (output_ctrl > 90) {
106 // Print coordinates
107 stream << e_geo_ptr->Global(ref_el_corners).col(sub_ent_num)
108 << '\n';
109 }
110
111 sub_ent_num += 1;
112
113 } // loop sub-ent
114 } // if output ctrl
115 } // loop codim
116
117 if (e_ref_el == lf::base::RefEl::kPoint() && output_ctrl > 90) {
118 stream << e_geo_ptr->Global(ref_el_corners) << '\n';
119 }
120
121 stream << "-----------------------" << '\n';
122
123 } // if
124} // PrintInfo
125
126} // end namespace lf::mesh::utils
Represents a reference element with all its properties.
Definition ref_el.h:109
constexpr RefEl(RefElType type) noexcept
Create a RefEl from a lf::base::RefElType enum.
Definition ref_el.h:175
const Eigen::MatrixXd & NodeCoords() const
Get the coordinates of the nodes of this reference element.
Definition ref_el.h:241
constexpr size_type NumSubEntities(dim_t sub_codim) const
Get the number of sub-entities of this RefEl with the given codimension.
Definition ref_el.h:308
constexpr dim_t Dimension() const
Return the dimension of this reference element.
Definition ref_el.h:204
static constexpr RefEl kPoint()
Returns the (0-dimensional) reference point.
Definition ref_el.h:144
Interface class for shape information on a mesh cell in the spirit of parametric finite element metho...
virtual base::RefEl RefEl() const =0
The Reference element that defines the domain of this mapping.
virtual Eigen::MatrixXd Global(const Eigen::MatrixXd &local) const =0
Map a number of points in local coordinates into the global coordinate system.
virtual dim_t DimLocal() const =0
Dimension of the domain of this mapping.
Interface class representing a topological entity in a cellular complex
Definition entity.h:42
virtual std::span< const Entity *const > SubEntities(unsigned rel_codim) const =0
Return all sub entities of this entity that have the given codimension (w.r.t. this entity!...
virtual const geometry::Geometry * Geometry() const =0
Describes the geometry of this entity.
virtual base::RefEl RefEl() const =0
Describes the reference element type of this entity.
Abstract interface for objects representing a single mesh.
lf::base::size_type size_type
lf::base::dim_t dim_t
virtual unsigned DimWorld() const =0
The dimension of the Euclidean space in which the mesh is embedded.
virtual std::span< const Entity *const > Entities(unsigned codim) const =0
All entities of a given codimension.
virtual size_type NumEntities(unsigned codim) const =0
The number of Entities that have the given codimension.
virtual unsigned DimMesh() const =0
The dimension of the manifold described by the mesh, or equivalently the maximum dimension of the ref...
virtual size_type Index(const Entity &e) const =0
Acess to the index of a mesh entity of any co-dimension.
unsigned int size_type
general type for variables related to size of arrays
Definition types.h:20
unsigned int dim_t
type for dimensions and co-dimensions and numbers derived from them
Definition types.h:32
Contains helper functions and classes that all operate on the interface classes defined in lf::mesh.
void PrintInfo(std::ostream &o, const lf::mesh::Mesh &mesh, int ctrl)
Definition print_info.cc:18