Loading [MathJax]/extensions/MathMenu.js
OGS
Element.h
Go to the documentation of this file.
1
15#pragma once
16
17#include <spdlog/fmt/ostr.h>
18
19#include <limits>
20#include <optional>
21#include <span>
22
23#include "MathLib/Point3d.h"
25#include "MeshLib/Mesh.h"
26#include "MeshLib/MeshEnums.h"
27
28namespace MeshLib
29{
30class Node;
31
36{
37 friend class Mesh;
38
39public:
46 std::optional<unsigned> addNeighbor(Element* e);
47
49 virtual double getContent() const = 0;
50
60 virtual const Node* getNode(unsigned idx) const = 0;
61 virtual Node* getNode(unsigned idx) = 0;
62
68 virtual void setNode(unsigned idx, Node* node) = 0;
69
71 virtual Node* const* getNodes() const = 0;
72
74 constexpr std::span<Node* const> nodes() const
75 {
76 return {getNodes(), getNumberOfNodes()};
77 }
78
80 virtual constexpr unsigned getDimension() const = 0;
81
83 virtual const Element* getEdge(unsigned i) const = 0;
84
86 virtual const Element* getFace(unsigned i) const = 0;
87
88 virtual const Element* getBoundary(unsigned i) const = 0;
89
91 std::size_t getID() const { return _id; }
92
93 virtual unsigned getNumberOfBoundaries() const = 0;
94
96 virtual unsigned getNumberOfEdges() const = 0;
97
99 virtual unsigned getNumberOfFaces() const = 0;
100
102 virtual const Element* getNeighbor(unsigned i) const = 0;
103
105 virtual unsigned getNumberOfNeighbors() const = 0;
106
110 virtual unsigned getNumberOfBaseNodes() const = 0;
111
114 virtual unsigned getNumberOfNodes() const = 0;
115
120 virtual MeshElemType getGeomType() const = 0;
121
126 virtual CellType getCellType() const = 0;
127
130 virtual bool isBoundaryElement() const;
131
133 virtual bool isEdge(unsigned i, unsigned j) const = 0;
134
142 virtual bool isPntInElement(
143 MathLib::Point3d const& pnt,
144 double eps = std::numeric_limits<double>::epsilon()) const = 0;
145
149 virtual ElementErrorCode validate() const = 0;
150
152 virtual ~Element();
153
160 virtual Element* clone() const = 0;
161
168 virtual Element* clone(Node** nodes, std::size_t id) const = 0;
169
175 virtual double computeVolume() = 0;
176
178 virtual unsigned identifyFace(Node const* nodes[3]) const = 0;
179
184 virtual bool testElementNodeOrder() const = 0;
185
187 virtual Node* getEdgeNode(unsigned edge_id, unsigned node_id) const = 0;
188
189 friend std::ostream& operator<<(std::ostream& os, Element const& e);
190
192 unsigned space_dimension_ = 3u;
193
194protected:
197 explicit Element(std::size_t id);
198
200 void setID(std::size_t id) { _id = id; }
201
202 std::size_t _id;
203
207 void setNeighbor(Element* neighbor, unsigned const face_id);
208}; /* class */
209
211bool areNeighbors(Element const* const element, Element const* const other);
212
214bool hasZeroVolume(MeshLib::Element const& element);
215
218
220std::pair<double, double> computeSqrNodeDistanceRange(
221 MeshLib::Element const& element, bool const check_allnodes = true);
222
224std::pair<double, double> computeSqrEdgeLengthRange(Element const& element);
225
234bool isPointInElementXY(MathLib::Point3d const& p, Element const& e);
235
237unsigned getNodeIDinElement(Element const& element, const Node* node);
238
250std::size_t getNodeIndex(Element const& element, unsigned idx);
251
252} // namespace MeshLib
253
254namespace fmt
255{
256template <>
257struct formatter<::MeshLib::Element> : ostream_formatter
258{
259};
260} // namespace fmt
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:108
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:204
virtual double computeVolume()=0
void setID(std::size_t id)
Sets the element ID.
Definition Element.h:200
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:101
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:202
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:74
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:91
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:192
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:154
CellType
Types of mesh elements supported by OpenGeoSys.
Definition MeshEnums.h:64
bool isPointInElementXY(MathLib::Point3d const &p, Element const &e)
Definition Element.cpp:189
bool hasZeroVolume(MeshLib::Element const &element)
Returns true if the element has zero length/area/volume.
Definition Element.cpp:137
std::pair< double, double > computeSqrEdgeLengthRange(Element const &element)
Compute the minimum and maximum squared edge length for this element.
Definition Element.cpp:174
std::size_t getNodeIndex(Element const &element, unsigned const idx)
Definition Element.cpp:237
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:224
MathLib::Point3d getCenterOfGravity(Element const &element)
Calculates the center of gravity for the mesh element.
Definition Element.cpp:142
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:124
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition MeshEnums.h:48
Definition AABB.h:288