OGS
MeshLib::MeshValidation Struct Referencefinal

Detailed Description

A collection of methods for testing mesh quality and correctness.

Definition at line 30 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 MeshLib::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 64 of file MeshValidation.cpp.

65{
66 INFO("Looking for unused nodes...");
67 NodeSearch ns(mesh);
68 ns.searchUnused();
69 if (!ns.getSearchedNodeIDs().empty())
70 {
71 INFO("{:d} unused mesh nodes found.", ns.getSearchedNodeIDs().size());
72 return false;
73 }
74 return true;
75}
void INFO(char const *fmt, Args const &... args)
Definition: Logging.h:34

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

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

◆ detectHoles()

unsigned MeshLib::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 207 of file MeshValidation.cpp.

208{
209 if (mesh.getDimension() == 1)
210 {
211 return 0;
212 }
213
215 mesh, "bulk_node_ids", "bulk_element_ids", "bulk_face_ids");
216 std::vector<MeshLib::Element*> const& elements(
217 boundary_mesh->getElements());
218
219 std::vector<unsigned> sfc_idx(elements.size(),
220 std::numeric_limits<unsigned>::max());
221 unsigned current_surface_id(0);
222 auto it = sfc_idx.cbegin();
223
224 while (it != sfc_idx.cend())
225 {
226 std::size_t const idx =
227 static_cast<std::size_t>(std::distance(sfc_idx.cbegin(), it));
228 trackSurface(elements[idx], sfc_idx, current_surface_id++);
229 it = std::find(sfc_idx.cbegin(),
230 sfc_idx.cend(),
231 std::numeric_limits<unsigned>::max());
232 }
233
234 // Subtract "1" from the number of surfaces found to get the number of
235 // holes.
236 return (--current_surface_id);
237}
std::unique_ptr< MeshLib::Mesh > getBoundaryElementsAsMesh(MeshLib::Mesh const &bulk_mesh, std::string const &subsfc_node_id_prop_name, std::string const &subsfc_element_id_prop_name, std::string const &face_id_prop_name)
static void trackSurface(MeshLib::Element const *const element, std::vector< unsigned > &sfc_idx, unsigned const current_index)

References MeshLib::BoundaryExtraction::getBoundaryElementsAsMesh(), MeshLib::Mesh::getDimension(), and MeshLib::trackSurface().

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

◆ ElementErrorCodeOutput()

std::array< std::string, static_cast< std::size_t >(ElementErrorFlag::MaxValue)> MeshLib::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 169 of file MeshValidation.cpp.

171{
172 const auto nErrorFlags(
173 static_cast<std::size_t>(ElementErrorFlag::MaxValue));
174 ElementErrorFlag flags[nErrorFlags] = {
177 const std::size_t nElements(error_codes.size());
178 std::array<std::string,
179 static_cast<std::size_t>(ElementErrorFlag::MaxValue)>
180 output;
181
182 for (std::size_t i = 0; i < nErrorFlags; ++i)
183 {
184 unsigned count(0);
185 std::string elementIdStr;
186
187 for (std::size_t j = 0; j < nElements; ++j)
188 {
189 if (error_codes[j][flags[i]])
190 {
191 elementIdStr += (std::to_string(j) + ", ");
192 count++;
193 }
194 }
195 const std::string nErrorsStr = (count) ? std::to_string(count) : "No";
196 output[i] = (nErrorsStr + " elements found with " +
197 ElementErrorCode::toString(flags[i]) + ".\n");
198
199 if (count)
200 {
201 output[i] += ("ElementIDs: " + elementIdStr + "\n");
202 }
203 }
204 return output;
205}
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 MeshLib::MeshValidation::evaluateElementGeometry ( MeshLib::Mesh const &  mesh)
static

Prints evaluation data computed by testElementGeometry.

Parameters
meshThe mesh that is tested

Definition at line 85 of file MeshValidation.cpp.

86{
87 const std::vector<ElementErrorCode> codes(
89 std::array<std::string,
90 static_cast<std::size_t>(ElementErrorFlag::MaxValue)>
92 for (auto& i : output_str)
93 {
94 INFO("{:s}", i);
95 }
96}
static std::vector< ElementErrorCode > testElementGeometry(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)

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

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

◆ existCollapsibleNodes()

bool MeshLib::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 77 of file MeshValidation.cpp.

78{
79 MeshRevision const rev(mesh);
80 INFO("Found {:d} potentially collapsible nodes.",
81 rev.getNumberOfCollapsibleNodes());
82 return (rev.getNumberOfCollapsibleNodes() > 0);
83}

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

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

◆ testElementGeometry()

std::vector< ElementErrorCode > MeshLib::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 98 of file MeshValidation.cpp.

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

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: