Skip to content
Snippets Groups Projects
Commit 873ceda6 authored by Karsten Rink's avatar Karsten Rink
Browse files

added neighbor management, nEdges, nFaces

parent d43994e8
No related branches found
No related tags found
No related merge requests found
Showing
with 182 additions and 70 deletions
......@@ -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:
......
......@@ -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;
}
}
......@@ -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:
......
......@@ -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();
......
......@@ -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();
}
......
......@@ -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.
......
......@@ -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();
}
......
......@@ -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.
......
......@@ -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();
}
......
......@@ -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.
......
......@@ -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();
}
......
......@@ -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.
......
......@@ -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();
}
......
......@@ -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; };
......
......@@ -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();
}
......
......@@ -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.
......
......@@ -31,7 +31,7 @@ public:
FemMesh(const std::string &file_name);
/// Destructor
~FemMesh();
virtual ~FemMesh();
}; /* class */
......
......@@ -31,7 +31,7 @@ public:
FemNode(const FemNode &node);
/// Destructor
~FemNode();
virtual ~FemNode();
}; /* class */
......
......@@ -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;
}
*/
}
......@@ -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; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment