diff --git a/AneuMeshLoader.cpp b/AneuMeshLoader.cpp index 9471038969a97f2a5f41b8d4a4db6e1943ae67ec..863403bf64603d32514b87f0e97e132b338d102f 100644 --- a/AneuMeshLoader.cpp +++ b/AneuMeshLoader.cpp @@ -1,8 +1,10 @@ #include "AneuMeshLoader.h" #include +#include "iostream" +#include "algorithm" -void AneuMeshLoader::loadMesh(const std::string& fileName) { +void AneuMeshLoader::loadMesh(const std::string &fileName) { std::ifstream inf(fileName); int amount, dim; inf >> amount >> dim; @@ -10,7 +12,7 @@ void AneuMeshLoader::loadMesh(const std::string& fileName) { Node tmp{}; inf >> tmp.x1 >> tmp.x2 >> tmp.x3; tmp.id = i; - tmp.flag = false; + tmp.vertex = false; nodes.push_back(tmp); } inf >> amount >> dim; @@ -37,4 +39,20 @@ void AneuMeshLoader::loadMesh(const std::string& fileName) { tmp.id = i; bfeVector.push_back(tmp); } + std::vector allBNodes = getBoundaryNodesId(); + for (auto &it: nodes) { + if (std::find(allBNodes.begin(), allBNodes.end(), it.id) != allBNodes.end()) { + it.vertex = true; + } + } } + +std::vector AneuMeshLoader::getBoundaryNodesId() { + std::vector res; + for (const auto &it: bfeVector) { + std::for_each(it.idLst.begin(), it.idLst.end(), [&res](int id) { + res.push_back(id); + }); + } + return res; +} \ No newline at end of file diff --git a/AneuMeshLoader.h b/AneuMeshLoader.h index ba95ff83402ffd307d6a969ce523e3e01d60935e..6c21a777cf5b5b233ecf1e1d85ebdf3fcefbaea5 100644 --- a/AneuMeshLoader.h +++ b/AneuMeshLoader.h @@ -1,12 +1,15 @@ #ifndef CPP_LAB1_ANEUMESHLOADER_H #define CPP_LAB1_ANEUMESHLOADER_H + #include "MeshLoader.h" #include "string" class AneuMeshLoader : MeshLoader { public: - void loadMesh(const std::string& fileName) override; + void loadMesh(const std::string &) override; + + std::vector getBoundaryNodesId(); }; diff --git a/MeshLoader.cpp b/MeshLoader.cpp index 20f33e4dff30390ad0a7b742798c194ae896925f..9be60076fcf0e7b0ba60d750912da71053306e14 100644 --- a/MeshLoader.cpp +++ b/MeshLoader.cpp @@ -2,6 +2,7 @@ #include "algorithm" #include "iostream" + std::vector MeshLoader::getNodes() { return nodes; } @@ -15,7 +16,7 @@ std::vector MeshLoader::getBFE() { } FiniteElement MeshLoader::getFEbyId(int n1, int n2, int n3) { - auto iter = std::find_if(feVector.begin(), feVector.end(), [&n1, &n2, &n3] (FiniteElement fe) { + auto iter = std::find_if(feVector.begin(), feVector.end(), [&n1, &n2, &n3](FiniteElement fe) { return (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()); @@ -24,7 +25,7 @@ FiniteElement MeshLoader::getFEbyId(int n1, int n2, int n3) { } FiniteElement MeshLoader::getFEbyEdge(int n1, int n2) { - auto iter = std::find_if(feVector.begin(), feVector.end(), [&n1, &n2] (FiniteElement fe) { + auto iter = std::find_if(feVector.begin(), feVector.end(), [&n1, &n2](FiniteElement fe) { return (std::find(fe.idLst.begin(), fe.idLst.end(), n1) != fe.idLst.end()) && (std::find(fe.idLst.begin(), fe.idLst.end(), n2) != fe.idLst.end()); }); @@ -33,12 +34,12 @@ FiniteElement MeshLoader::getFEbyEdge(int n1, int n2) { std::vector MeshLoader::getNodesByBoundaryId(int id) { std::vector bfeById; - std::copy_if(bfeVector.begin(), bfeVector.end(), bfeById.begin(), [&id] (const BoundaryFiniteElement& bfe) { + std::copy_if(bfeVector.begin(), bfeVector.end(), bfeById.begin(), [&id](const BoundaryFiniteElement &bfe) { return bfe.idB == id; }); std::vector res; - for (const auto& it : bfeById) { - std::for_each(it.idLst.begin(), it.idLst.end(), [it, this, &res] (int id) { + for (const auto &it: bfeById) { + std::for_each(it.idLst.begin(), it.idLst.end(), [it, this, &res](int id) { res.push_back(nodes[id]); }); } @@ -47,20 +48,20 @@ std::vector MeshLoader::getNodesByBoundaryId(int id) { std::vector MeshLoader::getBFEsByBoundaryId(int id) { std::vector res; - std::copy_if(bfeVector.begin(), bfeVector.end(), res.begin(), [&id] (const BoundaryFiniteElement& bfe) { + std::copy_if(bfeVector.begin(), bfeVector.end(), res.begin(), [&id](const BoundaryFiniteElement &bfe) { return bfe.idB == id; }); return res; } -void MeshLoader::printNode(const Node& node) { +void MeshLoader::printNode(const Node &node) { std::cout << node; } -void MeshLoader::printFE(const FiniteElement& fe) { +void MeshLoader::printFE(const FiniteElement &fe) { std::cout << fe; } -void MeshLoader::printBFE(const BoundaryFiniteElement& bfe) { +void MeshLoader::printBFE(const BoundaryFiniteElement &bfe) { std::cout << bfe; } diff --git a/MeshLoader.h b/MeshLoader.h index e49c1adf347f21877fd66b07caf82dfef7039612..824761774df8c3f2aa67974f6444cf218e0d0dbd 100644 --- a/MeshLoader.h +++ b/MeshLoader.h @@ -1,5 +1,6 @@ #ifndef CPP_LAB1_MESHLOADER_H #define CPP_LAB1_MESHLOADER_H + #include "Structures.h" @@ -9,23 +10,33 @@ protected: std::vector feVector; std::vector bfeVector; public: - virtual void loadMesh(const std::string&) = 0; + virtual void loadMesh(const std::string &) = 0; std::vector getNodes(); + std::vector getFE(); + std::vector getBFE(); FiniteElement getFEbyId(int, int, int); + FiniteElement getFEbyEdge(int, int); + std::vector getNodesByBoundaryId(int); + std::vector getFEsByAreaId(int); + std::vector getBFEsByBoundaryId(int); + void insertNode(Node); + std::vector> createContainer(); - void printNode(const Node&); - void printFE(const FiniteElement&); - void printBFE(const BoundaryFiniteElement&); + void printNode(const Node &); + + void printFE(const FiniteElement &); + + void printBFE(const BoundaryFiniteElement &); }; #endif diff --git a/Structures.cpp b/Structures.cpp index ced2e569b2d9c7560217fd4e05e1f0d48ef450c8..74c155dca484d0eea21610af4214fd6b6b1b3acf 100644 --- a/Structures.cpp +++ b/Structures.cpp @@ -1,28 +1,28 @@ #include "Structures.h" -std::ostream& operator<<(std::ostream& out, const Node& node) { +std::ostream &operator<<(std::ostream &out, const Node &node) { std::cout << "Node\t" << node.id; std::cout << "XYZ\t" << node.x1 << node.x2 << node.x1; - std::cout << "Vertex:\t" << node.flag; + std::cout << "Vertex:\t" << node.vertex; return out; } -std::ostream &operator<<(std::ostream& out, const FiniteElement& fe) { +std::ostream &operator<<(std::ostream &out, const FiniteElement &fe) { std::cout << "FE\t" << fe.id; std::cout << "Material Id\t" << fe.idM; std::cout << "Nodes Id:\n"; - for (auto & it : fe.idLst) { + for (auto &it: fe.idLst) { std::cout << it; } return out; } -std::ostream &operator<<(std::ostream& out, const BoundaryFiniteElement& bfe) { +std::ostream &operator<<(std::ostream &out, const BoundaryFiniteElement &bfe) { std::cout << "FE\t" << bfe.id; std::cout << "Boundary Id\t" << bfe.idB; std::cout << "Nodes Id:\n"; - for (auto & it : bfe.idLst) { + for (auto &it: bfe.idLst) { std::cout << it; } return out; diff --git a/Structures.h b/Structures.h index 6ed8dc704008b9a254c49d927af6897ca4c6f2ff..182abe43b1b4742746a96a770d97b075429a8b30 100644 --- a/Structures.h +++ b/Structures.h @@ -1,5 +1,6 @@ #ifndef CPP_LAB1_STRUCTURES_H #define CPP_LAB1_STRUCTURES_H + #include #include "iostream" #include "iomanip" @@ -9,9 +10,9 @@ class Node { public: int id; double x1, x2, x3; - bool flag; + bool vertex; - friend std::ostream& operator<<(std::ostream&, const Node&); + friend std::ostream &operator<<(std::ostream &, const Node &); }; class FiniteElement { @@ -20,7 +21,7 @@ public: int idM; std::vector idLst; - friend std::ostream& operator<<(std::ostream&, const FiniteElement&); + friend std::ostream &operator<<(std::ostream &, const FiniteElement &); }; @@ -30,7 +31,7 @@ public: int idB; std::vector idLst; - friend std::ostream& operator<<(std::ostream&, const BoundaryFiniteElement&); + friend std::ostream &operator<<(std::ostream &, const BoundaryFiniteElement &); }; diff --git a/main.cpp b/main.cpp index 1747030ec4087df7e7c0d79a308d29e75f4633f8..1b7ed60443ce05e5457af25e0ccdd14339b0bc3d 100644 --- a/main.cpp +++ b/main.cpp @@ -2,7 +2,7 @@ #include -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { AneuMeshLoader loader; loader.loadMesh("/home/nikitast/Downloads/cube.mesh"); return 0;