OGS
SizeDifferenceMetric.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
5
6#include <limits>
7
8namespace MeshToolsLib
9{
11{
12 std::vector<MeshLib::Element*> const& elements(_mesh.getElements());
13 std::size_t const nElements(_mesh.getNumberOfElements());
14 std::size_t const mesh_dim(_mesh.getDimension());
15
16 for (std::size_t k = 0; k < nElements; ++k)
17 {
18 MeshLib::Element const& elem(*elements[k]);
19 if (elem.getDimension() < mesh_dim)
20 {
22 continue;
23 }
24
25 std::size_t const n_neighbors(elem.getNumberOfNeighbors());
26 double const vol_a(elem.getContent());
27
28 double worst_ratio(1.0);
29 for (std::size_t i = 0; i < n_neighbors; ++i)
30 {
31 MeshLib::Element const* const neighbor(elem.getNeighbor(i));
32 if (neighbor == nullptr)
33 {
34 continue;
35 }
36 double const vol_b(neighbor->getContent());
37 double const ratio =
38 (vol_a > vol_b) ? vol_b / vol_a : vol_a / vol_b;
39 if (ratio < worst_ratio)
40 {
41 worst_ratio = ratio;
42 }
43 }
44 _element_quality_metric[k] = worst_ratio;
45 }
46}
47
48} // namespace MeshToolsLib
virtual double getContent() const =0
Returns the length, area or volume of a 1D, 2D or 3D element.
virtual unsigned getNumberOfNeighbors() const =0
Get the number of neighbors for this element.
virtual constexpr unsigned getDimension() const =0
Get dimension of the mesh element.
virtual const Element * getNeighbor(unsigned i) const =0
Get the specified neighbor.
std::vector< double > _element_quality_metric
void calculateQuality() override
Calculates the quality metric for each element of the mesh.