OGS 6.3.0-179-g962fdcd4e.dirty.20200403132553
Element.h
Go to the documentation of this file.
1 
15 #pragma once
16 
17 #include <limits>
18 #include <boost/optional.hpp>
19 
20 #include "MathLib/Point3d.h"
21 
22 #include "MeshLib/MeshEnums.h"
23 #include "MeshLib/Mesh.h"
25 
26 
27 namespace MeshLib {
28 
29 class Node;
30 
34 class Element
35 {
36  friend class Mesh;
37 
38 public:
40  virtual void computeSqrEdgeLengthRange(double &min, double &max) const;
41 
43  virtual void computeSqrNodeDistanceRange(double &min, double &max, bool check_allnodes=true) const;
44 
51  boost::optional<unsigned> addNeighbor(Element* e);
52 
55 
57  double getContent() const { return _content; }
58 
68  const Node* getNode(unsigned i) const;
69 
75  void setNode(unsigned idx, Node* node);
76 
78  Node* const* getNodes() const { return _nodes; }
79 
81  virtual unsigned getDimension() const = 0;
82 
84  virtual const Element* getEdge(unsigned i) const = 0;
85 
87  virtual const Element* getFace(unsigned i) const = 0;
88 
89  virtual const Element* getBoundary(unsigned i) const = 0;
90 
92  virtual std::size_t getID() const final { return _id; }
93 
94  virtual unsigned getNumberOfBoundaries() const = 0;
95 
97  virtual unsigned getNumberOfEdges() const = 0;
98 
100  virtual unsigned getNumberOfFaces() const = 0;
101 
103  const Element* getNeighbor(unsigned i) const;
104 
106  virtual unsigned getNumberOfNeighbors() const = 0;
107 
111  virtual unsigned getNumberOfBaseNodes() const = 0;
112 
114  virtual unsigned getNumberOfNodes() const = 0;
115 
117  virtual unsigned getNodeIDinElement(const MeshLib::Node* node) const;
118 
127  std::size_t getNodeIndex(unsigned i) const;
128 
132  virtual MeshElemType getGeomType() const = 0;
133 
138  virtual CellType getCellType() const = 0;
139 
140 
144  bool hasZeroVolume() const { return this->getContent() < std::numeric_limits<double>::epsilon(); }
145 
147  virtual bool isBoundaryElement() const;
148 
150  virtual bool isEdge(unsigned i, unsigned j) const = 0;
151 
158  virtual bool isPntInElement(MathLib::Point3d const& pnt, double eps = std::numeric_limits<double>::epsilon()) const = 0;
159 
163  virtual ElementErrorCode validate() const = 0;
164 
166  bool hasNeighbor(Element* elem) const;
167 
169  virtual ~Element();
170 
176  virtual Element* clone() const = 0;
177 
184  virtual Element* clone(Node** nodes, std::size_t id) const = 0;
185 
190  virtual double computeVolume() = 0;
191 
193  virtual unsigned identifyFace(Node* nodes[3]) const = 0;
194 
198  virtual bool testElementNodeOrder() const = 0;
199 
201  virtual Node* getEdgeNode(unsigned edge_id, unsigned node_id) const = 0;
202 
203 #ifndef NDEBUG
204  friend std::ostream& operator<<(std::ostream& os, Element const& e);
205 #endif // NDEBUG
206 
207 protected:
210  explicit Element(std::size_t id);
211 
213  virtual void setID(std::size_t id) final { _id = id; }
214 
216  std::size_t _id;
218  double _content;
219 
223  void setNeighbor(Element* neighbor, unsigned const face_id);
224 
225 }; /* class */
226 
235 bool isPointInElementXY(MathLib::Point3d const& p, Element const& e);
236 
237 } // namespace MeshLib
virtual unsigned getNumberOfBaseNodes() const =0
virtual bool isEdge(unsigned i, unsigned j) const =0
Returns true if these two indeces form an edge and false otherwise.
Definition of ElementErrorCodes.
virtual unsigned getNodeIDinElement(const MeshLib::Node *node) const
Returns the position of the given node in the node array of this element.
Definition: Element.cpp:145
MeshLib::Node getCenterOfGravity() const
Calculates the center of gravity for the mesh element.
Definition: Element.cpp:86
Definition of the Point3d class.
virtual unsigned identifyFace(Node *nodes[3]) const =0
Returns the ID of a face given an array of nodes.
virtual bool isBoundaryElement() const
Returns true if the element is located at a boundary (i.e. has at least one face without neighbour) ...
Definition: Element.cpp:209
friend std::ostream & operator<<(std::ostream &os, Element const &e)
Definition: Element.cpp:216
virtual unsigned getDimension() const =0
Get dimension of the mesh element.
Definition of the Mesh class.
virtual Element * clone() const =0
const Element * getNeighbor(unsigned i) const
Get the specified neighbor.
Definition: Element.cpp:131
void setNeighbor(Element *neighbor, unsigned const face_id)
Definition: Element.cpp:38
void setNode(unsigned idx, Node *node)
Definition: Element.cpp:172
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum. ...
Definition: MeshEnums.h:26
virtual ~Element()
Destructor.
Definition: Element.cpp:32
std::size_t _id
Definition: Element.h:216
Node ** _nodes
Definition: Element.h:215
boost::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:48
virtual unsigned getNumberOfFaces() const =0
Get the number of faces for this element.
virtual const Element * getBoundary(unsigned i) const =0
bool hasNeighbor(Element *elem) const
Returns true if elem is a neighbour of this element and false otherwise.
Definition: Element.cpp:196
virtual const Element * getFace(unsigned i) const =0
Returns the i-th face of the element.
bool hasZeroVolume() const
Definition: Element.h:144
Collects error flags for mesh elements.
std::size_t getNodeIndex(unsigned i) const
Definition: Element.cpp:182
Interface for heuristic search length strategy.
Definition: ProjectData.h:30
double getContent() const
Returns the length, area or volume of a 1D, 2D or 3D element.
Definition: Element.h:57
static const double p
virtual CellType getCellType() const =0
virtual unsigned getNumberOfEdges() const =0
Get the number of edges for this element.
virtual void computeSqrNodeDistanceRange(double &min, double &max, bool check_allnodes=true) const
Compute the minimum and maximum node distances for this element.
Definition: Element.cpp:115
Element(std::size_t id)
Definition: Element.cpp:27
virtual const Element * getEdge(unsigned i) const =0
Returns the i-th edge of the element.
virtual unsigned getNumberOfNeighbors() const =0
Get the number of neighbors for this element.
Definition of mesh-related Enumerations.
virtual bool testElementNodeOrder() const =0
virtual std::size_t getID() const final
Returns the ID of the element.
Definition: Element.h:92
virtual unsigned getNumberOfNodes() const =0
Returns the number of all nodes including both linear and nonlinear nodes.
virtual MeshElemType getGeomType() const =0
Node *const * getNodes() const
Get array of element nodes.
Definition: Element.h:78
CellType
Types of mesh elements supported by OpenGeoSys.
Definition: MeshEnums.h:42
Element ** _neighbors
Definition: Element.h:220
virtual Node * getEdgeNode(unsigned edge_id, unsigned node_id) const =0
Return a specific edge node.
virtual void setID(std::size_t id) final
Sets the element ID.
Definition: Element.h:213
virtual bool isPntInElement(MathLib::Point3d const &pnt, double eps=std::numeric_limits< double >::epsilon()) const =0
double _content
Content corresponds to length for 1D, area for 2D, and volume for 3D elements.
Definition: Element.h:218
bool isPointInElementXY(MathLib::Point3d const &p, Element const &e)
Definition: Element.cpp:235
virtual unsigned getNumberOfBoundaries() const =0
virtual ElementErrorCode validate() const =0
virtual double computeVolume()=0
const Node * getNode(unsigned i) const
Definition: Element.cpp:158
virtual void computeSqrEdgeLengthRange(double &min, double &max) const
Compute the minimum and maximum squared edge length for this element.
Definition: Element.cpp:102