OGS
MeshInformation.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "MeshInformation.h"
5
6#include <range/v3/action/sort.hpp>
7#include <range/v3/action/unique.hpp>
8#include <range/v3/range/conversion.hpp>
9#include <range/v3/view/unique.hpp>
10
14
15namespace
16{
17template <typename T>
19{
20 auto const bounds = MeshToolsLib::MeshInformation::getValueBounds(property);
21 if (!bounds.has_value())
22 {
23 INFO("\t{:s}: Could not get value bounds for property vector.",
24 property.getPropertyName());
25 return;
26 }
27 INFO("\t{:s}: ({:d} values) [{}, {}]", property.getPropertyName(),
28 property.size(), bounds->first, bounds->second);
29}
30} // namespace
31
32namespace MeshToolsLib
33{
35{
36 const std::vector<MeshLib::Node*>& nodes(mesh.getNodes());
37 return GeoLib::AABB(nodes.begin(), nodes.end());
38}
39
40std::map<MeshLib::MeshElemType, unsigned>
42{
43 std::map<MeshLib::MeshElemType, unsigned> n_element_types;
44 const std::vector<MeshLib::Element*>& elements(mesh.getElements());
45 for (auto element : elements)
46 {
47 MeshLib::MeshElemType t = element->getGeomType();
48 n_element_types[t]++;
49 }
50 return n_element_types;
51}
52
54{
55 auto const& nr_ele_types =
57
58 INFO("Number of elements in the mesh:");
59 for (auto entry : nr_ele_types)
60 {
61 INFO("\t{:s}s: {:d}",
63 static_cast<MeshLib::MeshElemType>(entry.first)),
64 entry.second);
65 }
66}
67
69{
70 auto const& properties = mesh.getProperties();
71 INFO("There are {:d} properties in the mesh:", properties.size());
72
73 for (auto [name, property] : properties)
74 {
75 if (auto const* p =
76 dynamic_cast<MeshLib::PropertyVector<double>*>(property))
77 {
78 printBounds(*p);
79 }
80 else if (auto const* p =
81 dynamic_cast<MeshLib::PropertyVector<float>*>(property))
82 {
83 printBounds(*p);
84 }
85 else if (auto const* p =
86 dynamic_cast<MeshLib::PropertyVector<int>*>(property))
87 {
88 printBounds(*p);
89 }
90 else if (auto const* p =
91 dynamic_cast<MeshLib::PropertyVector<unsigned>*>(property))
92 {
93 printBounds(*p);
94 }
95 else if (auto const* p =
96 dynamic_cast<MeshLib::PropertyVector<long>*>(property))
97 {
98 printBounds(*p);
99 }
100 else if (auto const* p =
102 property))
103 {
104 printBounds(*p);
105 }
106 else if (auto const* p =
108 property))
109 {
110 printBounds(*p);
111 }
112 else if (auto const* p =
114 property))
115 {
116 printBounds(*p);
117 }
118 else if (auto const* p =
120 property))
121 {
122 printBounds(*p);
123 }
124 else if (auto const* p =
125 dynamic_cast<MeshLib::PropertyVector<char>*>(property))
126 {
127 printBounds(*p);
128 }
129 else
130 {
131 INFO(
132 "\t{:s}: Could not get value bounds for property vector of "
133 "type '{:s}'.",
134 name, BaseLib::typeToString(*property));
135 }
136 }
137}
138
140{
141 INFO("Mesh Quality Control:");
145
146 unsigned const n_holes(MeshToolsLib::MeshValidation::detectHoles(mesh));
147 if (n_holes > 0)
148 {
149 INFO("{:d} hole(s) detected within the mesh", n_holes);
150 }
151 else
152 {
153 INFO("No holes found within the mesh.");
154 }
155}
156
158{
159 auto const* matids = MeshLib::materialIDs(mesh);
160 if (!matids)
161 {
162 INFO("No MaterialIDs were found.");
163 return {};
164 }
165
166 return *matids | ranges::views::unique | ranges::to<std::vector> |
167 ranges::actions::sort | ranges::actions::unique |
168 ranges::to<std::vector>;
169}
170
171} // namespace MeshToolsLib
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition AABB.h:45
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:97
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:100
Properties & getProperties()
Definition Mesh.h:125
std::string const & getPropertyName() const
constexpr 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 typeToString()
std::string MeshElemType2String(const MeshElemType t)
Given a MeshElemType this returns the appropriate string.
Definition MeshEnums.cpp:10
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition Mesh.cpp:258
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition MeshEnums.h:37
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)