OGS
TemplateElement.h
Go to the documentation of this file.
1
11#pragma once
12
13#include <array>
14#include <limits>
15
16#include "MathLib/Point3d.h"
17
18#include "MeshLib/Node.h"
23
24namespace MeshLib
25{
26
33template <class ELEMENT_RULE>
35{
36public:
38 static const unsigned n_all_nodes = ELEMENT_RULE::n_all_nodes;
39
41 static const unsigned n_base_nodes = ELEMENT_RULE::n_base_nodes;
42
44 static const unsigned dimension = ELEMENT_RULE::dimension;
45
52 explicit TemplateElement(
54 std::size_t id = std::numeric_limits<std::size_t>::max());
55
62 explicit TemplateElement(
63 std::array<Node*, n_all_nodes> const& nodes,
64 std::size_t id = std::numeric_limits<std::size_t>::max());
65
67 explicit TemplateElement(const TemplateElement& e);
68
70 Element* clone() const override { return new TemplateElement(*this); }
71 Element* clone(Node** nodes, std::size_t id) const override
72 {
73 return new TemplateElement(nodes, id);
74 }
75
77 constexpr unsigned getDimension() const override { return dimension; }
79 const Element* getEdge(unsigned i) const override
80 {
81 return ELEMENT_RULE::EdgeReturn::getEdge(this, i);
82 }
83
85 const Element* getFace(unsigned i) const override
86 {
87 return ELEMENT_RULE::getFace(this, i);
88 }
89
91 const Element* getBoundary(unsigned i) const override
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 }
103
105 unsigned getNumberOfBoundaries() const override
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 }
116
118 unsigned getNumberOfEdges() const override { return ELEMENT_RULE::n_edges; }
120 unsigned getNumberOfFaces() const override { return ELEMENT_RULE::n_faces; }
122 unsigned getNumberOfNeighbors() const override
123 {
124 return ELEMENT_RULE::n_neighbors;
125 }
126
127 const Element* getNeighbor(unsigned i) const override
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 }
142
144 unsigned getNumberOfBaseNodes() const override { return n_base_nodes; }
146 unsigned getNumberOfNodes() const override { return n_all_nodes; }
148 MeshElemType getGeomType() const override
149 {
150 return ELEMENT_RULE::mesh_elem_type;
151 }
152
154 CellType getCellType() const override { return ELEMENT_RULE::cell_type; }
156 bool isEdge(unsigned idx1, unsigned idx2) const override;
157
165 MathLib::Point3d const& pnt,
166 double eps = std::numeric_limits<double>::epsilon()) const override
167 {
168 return ELEMENT_RULE::isPntInElement(_nodes.data(), pnt, eps);
169 }
170
174 ElementErrorCode validate() const override
175 {
176 return ELEMENT_RULE::validate(this);
177 }
178
180 unsigned identifyFace(Node const* nodes[3]) const override
181 {
182 return ELEMENT_RULE::identifyFace(_nodes.data(), nodes);
183 }
184
186 double computeVolume() override
187 {
188 return ELEMENT_RULE::computeVolume(_nodes.data());
189 }
190
191 const Node* getNode(unsigned idx) const override;
192 Node* getNode(unsigned idx) override;
193 void setNode(unsigned idx, Node* node) override;
194 Node* const* getNodes() const override { return _nodes.data(); }
195
197 inline Node* getEdgeNode(unsigned edge_id, unsigned node_id) const override
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 }
207
212 bool testElementNodeOrder() const override
213 {
214 return ELEMENT_RULE::testElementNodeOrder(*this);
215 }
216
217 double getContent() const override final;
218
219 std::array<Node*, n_all_nodes> _nodes;
220};
221
222} // namespace MeshLib
223
224#include "TemplateElement-impl.h"
Definition of ElementErrorCodes.
Definition of the Element class.
#define OGS_FATAL(...)
Definition Error.h:26
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
Definition of the Node class.
Definition of the Point3d class.
Collects error flags for mesh elements.
const double * data() const
Definition Point3d.h:59
Element ** _neighbors
Definition Element.h:202
constexpr std::span< Node *const > nodes() const
Span of element's nodes, their pointers actually.
Definition Element.h:72
double computeVolume() override
Calculates the volume of a convex hexahedron by partitioning it into six tetrahedra.
const Element * getBoundary(unsigned i) const override
Returns the boundary i of the element.
std::array< Node *, n_all_nodes > _nodes
const Element * getEdge(unsigned i) const override
Returns the edge i of the element.
Element * clone() const override
Returns a copy of this object.
unsigned getNumberOfBoundaries() const override
Returns the number of boundaries of the element.
unsigned getNumberOfNodes() const override
Get the number of all nodes for this element.
bool isEdge(unsigned idx1, unsigned idx2) const override
Returns true if these two indices form an edge and false otherwise.
MeshElemType getGeomType() const override
Get the type of this element.
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.
void setNode(unsigned idx, Node *node) override
const Element * getFace(unsigned i) const override
Returns the face i of the element.
ElementErrorCode validate() const override
static const unsigned n_base_nodes
Constant: The number of base nodes for this element.
bool testElementNodeOrder() const override
unsigned getNumberOfFaces() const override
Get the number of faces for this element.
TemplateElement(Node *nodes[n_all_nodes], std::size_t id=std::numeric_limits< std::size_t >::max())
unsigned identifyFace(Node const *nodes[3]) const override
Returns the ID of a face given an array of nodes.
double getContent() const override final
Returns the length, area or volume of a 1D, 2D or 3D element.
const Element * getNeighbor(unsigned i) const override
Get the specified neighbor.
static const unsigned dimension
Constant: The dimension of this element.
CellType getCellType() const override
Get the FEM type of this element.
bool isPntInElement(MathLib::Point3d const &pnt, double eps=std::numeric_limits< double >::epsilon()) const override
unsigned getNumberOfEdges() const override
Get the number of edges for this element.
Node *const * getNodes() const override
Get array of element nodes.
Node * getEdgeNode(unsigned edge_id, unsigned node_id) const override
Return a specific edge node.
constexpr unsigned getDimension() const override
Get dimension of the mesh element.
const Node * getNode(unsigned idx) const override
unsigned getNumberOfBaseNodes() const override
Get the number of linear nodes for this element.
Element * clone(Node **nodes, std::size_t id) const override
CellType
Types of mesh elements supported by OpenGeoSys.
Definition MeshEnums.h:43
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition MeshEnums.h:27