OGS
MeshToolsLib::MeshValidation Struct Referencefinal

Detailed Description

A collection of methods for testing mesh quality and correctness.

Definition at line 24 of file MeshValidation.h.

#include <MeshValidation.h>

Static Public Member Functions

static bool allNodesUsed (MeshLib::Mesh const &mesh)
static bool existCollapsibleNodes (MeshLib::Mesh &mesh, double const eps)
static void evaluateElementGeometry (MeshLib::Mesh const &mesh)
static std::vector< ElementErrorCodetestElementGeometry (const MeshLib::Mesh &mesh, double min_volume=std::numeric_limits< double >::epsilon())
static std::array< std::string, static_cast< std::size_t >(ElementErrorFlag::MaxValue)> ElementErrorCodeOutput (const std::vector< ElementErrorCode > &error_codes)
static unsigned detectHoles (MeshLib::Mesh const &mesh)

Member Function Documentation

◆ allNodesUsed()

bool MeshToolsLib::MeshValidation::allNodesUsed ( MeshLib::Mesh const & mesh)
static

Tests if all nodes of the mesh are used in an element.

Parameters
meshThe mesh that is tested
Returns
true, if all nodes are used, else false

Definition at line 53 of file MeshValidation.cpp.

54{
55 INFO("Looking for unused nodes...");
56 MeshLib::NodeSearch ns(mesh);
57 ns.searchUnused();
58 if (!ns.getSearchedNodeIDs().empty())
59 {
60 INFO("{:d} unused mesh nodes found.", ns.getSearchedNodeIDs().size());
61 return false;
62 }
63 return true;
64}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28

References MeshLib::NodeSearch::getSearchedNodeIDs(), INFO(), and MeshLib::NodeSearch::searchUnused().

Referenced by MeshToolsLib::MeshInformation::writeMeshValidationResults().

◆ detectHoles()

unsigned MeshToolsLib::MeshValidation::detectHoles ( MeshLib::Mesh const & mesh)
static

Tests if holes are located within the mesh. In this context, a hole is a boundary of an element with no neighbor that cannot be reached from the actual boundary of the mesh. Examples include a missing triangle in a 2D mesh or a missing Tetrahedron in a 3D mesh. The method does not work for 1d-meshes. Note, that this method does not work when complex 3D structures are build from 2D mesh elements, e.g. using the LayeredVolume-class, where more than two 2D elements may share an edge.

Parameters
meshThe mesh that is tested
Returns
The number of holes that have been found.

Definition at line 197 of file MeshValidation.cpp.

198{
199 if (mesh.getDimension() == 1)
200 {
201 return 0;
202 }
203
204 auto boundary_mesh =
206 mesh,
210 std::vector<MeshLib::Element*> const& elements(
211 boundary_mesh->getElements());
212
213 std::vector<unsigned> sfc_idx(elements.size(),
214 std::numeric_limits<unsigned>::max());
215 unsigned current_surface_id(0);
216 auto it = sfc_idx.cbegin();
217
218 while (it != sfc_idx.cend())
219 {
220 std::size_t const idx =
221 static_cast<std::size_t>(std::distance(sfc_idx.cbegin(), it));
222 trackSurface(elements[idx], sfc_idx, current_surface_id++);
223 it = std::find(sfc_idx.cbegin(),
224 sfc_idx.cend(),
225 std::numeric_limits<unsigned>::max());
226 }
227
228 // Subtract "1" from the number of surfaces found to get the number of
229 // holes.
230 return (--current_surface_id);
231}
constexpr std::string_view getBulkIDString(MeshItemType mesh_item_type)
std::unique_ptr< MeshLib::Mesh > getBoundaryElementsAsMesh(MeshLib::Mesh const &bulk_mesh, std::string_view subsfc_node_id_prop_name, std::string_view subsfc_element_id_prop_name, std::string_view face_id_prop_name)
static void trackSurface(MeshLib::Element const *const element, std::vector< unsigned > &sfc_idx, unsigned const current_index)

References MeshLib::Cell, MeshLib::Face, MeshToolsLib::BoundaryExtraction::getBoundaryElementsAsMesh(), MeshLib::getBulkIDString(), MeshLib::Mesh::getDimension(), MeshLib::Node, and MeshToolsLib::trackSurface().

Referenced by MeshAnalysisDialog::on_startButton_pressed(), and MeshToolsLib::MeshInformation::writeMeshValidationResults().

◆ ElementErrorCodeOutput()

std::array< std::string, static_cast< std::size_t >(ElementErrorFlag::MaxValue)> MeshToolsLib::MeshValidation::ElementErrorCodeOutput ( const std::vector< ElementErrorCode > & error_codes)
static

Detailed output which ElementID is associated with which error(s)

Returns
String containing the report

Definition at line 159 of file MeshValidation.cpp.

