OGS
MeshLib::TemplateElement< ELEMENT_RULE > Class Template Reference

Detailed Description

template<class ELEMENT_RULE>
class MeshLib::TemplateElement< ELEMENT_RULE >

Template for implementing mesh element classes

Template Parameters
T_BASEBase element class, e.g. Face, Cell
ELEMENT_RULEGeometrical and topological rules of the element

Definition at line 34 of file TemplateElement.h.

#include <TemplateElement.h>

Inheritance diagram for MeshLib::TemplateElement< ELEMENT_RULE >:
[legend]
Collaboration diagram for MeshLib::TemplateElement< ELEMENT_RULE >:
[legend]

Public Member Functions

 TemplateElement (Node *nodes[n_all_nodes], std::size_t id=std::numeric_limits< std::size_t >::max())
 
 TemplateElement (std::array< Node *, n_all_nodes > const &nodes, std::size_t id=std::numeric_limits< std::size_t >::max())
 
 TemplateElement (const TemplateElement &e)
 Copy constructor. More...
 
Elementclone () const override
 Returns a copy of this object. More...
 
Elementclone (Node **nodes, std::size_t id) const override
 
constexpr unsigned getDimension () const override
 Get dimension of the mesh element. More...
 
const ElementgetEdge (unsigned i) const override
 Returns the edge i of the element. More...
 
const ElementgetFace (unsigned i) const override
 Returns the face i of the element. More...
 
const ElementgetBoundary (unsigned i) const override
 Returns the boundary i of the element. More...
 
unsigned getNumberOfBoundaries () const override
 Returns the number of boundaries of the element. More...
 
unsigned getNumberOfEdges () const override
 Get the number of edges for this element. More...
 
unsigned getNumberOfFaces () const override
 Get the number of faces for this element. More...
 
unsigned getNumberOfNeighbors () const override
 Get the number of neighbors for this element. More...
 
const ElementgetNeighbor (unsigned i) const override
 Get the specified neighbor. More...
 
unsigned getNumberOfBaseNodes () const override
 Get the number of linear nodes for this element. More...
 
unsigned getNumberOfNodes () const override
 Get the number of all nodes for this element. More...
 
MeshElemType getGeomType () const override
 Get the type of this element. More...
 
CellType getCellType () const override
 Get the FEM type of this element. More...
 
bool isEdge (unsigned idx1, unsigned idx2) const override
 Returns true if these two indices form an edge and false otherwise. More...
 
bool isPntInElement (MathLib::Point3d const &pnt, double eps=std::numeric_limits< double >::epsilon()) const override
 
ElementErrorCode validate () const override
 
unsigned identifyFace (Node const *nodes[3]) const override
 Returns the ID of a face given an array of nodes. More...
 
double computeVolume () override
 Calculates the volume of a convex hexahedron by partitioning it into six tetrahedra. More...
 
const NodegetNode (unsigned idx) const override
 
NodegetNode (unsigned idx) override
 
void setNode (unsigned idx, Node *node) override
 
Node *const * getNodes () const override
 Get array of element nodes. More...
 
NodegetEdgeNode (unsigned edge_id, unsigned node_id) const override
 Return a specific edge node. More...
 
bool testElementNodeOrder () const override
 
double getContent () const override final
 Returns the length, area or volume of a 1D, 2D or 3D element. More...
 
- Public Member Functions inherited from MeshLib::Element
std::optional< unsigned > addNeighbor (Element *e)
 Tries to add an element e as neighbour to this element. If the elements really are neighbours, the element is added to the neighbour-list and the face id of the neighbour connected to this element is returned. Otherwise the maximum value of the value type is returned. More...
 
virtual std::size_t getID () const final
 Returns the ID of the element. More...
 
virtual bool isBoundaryElement () const
 
virtual ~Element ()
 Destructor. More...
 

Public Attributes

std::array< Node *, n_all_nodes_nodes
 
- Public Attributes inherited from MeshLib::Element
unsigned space_dimension_ = 3u
 Dimension of the space, where the element exists. More...
 

Static Public Attributes

static const unsigned n_all_nodes = ELEMENT_RULE::n_all_nodes
 Constant: The number of all nodes for this element. More...
 
