OGS
ElementSizeMetric.cpp
Go to the documentation of this file.
1 
15 #include "ElementSizeMetric.h"
16 
17 #include <limits>
18 
19 namespace MeshLib
20 {
22 {
23  std::size_t error_count(0);
24  if (_mesh.getDimension() == 1)
25  {
26  error_count = calc1dQuality();
27  }
28  else if (_mesh.getDimension() == 2)
29  {
30  error_count = calc2dQuality();
31  }
32  else if (_mesh.getDimension() == 3)
33  {
34  error_count = calc3dQuality();
35  }
36 
37  INFO(
38  "ElementSizeMetric::calculateQuality() minimum: {:f}, max_volume: {:f}",
39  _min,
40  _max);
41  if (error_count > 0)
42  {
43  WARN("Warning: {:d} elements with zero volume found.", error_count);
44  }
45 }
46 
48 {
49  const std::vector<MeshLib::Element*>& elements(_mesh.getElements());
50  const std::size_t nElems(elements.size());
51  std::size_t error_count(0);
52 
53  for (std::size_t k(0); k < nElems; k++)
54  {
55  double area(std::numeric_limits<double>::max());
56  _element_quality_metric[k] = elements[k]->getContent();
58  std::sqrt(std::abs(std::numeric_limits<double>::epsilon())))
59  {
60  error_count++;
61  }
62 
63  // update _min and _max values
64  if (_min > area)
65  {
66  _min = area;
67  }
68  if (_max < area)
69  {
70  _max = area;
71  }
72  }
73  return error_count;
74 }
75 
77 {
78  const std::vector<MeshLib::Element*>& elements(_mesh.getElements());
79  const std::size_t nElems(elements.size());
80  std::size_t error_count(0);
81 
82  for (std::size_t k(0); k < nElems; k++)
83  {
84  Element const& elem(*elements[k]);
85 
86  if (elem.getDimension() == 1)
87  {
88  _element_quality_metric[k] = 0.0;
89  continue;
90  }
91  double const area = elem.getContent();
92  if (area < std::sqrt(std::abs(std::numeric_limits<double>::epsilon())))
93  {
94  error_count++;
95  }
96 
97  // update _min and _max values
98  if (_min > area)
99  {
100  _min = area;
101  }
102  if (_max < area)
103  {
104  _max = area;
105  }
106  _element_quality_metric[k] = area;
107  }
108  return error_count;
109 }
110 
112 {
113  const std::vector<MeshLib::Element*>& elements(_mesh.getElements());
114  const std::size_t nElems(elements.size());
115  std::size_t error_count(0);
116 
117  for (std::size_t k(0); k < nElems; k++)
118  {
119  Element const& elem(*elements[k]);
120  if (elem.getDimension() < 3)
121  {
122  _element_quality_metric[k] = 0.0;
123  continue;
124  }
125 
126  double const volume(elem.getContent());
127  if (volume < sqrt(std::abs(std::numeric_limits<double>::epsilon())))
128  {
129  error_count++;
130  }
131 
132  if (_min > volume)
133  {
134  _min = volume;
135  }
136  if (_max < volume)
137  {
138  _max = volume;
139  }
140  _element_quality_metric[k] = volume;
141  }
142  return error_count;
143 }
144 
145 } // end namespace MeshLib
Implementation of the AreaMetric class.
void INFO(char const *fmt, Args const &... args)
Definition: Logging.h:32
void WARN(char const *fmt, Args const &... args)
Definition: Logging.h:37
std::vector< double > _element_quality_metric
void calculateQuality() override
Calculates the quality metric for each element of the mesh.
virtual double getContent() const =0
Returns the length, area or volume of a 1D, 2D or 3D element.
virtual constexpr unsigned getDimension() const =0
Get dimension of the mesh element.
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition: Mesh.h:71
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition: Mesh.h:98