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>

Public Member Functions

 MeshValidation (MeshLib::Mesh &mesh)
 

Static Public Member Functions

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)
 

Constructor & Destructor Documentation

◆ MeshValidation()

MeshLib::MeshValidation::MeshValidation ( MeshLib::Mesh mesh)
explicit

Constructor

Warning
This might change the mesh when removing unused mesh nodes.

Definition at line 64 of file MeshValidation.cpp.

65 {
66  INFO("Mesh Quality Control:");
67  INFO("Looking for unused nodes...");
68  NodeSearch ns(mesh);
69  ns.searchUnused();
70  if (!ns.getSearchedNodeIDs().empty())
71  {
72  INFO("{:d} unused mesh nodes found.", ns.getSearchedNodeIDs().size());
73  }
74  MeshRevision rev(mesh);
75  INFO("Found {:d} potentially collapsible nodes.",
76  rev.getNumberOfCollapsableNodes());
77 
78  const std::vector<ElementErrorCode> codes(
80  std::array<std::string,
81  static_cast<std::size_t>(ElementErrorFlag::MaxValue)>
83  for (auto& i : output_str)
84  {
85  INFO("{:s}", i);
86  }
87 }
void INFO(char const *fmt, Args const &... args)
Definition: Logging.h:32
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(), MeshLib::MeshRevision::getNumberOfCollapsableNodes(), MeshLib::NodeSearch::getSearchedNodeIDs(), INFO(), MaxValue, MeshLib::NodeSearch::searchUnused(), and testElementGeometry().

Member Function Documentation

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

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

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

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

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

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

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


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