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)
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 196 of file MeshValidation.cpp.

197{
198 if (mesh.getDimension() == 1)
199 {
200 return 0;
201 }
202
203 auto boundary_mesh =
205 mesh,
209 std::vector<MeshLib::Element*> const& elements(
210 boundary_mesh->getElements());
211
212 std::vector<unsigned> sfc_idx(elements.size(),
213 std::numeric_limits<unsigned>::max());
214 unsigned current_surface_id(0);
215 auto it = sfc_idx.cbegin();
216
217 while (it != sfc_idx.cend())
218 {
219 std::size_t const idx =
220 static_cast<std::size_t>(std::distance(sfc_idx.cbegin(), it));
221 trackSurface(elements[idx], sfc_idx, current_surface_id++);
222 it = std::find(sfc_idx.cbegin(),
223 sfc_idx.cend(),
224 std::numeric_limits<unsigned>::max());
225 }
226
227 // Subtract "1" from the number of surfaces found to get the number of
228 // holes.
229 return (--current_surface_id);
230}
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 158 of file MeshValidation.cpp.

160{
161 const auto nErrorFlags(
162 static_cast<std::size_t>(ElementErrorFlag::MaxValue));
163 const ElementErrorFlag flags[nErrorFlags] = {
166 const std::size_t nElements(error_codes.size());
167 std::array<std::string,
168 static_cast<std::size_t>(ElementErrorFlag::MaxValue)>
169 output;
170
171 for (std::size_t i = 0; i < nErrorFlags; ++i)
172 {
173 unsigned count(0);
174 std::string elementIdStr;
175
176 for (std::size_t j = 0; j < nElements; ++j)
177 {
178 if (error_codes[j][flags[i]])
179 {
180 elementIdStr += (std::to_string(j) + ", ");
181 count++;
182 }
183 }
184 const std::string nErrorsStr = (count) ? std::to_string(count) : "No";
185 output[i] = (nErrorsStr + " elements found with " +
186 ElementErrorCode::toString(flags[i]) + ".\n");
187
188 if (count)
189 {
190 output[i] += ("ElementIDs: " + elementIdStr + "\n");
191 }
192 }
193 return output;
194}
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 74 of file MeshValidation.cpp.

75{
76 const std::vector<ElementErrorCode> codes(
78 std::array<std::string,
79 static_cast<std::size_t>(ElementErrorFlag::MaxValue)>
81 for (auto& i : output_str)
82 {
83 INFO("{:s}", i);
84 }
85}
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)
static

Tests if nodes of the mesh can be collapsed.

Parameters
meshThe mesh that is tested
Returns
true, if nodes can be collapsed, else false

Definition at line 66 of file MeshValidation.cpp.

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

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 87 of file MeshValidation.cpp.

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

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: