diff --git a/Applications/Utils/MeshEdit/NodeReordering.cpp b/Applications/Utils/MeshEdit/NodeReordering.cpp index 636872eafb68b3daaee53cf42e01c3ca1c8a585d..98d660ec22e64b7db3d22f732b721ebf1a3c41de 100644 --- a/Applications/Utils/MeshEdit/NodeReordering.cpp +++ b/Applications/Utils/MeshEdit/NodeReordering.cpp @@ -140,11 +140,9 @@ void reorderNonlinearNodes(MeshLib::Mesh& mesh) } BaseLib::makeVectorUnique(base_nodes, - [](MeshLib::Node* a, MeshLib::Node* b) - { return a->getID() < b->getID(); }); + MeshLib::idsComparator<MeshLib::Node*>); BaseLib::makeVectorUnique(nonlinear_nodes, - [](MeshLib::Node* a, MeshLib::Node* b) - { return a->getID() < b->getID(); }); + MeshLib::idsComparator<MeshLib::Node*>); std::vector<MeshLib::Node*>& allnodes = const_cast<std::vector<MeshLib::Node*>&>(mesh.getNodes()); diff --git a/MeshLib/Elements/Utils.h b/MeshLib/Elements/Utils.h index 721f95185be1c2bf77784a244584bf85f20cf37f..309c2de08468cbb60d163fdbea520f36be5d2ad8 100644 --- a/MeshLib/Elements/Utils.h +++ b/MeshLib/Elements/Utils.h @@ -34,9 +34,7 @@ inline std::vector<Node*> getBaseNodes(std::vector<Element*> const& elements) std::back_inserter(base_nodes)); } - BaseLib::makeVectorUnique(base_nodes, - [](Node const* const a, Node const* const b) - { return a->getID() < b->getID(); }); + BaseLib::makeVectorUnique(base_nodes, MeshLib::idsComparator<Node*>); return base_nodes; } diff --git a/MeshLib/Mesh.cpp b/MeshLib/Mesh.cpp index 64a21a16ad34aa4d0d5e15a1747a3de94c714cea..ac05a6129fa29ec833487df4f152fe86149d0e2a 100644 --- a/MeshLib/Mesh.cpp +++ b/MeshLib/Mesh.cpp @@ -325,8 +325,7 @@ std::vector<std::vector<Node*>> calculateNodesConnectedByElements( // Make nodes unique and sorted by their ids. // This relies on the node's id being equivalent to it's address. std::sort(adjacent_nodes.begin(), adjacent_nodes.end(), - [](Node const* const a, Node const* const b) - { return a->getID() < b->getID(); }); + idsComparator<Node*>); auto const last = std::unique(adjacent_nodes.begin(), adjacent_nodes.end()); adjacent_nodes.erase(last, adjacent_nodes.end()); diff --git a/MeshLib/Mesh.h b/MeshLib/Mesh.h index 871a036f060521c8531de4545af06628e82b210e..807561b408585f7c15691880b910497dc479b86f 100644 --- a/MeshLib/Mesh.h +++ b/MeshLib/Mesh.h @@ -195,6 +195,21 @@ bool isBaseNode(Node const& node, std::pair<double, double> minMaxEdgeLength( std::vector<Element*> const& elements); +/// Lexicographic comparison of ids of two objects of type T. T can be a pointer +/// or a value type. +template <typename T> +bool idsComparator(T const a, T const b) +{ + if constexpr (std::is_pointer_v<T>) + { + return a->getID() < b->getID(); + } + else + { + return a.getID() < b.getID(); + } +} + /// MeshLib specific, lazy, non-owning, non-mutating, composable range views. namespace views { diff --git a/ProcessLib/HeatTransportBHE/BHE/MeshUtils.cpp b/ProcessLib/HeatTransportBHE/BHE/MeshUtils.cpp index bb711d7240d7f169b78516f1bffaeffb7e497755..1ca62da3133ce42c795f8a35b65177597518f16d 100644 --- a/ProcessLib/HeatTransportBHE/BHE/MeshUtils.cpp +++ b/ProcessLib/HeatTransportBHE/BHE/MeshUtils.cpp @@ -100,8 +100,8 @@ BHEMeshData getBHEDataInMesh(MeshLib::Mesh const& mesh) } } BaseLib::makeVectorUnique(vec_nodes, - [](MeshLib::Node* node1, MeshLib::Node* node2) - { return node1->getID() < node2->getID(); }); + MeshLib::idsComparator<MeshLib::Node*>); + DBUG("-> found {:d} nodes on the BHE_{:d}", vec_nodes.size(), bhe_id); } diff --git a/ProcessLib/LIE/Common/MeshUtils.cpp b/ProcessLib/LIE/Common/MeshUtils.cpp index 2b30df8a75901174dbffb1e7cdb8a7f83320c40c..1144ec8708816a64d174d0027f56aded5f2f475b 100644 --- a/ProcessLib/LIE/Common/MeshUtils.cpp +++ b/ProcessLib/LIE/Common/MeshUtils.cpp @@ -287,8 +287,7 @@ void getFractureMatrixDataInMesh( } } BaseLib::makeVectorUnique(vec_nodes, - [](MeshLib::Node* node1, MeshLib::Node* node2) - { return node1->getID() < node2->getID(); }); + MeshLib::idsComparator<MeshLib::Node*>); DBUG("-> found {:d} nodes on the fracture {:d}", vec_nodes.size(), frac_id); } @@ -334,8 +333,7 @@ void getFractureMatrixDataInMesh( } } BaseLib::makeVectorUnique(vec_ele, - [](MeshLib::Element* e1, MeshLib::Element* e2) - { return e1->getID() < e2->getID(); }); + MeshLib::idsComparator<MeshLib::Element*>); // second, append fracture elements std::copy(fracture_elements.begin(), fracture_elements.end(),