static const unsigned n_base_nodes = ELEMENT_RULE::n_base_nodes
 Constant: The number of base nodes for this element. More...
 
static const unsigned dimension = ELEMENT_RULE::dimension
 Constant: The dimension of this element. More...
 

Additional Inherited Members

- Protected Member Functions inherited from MeshLib::Element
 Element (std::size_t id)
 
virtual void setID (std::size_t id) final
 Sets the element ID. More...
 
void setNeighbor (Element *neighbor, unsigned const face_id)
 
- Protected Attributes inherited from MeshLib::Element
std::size_t _id
 
Element ** _neighbors
 

Constructor & Destructor Documentation

◆ TemplateElement() [1/3]

template<class ELEMENT_RULE >
MeshLib::TemplateElement< ELEMENT_RULE >::TemplateElement ( Node nodes[n_all_nodes],
std::size_t  id = std::numeric_limits<std::size_t>::max() 
)
explicit

Constructor with an array of mesh nodes.

Parameters
nodesan array of pointers of mesh nodes which form this element
idelement id

Definition at line 16 of file TemplateElement-impl.h.

18  : Element(id)
19 {
20  std::copy_n(nodes, n_all_nodes, std::begin(_nodes));
21  delete[] nodes;
22  this->_neighbors = new Element*[getNumberOfNeighbors()];
23  std::fill(this->_neighbors, this->_neighbors + getNumberOfNeighbors(),
24  nullptr);
25 
26  this->space_dimension_ = ELEMENT_RULE::dimension;
27 }
Element ** _neighbors
Definition: Element.h:197
Element(std::size_t id)
Definition: Element.cpp:25
unsigned space_dimension_
Dimension of the space, where the element exists.
Definition: Element.h:185
std::array< Node *, n_all_nodes > _nodes
unsigned getNumberOfNeighbors() const override
Get the number of neighbors for this element.
static const unsigned n_all_nodes
Constant: The number of all nodes for this element.

References MeshLib::Element::_neighbors, MeshLib::TemplateElement< ELEMENT_RULE >::_nodes, MeshLib::TemplateElement< ELEMENT_RULE >::getNumberOfNeighbors(), MeshLib::TemplateElement< ELEMENT_RULE >::n_all_nodes, and MeshLib::Element::space_dimension_.

Referenced by MeshLib::TemplateElement< ELEMENT_RULE >::clone().

◆ TemplateElement() [2/3]

template<class ELEMENT_RULE >
MeshLib::TemplateElement< ELEMENT_RULE >::TemplateElement ( std::array< Node *, n_all_nodes > const &  nodes,
std::size_t  id = std::numeric_limits<std::size_t>::max() 
)
explicit

Constructor with an array of mesh nodes

Parameters
nodesan array of pointers of mesh nodes which form this element
idelement id

Definition at line 30 of file TemplateElement-impl.h.

32  : Element(id), _nodes{nodes}
33 {
34  this->_neighbors = new Element*[getNumberOfNeighbors()];
35  std::fill(this->_neighbors, this->_neighbors + getNumberOfNeighbors(), nullptr);
36 
37  this->space_dimension_ = ELEMENT_RULE::dimension;
38 }

References MeshLib::Element::_neighbors, MeshLib::TemplateElement< ELEMENT_RULE >::getNumberOfNeighbors(), and MeshLib::Element::space_dimension_.

◆ TemplateElement() [3/3]

template<class ELEMENT_RULE >
MeshLib::TemplateElement< ELEMENT_RULE >::TemplateElement ( const TemplateElement< ELEMENT_RULE > &  e)
explicit

Copy constructor.

Definition at line 41 of file TemplateElement-impl.h.

43  : Element(e.getID()), _nodes{e._nodes}
44 {
45  this->_neighbors = new Element*[getNumberOfNeighbors()];
46  for (unsigned i = 0; i < getNumberOfNeighbors(); i++)
47  {
48  this->_neighbors[i] = e._neighbors[i];
49  }
50 
51  this->space_dimension_ = e.space_dimension_;
52 }

References MeshLib::Element::_neighbors, MeshLib::TemplateElement< ELEMENT_RULE >::getNumberOfNeighbors(), and MeshLib::Element::space_dimension_.

Member Function Documentation

