OGS
HeuristicSearchLength.cpp
Go to the documentation of this file.
1
14
15#include "BaseLib/Logging.h"
17
18namespace MeshGeoToolsLib
19{
21 LengthType length_type)
22 : _mesh(mesh)
23{
24 double sum(0.0);
25 double sum_of_sqr(0.0); // total length of edges
26
27 std::size_t n_sampling(0); // total length of edges squared
28 std::vector<MeshLib::Element*> const& elements(_mesh.getElements());
29
30 if (length_type == LengthType::Edge)
31 {
32 for (auto element : elements)
33 {
34 std::size_t const n_edges(element->getNumberOfEdges());
35 for (std::size_t k(0); k < n_edges; k++)
36 {
37 auto edge =
38 element->getEdge(k); // allocation inside getEdge().
39 double const len = edge->getContent();
40 delete edge;
41 sum += len;
42 sum_of_sqr += len * len;
43 }
44 n_sampling += n_edges;
45 }
46 }
47 else
48 {
49 for (const MeshLib::Element* e : elements)
50 {
51 auto const [min, max] =
53 sum += std::sqrt(min);
54 sum_of_sqr += min;
55 }
56 n_sampling = _mesh.getNumberOfElements();
57 }
58
59 const double mean(sum / n_sampling);
60 const double variance((sum_of_sqr - (sum * sum) / n_sampling) /
61 (n_sampling - 1));
62
63 // Set the search length for the case of non-positive variance (which can
64 // happen due to numerics).
65 _search_length = mean / 2;
66
67 if (variance > 0)
68 {
69 if (variance < mean * mean / 4)
70 {
71 _search_length -= std::sqrt(variance);
72 }
73 else
74 {
75 _search_length = std::numeric_limits<double>::epsilon();
76 }
77 }
78
79 DBUG(
80 "[MeshNodeSearcher::MeshNodeSearcher] Calculated search length for "
81 "mesh '{:s}' is {:f}.",
83}
84
85} // end namespace MeshGeoToolsLib
Definition of the Element class.
Interface for heuristic search length strategy.
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
HeuristicSearchLength(MeshLib::Mesh const &mesh, LengthType length_type=LengthType::Edge)
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:109
const std::string getName() const
Get name of the mesh.
Definition Mesh.h:103
std::size_t getNumberOfElements() const
Get the number of elements.
Definition Mesh.h:97
std::pair< double, double > computeSqrNodeDistanceRange(MeshLib::Element const &element, bool const check_allnodes)
Compute the minimum and maximum node distances for this element.
Definition Element.cpp:136