diff --git a/AneuMeshLoader.cpp b/AneuMeshLoader.cpp index 7a73851b7911b6a4a6875137ad755a5f3869d672..0ea6cffc00da040ebf225b0ec4b64c9d3ae48926 100644 --- a/AneuMeshLoader.cpp +++ b/AneuMeshLoader.cpp @@ -2,11 +2,11 @@ std::set AneuMeshLoader::getBoundaryNodesId() { std::set res; - for (const auto &it: bfes) { - std::for_each(it.idLst.begin(), it.idLst.end(), [&res](int id) { + std::ranges::for_each(bfes, [&](const auto &it) { + std::ranges::for_each(it.idLst, [&res](int id) { res.insert(id); }); - } + }); return res; } diff --git a/MeshLoader.cpp b/MeshLoader.cpp index e652a654b814992a0ddf4f894b356504ac0424a9..d422b55167107d184521ac6fc2384c9e7f20abbe 100644 --- a/MeshLoader.cpp +++ b/MeshLoader.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "MeshLoader.h" #include "CustomHash.h" @@ -18,10 +19,10 @@ const std::vector &MeshLoader::getBFEs() { std::vector MeshLoader::getFEbyId(int n1, int n2, int n3) { std::vector res; - std::for_each(fes.begin(), fes.end(), [&n1, &n2, &n3, &res](const FiniteElement &fe) { - if ((std::find(fe.idLst.begin(), fe.idLst.end(), n1) != fe.idLst.end()) && - (std::find(fe.idLst.begin(), fe.idLst.end(), n2) != fe.idLst.end()) && - (std::find(fe.idLst.begin(), fe.idLst.end(), n3) != fe.idLst.end())) { + std::ranges::for_each(fes, [&n1, &n2, &n3, &res](const FiniteElement &fe) { + if ((std::ranges::find(fe.idLst, n1) != fe.idLst.end()) && + (std::ranges::find(fe.idLst, n2) != fe.idLst.end()) && + (std::ranges::find(fe.idLst, n3) != fe.idLst.end())) { res.push_back(fe.id); } }); @@ -30,9 +31,9 @@ std::vector MeshLoader::getFEbyId(int n1, int n2, int n3) { std::vector MeshLoader::getFEbyEdge(int n1, int n2) { std::vector res; - std::for_each(fes.begin(), fes.end(), [&n1, &n2, &res](const FiniteElement &fe) { - if ((std::find(fe.idLst.begin(), fe.idLst.end(), n1) != fe.idLst.end()) && - (std::find(fe.idLst.begin(), fe.idLst.end(), n2) != fe.idLst.end())) { + std::ranges::for_each(fes, [&n1, &n2, &res](const FiniteElement &fe) { + if ((std::ranges::find(fe.idLst, n1) != fe.idLst.end()) && + (std::ranges::find(fe.idLst, n2) != fe.idLst.end())) { res.push_back(fe.id); } }); @@ -48,10 +49,10 @@ std::vector MeshLoader::getNodesBySurfaceId(int id) { return bfe.idM == id; }); if (cur != bfes.end()) { - for (const auto &it: cur->idLst) { + std::ranges::for_each(cur->idLst, [&](int const& it) { Node nodeById = nodes[it]; res.insert(nodeById.id); - } + }); ++cur; } } @@ -60,7 +61,7 @@ std::vector MeshLoader::getNodesBySurfaceId(int id) { std::vector MeshLoader::getFEsByMaterialId(int id) { std::vector res; - std::for_each(fes.begin(), fes.end(), [&id, &res](const FiniteElement &fe) { + std::ranges::for_each(fes, [&id, &res](const FiniteElement &fe) { if (fe.idM == id) { res.push_back(fe.id); } @@ -70,7 +71,7 @@ std::vector MeshLoader::getFEsByMaterialId(int id) { std::vector MeshLoader::getFEsBySurfaceId(int id) { std::vector res; - std::for_each(bfes.begin(), bfes.end(), [&id, &res](const FiniteElement &bfe) { + std::ranges::for_each(bfes, [&id, &res](const FiniteElement &bfe) { if (bfe.idM == id) { res.push_back(bfe.id); } @@ -88,10 +89,10 @@ void MeshLoader::printFE(const FiniteElement &fe) { void MeshLoader::insertNodeMid() { std::unordered_set edges; - for (auto &elem: fes) { + std::ranges::for_each(fes, [&](auto& elem) { std::vector feNodesId = elem.idLst; for (int first = 0; first < 4; ++first) { - for (auto sec = first + 1; sec < 4; ++sec) { + for (int sec = first + 1; sec < 4; ++sec) { Edge curEdge(feNodesId[first], feNodesId[sec]); if (edges.insert(curEdge).second) { Node newNode = getMidNode(curEdge); @@ -103,8 +104,9 @@ void MeshLoader::insertNodeMid() { } } } - } - for (auto &el: bfes) { + }); + + std::ranges::for_each(bfes, [&](auto& el) { std::vector bfeNodesId = el.idLst; for (auto first = 0; first < 3; ++first) { for (auto sec = first + 1; sec < 3; ++sec) { @@ -115,7 +117,7 @@ void MeshLoader::insertNodeMid() { el.idLst.push_back(curEdgeIter->midNode); } } - } + }); } @@ -140,12 +142,21 @@ std::array MeshLoader::getNodeCoords(int id) { std::vector> MeshLoader::createNeighborsVector() { std::vector> neighbors(nodes.size() + 1); - for (const auto &elem: bfes) { - for (auto nodeId: elem.idLst) - for (auto anthNodeId: elem.idLst) + std::ranges::for_each(bfes, [&](const auto &elem) { + std::ranges::for_each(elem.idLst, [&](auto nodeId) { + std::ranges::for_each(elem.idLst, [&](auto anthNodeId) { if (nodeId != anthNodeId) neighbors[nodeId].insert(anthNodeId); - } - + }); + }); + }); + std::ranges::for_each(fes, [&](const auto &elem) { + std::ranges::for_each(elem.idLst, [&](auto nodeId) { + std::ranges::for_each(elem.idLst, [&](auto anthNodeId) { + if (nodeId != anthNodeId) + neighbors[nodeId].insert(anthNodeId); + }); + }); + }); return neighbors; } \ No newline at end of file