◆ clone() [1/2]

template<class ELEMENT_RULE >
Element* MeshLib::TemplateElement< ELEMENT_RULE >::clone ( ) const
inlineoverridevirtual

Returns a copy of this object.

Implements MeshLib::Element.

Definition at line 70 of file TemplateElement.h.

70 { return new TemplateElement(*this); }
TemplateElement(Node *nodes[n_all_nodes], std::size_t id=std::numeric_limits< std::size_t >::max())

References MeshLib::TemplateElement< ELEMENT_RULE >::TemplateElement().

◆ clone() [2/2]

template<class ELEMENT_RULE >
Element* MeshLib::TemplateElement< ELEMENT_RULE >::clone ( Node **  nodes,
std::size_t  id 
) const
inlineoverridevirtual

Constructs a new object polymorphically. This is similar to clone, but accepts new nodes and id.

Precondition
The length of the nodes vector is equal to the derived element's total number of nodes.

Implements MeshLib::Element.

Definition at line 71 of file TemplateElement.h.

72  {
73  return new TemplateElement(nodes, id);
74  }

References MeshLib::TemplateElement< ELEMENT_RULE >::TemplateElement().

◆ computeVolume()

template<class ELEMENT_RULE >
double MeshLib::TemplateElement< ELEMENT_RULE >::computeVolume ( )
inlineoverridevirtual

Calculates the volume of a convex hexahedron by partitioning it into six tetrahedra.

Implements MeshLib::Element.

Definition at line 186 of file TemplateElement.h.

187  {
188  return ELEMENT_RULE::computeVolume(_nodes.data());
189  }

References MeshLib::TemplateElement< ELEMENT_RULE >::_nodes.

◆ getBoundary()

template<class ELEMENT_RULE >
const Element* MeshLib::TemplateElement< ELEMENT_RULE >::getBoundary ( unsigned  i) const
inlineoverridevirtual

Returns the boundary i of the element.

Implements MeshLib::Element.

Definition at line 91 of file TemplateElement.h.

92  {
93  if constexpr (std::is_convertible<ELEMENT_RULE, FaceRule>::value)
94  {
95  return ELEMENT_RULE::EdgeReturn::getEdge(this, i);
96  }
97  if constexpr (std::is_convertible<ELEMENT_RULE, CellRule>::value)
98  {
99  return ELEMENT_RULE::getFace(this, i);
100  }
101  OGS_FATAL("TemplateElement::getBoundary for boundary {:d} failed.", i);
102  }
#define OGS_FATAL(...)
Definition: Error.h:26

References OGS_FATAL.

◆ getCellType()

template<class ELEMENT_RULE >
CellType MeshLib::TemplateElement< ELEMENT_RULE >::getCellType ( ) const
inlineoverridevirtual

Get the FEM type of this element.

Implements MeshLib::Element.

Definition at line 154 of file TemplateElement.h.

154 { return ELEMENT_RULE::cell_type; }

◆ getContent()

template<class ELEMENT_RULE >
double MeshLib::TemplateElement< ELEMENT_RULE >::getContent ( ) const
finaloverridevirtual

Returns the length, area or volume of a 1D, 2D or 3D element.

Implements MeshLib::Element.

Definition at line 55 of file TemplateElement-impl.h.

56 {
57  return ELEMENT_RULE::computeVolume(_nodes.data());
58 }

◆ getDimension()

template<class ELEMENT_RULE >
constexpr unsigned MeshLib::TemplateElement< ELEMENT_RULE >::getDimension ( ) const
inlineconstexproverridevirtual

Get dimension of the mesh element.

Implements MeshLib::Element.

Definition at line 77 of file TemplateElement.h.

77 { return dimension; }
static const unsigned dimension
Constant: The dimension of this element.

References MeshLib::TemplateElement< ELEMENT_RULE >::dimension.

◆ getEdge()

template<class ELEMENT_RULE >
const Element* MeshLib::TemplateElement< ELEMENT_RULE >::getEdge ( unsigned  i) const
inlineoverridevirtual

Returns the edge i of the element.

Implements MeshLib::Element.

Definition at line 79 of file TemplateElement.h.

80  {
81  return ELEMENT_RULE::EdgeReturn::getEdge(this, i);
82  }

◆ getEdgeNode()

template<class ELEMENT_RULE >
Node* MeshLib::TemplateElement< ELEMENT_RULE >::getEdgeNode ( unsigned  edge_id,
unsigned  node_id 
) const
inlineoverridevirtual

Return a specific edge node.

Implements MeshLib::Element.

Definition at line 197 of file TemplateElement.h.

198  {
199  if (getNumberOfEdges() > 0)
200  {
201  return const_cast<Node*>(
202  _nodes[ELEMENT_RULE::edge_nodes[edge_id][node_id]]);
203  }
204 
205  return nullptr;
206  }
unsigned getNumberOfEdges() const override
Get the number of edges for this element.

References MeshLib::TemplateElement< ELEMENT_RULE >::_nodes, and MeshLib::TemplateElement< ELEMENT_RULE >::getNumberOfEdges().

◆ getFace()

template<class ELEMENT_RULE >
const Element* MeshLib::TemplateElement< ELEMENT_RULE >::getFace ( unsigned  i) const
inlineoverridevirtual

Returns the face i of the element.

Implements MeshLib::Element.

Definition at line 85 of file TemplateElement.h.

86  {
87  return ELEMENT_RULE::getFace(this, i);
88  }

◆ getGeomType()

template<class ELEMENT_RULE >
MeshElemType MeshLib::TemplateElement< ELEMENT_RULE >::getGeomType ( ) const
inlineoverridevirtual

Get the type of this element.

Implements MeshLib::Element.

Definition at line 148 of file TemplateElement.h.

149  {
150  return ELEMENT_RULE::mesh_elem_type;
151  }

◆ getNeighbor()

template<class ELEMENT_RULE >
const Element* MeshLib::TemplateElement< ELEMENT_RULE >::getNeighbor ( unsigned  i) const
inlineoverridevirtual

Get the specified neighbor.

Implements MeshLib::Element.

Definition at line 127 of file TemplateElement.h.

128  {
129 #ifndef NDEBUG
130  if (i < ELEMENT_RULE::n_neighbors)
131 #endif
132  {
133  return _neighbors[i];
134  }
135 #ifndef NDEBUG
136  ERR("Error in MeshLib::TemplateElement::getNeighbor() - Index {:d} "
137  "does not exist.",
138  i);
139  return nullptr;
140 #endif
141  }
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42

References MeshLib::Element::_neighbors, and ERR().

◆ getNode() [1/2]

template<class ELEMENT_RULE >
const Node * MeshLib::TemplateElement< ELEMENT_RULE >::getNode ( unsigned  idx) const
overridevirtual

Get node with local index where the local index should be at most the number of nodes of the element.

Parameters
idxlocal index of node, at most the number of nodes of the element that you can obtain with Element::getNumberOfBaseNodes()
Returns
a pointer to the appropriate (and constant, i.e. not modifiable by the user) instance of class Node or a nullptr
See also
getNodeIndex()

Implements MeshLib::Element.

Definition at line 101 of file TemplateElement-impl.h.

