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.
 
Elementclone () const override
 Returns a copy of this object.
 
Elementclone (Node **nodes, std::size_t id) const override
 
constexpr unsigned getDimension () const override
 Get dimension of the mesh element.
 
const ElementgetEdge (unsigned i) const override
 Returns the edge i of the element.
 
const ElementgetFace (unsigned i) const override
 Returns the face i of the element.
 
const ElementgetBoundary (unsigned i) const override
 Returns the boundary i of the element.
 
unsigned getNumberOfBoundaries () const override
 Returns the number of boundaries of the element.
 
unsigned getNumberOfEdges () const override
 Get the number of edges for this element.
 
unsigned getNumberOfFaces () const override
 Get the number of faces for this element.
 
unsigned getNumberOfNeighbors () const override
 Get the number of neighbors for this element.
 
const ElementgetNeighbor (unsigned i) const override
 Get the specified neighbor.
 
unsigned getNumberOfBaseNodes () const override
 Get the number of linear nodes for this element.
 
unsigned getNumberOfNodes () const override
 Get the number of all nodes for this element.
 
MeshElemType getGeomType () const override
 Get the type of this element.
 
CellType getCellType () const override
 Get the FEM type of this element.
 
bool isEdge (unsigned idx1, unsigned idx2) const override
 Returns true if these two indices form an edge and false otherwise.
 
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.
 
double computeVolume () override
 Calculates the volume of a convex hexahedron by partitioning it into six tetrahedra.
 
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.
 
NodegetEdgeNode (unsigned edge_id, unsigned node_id) const override
 Return a specific edge node.
 
bool testElementNodeOrder () const override
 
double getContent () const override final
 Returns the length, area or volume of a 1D, 2D or 3D element.
 
- 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.
 
constexpr std::span< Node *const > nodes () const
 Span of element's nodes, their pointers actually.
 
std::size_t getID () const
 Returns the ID of the element.
 
virtual bool isBoundaryElement () const
 
virtual ~Element ()
 Destructor.
 

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.
 

Static Public Attributes

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

Additional Inherited Members

- Protected Member Functions inherited from MeshLib::Element
 Element (std::size_t id)
 
void setID (std::size_t id)
 Sets the element ID.
 
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*[ELEMENT_RULE::n_neighbors];
23 std::fill(this->_neighbors, this->_neighbors + ELEMENT_RULE::n_neighbors,
24 nullptr);
25
26 this->space_dimension_ = ELEMENT_RULE::dimension;
27}
Element ** _neighbors
Definition Element.h:202
Element(std::size_t id)
Definition Element.cpp:25
constexpr std::span< Node *const > nodes() const
Span of element's nodes, their pointers actually.
Definition Element.h:72
unsigned space_dimension_
Dimension of the space, where the element exists.
Definition Element.h:190
std::array< Node *, n_all_nodes > _nodes
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 >::n_all_nodes, MeshLib::Element::nodes(), and MeshLib::Element::space_dimension_.

Referenced by MeshLib::TemplateElement< ELEMENT_RULE >::clone(), and 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*[ELEMENT_RULE::n_neighbors];
35 std::fill(this->_neighbors, this->_neighbors + ELEMENT_RULE::n_neighbors,
36 nullptr);
37
38 this->space_dimension_ = ELEMENT_RULE::dimension;
39}

References MeshLib::Element::_neighbors, 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 42 of file TemplateElement-impl.h.

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

References MeshLib::Element::_neighbors, 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(), and MeshLib::Element::nodes().

◆ 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 56 of file TemplateElement-impl.h.

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

◆ 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(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45

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 102 of file TemplateElement-impl.h.

103{
104#ifndef NDEBUG
105 if (idx >= getNumberOfNodes())
106 {
107 ERR("Error in MeshLib::TemplateElement::getNode() - Index {:d} in {:s}",
109 return nullptr;
110 }
111#endif
112 return _nodes[idx];
113}
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 116 of file TemplateElement-impl.h.

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

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, and MathLib::Point3d::data().

◆ 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 }

◆ 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, and MeshLib::Element::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 89 of file TemplateElement-impl.h.

90{
91 for (unsigned i(0); i<getNumberOfEdges(); i++)
92 {
93 if (details::isEdge(ELEMENT_RULE::edge_nodes[i], idx1, idx2))
94 {
95 return true;
96 }
97 }
98 return false;
99}
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 130 of file TemplateElement-impl.h.

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

◆ 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: