OGS
Element.h
Go to the documentation of this file.
1
15#pragma once
16
17#include <limits>
18#include <optional>
19#include <span>
20
21#include "MathLib/Point3d.h"
23#include "MeshLib/Mesh.h"
24#include "MeshLib/MeshEnums.h"
25
26namespace MeshLib
27{
28class Node;
29
34{
35 friend class Mesh;
36
37public:
44 std::optional<unsigned> addNeighbor(Element* e);
45
47 virtual double getContent() const = 0;
48
58 virtual const Node* getNode(unsigned idx) const = 0;
59 virtual Node* getNode(unsigned idx) = 0;
60
66 virtual void setNode(unsigned idx, Node* node) = 0;
67
69 virtual Node* const* getNodes() const = 0;
70
72 constexpr std::span<Node* const> nodes() const
73 {
74 return {getNodes(), getNumberOfNodes()};
75 }
76
78 virtual constexpr unsigned getDimension() const = 0;
79
81 virtual const Element* getEdge(unsigned i) const = 0;
82
84 virtual const Element* getFace(unsigned i) const = 0;
85
86 virtual const Element* getBoundary(unsigned i) const = 0;
87
89 std::size_t getID() const { return _id; }
90
91 virtual unsigned getNumberOfBoundaries() const = 0;
92
94 virtual unsigned getNumberOfEdges() const = 0;
95
97 virtual unsigned getNumberOfFaces() const = 0;
98
100 virtual const Element* getNeighbor(unsigned i) const = 0;
101
103 virtual unsigned getNumberOfNeighbors() const = 0;
104
108 virtual unsigned getNumberOfBaseNodes() const = 0;
109
112 virtual unsigned getNumberOfNodes() const = 0;
113
118 virtual MeshElemType getGeomType() const = 0;
119
124 virtual CellType getCellType() const = 0;
125
128 virtual bool isBoundaryElement() const;
129
131 virtual bool isEdge(unsigned i, unsigned j) const = 0;
132
140 virtual bool isPntInElement(
141 MathLib::Point3d const& pnt,
142 double eps = std::numeric_limits<double>::epsilon()) const = 0;
143
147 virtual ElementErrorCode validate() const = 0;
148
150 virtual ~Element();
151
158 virtual Element* clone() const = 0;
159
166 virtual Element* clone(Node** nodes, std::size_t id) const = 0;
167
173 virtual double computeVolume() = 0;
174
176 virtual unsigned identifyFace(Node const* nodes[3]) const = 0;
177
182 virtual bool testElementNodeOrder() const = 0;
183
185 virtual Node* getEdgeNode(unsigned edge_id, unsigned node_id) const = 0;
186
187 friend std::ostream& operator<<(std::ostream& os, Element const& e);
188
190 unsigned space_dimension_ = 3u;
191
192protected:
195 explicit Element(std::size_t id);
196
198 void setID(std::size_t id) { _id = id; }
199
200 std::size_t _id;
201
205 void setNeighbor(Element* neighbor, unsigned const face_id);
206}; /* class */
207
209bool areNeighbors(Element const* const element, Element const* const other);
210
212bool hasZeroVolume(MeshLib::Element const& element);
213
216
218std::pair<double, double> computeSqrNodeDistanceRange(
219 MeshLib::Element const& element, bool const check_allnodes = true);
220
222std::pair<double, double> computeSqrEdgeLengthRange(Element const& element);
223
232bool isPointInElementXY(MathLib::Point3d const& p, Element const& e);
233
235unsigned getNodeIDinElement(Element const& element, const Node* node);
236
248std::size_t getNodeIndex(Element const& element, unsigned idx);
249
250} // namespace MeshLib
Definition of ElementErrorCodes.
Definition of mesh-related Enumerations.
Definition of the Mesh class.
Definition of the Point3d class.
Collects error flags for mesh elements.
virtual MeshElemType getGeomType() const =0
void setNeighbor(Element *neighbor, unsigned const face_id)
Definition Element.cpp:32
virtual ~Element()
Destructor.
Definition Element.cpp:27
virtual const Element * getEdge(unsigned i) const =0
Returns the i-th edge of the element.
friend std::ostream & operator<<(std::ostream &os, Element const &e)
Definition Element.cpp:88
virtual CellType getCellType() const =0
virtual bool isPntInElement(MathLib::Point3d const &pnt, double eps=std::numeric_limits< double >::epsilon()) const =0
virtual unsigned getNumberOfNodes() const =0
virtual ElementErrorCode validate() const =0
virtual Node * getNode(unsigned idx)=0
virtual Element * clone() const =0
virtual double getContent() const =0
Returns the length, area or volume of a 1D, 2D or 3D element.
Element ** _neighbors
Definition Element.h:202
virtual double computeVolume()=0
void setID(std::size_t id)
Sets the element ID.
Definition Element.h:198
Element(std::size_t id)
Definition Element.cpp:25
virtual unsigned getNumberOfBoundaries() const =0
virtual unsigned getNumberOfFaces() const =0
Get the number of faces for this element.
virtual const Element * getFace(unsigned i) const =0
Returns the i-th face of the element.
virtual unsigned getNumberOfBaseNodes() const =0
virtual bool isBoundaryElement() const
Definition Element.cpp:81
virtual bool testElementNodeOrder() const =0
virtual const Node * getNode(unsigned idx) const =0
virtual unsigned getNumberOfNeighbors() const =0
Get the number of neighbors for this element.
virtual void setNode(unsigned idx, Node *node)=0
std::size_t _id
Definition Element.h:200
virtual unsigned getNumberOfEdges() const =0
Get the number of edges for this element.
virtual bool isEdge(unsigned i, unsigned j) const =0
Returns true if these two indices form an edge and false otherwise.
virtual constexpr unsigned getDimension() const =0
Get dimension of the mesh element.
virtual Element * clone(Node **nodes, std::size_t id) const =0
std::optional< unsigned > addNeighbor(Element *e)
Tries to add an element e as neighbour to this element. If the elements really are neighbours,...
Definition Element.cpp:42
constexpr std::span< Node *const > nodes() const
Span of element's nodes, their pointers actually.
Definition Element.h:72
virtual Node *const * getNodes() const =0
Get array of element nodes.
std::size_t getID() const
Returns the ID of the element.
Definition Element.h:89
virtual const Element * getNeighbor(unsigned i) const =0
Get the specified neighbor.
unsigned space_dimension_
Dimension of the space, where the element exists.
Definition Element.h:190
virtual Node * getEdgeNode(unsigned edge_id, unsigned node_id) const =0
Return a specific edge node.
virtual const Element * getBoundary(unsigned i) const =0
virtual unsigned identifyFace(Node const *nodes[3]) const =0
Returns the ID of a face given an array of nodes.
std::pair< double, double > computeSqrNodeDistanceRange(MeshLib::Element const &element, bool const check_allnodes)
Compute the minimum and maximum node distances for this element.
Definition Element.cpp:136
CellType
Types of mesh elements supported by OpenGeoSys.
Definition MeshEnums.h:43
bool isPointInElementXY(MathLib::Point3d const &p, Element const &e)
Definition Element.cpp:171
bool hasZeroVolume(MeshLib::Element const &element)
Returns true if the element has zero length/area/volume.
Definition Element.cpp:119
std::pair< double, double > computeSqrEdgeLengthRange(Element const &element)
Compute the minimum and maximum squared edge length for this element.
Definition Element.cpp:156
std::size_t getNodeIndex(Element const &element, unsigned const idx)
Definition Element.cpp:219
unsigned getNodeIDinElement(Element const &element, const MeshLib::Node *node)
Returns the position of the given node in the node array of this element.
Definition Element.cpp:206
MathLib::Point3d getCenterOfGravity(Element const &element)
Calculates the center of gravity for the mesh element.
Definition Element.cpp:124
bool areNeighbors(Element const *const element, Element const *const other)
Returns true if elem is a neighbour of this element and false otherwise.
Definition Element.cpp:106
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition MeshEnums.h:27