161{
162 const auto nErrorFlags(
163 static_cast<std::size_t>(ElementErrorFlag::MaxValue));
164 const ElementErrorFlag flags[nErrorFlags] = {
167 const std::size_t nElements(error_codes.size());
168 std::array<std::string,
169 static_cast<std::size_t>(ElementErrorFlag::MaxValue)>
170 output;
171
172 for (std::size_t i = 0; i < nErrorFlags; ++i)
173 {
174 unsigned count(0);
175 std::string elementIdStr;
176
177 for (std::size_t j = 0; j < nElements; ++j)
178 {
179 if (error_codes[j][flags[i]])
180 {
181 elementIdStr += (std::to_string(j) + ", ");
182 count++;
183 }
184 }
185 const std::string nErrorsStr = (count) ? std::to_string(count) : "No";
186 output[i] = (nErrorsStr + " elements found with " +
187 ElementErrorCode::toString(flags[i]) + ".\n");
188
189 if (count)
190 {
191 output[i] += ("ElementIDs: " + elementIdStr + "\n");
192 }
193 }
194 return output;
195}
ElementErrorFlag
Possible error flags for mesh elements.
static std::string toString(const ElementErrorFlag e)
Returns a string output for a specific error flag.

References MaxValue, NodeOrder, NonConvex, NonCoplanar, ElementErrorCode::toString(), and ZeroVolume.

Referenced by MeshAnalysisDialog::elementsMsgOutput(), and evaluateElementGeometry().

◆ evaluateElementGeometry()

void MeshToolsLib::MeshValidation::evaluateElementGeometry ( MeshLib::Mesh const & mesh)
static

Prints evaluation data computed by testElementGeometry.

Parameters
meshThe mesh that is tested

Definition at line 75 of file MeshValidation.cpp.

76{
77 const std::vector<ElementErrorCode> codes(
79 std::array<std::string,
80 static_cast<std::size_t>(ElementErrorFlag::MaxValue)>
82 for (auto& i : output_str)
83 {
84 INFO("{:s}", i);
85 }
86}
static std::array< std::string, static_cast< std::size_t >(ElementErrorFlag::MaxValue)> ElementErrorCodeOutput(const std::vector< ElementErrorCode > &error_codes)
static std::vector< ElementErrorCode > testElementGeometry(const MeshLib::Mesh &mesh, double min_volume=std::numeric_limits< double >::epsilon())

References ElementErrorCodeOutput(), INFO(), MaxValue, and testElementGeometry().

Referenced by MeshToolsLib::MeshInformation::writeMeshValidationResults().

◆ existCollapsibleNodes()

bool MeshToolsLib::MeshValidation::existCollapsibleNodes ( MeshLib::Mesh & mesh,
double const eps )
static

Tests if nodes of the mesh can be collapsed.

Parameters
meshThe mesh that is tested
epsDistance threshold, if distance of two nodes is less than the eps then they are considered as collapsible.
Returns
true, if nodes can be collapsed, else false

Definition at line 66 of file MeshValidation.cpp.

68{
69 MeshRevision const rev(mesh);
70 INFO("Found {:d} potentially collapsible nodes.",
71 rev.getNumberOfCollapsibleNodes(eps));
72 return (rev.getNumberOfCollapsibleNodes() > 0);
73}

References MeshToolsLib::MeshRevision::getNumberOfCollapsibleNodes(), and INFO().

Referenced by MeshToolsLib::MeshInformation::writeMeshValidationResults().

◆ testElementGeometry()

std::vector< ElementErrorCode > MeshToolsLib::MeshValidation::testElementGeometry ( const MeshLib::Mesh & mesh,
double min_volume = std::numeric_limits<double>::epsilon() )
static

Tests if elements are geometrically correct.

Parameters
meshThe mesh that is tested
min_volumeThe minimum required volume for a mesh element, so it is NOT considered faulty
Returns
Vector of error codes for each mesh element

Definition at line 88 of file MeshValidation.cpp.

90{
91 INFO("Testing mesh element geometry:");
92 const auto nErrorCodes(
93 static_cast<std::size_t>(ElementErrorFlag::MaxValue));
94 unsigned error_count[nErrorCodes];
95 std::fill_n(error_count, 4, 0);
96 const std::size_t nElements(mesh.getNumberOfElements());
97 const std::vector<MeshLib::Element*>& elements(mesh.getElements());
98 std::vector<ElementErrorCode> error_code_vector;
99 error_code_vector.reserve(nElements);
100
101 for (std::size_t i = 0; i < nElements; ++i)
102 {
103 const ElementErrorCode e = elements[i]->validate();
104 error_code_vector.push_back(e);
105 if (e.none())
106 {
107 continue;
108 }
109
110 // increment error statistics
111 const std::bitset<static_cast<std::size_t>(ElementErrorFlag::MaxValue)>
112 flags(static_cast<std::bitset<static_cast<std::size_t>(
114 for (unsigned j = 0; j < nErrorCodes; ++j)
115 {
116 error_count[j] += flags[j];
117 }
118 }
119
120 // if a larger volume threshold is given, evaluate elements again to add
121 // them even if they are formally okay
122 if (min_volume > std::numeric_limits<double>::epsilon())
123 {
124 for (std::size_t i = 0; i < nElements; ++i)
125 {
126 if (elements[i]->getContent() < min_volume)
127 {
128 error_code_vector[i].set(ElementErrorFlag::ZeroVolume);
129 }
130 }
131 }
132
133 // output
134 const auto error_sum(static_cast<unsigned>(
135 std::accumulate(error_count, error_count + nErrorCodes, 0.0)));
136 if (error_sum != 0)
137 {
138 ElementErrorFlag const flags[nErrorCodes] = {
141 for (std::size_t i = 0; i < nErrorCodes; ++i)
142 {
143 if (error_count[i])
144 {
145 INFO("{:d} elements found with {:s}.",
146 error_count[i],
148 }
149 }
150 }
151 else
152 {
153 INFO("No errors found.");
154 }
155 return error_code_vector;
156}
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:101
std::size_t getNumberOfElements() const
Get the number of elements.
Definition Mesh.h:89

References MeshLib::Mesh::getElements(), MeshLib::Mesh::getNumberOfElements(), INFO(), MaxValue, NodeOrder, NonConvex, NonCoplanar, ElementErrorCode::toString(), and ZeroVolume.

Referenced by evaluateElementGeometry(), and MeshAnalysisDialog::on_startButton_pressed().


The documentation for this struct was generated from the following files: