OGS
MeshInformation.cpp
Go to the documentation of this file.
1
15#include "MeshInformation.h"
16
17#include <range/v3/action/sort.hpp>
18#include <range/v3/action/unique.hpp>
19#include <range/v3/range/conversion.hpp>
20#include <range/v3/view/unique.hpp>
21
24
25namespace
26{
27template <typename T>
29{
30 auto const bounds = MeshToolsLib::MeshInformation::getValueBounds(property);
31 if (!bounds.has_value())
32 {
33 INFO("\t{:s}: Could not get value bounds for property vector.",
34 property.getPropertyName());
35 return;
36 }
37 INFO("\t{:s}: ({:d} values) [{}, {}]", property.getPropertyName(),
38 property.size(), bounds->first, bounds->second);
39}
40} // namespace
41
42namespace MeshToolsLib
43{
45{
46 const std::vector<MeshLib::Node*>& nodes(mesh.getNodes());
47 return GeoLib::AABB(nodes.begin(), nodes.end());
48}
49
50std::map<MeshLib::MeshElemType, unsigned>
52{
53 std::map<MeshLib::MeshElemType, unsigned> n_element_types;
54 const std::vector<MeshLib::Element*>& elements(mesh.getElements());
55 for (auto element : elements)
56 {
57 MeshLib::MeshElemType t = element->getGeomType();
58 n_element_types[t]++;
59 }
60 return n_element_types;
61}
62
64{
65 auto const& nr_ele_types =
67
68 INFO("Number of elements in the mesh:");
69 for (auto entry : nr_ele_types)
70 {
71 INFO("\t{:s}s: {:d}",
73 static_cast<MeshLib::MeshElemType>(entry.first)),
74 entry.second);
75 }
76}
77
79{
80 auto const& properties = mesh.getProperties();
81 INFO("There are {:d} properties in the mesh:", properties.size());
82
83 for (auto [name, property] : properties)
84 {
85 if (auto const* p =
86 dynamic_cast<MeshLib::PropertyVector<double>*>(property))
87 {
88 printBounds(*p);
89 }
90 else if (auto const* p =
91 dynamic_cast<MeshLib::PropertyVector<float>*>(property))
92 {
93 printBounds(*p);
94 }
95 else if (auto const* p =
96 dynamic_cast<MeshLib::PropertyVector<int>*>(property))
97 {
98 printBounds(*p);
99 }
100 else if (auto const* p =
101 dynamic_cast<MeshLib::PropertyVector<unsigned>*>(property))
102 {
103 printBounds(*p);
104 }
105 else if (auto const* p =
106 dynamic_cast<MeshLib::PropertyVector<long>*>(property))
107 {
108 printBounds(*p);
109 }
110 else if (auto const* p =
112 property))
113 {
114 printBounds(*p);
115 }
116 else if (auto const* p =
118 property))
119 {
120 printBounds(*p);
121 }
122 else if (auto const* p =
124 property))
125 {
126 printBounds(*p);
127 }
128 else if (auto const* p =
130 property))
131 {
132 printBounds(*p);
133 }
134 else if (auto const* p =
135 dynamic_cast<MeshLib::PropertyVector<char>*>(property))
136 {
137 printBounds(*p);
138 }
139 else
140 {
141 INFO(
142 "\t{:s}: Could not get value bounds for property vector of "
143 "type '{:s}'.",
144 name, typeid(*p).name());
145 }
146 }
147}
148
150{
151 INFO("Mesh Quality Control:");
155
156 unsigned const n_holes(MeshToolsLib::MeshValidation::detectHoles(mesh));
157 if (n_holes > 0)
158 {
159 INFO("{:d} hole(s) detected within the mesh", n_holes);
160 }
161 else
162 {
163 INFO("No holes found within the mesh.");
164 }
165}
166
168{
169 auto const* matids = MeshLib::materialIDs(mesh);
170 if (!matids)
171 {
172 INFO("No MaterialIDs were found.");
173 return {};
174 }
175
176 return *matids | ranges::views::unique | ranges::to<std::vector> |
177 ranges::actions::sort | ranges::actions::unique |
178 ranges::to<std::vector>;
179}
180
181} // namespace MeshToolsLib
Definition of the Element class.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
Definition of the MeshInformation class.
Definition of the MeshValidation class.
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition AABB.h:56
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:108
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:111
Properties & getProperties()
Definition Mesh.h:136
std::string const & getPropertyName() const
std::size_t size() const
static GeoLib::AABB getBoundingBox(const MeshLib::Mesh &mesh)
Returns the bounding box of the mesh.
static void writeMeshValidationResults(MeshLib::Mesh &mesh)
static std::optional< std::pair< T, T > > const getValueBounds(MeshLib::PropertyVector< T > const &property)
static std::vector< int > getMaterialIDs(const MeshLib::Mesh &mesh)
writes out a list of all material IDs that occur in the mesh.
static void writeAllNumbersOfElementTypes(const MeshLib::Mesh &mesh)
writes all numbers of element types
static std::map< MeshLib::MeshElemType, unsigned > getNumberOfElementTypes(const MeshLib::Mesh &mesh)
static void writePropertyVectorInformation(const MeshLib::Mesh &mesh)
writes out property vector information
std::string MeshElemType2String(const MeshElemType t)
Given a MeshElemType this returns the appropriate string.
Definition MeshEnums.cpp:21
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition Mesh.cpp:268
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition MeshEnums.h:48
void printBounds(MeshLib::PropertyVector< T > const &property)
static bool existCollapsibleNodes(MeshLib::Mesh &mesh)
static unsigned detectHoles(MeshLib::Mesh const &mesh)
static bool allNodesUsed(MeshLib::Mesh const &mesh)
static void evaluateElementGeometry(MeshLib::Mesh const &mesh)