102 {
103 #ifndef NDEBUG
104  if (idx >= getNumberOfNodes())
105  {
106  ERR("Error in MeshLib::TemplateElement::getNode() - Index {:d} in {:s}",
108  return nullptr;
109  }
110 #endif
111  return _nodes[idx];
112 }
unsigned getNumberOfNodes() const override
Get the number of all nodes for this element.
MeshElemType getGeomType() const override
Get the type of this element.
std::string MeshElemType2String(const MeshElemType t)
Given a MeshElemType this returns the appropriate string.
Definition: MeshEnums.cpp:21

References ERR(), and MeshLib::MeshElemType2String().

◆ getNode() [2/2]

template<class ELEMENT_RULE >
Node * MeshLib::TemplateElement< ELEMENT_RULE >::getNode ( unsigned  idx)
overridevirtual

Implements MeshLib::Element.

Definition at line 115 of file TemplateElement-impl.h.

116 {
117 #ifndef NDEBUG
118  if (idx >= getNumberOfNodes())
119  {
120  ERR("Error in MeshLib::TemplateElement::getNode() - Index {:d} in {:s}",
122  return nullptr;
123  }
124 #endif
125  return _nodes[idx];
126 }

References ERR(), and MeshLib::MeshElemType2String().

◆ getNodes()

template<class ELEMENT_RULE >
Node* const* MeshLib::TemplateElement< ELEMENT_RULE >::getNodes ( ) const
inlineoverridevirtual

Get array of element nodes.

Implements MeshLib::Element.

Definition at line 194 of file TemplateElement.h.

194 { return _nodes.data(); }

References MeshLib::TemplateElement< ELEMENT_RULE >::_nodes.

◆ getNumberOfBaseNodes()

template<class ELEMENT_RULE >
unsigned MeshLib::TemplateElement< ELEMENT_RULE >::getNumberOfBaseNodes ( ) const
inlineoverridevirtual

Get the number of linear nodes for this element.

Implements MeshLib::Element.

Definition at line 144 of file TemplateElement.h.

144 { return n_base_nodes; }
static const unsigned n_base_nodes
Constant: The number of base nodes for this element.

References MeshLib::TemplateElement< ELEMENT_RULE >::n_base_nodes.

◆ getNumberOfBoundaries()

template<class ELEMENT_RULE >
unsigned MeshLib::TemplateElement< ELEMENT_RULE >::getNumberOfBoundaries ( ) const
inlineoverridevirtual

Returns the number of boundaries of the element.

Implements MeshLib::Element.

Definition at line 105 of file TemplateElement.h.

106  {
107  if constexpr (std::is_convertible<ELEMENT_RULE, FaceRule>::value)
108  {
109  return ELEMENT_RULE::n_edges;
110  }
111  else
112  {
113  return ELEMENT_RULE::n_faces;
114  }
115  }

◆ getNumberOfEdges()

template<class ELEMENT_RULE >
unsigned MeshLib::TemplateElement< ELEMENT_RULE >::getNumberOfEdges ( ) const
inlineoverridevirtual

Get the number of edges for this element.

Implements MeshLib::Element.

Definition at line 118 of file TemplateElement.h.

118 { return ELEMENT_RULE::n_edges; }

Referenced by MeshLib::TemplateElement< ELEMENT_RULE >::getEdgeNode().

◆ getNumberOfFaces()

template<class ELEMENT_RULE >
unsigned MeshLib::TemplateElement< ELEMENT_RULE >::getNumberOfFaces ( ) const
inlineoverridevirtual

Get the number of faces for this element.

Implements MeshLib::Element.

Definition at line 120 of file TemplateElement.h.

120 { return ELEMENT_RULE::n_faces; }

◆ getNumberOfNeighbors()

template<class ELEMENT_RULE >
unsigned MeshLib::TemplateElement< ELEMENT_RULE >::getNumberOfNeighbors ( ) const
inlineoverridevirtual

Get the number of neighbors for this element.

Implements MeshLib::Element.

Definition at line 122 of file TemplateElement.h.

123  {
124  return ELEMENT_RULE::n_neighbors;
125  }

Referenced by MeshLib::TemplateElement< ELEMENT_RULE >::TemplateElement().

◆ getNumberOfNodes()

template<class ELEMENT_RULE >
unsigned MeshLib::TemplateElement< ELEMENT_RULE >::getNumberOfNodes ( ) const
inlineoverridevirtual

Get the number of all nodes for this element.

Implements MeshLib::Element.

Definition at line 146 of file TemplateElement.h.

146 { return n_all_nodes; }

References MeshLib::TemplateElement< ELEMENT_RULE >::n_all_nodes.

◆ identifyFace()

template<class ELEMENT_RULE >
unsigned MeshLib::TemplateElement< ELEMENT_RULE >::identifyFace ( Node const *  nodes[3]) const
inlineoverridevirtual

Returns the ID of a face given an array of nodes.

Implements MeshLib::Element.

Definition at line 180 of file TemplateElement.h.

181  {
182  return ELEMENT_RULE::identifyFace(_nodes.data(), nodes);
183  }

References MeshLib::TemplateElement< ELEMENT_RULE >::_nodes.

◆ isEdge()

template<class ELEMENT_RULE >
bool MeshLib::TemplateElement< ELEMENT_RULE >::isEdge ( unsigned  idx1,
unsigned  idx2 
) const
overridevirtual

Returns true if these two indices form an edge and false otherwise.

Implements MeshLib::Element.

Definition at line 88 of file TemplateElement-impl.h.

89 {
90  for (unsigned i(0); i<getNumberOfEdges(); i++)
91  {
92  if (details::isEdge(ELEMENT_RULE::edge_nodes[i], idx1, idx2))
93  {
94  return true;
95  }
96  }
97  return false;
98 }
bool isEdge(unsigned const (&edge_nodes)[N], unsigned idx1, unsigned idx2)

References MeshLib::details::isEdge().

◆ isPntInElement()

template<class ELEMENT_RULE >
bool MeshLib::TemplateElement< ELEMENT_RULE >::isPntInElement ( MathLib::Point3d const &  pnt,
double  eps = std::numeric_limits<double>::epsilon() 
) const
inlineoverridevirtual

Checks if a point is inside the element.

Parameters
pnta 3D MathLib::Point3d object
epstolerance for numerical algorithm used or computing the property
Returns
true if the point is not outside the element, false otherwise

This is actually calling the correct implementation of this function passing the element's nodes.

Implements MeshLib::Element.

Definition at line 164 of file TemplateElement.h.

167  {
168  return ELEMENT_RULE::isPntInElement(_nodes.data(), pnt, eps);
169  }

References MeshLib::TemplateElement< ELEMENT_RULE >::_nodes.

◆ setNode()

template<class ELEMENT_RULE >
void MeshLib::TemplateElement< ELEMENT_RULE >::setNode ( unsigned  idx,
Node node 
)
overridevirtual

(Re)Sets the node of the element.

Parameters
idxthe index of the pointer to a node within the element
nodea pointer to a node

Implements MeshLib::Element.

Definition at line 129 of file TemplateElement-impl.h.

130 {
131 #ifndef NDEBUG
132  if (idx < getNumberOfNodes())
133 #endif
134  {
135  _nodes[idx] = node;
136  }
137 }

◆ testElementNodeOrder()

template<class ELEMENT_RULE >
bool MeshLib::TemplateElement< ELEMENT_RULE >::testElementNodeOrder ( ) const
inlineoverridevirtual

Checks if the node order of an element is correct by testing surface normals. For 1D elements this always returns true.

Implements MeshLib::Element.

Definition at line 212 of file TemplateElement.h.

213  {
214  return ELEMENT_RULE::testElementNodeOrder(*this);
215  }

◆ validate()

template<class ELEMENT_RULE >
ElementErrorCode MeshLib::TemplateElement< ELEMENT_RULE >::validate ( ) const
inlineoverridevirtual

Tests if the element is geometrically valid.

Implements MeshLib::Element.

Definition at line 174 of file TemplateElement.h.

175  {
176  return ELEMENT_RULE::validate(this);
177  }

Member Data Documentation

◆ _nodes

◆ dimension

template<class ELEMENT_RULE >
const unsigned MeshLib::TemplateElement< ELEMENT_RULE >::dimension = ELEMENT_RULE::dimension
static

Constant: The dimension of this element.

Definition at line 44 of file TemplateElement.h.

Referenced by MeshLib::TemplateElement< ELEMENT_RULE >::getDimension().

◆ n_all_nodes

template<class ELEMENT_RULE >
const unsigned MeshLib::TemplateElement< ELEMENT_RULE >::n_all_nodes = ELEMENT_RULE::n_all_nodes
static

Constant: The number of all nodes for this element.

Todo:
Windows compiler does not accept this definition and issues a linking error.

Definition at line 38 of file TemplateElement.h.

Referenced by MeshLib::TemplateElement< ELEMENT_RULE >::TemplateElement(), and MeshLib::TemplateElement< ELEMENT_RULE >::getNumberOfNodes().

◆ n_base_nodes

template<class ELEMENT_RULE >
const unsigned MeshLib::TemplateElement< ELEMENT_RULE >::n_base_nodes = ELEMENT_RULE::n_base_nodes
static

Constant: The number of base nodes for this element.

Definition at line 41 of file TemplateElement.h.

Referenced by MeshLib::TemplateElement< ELEMENT_RULE >::getNumberOfBaseNodes().


The documentation for this class was generated from the following files: