Skip to content
Snippets Groups Projects
Commit 64396584 authored by Tom Fischer's avatar Tom Fischer
Browse files

added (default) parameter to virtual method Element::getNNodes()

parent 725c6a60
No related branches found
No related tags found
No related merge requests found
......@@ -16,10 +16,12 @@
#include <limits>
#include "Element.h"
#include "Node.h"
#include "MathTools.h"
namespace MeshLib {
class Node;
namespace MeshLib {
/**
* A 1d Edge or Line Element.
......@@ -27,20 +29,30 @@ class Node;
* 0--------1
* @endcode
*/
class Edge : public Element
template <unsigned ORDER, unsigned NNODES>
class TemplateEdge : public Element
{
public:
/// Constructor with an array of mesh nodes.
Edge(Node* nodes[2], unsigned value = 0);
/// Constructor using single nodes
Edge(Node* n1, Node* n2, unsigned value = 0);
TemplateEdge(Node* nodes[NNODES], unsigned value = 0) :
Element(value)
{
_nodes = nodes;
this->_length = this->computeVolume();
}
/// Copy constructor
Edge(const Edge &edge);
TemplateEdge(const TemplateEdge<ORDER, NNODES> &edge) :
Element(edge.getValue())
{
_nodes = new Node*[NNODES];
for (unsigned k(0); k<NNODES; k++)
_nodes[k] = edge._nodes[k];
_length = edge.getLength();
}
/// Destructor
virtual ~Edge();
virtual ~TemplateEdge() {};
/// Returns the length, area or volume of a 1D, 2D or 3D element
double getContent() const { return _length; };
......@@ -73,7 +85,10 @@ public:
unsigned getNNeighbors() const { return 0; };
/// Get the number of nodes for this element.
virtual unsigned getNNodes() const { return 2; };
virtual unsigned getNNodes(unsigned order) const
{
return order == ORDER ? NNODES : 2;
}
/**
* Method returns the type of the element. In this case EDGE will be returned.
......@@ -81,19 +96,38 @@ public:
*/
virtual MshElemType::type getType() const { return MshElemType::EDGE; }
/// Returns true if these two indeces form an edge and false otherwise
bool isEdge(unsigned i, unsigned j) const;
/// Returns true if these two indices form an edge and false otherwise
bool isEdge(unsigned idx1, unsigned idx2) const
{
if (0==idx1 && 1==idx2) return true;
if (1==idx1 && 0==idx2) return true;
return false;
}
virtual Element* clone() const;
virtual Element* clone() const
{
return new TemplateEdge<ORDER,NNODES>(*this);
}
/**
* If for instance two nodes of the element are collapsed the Edge element disappears.
* @return NULL
*/
virtual Element* reviseElement() const;
virtual Element* reviseElement() const
{
if (_nodes[0] == _nodes[1]) {
return NULL;
}
return NULL;
}
protected:
double computeVolume();
double computeVolume()
{
return sqrt(MathLib::sqrDist(_nodes[0]->getCoords(), _nodes[1]->getCoords()));
}
/// 1D elements have no edges.
Node* getEdgeNode(unsigned edge_id, unsigned node_id) const { (void)edge_id; (void)node_id; return NULL; };
......@@ -107,6 +141,8 @@ protected:
}; /* class */
typedef TemplateEdge<1,2> Edge;
} /* namespace */
#endif /* EDGE_H_ */
......
......@@ -88,8 +88,12 @@ public:
/// Get the number of neighbors for this element.
virtual unsigned getNNeighbors() const = 0;
/// Get the number of nodes for this element.
virtual unsigned getNNodes() const = 0;
/**
* Get the number of nodes for this element with respect to the order.
* @param order (default = 1)
* @return the number of nodes with respect to the order.
*/
virtual unsigned getNNodes(unsigned order = 1) const = 0;
/// Returns the position of the given node in the node array of this element.
virtual unsigned getNodeIDinElement(const MeshLib::Node* node) const;
......
......@@ -73,7 +73,7 @@ public:
unsigned getNNeighbors() const { return 6; };
/// Get the number of nodes for this element.
virtual unsigned getNNodes() const { return 8; };
virtual unsigned getNNodes(unsigned order = 1) const { return 8; };
/**
* Method returns the type of the element. In this case HEXAHEDRON will be returned.
......
......@@ -71,7 +71,7 @@ public:
unsigned getNNeighbors() const { return 5; };
/// Get the number of nodes for this element.
virtual unsigned getNNodes() const { return 6; };
virtual unsigned getNNodes(unsigned order) const { return 6; };
/**
* Method returns the type of the element. In this case PRISM will be returned.
......
......@@ -69,7 +69,7 @@ public:
unsigned getNNeighbors() const { return 5; };
/// Get the number of nodes for this element.
virtual unsigned getNNodes() const { return 5; };
virtual unsigned getNNodes(unsigned order = 1) const { return 5; };
/**
* Method returns the type of the element. In this case PYRAMID will be returned.
......
......@@ -54,7 +54,7 @@ public:
unsigned getNNeighbors() const { return 4; };
/// Get the number of nodes for this element.
virtual unsigned getNNodes() const { return 4; };
virtual unsigned getNNodes(unsigned order = 1) const { return 4; };
/**
* Method returns the type of the element. In this case QUAD will be returned.
......
......@@ -68,7 +68,7 @@ public:
unsigned getNNeighbors() const { return 4; };
/// Get the number of nodes for this element.
virtual unsigned getNNodes() const { return 4; };
virtual unsigned getNNodes(unsigned order = 1) const { return 4; };
/**
* Method returns the type of the element. In this case TETRAHEDRON will be returned.
......
......@@ -59,7 +59,7 @@ public:
virtual ~Tet10();
/// Get the number of nodes for this element.
unsigned getNNodes() const { return 10; };
unsigned getNNodes(unsigned order = 1) const { return 10; };
/**
* Method returns the type of the element. In this case TETRAHEDRON will be returned.
......
......@@ -106,11 +106,17 @@ Element* Tri::reviseElement() const
{
// try to create an edge
if (_nodes[0] == _nodes[1] || _nodes[1] == _nodes[2]) {
return new Edge(_nodes[0], _nodes[2], _value);
Node** nodes (new Node*[2]);
nodes[0] = _nodes[0];
nodes[1] = _nodes[2];
return new Edge(nodes, _value);
}
if (_nodes[0] == _nodes[2]) {
return new Edge(_nodes[0], _nodes[1], _value);
Node** nodes (new Node*[2]);
nodes[0] = _nodes[0];
nodes[1] = _nodes[1];
return new Edge(nodes, _value);
}
return NULL;
......
......@@ -56,7 +56,7 @@ public:
unsigned getNNeighbors() const { return 3; };
/// Get the number of nodes for this element.
virtual unsigned getNNodes() const { return 3; };
virtual unsigned getNNodes(unsigned order = 1) const { return 3; };
/**
* Method returns the type of the element. In this case TRIANGLE will be returned.
......@@ -64,7 +64,7 @@ public:
*/
virtual MshElemType::type getType() const { return MshElemType::TRIANGLE; }
/// Returns true if these two indeces form an edge and false otherwise
/// Returns true if these two indices form an edge and false otherwise
bool isEdge(unsigned i, unsigned j) const;
/**
......
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