OGS
MeshGeoToolsLib::HeuristicSearchLength Class Reference

Detailed Description

HeuristicSearchLength implements a mesh dependent criterion for searching mesh nodes near a geometry. For this purpose it computes the average \(\mu\) and the standard deviation \(\sigma\) of edge length or node distance of mesh elements. The search length is set to \(\mu-2\sigma\). This strategy is useful for meshes with different sizes of elements.

Definition at line 30 of file HeuristicSearchLength.h.

#include <HeuristicSearchLength.h>

Inheritance diagram for MeshGeoToolsLib::HeuristicSearchLength:
[legend]
Collaboration diagram for MeshGeoToolsLib::HeuristicSearchLength:
[legend]

Public Types

enum class  LengthType { Edge , Node }
 Type of length to be sampled. More...
 

Public Member Functions

 HeuristicSearchLength (MeshLib::Mesh const &mesh, LengthType length_type=LengthType::Edge)
 
- Public Member Functions inherited from MeshGeoToolsLib::SearchLength
 SearchLength (double search_length=1e-9)
 
 SearchLength (SearchLength const &)=default
 
SearchLengthoperator= (SearchLength const &)=default
 
virtual ~SearchLength ()=default
 
virtual double getSearchLength () const
 

Private Attributes

MeshLib::Mesh const & _mesh
 

Additional Inherited Members

- Protected Attributes inherited from MeshGeoToolsLib::SearchLength
double _search_length
 

Member Enumeration Documentation

◆ LengthType

Type of length to be sampled.

Enumerator
Edge 
Node 

edge length of elements, which is recommended for meshes without nonlinear nodes

distance between nodes

Definition at line 34 of file HeuristicSearchLength.h.

35 {
36 Edge,
37 Node
38 };
@ Node
edge length of elements, which is recommended for meshes without nonlinear nodes

Constructor & Destructor Documentation

◆ HeuristicSearchLength()

MeshGeoToolsLib::HeuristicSearchLength::HeuristicSearchLength ( MeshLib::Mesh const & mesh,
LengthType length_type = LengthType::Edge )
explicit

Constructor

Parameters
meshmesh object
length_typelength type to be sampled

Definition at line 20 of file HeuristicSearchLength.cpp.

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}
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
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

References _mesh, MeshGeoToolsLib::SearchLength::_search_length, MeshLib::computeSqrNodeDistanceRange(), DBUG(), Edge, MeshLib::Mesh::getElements(), MeshLib::Mesh::getName(), and MeshLib::Mesh::getNumberOfElements().

Member Data Documentation

◆ _mesh

MeshLib::Mesh const& MeshGeoToolsLib::HeuristicSearchLength::_mesh
private

Definition at line 49 of file HeuristicSearchLength.h.

Referenced by HeuristicSearchLength().


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