OGS
Element.h
Go to the documentation of this file.
1 
15 #pragma once
16 
17 #include <limits>
18 #include <optional>
19 
20 #include "MathLib/Point3d.h"
22 #include "MeshLib/Mesh.h"
23 #include "MeshLib/MeshEnums.h"
24 
25 namespace MeshLib
26 {
27 class Node;
28 
32 class Element
33 {
34  friend class Mesh;
35 
36 public:
43  std::optional<unsigned> addNeighbor(Element* e);
44 
46  virtual double getContent() const = 0;
47 
57  virtual const Node* getNode(unsigned idx) const = 0;
58  virtual Node* getNode(unsigned idx) = 0;
59 
65  virtual void setNode(unsigned idx, Node* node) = 0;
66 
68  virtual Node* const* getNodes() const = 0;
69 
71  virtual constexpr unsigned getDimension() const = 0;
72 
74  virtual const Element* getEdge(unsigned i) const = 0;
75 
77  virtual const Element* getFace(unsigned i) const = 0;
78 
79  virtual const Element* getBoundary(unsigned i) const = 0;
80 
82  virtual std::size_t getID() const final { return _id; }
83 
84  virtual unsigned getNumberOfBoundaries() const = 0;
85 
87  virtual unsigned getNumberOfEdges() const = 0;
88 
90  virtual unsigned getNumberOfFaces() const = 0;
91 
93  virtual const Element* getNeighbor(unsigned i) const = 0;
94 
96  virtual unsigned getNumberOfNeighbors() const = 0;
97 
101  virtual unsigned getNumberOfBaseNodes() const = 0;
102 
105  virtual unsigned getNumberOfNodes() const = 0;
106 
111  virtual MeshElemType getGeomType() const = 0;
112 
117  virtual CellType getCellType() const = 0;
118 
121  virtual bool isBoundaryElement() const;
122 
124  virtual bool isEdge(unsigned i, unsigned j) const = 0;
125 
133  virtual bool isPntInElement(
134  MathLib::Point3d const& pnt,
135  double eps = std::numeric_limits<double>::epsilon()) const = 0;
136 
140  virtual ElementErrorCode validate() const = 0;
141 
143  virtual ~Element();
144 
151  virtual Element* clone() const = 0;
152 
159  virtual Element* clone(Node** nodes, std::size_t id) const = 0;
160 
166  virtual double computeVolume() = 0;
167 
169  virtual unsigned identifyFace(Node const* nodes[3]) const = 0;
170 
175  virtual bool testElementNodeOrder() const = 0;
176 
178  virtual Node* getEdgeNode(unsigned edge_id, unsigned node_id) const = 0;
179 
180 #ifndef NDEBUG
181  friend std::ostream& operator<<(std::ostream& os, Element const& e);
182 #endif // NDEBUG
183 
185  unsigned space_dimension_ = 3u;
186 
187 protected:
190  explicit Element(std::size_t id);
191 
193  virtual void setID(std::size_t id) final { _id = id; }
194 
195  std::size_t _id;
196 
200  void setNeighbor(Element* neighbor, unsigned const face_id);
201 }; /* class */
202 
204 bool areNeighbors(Element const* const element, Element const* const other);
205 
207 bool hasZeroVolume(MeshLib::Element const& element);
208 
211 
213 std::pair<double, double> computeSqrNodeDistanceRange(
214  MeshLib::Element const& element, bool const check_allnodes = true);
215 
217 std::pair<double, double> computeSqrEdgeLengthRange(Element const& element);
218 
227 bool isPointInElementXY(MathLib::Point3d const& p, Element const& e);
228 
230 unsigned getNodeIDinElement(Element const& element, const Node* node);
231 
243 std::size_t getNodeIndex(Element const& element, unsigned idx);
244 
245 } // 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 Node * getNode(unsigned idx)=0
virtual const Element * getBoundary(unsigned i) const =0
virtual Node *const * getNodes() const =0
Get array of element nodes.
virtual ~Element()
Destructor.
Definition: Element.cpp:27
virtual CellType getCellType() const =0
virtual const Node * getNode(unsigned idx) 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 double getContent() const =0
Returns the length, area or volume of a 1D, 2D or 3D element.
virtual const Element * getNeighbor(unsigned i) const =0
Get the specified neighbor.
Element ** _neighbors
Definition: Element.h:197
virtual double computeVolume()=0
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 Element * clone() const =0
virtual unsigned getNumberOfBaseNodes() const =0
virtual void setID(std::size_t id) final
Sets the element ID.
Definition: Element.h:193
virtual Node * getEdgeNode(unsigned edge_id, unsigned node_id) const =0
Return a specific edge node.
virtual bool isBoundaryElement() const
Definition: Element.cpp:81
friend std::ostream & operator<<(std::ostream &os, Element const &e)
Definition: Element.cpp:89
virtual Element * clone(Node **nodes, std::size_t id) const =0
virtual bool testElementNodeOrder() const =0
virtual const Element * getFace(unsigned i) const =0
Returns the i-th face of the element.
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:195
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.
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
virtual const Element * getEdge(unsigned i) const =0
Returns the i-th edge of the element.
virtual std::size_t getID() const final
Returns the ID of the element.
Definition: Element.h:82
unsigned space_dimension_
Dimension of the space, where the element exists.
Definition: Element.h:185
virtual unsigned identifyFace(Node const *nodes[3]) const =0
Returns the ID of a face given an array of nodes.
static const double p
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:142
CellType
Types of mesh elements supported by OpenGeoSys.
Definition: MeshEnums.h:43
bool isPointInElementXY(MathLib::Point3d const &p, Element const &e)
Definition: Element.cpp:177
bool hasZeroVolume(MeshLib::Element const &element)
Returns true if the element has zero length/area/volume.
Definition: Element.cpp:121
std::pair< double, double > computeSqrEdgeLengthRange(Element const &element)
Compute the minimum and maximum squared edge length for this element.
Definition: Element.cpp:162
std::size_t getNodeIndex(Element const &element, unsigned const idx)
Definition: Element.cpp:225
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:212
MeshLib::Node getCenterOfGravity(Element const &element)
Calculates the center of gravity for the mesh element.
Definition: Element.cpp:126
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:108
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition: MeshEnums.h:27