diff --git a/MeshLib/Elements/Edge.h b/MeshLib/Elements/Edge.h index a2ea4e79beecb6f9ecd3d65b6a0dce42ddd01c73..13e7e78dc241342cb31bab65c3a4ac096eb6a8f3 100644 --- a/MeshLib/Elements/Edge.h +++ b/MeshLib/Elements/Edge.h @@ -38,14 +38,23 @@ public: /// Destructor virtual ~Edge(); + /// 1D elements have no edges + size_t getNEdges() const { return 0; }; + + /// Get the number of faces for this element. + size_t getNFaces() const { return 0; }; + /// Get the length of this 1d element. double getLength() const { return _length; }; /// Get dimension of the mesh element. size_t getDimension() const { return 1; }; + /// Get the number of neighbors for this element. + size_t getNNeighbors() const { return 0; }; + /// Get the number of nodes for this element. - size_t getNNodes() const { return 2; }; + virtual size_t getNNodes() const { return 2; }; protected: diff --git a/MeshLib/Elements/Element.cpp b/MeshLib/Elements/Element.cpp index 6f21f44c46a18ea209c244e1fadb6a7bc34d1e65..faf6b77a99cc6455223f3d4079e17e404e41c036 100644 --- a/MeshLib/Elements/Element.cpp +++ b/MeshLib/Elements/Element.cpp @@ -26,19 +26,36 @@ Element::Element(MshElemType::type type, size_t value) Element::~Element() { delete[] this->_nodes; + delete[] this->_neighbors; +} + +const Element* Element::getNeighbor(size_t i) const +{ + assert(i < getNNeighbors() && "Error in MeshLib::Element::getNeighbor() - Index does not exist."); + return _neighbors[i]; } const Node* Element::getNode(size_t i) const { - assert(i<getNNodes() && "Error in MeshLib::Element - Index does not exist."); + assert(i < getNNodes() && "Error in MeshLib::Element::getNode() - Index does not exist."); + assert(_nodes[i] != NULL && "Error in MeshLib::Element::getNode() - Node is NULL."); return _nodes[i]; } size_t Element::getNodeIndex(size_t i) const { - assert(i<getNNodes() && "Error in MeshLib::Element - Index does not exist."); + assert(i<getNNodes() && "Error in MeshLib::Element::getNodeIndex() - Index does not exist."); return _nodes[i]->getID(); } +bool Element::hasNeighbor(Element* elem) const +{ + size_t nNeighbors (this->getNNeighbors()); + for (size_t i=0; i<nNeighbors; i++) + if (this->_neighbors[i]==elem) + return true; + return false; +} + } diff --git a/MeshLib/Elements/Element.h b/MeshLib/Elements/Element.h index f611738f44e4bcf82f0eb99fdaf0728ffb9f9443..d3a4d20265ab518138d3691c068bfbb7950316db 100644 --- a/MeshLib/Elements/Element.h +++ b/MeshLib/Elements/Element.h @@ -31,6 +31,18 @@ public: /// Get dimension of the mesh element. virtual size_t getDimension() const = 0; + /// Get the number of edges for this element. + virtual size_t getNEdges() const = 0; + + /// Get the number of faces for this element. + virtual size_t getNFaces() const = 0; + + /// Get the specified neighbor. + const Element* getNeighbor(size_t i) const; + + /// Get the number of neighbors for this element. + virtual size_t getNNeighbors() const = 0; + /// Get the number of nodes for this element. virtual size_t getNNodes() const = 0; @@ -43,6 +55,8 @@ public: /// Get the value for this element. size_t getValue() const { return _value; }; + bool hasNeighbor(Element* elem) const; + /// Destructor virtual ~Element(); @@ -63,7 +77,7 @@ protected: Node** _nodes; MshElemType::type _type; size_t _value; - std::vector<Element*> _neighbors; + Element** _neighbors; private: diff --git a/MeshLib/Elements/Face.h b/MeshLib/Elements/Face.h index 489acacf6e19f372ca181a3d43adb52612f95324..2509be570ff780008b8de06d24edffbbf8b69af1 100644 --- a/MeshLib/Elements/Face.h +++ b/MeshLib/Elements/Face.h @@ -24,6 +24,9 @@ public: /// Get dimension of the mesh element. size_t getDimension() const { return 2; }; + /// 2D elements have no faces. + size_t getNFaces() const { return 0; }; + /// Destructor virtual ~Face(); diff --git a/MeshLib/Elements/Hex.cpp b/MeshLib/Elements/Hex.cpp index c4bdbcfd870c9652bee8be2c9456d6c27bcd8dba..b89c6ca4494f0287d2471daac53bbaa16c589328 100644 --- a/MeshLib/Elements/Hex.cpp +++ b/MeshLib/Elements/Hex.cpp @@ -17,6 +17,27 @@ Hex::Hex(Node* nodes[8], size_t value) : Cell(MshElemType::HEXAHEDRON, value) { _nodes = nodes; + _neighbors = new Element*[6]; + for (size_t i=0; i<6; i++) + _neighbors[i] = NULL; + this->_volume = this->calcVolume(); +} + +Hex::Hex(Node* n0, Node* n1, Node* n2, Node* n3, Node* n4, Node* n5, Node* n6, Node* n7, size_t value) + : Cell(MshElemType::HEXAHEDRON, value) +{ + _nodes = new Node*[8]; + _nodes[0] = n0; + _nodes[1] = n1; + _nodes[2] = n2; + _nodes[3] = n3; + _nodes[4] = n4; + _nodes[5] = n5; + _nodes[6] = n6; + _nodes[7] = n7; + _neighbors = new Element*[6]; + for (size_t i=0; i<6; i++) + _neighbors[i] = NULL; this->_volume = this->calcVolume(); } @@ -26,6 +47,9 @@ Hex::Hex(const Hex &hex) _nodes = new Node*[8]; for (size_t i=0; i<8; i++) _nodes[i] = hex._nodes[i]; + _neighbors = new Element*[6]; + for (size_t i=0; i<6; i++) + _neighbors[i] = hex._neighbors[i]; _volume = hex.getVolume(); } diff --git a/MeshLib/Elements/Hex.h b/MeshLib/Elements/Hex.h index 4533171d2203275ff6b85100fa6ff0116a14236b..56d488b9c2ca47607499d241668f915a5bffbf53 100644 --- a/MeshLib/Elements/Hex.h +++ b/MeshLib/Elements/Hex.h @@ -37,14 +37,26 @@ public: /// Constructor with an array of mesh nodes. Hex(Node* nodes[8], size_t value = 0); + /// Constructor using single mesh nodes. + Hex(Node* n0, Node* n1, Node* n2, Node* n3, Node* n4, Node* n5, Node* n6, Node* n7, size_t value); + /// Copy constructor Hex(const Hex &hex); /// Destructor virtual ~Hex(); + /// Get the number of edges for this element. + size_t getNEdges() const { return 12; }; + + /// Get the number of faces for this element. + size_t getNFaces() const { return 6; }; + + /// Get the number of neighbors for this element. + size_t getNNeighbors() const { return 6; }; + /// Get the number of nodes for this element. - size_t getNNodes() const { return 8; }; + virtual size_t getNNodes() const { return 8; }; protected: /// Calculates the volume of a convex hexahedron by partitioning it into six tetrahedra. diff --git a/MeshLib/Elements/Prism.cpp b/MeshLib/Elements/Prism.cpp index ebcc2dfc49c55c824130a02aacdda45b3caf7825..cf9b8e5046c7cbbd6ce503c15f1ccc4cc3bb2739 100644 --- a/MeshLib/Elements/Prism.cpp +++ b/MeshLib/Elements/Prism.cpp @@ -16,6 +16,9 @@ Prism::Prism(Node* nodes[6], size_t value) : Cell(MshElemType::PRISM, value) { _nodes = _nodes; + _neighbors = new Element*[5]; + for (size_t i=0; i<5; i++) + _neighbors[i] = NULL; this->_volume = this->calcVolume(); } @@ -29,7 +32,9 @@ Prism::Prism(Node* n0, Node* n1, Node* n2, Node* n3, Node* n4, Node* n5, size_t _nodes[3] = n3; _nodes[4] = n4; _nodes[5] = n5; - + _neighbors = new Element*[5]; + for (size_t i=0; i<5; i++) + _neighbors[i] = NULL; this->_volume = this->calcVolume(); } @@ -39,6 +44,9 @@ Prism::Prism(const Prism &prism) _nodes = new Node*[6]; for (size_t i=0; i<6; i++) _nodes[i] = prism._nodes[i]; + _neighbors = new Element*[5]; + for (size_t i=0; i<5; i++) + _neighbors[i] = prism._neighbors[i]; _volume = prism.getVolume(); } diff --git a/MeshLib/Elements/Prism.h b/MeshLib/Elements/Prism.h index d1dc9fa1ea0ae0169c8fa72f00b34573defa052c..e36d0b901633b655acbab4fe186a8bf0d89005db 100644 --- a/MeshLib/Elements/Prism.h +++ b/MeshLib/Elements/Prism.h @@ -44,8 +44,17 @@ public: /// Destructor virtual ~Prism(); + /// Get the number of edges for this element. + size_t getNEdges() const { return 9; }; + + /// Get the number of faces for this element. + size_t getNFaces() const { return 5; }; + + /// Get the number of neighbors for this element. + size_t getNNeighbors() const { return 5; }; + /// Get the number of nodes for this element. - size_t getNNodes() const { return 6; }; + virtual size_t getNNodes() const { return 6; }; protected: /// Calculates the volume of a prism by subdividing it into three tetrahedra. diff --git a/MeshLib/Elements/Pyramid.cpp b/MeshLib/Elements/Pyramid.cpp index ac19c7ab39f3083b8cb4920d7604933e400149a3..bea57f8bf64a25c4e49e434e1afb78b983907736 100644 --- a/MeshLib/Elements/Pyramid.cpp +++ b/MeshLib/Elements/Pyramid.cpp @@ -16,6 +16,9 @@ Pyramid::Pyramid(Node* nodes[5], size_t value) : Cell(MshElemType::PYRAMID, value) { _nodes = nodes; + _neighbors = new Element*[5]; + for (size_t i=0; i<5; i++) + _neighbors[i] = NULL; this->_volume = this->calcVolume(); } @@ -28,6 +31,9 @@ Pyramid::Pyramid(Node* n0, Node* n1, Node* n2, Node* n3, Node* n4, size_t value) _nodes[2] = n2; _nodes[3] = n3; _nodes[4] = n4; + _neighbors = new Element*[5]; + for (size_t i=0; i<5; i++) + _neighbors[i] = NULL; this->_volume = this->calcVolume(); } @@ -36,8 +42,12 @@ Pyramid::Pyramid(const Pyramid &pyramid) : Cell(MshElemType::PYRAMID, pyramid.getValue()) { _nodes = new Node*[5]; + _neighbors = new Element*[5]; for (size_t i=0; i<5; i++) + { _nodes[i] = pyramid._nodes[i]; + _neighbors[i] = pyramid._neighbors[i]; + } _volume = pyramid.getVolume(); } diff --git a/MeshLib/Elements/Pyramid.h b/MeshLib/Elements/Pyramid.h index 8cdc379edabf87ff5445575688faad133816ff4e..10f9715b37ff1ec3a3fed183509ad61467ebc306 100644 --- a/MeshLib/Elements/Pyramid.h +++ b/MeshLib/Elements/Pyramid.h @@ -44,8 +44,17 @@ public: /// Destructor virtual ~Pyramid(); + /// Get the number of edges for this element. + size_t getNEdges() const { return 8; }; + + /// Get the number of faces for this element. + size_t getNFaces() const { return 5; }; + + /// Get the number of neighbors for this element. + size_t getNNeighbors() const { return 5; }; + /// Get the number of nodes for this element. - size_t getNNodes() const { return 5; }; + virtual size_t getNNodes() const { return 5; }; protected: /// Calculates the volume of a prism by subdividing it into two tetrahedra. diff --git a/MeshLib/Elements/Quad.cpp b/MeshLib/Elements/Quad.cpp index 99d99e1bbf258800acc2e1ee6cc8f11ca25f716a..61dc76e74752a73a689eb6d43b7bc347234bcdd4 100644 --- a/MeshLib/Elements/Quad.cpp +++ b/MeshLib/Elements/Quad.cpp @@ -16,6 +16,9 @@ Quad::Quad(Node* nodes[4], size_t value) : Face(MshElemType::TRIANGLE, value) { _nodes = nodes; + _neighbors = new Element*[4]; + for (size_t i=0; i<4; i++) + _neighbors[i] = NULL; this->_area = this->calcArea(); } @@ -27,7 +30,9 @@ Quad::Quad(Node* n0, Node* n1, Node* n2, Node* n3, size_t value) _nodes[1] = n1; _nodes[2] = n2; _nodes[3] = n3; - + _neighbors = new Element*[4]; + for (size_t i=0; i<4; i++) + _neighbors[i] = NULL; this->_area = this->calcArea(); } @@ -35,8 +40,12 @@ Quad::Quad(const Quad &quad) : Face(MshElemType::QUAD, quad.getValue()) { _nodes = new Node*[4]; + _neighbors = new Element*[4]; for (size_t i=0; i<4; i++) + { _nodes[i] = quad._nodes[i]; + _neighbors[i] = quad._neighbors[i]; + } _area = quad.getArea(); } diff --git a/MeshLib/Elements/Quad.h b/MeshLib/Elements/Quad.h index 8b92074281f24a276bd59b521066a9b423ce8ef6..8ba871af1038413a01c89508aa22e151daf51b0d 100644 --- a/MeshLib/Elements/Quad.h +++ b/MeshLib/Elements/Quad.h @@ -43,8 +43,14 @@ public: /// Destructor virtual ~Quad(); + /// Get the number of edges for this element. + size_t getNEdges() const { return 4; }; + + /// Get the number of neighbors for this element. + size_t getNNeighbors() const { return 4; }; + /// Get the number of nodes for this element. - size_t getNNodes() const { return 4; }; + virtual size_t getNNodes() const { return 4; }; protected: /// Calculates the area of a convex quadliteral by dividing it into two triangles. diff --git a/MeshLib/Elements/Tet.cpp b/MeshLib/Elements/Tet.cpp index 9bf8caa0ebff996420b98202b2979319c655440a..d9a8aa5918e533ab4dd2b732a8de3f70cb5a2b2f 100644 --- a/MeshLib/Elements/Tet.cpp +++ b/MeshLib/Elements/Tet.cpp @@ -16,6 +16,9 @@ Tet::Tet(Node* nodes[4], size_t value) : Cell(MshElemType::TETRAHEDRON, value) { _nodes = nodes; + _neighbors = new Element*[4]; + for (size_t i=0; i<4; i++) + _neighbors[i] = NULL; this->_volume = this->calcVolume(); } @@ -27,21 +30,30 @@ Tet::Tet(Node* n0, Node* n1, Node* n2, Node* n3, size_t value) _nodes[1] = n1; _nodes[2] = n2; _nodes[3] = n3; - + _neighbors = new Element*[4]; + for (size_t i=0; i<4; i++) + _neighbors[i] = NULL; this->_volume = this->calcVolume(); } Tet::Tet(size_t value) : Cell(MshElemType::TETRAHEDRON, value) { + _neighbors = new Element*[4]; + for (size_t i=0; i<4; i++) + _neighbors[i] = NULL; } Tet::Tet(const Tet &tet) : Cell(MshElemType::TETRAHEDRON, tet.getValue()) { _nodes = new Node*[4]; + _neighbors = new Element*[4]; for (size_t i=0; i<4; i++) + { _nodes[i] = tet._nodes[i]; + _neighbors[i] = tet._neighbors[i]; + } _volume = tet.getVolume(); } diff --git a/MeshLib/Elements/Tet.h b/MeshLib/Elements/Tet.h index 12c4c55283a33a1591ef3aff4a6afa80989ecce9..e6ac4c9c5d3f85e606424929847fa0ae20fef574 100644 --- a/MeshLib/Elements/Tet.h +++ b/MeshLib/Elements/Tet.h @@ -45,6 +45,15 @@ public: /// Destructor virtual ~Tet(); + /// Get the number of edges for this element. + size_t getNEdges() const { return 6; }; + + /// Get the number of faces for this element. + size_t getNFaces() const { return 4; }; + + /// Get the number of neighbors for this element. + size_t getNNeighbors() const { return 4; }; + /// Get the number of nodes for this element. virtual size_t getNNodes() const { return 4; }; diff --git a/MeshLib/Elements/Tri.cpp b/MeshLib/Elements/Tri.cpp index 925f45e1b7ee9b918fd0071a791a79a0167763a0..a99e5a619393dd8f644eedf73db47026c35564a3 100644 --- a/MeshLib/Elements/Tri.cpp +++ b/MeshLib/Elements/Tri.cpp @@ -16,6 +16,9 @@ Tri::Tri(Node* nodes[3], size_t value) : Face(MshElemType::TRIANGLE, value) { _nodes = nodes; + _neighbors = new Element*[3]; + for (size_t i=0; i<3; i++) + _neighbors[i] = NULL; this->_area = this->calcArea(); } @@ -26,7 +29,9 @@ Tri::Tri(Node* n0, Node* n1, Node* n2, size_t value) _nodes[0] = n0; _nodes[1] = n1; _nodes[2] = n2; - + _neighbors = new Element*[3]; + for (size_t i=0; i<3; i++) + _neighbors[i] = NULL; this->_area = this->calcArea(); } @@ -34,8 +39,12 @@ Tri::Tri(const Tri &tri) : Face(MshElemType::TRIANGLE, tri.getValue()) { _nodes = new Node*[3]; + _neighbors = new Element*[3]; for (size_t i=0; i<3; i++) + { _nodes[i] = tri._nodes[i]; + _neighbors[i] = tri._neighbors[i]; + } _area = tri.getArea(); } diff --git a/MeshLib/Elements/Tri.h b/MeshLib/Elements/Tri.h index 383ecba086411409ada643bb960b7164f4c2ae6d..4152eb8db375ac5ab8b2f84b5288ea95fe210176 100644 --- a/MeshLib/Elements/Tri.h +++ b/MeshLib/Elements/Tri.h @@ -43,8 +43,14 @@ public: /// Destructor virtual ~Tri(); + /// Get the number of edges for this element. + size_t getNEdges() const { return 3; }; + + /// Get the number of neighbors for this element. + size_t getNNeighbors() const { return 3; }; + /// Get the number of nodes for this element. - size_t getNNodes() const { return 3; }; + virtual size_t getNNodes() const { return 3; }; protected: /// Calculates the area of the triangle by returning half of the area of the corresponding parallelogram. diff --git a/MeshLib/FemMesh.h b/MeshLib/FemMesh.h index 967708fd6ce73e53583e0db9fac83d9a9afa4179..335ca5187896b765edc63fb1a78a40257009dd4a 100644 --- a/MeshLib/FemMesh.h +++ b/MeshLib/FemMesh.h @@ -31,7 +31,7 @@ public: FemMesh(const std::string &file_name); /// Destructor - ~FemMesh(); + virtual ~FemMesh(); }; /* class */ diff --git a/MeshLib/FemNode.h b/MeshLib/FemNode.h index ff8eb8c6cf490e6edfd451516105c1795b42defa..4a035df0817dd5325c4a45783411402e5291de05 100644 --- a/MeshLib/FemNode.h +++ b/MeshLib/FemNode.h @@ -31,7 +31,7 @@ public: FemNode(const FemNode &node); /// Destructor - ~FemNode(); + virtual ~FemNode(); }; /* class */ diff --git a/MeshLib/Mesh.cpp b/MeshLib/Mesh.cpp index 528d54541378d2a5ed105a6f9533b95bfdd471b9..ec6043e35026ed91e8cb4ab241244e3dc720142c 100644 --- a/MeshLib/Mesh.cpp +++ b/MeshLib/Mesh.cpp @@ -64,48 +64,7 @@ void Mesh::addElement(Element* elem) for (size_t i=0; i<nNodes; i++) elem->getNode(i)->addElement(elem); } -/* -void Mesh::removeNode(size_t idx) -{ - if (idx < _nodes.size()) - { - const std::vector<const Element*> node_elems = _nodes[idx]->getElements(); - for (std::vector<const Element*>::const_iterator it = node_elems.begin(); - it != node_elems.end(); ++it) - { - - //for (si - } - _nodes.erase(_nodes.begin()+idx); - return; - } - std::cerr << "Mesh::removeNode(" << idx << ") - Index does not exist." << std::endl; -} -void Mesh::removeElement(size_t idx) -{ - if (idx < _elements.size()) - { - Element* elem (_elements[idx]); - size_t nNodes (elem->getNNodes()); - for (size_t i=0; i<nNodes; i++) - { - Node* node (const_cast<Node*>(elem->getNode(i))); - // remove element from nodes element-list - if (node->getNElements()>1) - { - std::vector<Node*>::iterator it (_nodes.begin()+node->getID()); - delete node; - _nodes.erase(it); - } - // delete node if it is not part of any element - else - node->removeElement(elem); - } - return; - } - std::cerr << "Mesh::removeElement(" << idx << ") - Index does not exist." << std::endl; -} -*/ + } diff --git a/MeshLib/Mesh.h b/MeshLib/Mesh.h index 14619f88b1b97dedde0c15fdfa4f68c61d222b0e..3c5b61f7df09823cb36104bc3be6db15dd5ecd7c 100644 --- a/MeshLib/Mesh.h +++ b/MeshLib/Mesh.h @@ -53,19 +53,6 @@ public: /// Get the number of nodes size_t getNNodes() const { return _nodes.size(); }; - /** - * Remove the node with the given index. - * NOTE: Removing a node also removes all elements that this node is part of! - */ - //void removeNode(size_t idx); - - /** - * Remove the element with the given index. - * NOTE: If any node of this element is not part of any other element it will - * also be removed! - */ - //void removeElement(size_t idx); - /// Get name of the mesh. const std::string getName() const { return _name; }; diff --git a/MeshLib/Node.cpp b/MeshLib/Node.cpp index 4b9579e3e2f268a666278fcc05358189ff2aaa44..8e3030bde23835afd40654747de19009c01afa01 100644 --- a/MeshLib/Node.cpp +++ b/MeshLib/Node.cpp @@ -27,19 +27,6 @@ Node::Node(const Node &node) Node::~Node() { } -/* -void Node::removeElement(const Element* elem) -{ - for (std::vector<const Element*>::iterator it = _elements.begin(); - it != _elements.end(); ++it) - { - if (*it == elem) - { - _elements.erase(it); - return; - } - } -} -*/ + } diff --git a/MeshLib/Node.h b/MeshLib/Node.h index a2813d4b14a56f65f29b7a58aeaa5a0d52c97850..a73b01d01ce153466a1b2685083d8af8f0fbb6cc 100644 --- a/MeshLib/Node.h +++ b/MeshLib/Node.h @@ -44,7 +44,7 @@ public: size_t getNElements() const { return _elements.size(); }; /// Destructor - ~Node(); + virtual ~Node(); protected: /** @@ -53,9 +53,6 @@ protected: */ void addElement(const Element* elem) { _elements.push_back(elem); }; - /// Remove an element the node is part of. - //void removeElement(const Element* elem); - std::vector<const Element*> _elements; /* friend functions: */